summaryrefslogtreecommitdiff
path: root/src/gui/nodeitem.cpp
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2018-04-17 11:03:24 +0300
committerAleks Kissinger <aleks0@gmail.com>2018-04-17 11:03:24 +0300
commit8ac7248513189d82fe5bdf90c0d7fc15f2e718ce (patch)
treea537036afd281726cad73b1622935d3084c68f15 /src/gui/nodeitem.cpp
parent34b60b77d3f9830ddb6a0107bd65aa3c79701305 (diff)
fixed bounding box bug
Diffstat (limited to 'src/gui/nodeitem.cpp')
-rw-r--r--src/gui/nodeitem.cpp46
1 files changed, 31 insertions, 15 deletions
diff --git a/src/gui/nodeitem.cpp b/src/gui/nodeitem.cpp
index 06b46ff..b0b7ea6 100644
--- a/src/gui/nodeitem.cpp
+++ b/src/gui/nodeitem.cpp
@@ -18,6 +18,7 @@ NodeItem::NodeItem(Node *node)
//setFlag(QGraphicsItem::ItemIsMovable);
//setFlag(QGraphicsItem::ItemSendsGeometryChanges);
readPos();
+ updateBounds();
}
void NodeItem::readPos()
@@ -98,27 +99,42 @@ QPainterPath NodeItem::shape() const
return path;
}
+// TODO: nodeitem should sync boundingRect()-relevant stuff (label etc) explicitly,
+// to allow prepareGeometryChange()
QRectF NodeItem::boundingRect() const
{
- QRectF r = labelRect();
- return r.united(shape().boundingRect()).adjusted(-4,-4,4,4);
+ return _boundingRect;
}
-Node *NodeItem::node() const
+void NodeItem::updateBounds()
{
- return _node;
+ prepareGeometryChange();
+ QString label = _node->label();
+ if (label != "") {
+ QFontMetrics fm(Tikzit::LABEL_FONT);
+ QRectF labelRect = fm.boundingRect(label);
+ labelRect.moveCenter(QPointF(0, 0));
+ _boundingRect = labelRect.united(shape().boundingRect()).adjusted(-4, -4, 4, 4);
+ } else {
+ _boundingRect = shape().boundingRect().adjusted(-4, -4, 4, 4);
+ }
}
-QVariant NodeItem::itemChange(GraphicsItemChange change, const QVariant &value)
+Node *NodeItem::node() const
{
- 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);
- }
+ return _node;
}
+
+//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);
+// }
+//}