Add attached Window::contentItem property
authorJ-P Nurmi <jpnurmi@theqtcompany.com>
Mon, 3 Nov 2014 16:23:11 +0000 (17:23 +0100)
committerJ-P Nurmi <jpnurmi@theqtcompany.com>
Wed, 5 Nov 2014 15:19:31 +0000 (16:19 +0100)
This is essential to the Qt Quick Controls for implementing floating
text selection handle popups.

Change-Id: Ibae65110a5db6d65dacd197fef3ad567d11342dc
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
src/quick/items/qquickwindow.cpp
src/quick/items/qquickwindowattached.cpp
src/quick/items/qquickwindowattached_p.h
tests/auto/quick/qquickwindow/data/windowattached.qml
tests/auto/quick/qquickwindow/tst_qquickwindow.cpp

index f6c1412..619e539 100644 (file)
@@ -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
index 121da9e..f74e903 100644 (file)
@@ -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.
index 12dd273..7c2b0bc 100644 (file)
@@ -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*);
index e000d5c..0e3f1d4 100644 (file)
@@ -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
         }
     }
 }
index 5bd7492..043203c 100644 (file)
@@ -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<QQuickItem*>(), view.contentItem());
 
     QQuickWindow *innerWindow = view.rootObject()->findChild<QQuickWindow*>("extraWindow");
     QVERIFY(innerWindow);
@@ -1961,6 +1962,7 @@ void tst_qquickwindow::attachedProperty()
     QQuickText *text = view.rootObject()->findChild<QQuickText*>("extraWindowText");
     QVERIFY(text);
     QCOMPARE(text->text(), QLatin1String("active\nvisibility: 2"));
+    QCOMPARE(text->property("contentItem").value<QQuickItem*>(), innerWindow->contentItem());
 }
 
 class RenderJob : public QRunnable