diff options
Diffstat (limited to 'tikzit/src/gui/nodeitem.cpp')
-rw-r--r-- | tikzit/src/gui/nodeitem.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tikzit/src/gui/nodeitem.cpp b/tikzit/src/gui/nodeitem.cpp index d91bfd6..6e21ea4 100644 --- a/tikzit/src/gui/nodeitem.cpp +++ b/tikzit/src/gui/nodeitem.cpp @@ -1,7 +1,10 @@ #include "tikzit.h" #include "nodeitem.h" +#include "tikzscene.h" +#include <cmath> #include <QPen> +#include <QApplication> #include <QBrush> #include <QDebug> #include <QFont> @@ -13,6 +16,7 @@ NodeItem::NodeItem(Node *node) _node = node; setFlag(QGraphicsItem::ItemIsSelectable); setFlag(QGraphicsItem::ItemIsMovable); + setFlag(QGraphicsItem::ItemSendsGeometryChanges); syncPos(); } @@ -91,3 +95,17 @@ QRectF NodeItem::boundingRect() const { return shape().boundingRect().adjusted(-4,-4,4,4); } + +QVariant NodeItem::itemChange(GraphicsItemChange change, const QVariant &value) +{ + if (change == ItemPositionChange) { + QPointF newPos = value.toPointF(); + int gridSize = GLOBAL_SCALE / 8; + QPointF gridPos(round(newPos.x()/gridSize)*gridSize, round(newPos.y()/gridSize)*gridSize); + _node->setPoint(fromScreen(gridPos)); + + return gridPos; + } else { + return QGraphicsItem::itemChange(change, value); + } +} |