edge can be added to active node with pressing 'a' and then selecting the endpoint with mouse click or hint mode. The add can be cancelled with 'esc'

master
Denes Matetelki 14 years ago
parent caeafb77fb
commit 0565dd3c8a

@ -16,7 +16,8 @@ GraphWidget::GraphWidget(QWidget *parent) :
m_activeNode(0), m_activeNode(0),
m_showingNodeNumbers(false), m_showingNodeNumbers(false),
m_hintNode(0), m_hintNode(0),
m_editingNode(false) m_editingNode(false),
m_edgeAdding(false)
{ {
m_scene = new QGraphicsScene(this); m_scene = new QGraphicsScene(this);
m_scene->setItemIndexMethod(QGraphicsScene::NoIndex); m_scene->setItemIndexMethod(QGraphicsScene::NoIndex);
@ -145,7 +146,26 @@ void GraphWidget::keyPressEvent(QKeyEvent *event)
} }
switch (event->key()) { switch (event->key())
{
case Qt::Key_Escape:
if (m_edgeAdding)
{
m_edgeAdding = false;
dynamic_cast<MainWindow *>(m_parent)->getStatusBar()->showMessage(
tr("Edge adding cancelled"),
5000); // millisec
}
else if(m_showingNodeNumbers)
{
m_hintNumber.clear();
showingAllNodeNumbers(false);
m_showingNodeNumbers = false;
}
break;
// move sceve, or move node if modkey is ctrl // move sceve, or move node if modkey is ctrl
case Qt::Key_Up: case Qt::Key_Up:
@ -260,10 +280,18 @@ void GraphWidget::keyPressEvent(QKeyEvent *event)
if (m_hintNode && m_showingNodeNumbers) if (m_hintNode && m_showingNodeNumbers)
{ {
showingAllNodeNumbers(false); showingAllNodeNumbers(false);
if (m_edgeAdding)
{
m_scene->addItem(new Edge(m_activeNode, m_hintNode));
}
else // selecting
{
if (m_activeNode) if (m_activeNode)
m_activeNode->setActive(false); m_activeNode->setActive(false);
m_activeNode = m_hintNode; m_activeNode = m_hintNode;
m_activeNode->setActive(); m_activeNode->setActive();
}
m_showingNodeNumbers = false; m_showingNodeNumbers = false;
} }
@ -318,6 +346,8 @@ void GraphWidget::keyPressEvent(QKeyEvent *event)
dynamic_cast<MainWindow *>(m_parent)->getStatusBar()->showMessage( dynamic_cast<MainWindow *>(m_parent)->getStatusBar()->showMessage(
tr("Add node: select destination node"), tr("Add node: select destination node"),
5000); // millisec 5000); // millisec
m_edgeAdding = true;
} }
else else
{ {
@ -430,11 +460,20 @@ void GraphWidget::showingNodeNumbersBeginWithNumber(const int &number,
if (hit==1) if (hit==1)
{ {
showingAllNodeNumbers(false); showingAllNodeNumbers(false);
if (m_edgeAdding)
{
m_scene->addItem(new Edge(m_activeNode, m_hintNode));
m_edgeAdding = false;
}
else // selecting
{
if (m_activeNode) if (m_activeNode)
m_activeNode->setActive(false); m_activeNode->setActive(false);
m_activeNode = m_hintNode; m_activeNode = m_hintNode;
m_activeNode->setActive(); m_activeNode->setActive();
}
m_showingNodeNumbers = false; m_showingNodeNumbers = false;
} }
else if (hit == 0) else if (hit == 0)
@ -455,3 +494,16 @@ void GraphWidget::setActiveNodeEditable()
m_activeNode->setEditable(); m_activeNode->setEditable();
m_scene->setFocusItem(m_activeNode); m_scene->setFocusItem(m_activeNode);
} }
void GraphWidget::nodeSelected(Node *node)
{
if (m_edgeAdding)
{
m_scene->addItem(new Edge(m_activeNode, node));
m_edgeAdding = false;
}
else
{
setActiveNode(node);
}
}

@ -20,6 +20,7 @@ public:
void setActiveNode(Node *node); void setActiveNode(Node *node);
void insertNode(); void insertNode();
void setActiveNodeEditable(); void setActiveNodeEditable();
void nodeSelected(Node *node);
protected: protected:
@ -45,6 +46,7 @@ private:
QString m_hintNumber; QString m_hintNumber;
Node *m_hintNode; Node *m_hintNode;
bool m_editingNode; bool m_editingNode;
bool m_edgeAdding;
}; };
#endif // GRAPHWIDGET_H #endif // GRAPHWIDGET_H

@ -125,7 +125,7 @@ void Node::setActive(const bool &active)
void Node::mousePressEvent(QGraphicsSceneMouseEvent *event) void Node::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
m_graph->setActiveNode(this); m_graph->nodeSelected(this);
QGraphicsItem::mousePressEvent(event); QGraphicsItem::mousePressEvent(event);
} }

Loading…
Cancel
Save