//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?
anchors.verticalCenterOffset: 30
anchors.horizontalCenterOffset: 10
}
+
+ Rectangle {
+ objectName: "centered2"
+ width: 11; height: 11; color: "green"
+ anchors.centerIn: parent;
+ }
}
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<QQuickRectangle>(view->rootObject(), QLatin1String("centered2"));
+ QCOMPARE(rect2->x(), 94.5);
+ QCOMPARE(rect2->y(), 94.5);
+
delete view;
}
QQuickRectangle* outer = findItem<QQuickRectangle>(view->rootObject(), QLatin1String("outer"));
QQuickRectangle* inner = findItem<QQuickRectangle>(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));