diff options
-rw-r--r-- | src/declarative/graphicsitems/qmlgraphicsanchors.cpp | 8 | ||||
-rw-r--r-- | tests/auto/declarative/anchors/data/centerin.qml | 12 | ||||
-rw-r--r-- | tests/auto/declarative/anchors/tst_anchors.cpp | 16 |
3 files changed, 32 insertions, 4 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp index c838d7d..153149e4 100644 --- a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp @@ -183,14 +183,14 @@ void QmlGraphicsAnchorsPrivate::centerInChanged() ++updatingCenterIn; if (centerIn == item->parentItem()) { - QPointF p((item->parentItem()->width() - item->width()) / 2., - (item->parentItem()->height() - item->height()) / 2.); + QPointF p((item->parentItem()->width() - item->width()) / 2. + hCenterOffset, + (item->parentItem()->height() - item->height()) / 2. + vCenterOffset); setItemPos(p); } else if (centerIn->parentItem() == item->parentItem()) { - QPointF p(centerIn->x() + (centerIn->width() - item->width()) / 2., - centerIn->y() + (centerIn->height() - item->height()) / 2.); + QPointF p(centerIn->x() + (centerIn->width() - item->width()) / 2. + hCenterOffset, + centerIn->y() + (centerIn->height() - item->height()) / 2. + vCenterOffset); setItemPos(p); } diff --git a/tests/auto/declarative/anchors/data/centerin.qml b/tests/auto/declarative/anchors/data/centerin.qml new file mode 100644 index 0000000..09b97f6 --- /dev/null +++ b/tests/auto/declarative/anchors/data/centerin.qml @@ -0,0 +1,12 @@ +import Qt 4.6 + +Rectangle { + width: 200; height: 200 + Rectangle { + objectName: "centered" + width: 50; height: 50; color: "blue" + anchors.centerIn: parent; + anchors.verticalCenterOffset: 30 + anchors.horizontalCenterOffset: 10 + } +} diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp index 7378d95..bbe5ef1 100644 --- a/tests/auto/declarative/anchors/tst_anchors.cpp +++ b/tests/auto/declarative/anchors/tst_anchors.cpp @@ -71,6 +71,7 @@ private slots: void nullItem(); void nullItem_data(); void crash1(); + void centerIn(); }; /* @@ -378,6 +379,21 @@ void tst_anchors::crash1() delete view; } +void tst_anchors::centerIn() +{ + QmlView *view = new QmlView; + + view->setUrl(QUrl("file://" SRCDIR "/data/centerin.qml")); + + view->execute(); + qApp->processEvents(); + + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("centered"))->x(), 85.0); + QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("centered"))->y(), 105.0); + + delete view; +} + QTEST_MAIN(tst_anchors) #include "tst_anchors.moc" |