From 74ec242dd6e0def7734362c5650a0bfa2560b4e5 Mon Sep 17 00:00:00 2001 From: Denes Matetelki Date: Sat, 11 Jun 2011 21:56:52 +0200 Subject: [PATCH] mouse double click sets selected node editable, when inserting a new node, the new node gets focus and become editable --- graphwidget.cpp | 14 +++++++++++--- graphwidget.h | 1 + node.cpp | 11 +++++------ node.h | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/graphwidget.cpp b/graphwidget.cpp index 6ff1132..82d86e4 100644 --- a/graphwidget.cpp +++ b/graphwidget.cpp @@ -275,9 +275,7 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) if (m_activeNode) { - m_editingNode = true; - m_activeNode->setEditable(); - m_scene->setFocusItem(m_activeNode); + setActiveNodeEditable(); } else { @@ -380,6 +378,9 @@ void GraphWidget::insertNode() m_nodeList.append(node); m_scene->addItem(new Edge(m_activeNode, node)); + + setActiveNode(node); + setActiveNodeEditable(); } void GraphWidget::showingAllNodeNumbers(const bool &show) @@ -432,3 +433,10 @@ bool GraphWidget::numberStartsWithNumber(const int &number, const int &prefix) { return (QString::number(number)).startsWith(QString::number(prefix)); } + +void GraphWidget::setActiveNodeEditable() +{ + m_editingNode = true; + m_activeNode->setEditable(); + m_scene->setFocusItem(m_activeNode); +} diff --git a/graphwidget.h b/graphwidget.h index e18d07a..c5743a6 100644 --- a/graphwidget.h +++ b/graphwidget.h @@ -19,6 +19,7 @@ public: QGraphicsScene *getScene(); void setActiveNode(Node *node); void insertNode(); + void setActiveNodeEditable(); protected: diff --git a/node.cpp b/node.cpp index fe5a1f2..5920b0f 100644 --- a/node.cpp +++ b/node.cpp @@ -132,12 +132,11 @@ void Node::mousePressEvent(QGraphicsSceneMouseEvent *event) QGraphicsItem::mousePressEvent(event); } -//void Node::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) -//{ -// m_graph->insertNode(); - -// QGraphicsItem::mouseDoubleClickEvent(event); -//} +void Node::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) +{ + Q_UNUSED(event); + m_graph->setActiveNodeEditable(); +} void Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { diff --git a/node.h b/node.h index b4ceaf5..83aadf3 100644 --- a/node.h +++ b/node.h @@ -33,7 +33,7 @@ protected: QWidget *widget); QVariant itemChange(GraphicsItemChange change, const QVariant &value); void mousePressEvent(QGraphicsSceneMouseEvent *event); - //void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent *event); void linkActivated(const QString &link);