diff options
author | Joona Petrell <joona.t.petrell@nokia.com> | 2011-02-24 02:33:11 (GMT) |
---|---|---|
committer | Joona Petrell <joona.t.petrell@nokia.com> | 2011-03-01 07:17:41 (GMT) |
commit | 2c7cab4172f1acc86fd49345a2847417e162f2c3 (patch) | |
tree | 2df2e2bfccd17ed94980db0221ed3aec83afccb2 /src/declarative/graphicsitems/qdeclarativeanchors.cpp | |
parent | a4b37abd96860a5bc46f88205bb11706cbaec228 (diff) | |
download | Qt-2c7cab4172f1acc86fd49345a2847417e162f2c3.zip Qt-2c7cab4172f1acc86fd49345a2847417e162f2c3.tar.gz Qt-2c7cab4172f1acc86fd49345a2847417e162f2c3.tar.bz2 |
Add LayoutMirroring attached property for mirroring QML layouts
Task-number: QTBUG-17280
Reviewed-by: Martin Jones
Change-Id: I34a623b49ce0fd5c05ae7a7ea5d0437c107b8a9b
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativeanchors.cpp')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeanchors.cpp | 40 |
1 files changed, 13 insertions, 27 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeanchors.cpp b/src/declarative/graphicsitems/qdeclarativeanchors.cpp index a2d6261..5ff6d2c 100644 --- a/src/declarative/graphicsitems/qdeclarativeanchors.cpp +++ b/src/declarative/graphicsitems/qdeclarativeanchors.cpp @@ -175,13 +175,14 @@ QDeclarativeAnchors::~QDeclarativeAnchors() void QDeclarativeAnchorsPrivate::fillChanged() { + Q_Q(QDeclarativeAnchors); if (!fill || !isItemComplete()) return; if (updatingFill < 2) { ++updatingFill; - qreal horizontalMargin = isMirrored() ? rightMargin : leftMargin; + qreal horizontalMargin = q->mirrored() ? rightMargin : leftMargin; if (fill == item->parentItem()) { //child-parent setItemPos(QPointF(horizontalMargin, topMargin)); @@ -201,13 +202,14 @@ void QDeclarativeAnchorsPrivate::fillChanged() void QDeclarativeAnchorsPrivate::centerInChanged() { + Q_Q(QDeclarativeAnchors); if (!centerIn || fill || !isItemComplete()) return; if (updatingCenterIn < 2) { ++updatingCenterIn; - qreal effectiveHCenterOffset = isMirrored() ? -hCenterOffset : hCenterOffset; + qreal effectiveHCenterOffset = q->mirrored() ? -hCenterOffset : hCenterOffset; if (centerIn == item->parentItem()) { QPointF p(hcenter(item->parentItem()) - hcenter(item) + effectiveHCenterOffset, vcenter(item->parentItem()) - vcenter(item) + vCenterOffset); @@ -315,6 +317,13 @@ void QDeclarativeAnchors::componentComplete() d->componentComplete = true; } +bool QDeclarativeAnchors::mirrored() +{ + Q_D(QDeclarativeAnchors); + QGraphicsItemPrivate * itemPrivate = QGraphicsItemPrivate::get(d->item); + return itemPrivate->isDeclarativeItem ? static_cast<QDeclarativeItemPrivate *>(itemPrivate)->effectiveLayoutMirror : false; +} + void QDeclarativeAnchorsPrivate::setItemHeight(qreal v) { updatingMe = true; @@ -502,11 +511,6 @@ bool QDeclarativeAnchorsPrivate::calcStretch(const QDeclarativeAnchorLine &edge1 return invalid; } -bool QDeclarativeAnchorsPrivate::isMirrored() const -{ - return layoutDirection == Qt::RightToLeft; -} - void QDeclarativeAnchorsPrivate::updateVerticalAnchors() { if (fill || centerIn || !isItemComplete()) @@ -591,6 +595,7 @@ inline QDeclarativeAnchorLine::AnchorLine reverseAnchorLine(QDeclarativeAnchorLi void QDeclarativeAnchorsPrivate::updateHorizontalAnchors() { + Q_Q(QDeclarativeAnchors); if (fill || centerIn || !isItemComplete()) return; @@ -599,7 +604,7 @@ void QDeclarativeAnchorsPrivate::updateHorizontalAnchors() qreal effectiveRightMargin, effectiveLeftMargin, effectiveHorizontalCenterOffset; QDeclarativeAnchorLine effectiveLeft, effectiveRight, effectiveHorizontalCenter; QDeclarativeAnchors::Anchor effectiveLeftAnchor, effectiveRightAnchor; - if (isMirrored()) { + if (q->mirrored()) { effectiveLeftAnchor = QDeclarativeAnchors::RightAnchor; effectiveRightAnchor = QDeclarativeAnchors::LeftAnchor; effectiveLeft.item = right.item; @@ -1086,25 +1091,6 @@ QDeclarativeAnchors::Anchors QDeclarativeAnchors::usedAnchors() const return d->usedAnchors; } - -Qt::LayoutDirection QDeclarativeAnchors::layoutDirection() const -{ - Q_D(const QDeclarativeAnchors); - return d->layoutDirection; -} - -void QDeclarativeAnchors::setLayoutDirection(Qt::LayoutDirection layoutDirection) -{ - Q_D(QDeclarativeAnchors); - if (d->layoutDirection != layoutDirection) { - d->layoutDirection = layoutDirection; - d->fillChanged(); - d->centerInChanged(); - d->updateHorizontalAnchors(); - emit layoutDirectionChanged(); - } -} - bool QDeclarativeAnchorsPrivate::checkHValid() const { if (usedAnchors & QDeclarativeAnchors::LeftAnchor && |