move subtree with mouse

master
Denes Matetelki 14 years ago
parent 92e3eee7e9
commit 290881c066

@ -665,6 +665,22 @@ void GraphWidget::nodeSelected(Node *node)
}
}
void GraphWidget::nodeMoved(QGraphicsSceneMouseEvent *event)
{
QList <Node *> 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())

@ -4,7 +4,7 @@
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QKeyEvent>
#include <QMovie>
#include <QGraphicsSceneMouseEvent>
#include "node.h"
@ -21,6 +21,7 @@ public:
void insertNode();
void setActiveNodeEditable();
void nodeSelected(Node *node);
void nodeMoved(QGraphicsSceneMouseEvent *event);
QList<Edge *> edges() const;
void contentChanged(const bool &changed = true);

@ -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

@ -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);

Loading…
Cancel
Save