From 77711c65c1fdb6c5d94d26fef828959d29643516 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 3 Nov 2014 17:23:11 +0100 Subject: [PATCH] Add attached Window::contentItem property This is essential to the Qt Quick Controls for implementing floating text selection handle popups. Change-Id: Ibae65110a5db6d65dacd197fef3ad567d11342dc Reviewed-by: Alan Alpert Reviewed-by: Shawn Rutledge --- src/quick/items/qquickwindow.cpp | 8 ++++++++ src/quick/items/qquickwindowattached.cpp | 6 ++++++ src/quick/items/qquickwindowattached_p.h | 3 +++ tests/auto/quick/qquickwindow/data/windowattached.qml | 2 ++ tests/auto/quick/qquickwindow/tst_qquickwindow.cpp | 2 ++ 5 files changed, 21 insertions(+) diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index f6c1412..619e539 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -1250,6 +1250,14 @@ bool QQuickWindow::isPersistentSceneGraph() const +/*! + \qmlattachedproperty Item Window::contentItem + \since 5.4 + + This attached property holds the invisible root item of the scene or + \c null if the item is not in a window. The Window attached property + can be attached to any Item. +*/ /*! \property QQuickWindow::contentItem diff --git a/src/quick/items/qquickwindowattached.cpp b/src/quick/items/qquickwindowattached.cpp index 121da9e..f74e903 100644 --- a/src/quick/items/qquickwindowattached.cpp +++ b/src/quick/items/qquickwindowattached.cpp @@ -65,6 +65,11 @@ QQuickItem *QQuickWindowAttached::activeFocusItem() const return (m_window ? m_window->activeFocusItem() : Q_NULLPTR); } +QQuickItem *QQuickWindowAttached::contentItem() const +{ + return (m_window ? m_window->contentItem() : Q_NULLPTR); +} + void QQuickWindowAttached::windowChanged(QQuickWindow *window) { if (window != m_window) { @@ -83,6 +88,7 @@ void QQuickWindowAttached::windowChanged(QQuickWindow *window) emit activeChanged(); if (!oldWindow || window->activeFocusItem() != oldWindow->activeFocusItem()) emit activeFocusItemChanged(); + emit contentItemChanged(); // QQuickWindowQmlImpl::visibilityChanged also exists, and window might even // be QQuickWindowQmlImpl, but that's not what we are connecting to. diff --git a/src/quick/items/qquickwindowattached_p.h b/src/quick/items/qquickwindowattached_p.h index 12dd273..7c2b0bc 100644 --- a/src/quick/items/qquickwindowattached_p.h +++ b/src/quick/items/qquickwindowattached_p.h @@ -49,6 +49,7 @@ class Q_AUTOTEST_EXPORT QQuickWindowAttached : public QObject Q_PROPERTY(QWindow::Visibility visibility READ visibility NOTIFY visibilityChanged) Q_PROPERTY(bool active READ isActive NOTIFY activeChanged) Q_PROPERTY(QQuickItem* activeFocusItem READ activeFocusItem NOTIFY activeFocusItemChanged) + Q_PROPERTY(QQuickItem* contentItem READ contentItem NOTIFY contentItemChanged) public: QQuickWindowAttached(QObject* attachee); @@ -56,12 +57,14 @@ public: QWindow::Visibility visibility() const; bool isActive() const; QQuickItem* activeFocusItem() const; + QQuickItem* contentItem() const; Q_SIGNALS: void visibilityChanged(); void activeChanged(); void activeFocusItemChanged(); + void contentItemChanged(); protected Q_SLOTS: void windowChanged(QQuickWindow*); diff --git a/tests/auto/quick/qquickwindow/data/windowattached.qml b/tests/auto/quick/qquickwindow/data/windowattached.qml index e000d5c..0e3f1d4 100644 --- a/tests/auto/quick/qquickwindow/data/windowattached.qml +++ b/tests/auto/quick/qquickwindow/data/windowattached.qml @@ -6,6 +6,7 @@ Rectangle { width: 100 height: 100 property bool windowActive: root.Window.active + property Item contentItem: root.Window.contentItem Text { objectName: "rectangleWindowText" anchors.centerIn: parent @@ -20,6 +21,7 @@ Rectangle { objectName: "extraWindowText" anchors.centerIn: parent text: (extraWindow.active ? "active" : "inactive") + "\nvisibility: " + Window.visibility + property Item contentItem: Window.contentItem } } } diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index 5bd7492..043203c 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -1952,6 +1952,7 @@ void tst_qquickwindow::attachedProperty() view.requestActivate(); QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(view.rootObject()->property("windowActive").toBool()); + QCOMPARE(view.rootObject()->property("contentItem").value(), view.contentItem()); QQuickWindow *innerWindow = view.rootObject()->findChild("extraWindow"); QVERIFY(innerWindow); @@ -1961,6 +1962,7 @@ void tst_qquickwindow::attachedProperty() QQuickText *text = view.rootObject()->findChild("extraWindowText"); QVERIFY(text); QCOMPARE(text->text(), QLatin1String("active\nvisibility: 2")); + QCOMPARE(text->property("contentItem").value(), innerWindow->contentItem()); } class RenderJob : public QRunnable -- 2.7.4