diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-01-05 21:00:40 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2015-01-09 21:40:52 +0100 |
commit | 40f394ef2e06a6466445e4df54735250939084f0 (patch) | |
tree | 815635f1adf7b2dee2ee271e9092f96695c41936 | |
parent | b40a2a881291b3eaea4b4834a162091537e6a34e (diff) |
Add Window.width and Window.height attached properties
[ChangeLog][QtQuick] Added Window.width and Window.height attached
properties
Change-Id: I3ef590a0d3e6fa660ed88992d5ae843deb09c7bc
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
-rw-r--r-- | src/quick/items/qquickwindow.cpp | 9 | ||||
-rw-r--r-- | src/quick/items/qquickwindowattached.cpp | 18 | ||||
-rw-r--r-- | src/quick/items/qquickwindowattached_p.h | 6 | ||||
-rw-r--r-- | tests/auto/quick/qquickwindow/data/windowattached.qml | 4 | ||||
-rw-r--r-- | tests/auto/quick/qquickwindow/tst_qquickwindow.cpp | 4 |
5 files changed, 41 insertions, 0 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index aba36ce118..2c8b24baf6 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -3767,6 +3767,15 @@ void QQuickWindow::resetOpenGLState() */ /*! + \qmlattachedproperty int Window::width + \qmlattachedproperty int Window::height + \since 5.5 + + These attached properties hold the size of the item's window. + The Window attached property can be attached to any Item. +*/ + +/*! \qmlproperty int Window::x \qmlproperty int Window::y \qmlproperty int Window::width diff --git a/src/quick/items/qquickwindowattached.cpp b/src/quick/items/qquickwindowattached.cpp index f74e903be3..70985bdd45 100644 --- a/src/quick/items/qquickwindowattached.cpp +++ b/src/quick/items/qquickwindowattached.cpp @@ -70,6 +70,16 @@ QQuickItem *QQuickWindowAttached::contentItem() const return (m_window ? m_window->contentItem() : Q_NULLPTR); } +int QQuickWindowAttached::width() const +{ + return (m_window ? m_window->width() : 0); +} + +int QQuickWindowAttached::height() const +{ + return (m_window ? m_window->height() : 0); +} + void QQuickWindowAttached::windowChanged(QQuickWindow *window) { if (window != m_window) { @@ -89,6 +99,10 @@ void QQuickWindowAttached::windowChanged(QQuickWindow *window) if (!oldWindow || window->activeFocusItem() != oldWindow->activeFocusItem()) emit activeFocusItemChanged(); emit contentItemChanged(); + if (!oldWindow || window->width() != oldWindow->width()) + emit widthChanged(); + if (!oldWindow || window->height() != oldWindow->height()) + emit heightChanged(); // QQuickWindowQmlImpl::visibilityChanged also exists, and window might even // be QQuickWindowQmlImpl, but that's not what we are connecting to. @@ -102,6 +116,10 @@ void QQuickWindowAttached::windowChanged(QQuickWindow *window) this, &QQuickWindowAttached::activeChanged); connect(window, &QQuickWindow::activeFocusItemChanged, this, &QQuickWindowAttached::activeFocusItemChanged); + connect(window, &QQuickWindow::widthChanged, + this, &QQuickWindowAttached::widthChanged); + connect(window, &QQuickWindow::heightChanged, + this, &QQuickWindowAttached::heightChanged); } } diff --git a/src/quick/items/qquickwindowattached_p.h b/src/quick/items/qquickwindowattached_p.h index 7c2b0bc873..df1499c692 100644 --- a/src/quick/items/qquickwindowattached_p.h +++ b/src/quick/items/qquickwindowattached_p.h @@ -50,6 +50,8 @@ class Q_AUTOTEST_EXPORT QQuickWindowAttached : public QObject Q_PROPERTY(bool active READ isActive NOTIFY activeChanged) Q_PROPERTY(QQuickItem* activeFocusItem READ activeFocusItem NOTIFY activeFocusItemChanged) Q_PROPERTY(QQuickItem* contentItem READ contentItem NOTIFY contentItemChanged) + Q_PROPERTY(int width READ width NOTIFY widthChanged) + Q_PROPERTY(int height READ height NOTIFY heightChanged) public: QQuickWindowAttached(QObject* attachee); @@ -58,6 +60,8 @@ public: bool isActive() const; QQuickItem* activeFocusItem() const; QQuickItem* contentItem() const; + int width() const; + int height() const; Q_SIGNALS: @@ -65,6 +69,8 @@ Q_SIGNALS: void activeChanged(); void activeFocusItemChanged(); void contentItemChanged(); + void widthChanged(); + void heightChanged(); 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 0e3f1d4b62..a9f052d55e 100644 --- a/tests/auto/quick/qquickwindow/data/windowattached.qml +++ b/tests/auto/quick/qquickwindow/data/windowattached.qml @@ -7,6 +7,8 @@ Rectangle { height: 100 property bool windowActive: root.Window.active property Item contentItem: root.Window.contentItem + property int windowWidth: root.Window.width + property int windowHeight: root.Window.height Text { objectName: "rectangleWindowText" anchors.centerIn: parent @@ -22,6 +24,8 @@ Rectangle { anchors.centerIn: parent text: (extraWindow.active ? "active" : "inactive") + "\nvisibility: " + Window.visibility property Item contentItem: Window.contentItem + property int windowWidth: Window.width + property int windowHeight: Window.height } } } diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index 7c94cf6d17..e019c57ccb 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -1978,6 +1978,8 @@ void tst_qquickwindow::attachedProperty() QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(view.rootObject()->property("windowActive").toBool()); QCOMPARE(view.rootObject()->property("contentItem").value<QQuickItem*>(), view.contentItem()); + QCOMPARE(view.rootObject()->property("windowWidth").toInt(), view.width()); + QCOMPARE(view.rootObject()->property("windowHeight").toInt(), view.height()); QQuickWindow *innerWindow = view.rootObject()->findChild<QQuickWindow*>("extraWindow"); QVERIFY(innerWindow); @@ -1988,6 +1990,8 @@ void tst_qquickwindow::attachedProperty() QVERIFY(text); QCOMPARE(text->text(), QLatin1String("active\nvisibility: 2")); QCOMPARE(text->property("contentItem").value<QQuickItem*>(), innerWindow->contentItem()); + QCOMPARE(text->property("windowWidth").toInt(), innerWindow->width()); + QCOMPARE(text->property("windowHeight").toInt(), innerWindow->height()); } class RenderJob : public QRunnable |