diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-08-26 10:58:32 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-09-12 17:51:17 +0000 |
commit | 8373853c45f8ba17b5fe38d9ab0c12cf0ac39ff3 (patch) | |
tree | 7b49cb8d971a6e9e43c5e49bb478f2d40583c902 | |
parent | d82ce2b82c4d315cb727a84d7a85ff4db7602170 (diff) |
Make LayoutMirroring work with Window
[ChangeLog][QtQuick][LayoutMirroring] Made it possible to attach
LayoutMirroring to a Window.
Task-number: QTBUG-55517
Change-Id: I3bc5960bf2a9c28b0edc801722dbd6499b803ff3
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r-- | src/quick/items/qquickitem.cpp | 13 | ||||
-rw-r--r-- | tests/auto/quick/qquickitem2/data/layoutmirroring_window.qml | 7 | ||||
-rw-r--r-- | tests/auto/quick/qquickitem2/tst_qquickitem.cpp | 20 |
3 files changed, 36 insertions, 4 deletions
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index d38edfb7ab..f983d3d649 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -1450,6 +1450,9 @@ QQuickKeysAttached *QQuickKeysAttached::qmlAttachedProperties(QObject *obj) behavior to all child items as well. If the \c LayoutMirroring attached property has not been defined for an item, mirroring is not enabled. + \note Since Qt 5.8, \c LayoutMirroring can be attached to a \l Window. In practice, it is the same as + attaching \c LayoutMirroring to the window's \c contentItem. + The following example shows mirroring in action. The \l Row below is specified as being anchored to the left of its parent. However, since mirroring has been enabled, the anchor is horizontally reversed and it is now anchored to the right. Also, since items in a \l Row are positioned @@ -1499,11 +1502,15 @@ QQuickKeysAttached *QQuickKeysAttached::qmlAttachedProperties(QObject *obj) QQuickLayoutMirroringAttached::QQuickLayoutMirroringAttached(QObject *parent) : QObject(parent), itemPrivate(0) { - if (QQuickItem *item = qobject_cast<QQuickItem*>(parent)) { + if (QQuickItem *item = qobject_cast<QQuickItem *>(parent)) itemPrivate = QQuickItemPrivate::get(item); + else if (QQuickWindow *window = qobject_cast<QQuickWindow *>(parent)) + itemPrivate = QQuickItemPrivate::get(window->contentItem()); + + if (itemPrivate) itemPrivate->extra.value().layoutDirectionAttached = this; - } else - qmlInfo(parent) << tr("LayoutDirection attached property only works with Items"); + else + qmlInfo(parent) << tr("LayoutDirection attached property only works with Items and Windows"); } QQuickLayoutMirroringAttached * QQuickLayoutMirroringAttached::qmlAttachedProperties(QObject *object) diff --git a/tests/auto/quick/qquickitem2/data/layoutmirroring_window.qml b/tests/auto/quick/qquickitem2/data/layoutmirroring_window.qml new file mode 100644 index 0000000000..3bac0716e8 --- /dev/null +++ b/tests/auto/quick/qquickitem2/data/layoutmirroring_window.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 +import QtQuick.Window 2.0 + +Window { + LayoutMirroring.enabled: true + LayoutMirroring.childrenInherit: true +} diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp index 169ef1cbab..7130dc4cf2 100644 --- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp @@ -88,6 +88,7 @@ private slots: void keyNavigation_focusReason(); void keyNavigation_loop(); void layoutMirroring(); + void layoutMirroringWindow(); void layoutMirroringIllegalParent(); void smooth(); void antialiasing(); @@ -1776,11 +1777,28 @@ void tst_QQuickItem::layoutMirroring() delete parentItem2; } +void tst_QQuickItem::layoutMirroringWindow() +{ + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("layoutmirroring_window.qml")); + QScopedPointer<QObject> object(component.create()); + QQuickWindow *window = qobject_cast<QQuickWindow *>(object.data()); + QVERIFY(window); + window->show(); + + QQuickItemPrivate *content = QQuickItemPrivate::get(window->contentItem()); + QCOMPARE(content->effectiveLayoutMirror, true); + QCOMPARE(content->inheritedLayoutMirror, true); + QCOMPARE(content->isMirrorImplicit, false); + QCOMPARE(content->inheritMirrorFromParent, true); + QCOMPARE(content->inheritMirrorFromItem, true); +} + void tst_QQuickItem::layoutMirroringIllegalParent() { QQmlComponent component(&engine); component.setData("import QtQuick 2.0; QtObject { LayoutMirroring.enabled: true; LayoutMirroring.childrenInherit: true }", QUrl::fromLocalFile("")); - QTest::ignoreMessage(QtWarningMsg, "<Unknown File>:1:21: QML QtObject: LayoutDirection attached property only works with Items"); + QTest::ignoreMessage(QtWarningMsg, "<Unknown File>:1:21: QML QtObject: LayoutDirection attached property only works with Items and Windows"); QObject *object = component.create(); QVERIFY(object != 0); } |