diff --git a/graphwidget.cpp b/graphwidget.cpp index 4c0e604..276cf4f 100644 --- a/graphwidget.cpp +++ b/graphwidget.cpp @@ -665,6 +665,22 @@ void GraphWidget::nodeSelected(Node *node) } } +void GraphWidget::nodeMoved(QGraphicsSceneMouseEvent *event) +{ + QList nodeList; + if (event->modifiers() == Qt::ShiftModifier) + { + nodeList = m_activeNode->subtree(); + } + else + { + nodeList.push_back(m_activeNode); + } + + foreach(Node *node, nodeList) + node->setPos(node->pos() + event->scenePos() - event->lastScenePos()); +} + void GraphWidget::addEdge(Node *source, Node *destination) { if (destination == m_nodeList.first()) diff --git a/graphwidget.h b/graphwidget.h index 8824460..60e0cb4 100644 --- a/graphwidget.h +++ b/graphwidget.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include "node.h" @@ -21,6 +21,7 @@ public: void insertNode(); void setActiveNodeEditable(); void nodeSelected(Node *node); + void nodeMoved(QGraphicsSceneMouseEvent *event); QList edges() const; void contentChanged(const bool &changed = true); diff --git a/node.cpp b/node.cpp index d212b6f..3224ad9 100644 --- a/node.cpp +++ b/node.cpp @@ -35,6 +35,11 @@ Node::~Node() foreach (EdgeElement element, m_edgeList) delete element.edge; } +void Node::moveNode(QGraphicsSceneMouseEvent *event) +{ + QGraphicsItem::mouseMoveEvent(event); +} + void Node::addEdge(Edge *edge, bool startsFromThisNode) { m_edgeList.push_back(EdgeElement(edge, startsFromThisNode)); @@ -444,7 +449,7 @@ void Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void Node::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - QGraphicsItem::mouseMoveEvent(event); + m_graph->nodeMoved(event); } QPainterPath Node::shape () const diff --git a/node.h b/node.h index c1fe133..9d83a0f 100644 --- a/node.h +++ b/node.h @@ -16,6 +16,7 @@ public: Node(GraphWidget *graphWidget = 0); ~Node(); + void moveNode(QGraphicsSceneMouseEvent *event); void addEdge(Edge *edge, bool startsFromThisNode); void deleteEdge(Node *otherEnd); void removeEdgeFromList(Edge *edge);