diff options
author | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2009-09-09 13:54:40 (GMT) |
---|---|---|
committer | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2009-09-11 12:48:59 (GMT) |
commit | 33d1c616d8d4085ba6fa848bafaec66576eba224 (patch) | |
tree | efaa235d14f04a23cc831b9565a7d4a73c1f1862 /src/gui/graphicsview | |
parent | 49b0c307cf5ab5f18d34fbbd3e1c83949640bcf7 (diff) | |
download | Qt-33d1c616d8d4085ba6fa848bafaec66576eba224.zip Qt-33d1c616d8d4085ba6fa848bafaec66576eba224.tar.gz Qt-33d1c616d8d4085ba6fa848bafaec66576eba224.tar.bz2 |
Respect the layoutDirection property of the parent widget.
Add a layoutDirection autotest, and sprinkle some of the tests
with checkReverseDirection()
Reviewed-by: Eduardo M. Fleury
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout.cpp | 2 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 45 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout_p.h | 2 |
3 files changed, 29 insertions, 20 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.cpp b/src/gui/graphicsview/qgraphicsanchorlayout.cpp index 3bb8c29..c7033c6 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout.cpp @@ -383,7 +383,7 @@ void QGraphicsAnchorLayout::setGeometry(const QRectF &geom) QGraphicsLayout::setGeometry(geom); d->calculateVertexPositions(QGraphicsAnchorLayoutPrivate::Horizontal); d->calculateVertexPositions(QGraphicsAnchorLayoutPrivate::Vertical); - d->setItemsGeometries(); + d->setItemsGeometries(geom); } /*! diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 787060f..f81ede0 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -1772,20 +1772,42 @@ QGraphicsAnchorLayoutPrivate::getGraphParts(Orientation orientation) Use the current vertices distance to calculate and set the geometry of each item. */ -void QGraphicsAnchorLayoutPrivate::setItemsGeometries() +void QGraphicsAnchorLayoutPrivate::setItemsGeometries(const QRectF &geom) { + Q_Q(QGraphicsAnchorLayout); AnchorVertex *firstH, *secondH, *firstV, *secondV; + qreal top; + qreal left; + qreal right; + + q->getContentsMargins(&left, &top, &right, 0); + const Qt::LayoutDirection visualDir = visualDirection(); + if (visualDir == Qt::RightToLeft) + qSwap(left, right); + + left += geom.left(); + top += geom.top(); + right = geom.right() - right; + foreach (QGraphicsLayoutItem *item, items) { firstH = internalVertex(item, Qt::AnchorLeft); secondH = internalVertex(item, Qt::AnchorRight); firstV = internalVertex(item, Qt::AnchorTop); secondV = internalVertex(item, Qt::AnchorBottom); - QPointF topLeft(firstH->distance, firstV->distance); - QPointF bottomRight(secondH->distance, secondV->distance); + QRectF newGeom; + newGeom.setTop(top + firstV->distance); + newGeom.setBottom(top + secondV->distance); - item->setGeometry(QRectF(topLeft, bottomRight)); + if (visualDir == Qt::LeftToRight) { + newGeom.setLeft(left + firstH->distance); + newGeom.setRight(left + secondH->distance); + } else { + newGeom.setLeft(right - secondH->distance); + newGeom.setRight(right - firstH->distance); + } + item->setGeometry(newGeom); } } @@ -1798,26 +1820,13 @@ void QGraphicsAnchorLayoutPrivate::setItemsGeometries() void QGraphicsAnchorLayoutPrivate::calculateVertexPositions( QGraphicsAnchorLayoutPrivate::Orientation orientation) { - Q_Q(QGraphicsAnchorLayout); QQueue<QPair<AnchorVertex *, AnchorVertex *> > queue; QSet<AnchorVertex *> visited; // Get root vertex AnchorVertex *root = graph[orientation].rootVertex(); - qreal widgetMargin; - qreal layoutMargin; - - // Initialize the first vertex - if (orientation == Horizontal) { - widgetMargin = q->geometry().x(); - q->getContentsMargins(&layoutMargin, 0, 0, 0); - } else { - // Root position is equal to the top margin - widgetMargin = q->geometry().y(); - q->getContentsMargins(0, &layoutMargin, 0, 0); - } - root->distance = widgetMargin + layoutMargin; + root->distance = 0; visited.insert(root); // Add initial edges to the queue diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h index 1470fb3..31da1a1 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h @@ -437,7 +437,7 @@ public: void removeInternalVertex(QGraphicsLayoutItem *item, Qt::AnchorPoint edge); // Geometry interpolation methods - void setItemsGeometries(); + void setItemsGeometries(const QRectF &geom); void calculateVertexPositions(Orientation orientation); void setupEdgesInterpolation(Orientation orientation); |