|
|
|
@ -192,34 +192,40 @@ void GraphWidget::keyPressEvent(QKeyEvent *e)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Qt::Key_Space: {
|
|
|
|
|
for (QList<Edge*>::iterator it = m_route.begin(); it != m_route.end(); ++it)
|
|
|
|
|
(*it)->setIsRoute(false);
|
|
|
|
|
modifyRoute();
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
QGraphicsView::keyPressEvent(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList <QGraphicsItem* > selectedItems = scene()->selectedItems();
|
|
|
|
|
if (selectedItems.isEmpty())
|
|
|
|
|
break;
|
|
|
|
|
void GraphWidget::modifyRoute()
|
|
|
|
|
{
|
|
|
|
|
for (QList<Edge*>::iterator it = m_route.begin(); it != m_route.end(); ++it)
|
|
|
|
|
(*it)->setIsRoute(false);
|
|
|
|
|
|
|
|
|
|
QGraphicsItem* selectedItem = selectedItems.first();
|
|
|
|
|
Node* selectedNode = dynamic_cast<Node*>(selectedItem);
|
|
|
|
|
QList <QGraphicsItem* > selectedItems = scene()->selectedItems();
|
|
|
|
|
if (selectedItems.isEmpty())
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
const QPoint global_p = QCursor::pos();
|
|
|
|
|
const QPoint widget_p = mapFromGlobal(global_p);
|
|
|
|
|
const QPointF scene_p = mapToScene(widget_p);
|
|
|
|
|
QGraphicsItem* selectedItem = selectedItems.first();
|
|
|
|
|
Node* selectedNode = dynamic_cast<Node*>(selectedItem);
|
|
|
|
|
|
|
|
|
|
QGraphicsItem* item_under_mouse = scene()->itemAt(scene_p);
|
|
|
|
|
Node* nodeUnderMouse = dynamic_cast<Node*>(item_under_mouse);
|
|
|
|
|
const QPoint global_p = QCursor::pos();
|
|
|
|
|
const QPoint widget_p = mapFromGlobal(global_p);
|
|
|
|
|
const QPointF scene_p = mapToScene(widget_p);
|
|
|
|
|
|
|
|
|
|
if (nodeUnderMouse != 0 && nodeUnderMouse != selectedNode) {
|
|
|
|
|
m_route = calculateShortestRoute(scene(), m_graph, selectedNode, nodeUnderMouse);
|
|
|
|
|
for (QList<Edge*>::iterator it = m_route.begin(); it != m_route.end(); ++it)
|
|
|
|
|
(*it)->setIsRoute(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
QGraphicsView::keyPressEvent(e);
|
|
|
|
|
}
|
|
|
|
|
QGraphicsItem* item_under_mouse = scene()->itemAt(scene_p);
|
|
|
|
|
Node* nodeUnderMouse = dynamic_cast<Node*>(item_under_mouse);
|
|
|
|
|
|
|
|
|
|
if (nodeUnderMouse != 0 && nodeUnderMouse != selectedNode) {
|
|
|
|
|
m_route = calculateShortestRoute(scene(), m_graph, selectedNode, nodeUnderMouse);
|
|
|
|
|
for (QList<Edge*>::iterator it = m_route.begin(); it != m_route.end(); ++it)
|
|
|
|
|
(*it)->setIsRoute(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GraphWidget::removeEdge(Node* selectedNode, Node* nodeUnderMouse)
|
|
|
|
|
{
|
|
|
|
|
const float2 source_pos = float2FromQPointF(selectedNode->pos());
|
|
|
|
|