diff options
-rw-r--r-- | src/declarative/graphicsitems/qmlgraphicsanchors.cpp | 30 | ||||
-rw-r--r-- | tests/auto/declarative/anchors/data/fill.qml | 14 | ||||
-rw-r--r-- | tests/auto/declarative/anchors/tst_anchors.cpp | 38 |
3 files changed, 73 insertions, 9 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp index b72f010..c28ca02 100644 --- a/src/declarative/graphicsitems/qmlgraphicsanchors.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsanchors.cpp @@ -833,7 +833,10 @@ void QmlGraphicsAnchors::setLeftMargin(qreal offset) if (d->leftMargin == offset) return; d->leftMargin = offset; - d->updateHorizontalAnchors(); + if(d->fill) + d->fillChanged(); + else + d->updateHorizontalAnchors(); emit leftMarginChanged(); } @@ -849,7 +852,10 @@ void QmlGraphicsAnchors::setRightMargin(qreal offset) if (d->rightMargin == offset) return; d->rightMargin = offset; - d->updateHorizontalAnchors(); + if(d->fill) + d->fillChanged(); + else + d->updateHorizontalAnchors(); emit rightMarginChanged(); } @@ -865,7 +871,10 @@ void QmlGraphicsAnchors::setHorizontalCenterOffset(qreal offset) if (d->hCenterOffset == offset) return; d->hCenterOffset = offset; - d->updateHorizontalAnchors(); + if(d->centerIn) + d->centerInChanged(); + else + d->updateHorizontalAnchors(); emit horizontalCenterOffsetChanged(); } @@ -881,7 +890,10 @@ void QmlGraphicsAnchors::setTopMargin(qreal offset) if (d->topMargin == offset) return; d->topMargin = offset; - d->updateVerticalAnchors(); + if(d->fill) + d->fillChanged(); + else + d->updateVerticalAnchors(); emit topMarginChanged(); } @@ -897,7 +909,10 @@ void QmlGraphicsAnchors::setBottomMargin(qreal offset) if (d->bottomMargin == offset) return; d->bottomMargin = offset; - d->updateVerticalAnchors(); + if(d->fill) + d->fillChanged(); + else + d->updateVerticalAnchors(); emit bottomMarginChanged(); } @@ -913,7 +928,10 @@ void QmlGraphicsAnchors::setVerticalCenterOffset(qreal offset) if (d->vCenterOffset == offset) return; d->vCenterOffset = offset; - d->updateVerticalAnchors(); + if(d->centerIn) + d->centerInChanged(); + else + d->updateVerticalAnchors(); emit verticalCenterOffsetChanged(); } diff --git a/tests/auto/declarative/anchors/data/fill.qml b/tests/auto/declarative/anchors/data/fill.qml new file mode 100644 index 0000000..902465c --- /dev/null +++ b/tests/auto/declarative/anchors/data/fill.qml @@ -0,0 +1,14 @@ +import Qt 4.6 + +Rectangle { + width: 200; height: 200 + Rectangle { + objectName: "filler" + width: 50; height: 50; color: "blue" + anchors.fill: parent; + anchors.leftMargin: 10; + anchors.rightMargin: 20; + anchors.topMargin: 30; + anchors.bottomMargin: 40; + } +} diff --git a/tests/auto/declarative/anchors/tst_anchors.cpp b/tests/auto/declarative/anchors/tst_anchors.cpp index bbe5ef1..8967725 100644 --- a/tests/auto/declarative/anchors/tst_anchors.cpp +++ b/tests/auto/declarative/anchors/tst_anchors.cpp @@ -72,6 +72,7 @@ private slots: void nullItem_data(); void crash1(); void centerIn(); + void fill(); }; /* @@ -379,6 +380,32 @@ void tst_anchors::crash1() delete view; } +void tst_anchors::fill() +{ + QmlView *view = new QmlView; + + view->setUrl(QUrl("file://" SRCDIR "/data/fill.qml")); + + view->execute(); + qApp->processEvents(); + QmlGraphicsRectangle* rect = findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("filler")); + QCOMPARE(rect->x(), 0.0 + 10); + QCOMPARE(rect->y(), 0.0 + 30); + QCOMPARE(rect->width(), 200.0 - 10.0 - 20.0); + QCOMPARE(rect->height(), 200.0 - 30.0 - 40.0); + //Alter Offsets (QTBUG-6631) + rect->anchors()->setLeftMargin(20.0); + rect->anchors()->setRightMargin(0.0); + rect->anchors()->setBottomMargin(0.0); + rect->anchors()->setTopMargin(10.0); + QCOMPARE(rect->x(), 0.0 + 20.0); + QCOMPARE(rect->y(), 0.0 + 10.0); + QCOMPARE(rect->width(), 200.0 - 20.0); + QCOMPARE(rect->height(), 200.0 - 10.0); + + delete view; +} + void tst_anchors::centerIn() { QmlView *view = new QmlView; @@ -387,9 +414,14 @@ void tst_anchors::centerIn() view->execute(); qApp->processEvents(); - - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("centered"))->x(), 85.0); - QCOMPARE(findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("centered"))->y(), 105.0); + QmlGraphicsRectangle* rect = findItem<QmlGraphicsRectangle>(view->root(), QLatin1String("centered")); + QCOMPARE(rect->x(), 75.0 + 10); + QCOMPARE(rect->y(), 75.0 + 30); + //Alter Offsets (QTBUG-6631) + rect->anchors()->setHorizontalCenterOffset(-20.0); + rect->anchors()->setVerticalCenterOffset(-10.0); + QCOMPARE(rect->x(), 75.0 - 20.0); + QCOMPARE(rect->y(), 75.0 - 10.0); delete view; } |