From e99c5a3f113bbc1b8f8db996b4b0d5715eea2d89 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 10 Feb 2012 10:15:13 +1000 Subject: [PATCH] Fix anchor jitters that could occur during animation. The anchors were using a different definition of center than the actual center (9337c140cab7db1285f893b66d0e56423a74c253). With this change center-anchored Rectangles may sometimes have fuzzy antialiasing again. Task-number: QTBUG-12441 Task-number: QTBUG-21730 Change-Id: Iaf61409c7c523510d0d657fe7ba96f29a8610090 Reviewed-by: Martin Jones --- src/quick/items/qquickanchors.cpp | 18 ++++-------------- .../auto/qtquick2/qquickanchors/data/centerin.qml | 6 ++++++ .../qtquick2/qquickanchors/tst_qquickanchors.cpp | 6 +++++- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/quick/items/qquickanchors.cpp b/src/quick/items/qquickanchors.cpp index 2d852f7..2df304e 100644 --- a/src/quick/items/qquickanchors.cpp +++ b/src/quick/items/qquickanchors.cpp @@ -51,24 +51,14 @@ QT_BEGIN_NAMESPACE //TODO: should we cache relationships, so we don't have to check each time (parent-child or sibling)? //TODO: support non-parent, non-sibling (need to find lowest common ancestor) -static qreal hcenter(QQuickItem *item) +static inline qreal hcenter(QQuickItem *item) { - qreal width = item->width(); - int iw = width; - if (iw % 2) - return (width + 1) / 2; - else - return width / 2; + return item->width() / 2; } -static qreal vcenter(QQuickItem *item) +static inline qreal vcenter(QQuickItem *item) { - qreal height = item->height(); - int ih = height; - if (ih % 2) - return (height + 1) / 2; - else - return height / 2; + return item->height() / 2; } //### const item? diff --git a/tests/auto/qtquick2/qquickanchors/data/centerin.qml b/tests/auto/qtquick2/qquickanchors/data/centerin.qml index e5f64f1..e6c9179 100644 --- a/tests/auto/qtquick2/qquickanchors/data/centerin.qml +++ b/tests/auto/qtquick2/qquickanchors/data/centerin.qml @@ -9,4 +9,10 @@ Rectangle { anchors.verticalCenterOffset: 30 anchors.horizontalCenterOffset: 10 } + + Rectangle { + objectName: "centered2" + width: 11; height: 11; color: "green" + anchors.centerIn: parent; + } } diff --git a/tests/auto/qtquick2/qquickanchors/tst_qquickanchors.cpp b/tests/auto/qtquick2/qquickanchors/tst_qquickanchors.cpp index ff3426b..d046f4e 100644 --- a/tests/auto/qtquick2/qquickanchors/tst_qquickanchors.cpp +++ b/tests/auto/qtquick2/qquickanchors/tst_qquickanchors.cpp @@ -535,6 +535,11 @@ void tst_qquickanchors::centerIn() QCOMPARE(rect->x(), 75.0 - 20.0); QCOMPARE(rect->y(), 75.0 - 10.0); + //QTBUG-21730 (use actual center to prevent animation jitter) + QQuickRectangle* rect2 = findItem(view->rootObject(), QLatin1String("centered2")); + QCOMPARE(rect2->x(), 94.5); + QCOMPARE(rect2->y(), 94.5); + delete view; } @@ -567,7 +572,6 @@ void tst_qquickanchors::centerInRotation() QQuickRectangle* outer = findItem(view->rootObject(), QLatin1String("outer")); QQuickRectangle* inner = findItem(view->rootObject(), QLatin1String("inner")); - QEXPECT_FAIL("", "QTBUG-12441", Abort); QCOMPARE(outer->x(), qreal(49.5)); QCOMPARE(outer->y(), qreal(49.5)); QCOMPARE(inner->x(), qreal(25.5)); -- 1.7.2.5