diff options
author | Eduardo M. Fleury <eduardo.fleury@openbossa.org> | 2009-09-11 20:59:46 (GMT) |
---|---|---|
committer | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2009-09-17 11:57:55 (GMT) |
commit | 17607be158a8d5605ea2426ec4aa9925bd628a2a (patch) | |
tree | a3716c9f5a157cbcf9bc3bee013688c0b0d05869 | |
parent | e7c36fc2e420f1cee4370020b9f50bb5a6dfe92a (diff) | |
download | Qt-17607be158a8d5605ea2426ec4aa9925bd628a2a.zip Qt-17607be158a8d5605ea2426ec4aa9925bd628a2a.tar.gz Qt-17607be158a8d5605ea2426ec4aa9925bd628a2a.tar.bz2 |
QGraphicsAnchorLayout: Fix anchor creation heuristics
Fixing the case where creating an anchor between the
layout Left edge and an item Right edge (or vice-versa)
would have different behaviors depending on the argument
order.
Now both calls below have the same meaning:
addAnchor(layout, Qt::AnchorLeft, widget, Qt::AnchorRight)
addAnchor(widget, Qt::AnchorRight, layout, Qt::AnchorLeft)
Signed-off-by: Eduardo M. Fleury <eduardo.fleury@openbossa.org>
Reviewed-by: Jesus Sanchez-Palencia <jesus.palencia@openbossa.org>
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index a37ec96..11e28ac 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -1360,25 +1360,23 @@ void QGraphicsAnchorLayoutPrivate::correctEdgeDirection(QGraphicsLayoutItem *&fi { Q_Q(QGraphicsAnchorLayout); - Qt::AnchorPoint effectiveFirst = firstEdge; - Qt::AnchorPoint effectiveSecond = secondEdge; - - if (firstItem == q) - effectiveFirst = QGraphicsAnchorLayoutPrivate::oppositeEdge(firstEdge); - if (secondItem == q) - effectiveSecond = QGraphicsAnchorLayoutPrivate::oppositeEdge(secondEdge); - - if (effectiveFirst < effectiveSecond) { - - // ### DEBUG - /* printf("Swapping Anchor from %s %d --to--> %s %d\n", - firstItem->isLayout() ? "<layout>" : - qPrintable(static_cast<QGraphicsWidget *>(firstItem)->data(0).toString()), - firstEdge, - secondItem->isLayout() ? "<layout>" : - qPrintable(static_cast<QGraphicsWidget *>(secondItem)->data(0).toString()), - secondEdge); - */ + if ((firstItem != q) && (secondItem != q)) { + // If connection is between widgets (not the layout itself) + // Ensure that "right-edges" sit to the left of "left-edges". + if (firstEdge < secondEdge) { + qSwap(firstItem, secondItem); + qSwap(firstEdge, secondEdge); + } + } else if (firstItem == q) { + // If connection involves the right or bottom of a layout, ensure + // the layout is the second item. + if ((firstEdge == Qt::AnchorRight) || (firstEdge == Qt::AnchorBottom)) { + qSwap(firstItem, secondItem); + qSwap(firstEdge, secondEdge); + } + } else if ((secondEdge != Qt::AnchorRight) && (secondEdge != Qt::AnchorBottom)) { + // If connection involves the left, center or top of layout, ensure + // the layout is the first item. qSwap(firstItem, secondItem); qSwap(firstEdge, secondEdge); } |