summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEduardo M. Fleury <eduardo.fleury@openbossa.org>2009-09-11 21:21:08 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-09-17 11:57:59 (GMT)
commit26d3ead5771a67a15a672441ce30359aa355b911 (patch)
treee88a8282861be3784320664a06c7b47a96d630e7 /src
parent17607be158a8d5605ea2426ec4aa9925bd628a2a (diff)
downloadQt-26d3ead5771a67a15a672441ce30359aa355b911.zip
Qt-26d3ead5771a67a15a672441ce30359aa355b911.tar.gz
Qt-26d3ead5771a67a15a672441ce30359aa355b911.tar.bz2
QGraphicsAnchorLayout: Handle negative spacing in "setAnchorSpacing"
The simplex solver cannot handle negative-sized anchors. Those should be handled by the layout itself. This is done by inverting such anchors and making their size positive again. Ie. A --> B with size -10 becomes B --> A with size 10 Signed-off-by: Eduardo M. Fleury <eduardo.fleury@openbossa.org> Reviewed-by: Jesus Sanchez-Palencia <jesus.palencia@openbossa.org>
Diffstat (limited to 'src')
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.cpp27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
index 11e28ac..50d1a61 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
@@ -1225,12 +1225,35 @@ void QGraphicsAnchorLayoutPrivate::setAnchorSize(AnchorData *data, const qreal *
// search recursively through all composite anchors
Q_ASSERT(data);
restoreSimplifiedGraph(edgeOrientation(data->from->m_edge));
+
+ QGraphicsLayoutItem *firstItem = data->from->m_item;
+ QGraphicsLayoutItem *secondItem = data->to->m_item;
+ Qt::AnchorPoint firstEdge = data->from->m_edge;
+ Qt::AnchorPoint secondEdge = data->to->m_edge;
+
+ // Use heuristics to find out what the user meant with this anchor.
+ correctEdgeDirection(firstItem, firstEdge, secondItem, secondEdge);
+ if (data->from->m_item != firstItem)
+ qSwap(data->from, data->to);
+
if (anchorSize) {
- data->setFixedSize(*anchorSize);
+ // ### The current implementation makes "setAnchorSize" behavior
+ // dependent on the argument order for cases where we have
+ // no heuristic. Ie. two widgets, same anchor point.
+
+ // We cannot have negative sizes inside the graph. This would cause
+ // the simplex solver to fail because all simplex variables are
+ // positive by definition.
+ // "negative spacing" is handled by inverting the standard item order.
+ if (*anchorSize >= 0) {
+ data->setFixedSize(*anchorSize);
+ } else {
+ data->setFixedSize(-*anchorSize);
+ qSwap(data->from, data->to);
+ }
} else {
data->unsetSize();
}
-
q->invalidate();
}