aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quick/items/qquickitem.cpp13
-rw-r--r--tests/auto/quick/qquickitem2/data/layoutmirroring_window.qml7
-rw-r--r--tests/auto/quick/qquickitem2/tst_qquickitem.cpp20
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);
}