diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2016-09-22 14:22:26 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2016-10-10 11:48:57 +0000 |
commit | d6dfbe8fd5d09388fc624d85c4aefa0269c20db9 (patch) | |
tree | 981dd2ab5444b5d83a3538fb7ca444e327f76d8a /tests/auto/quick/qquickscreen | |
parent | e91bd092f26a9a90ea6df57b84d8c1678c76ba4d (diff) |
Enable making window-screen associations from QML
Qt Quick provides a Screen attached property to query information
about the screen an item's window belongs to. This is a good start,
but has two problems: it lacks some virtual desktop related info
(e.g. the position in the virtual desktop) and it cannot be used in
combination with the Window element in order to achieve a QML
equivalent of QWindow::setScreen().
Therefore add the missing virtualX and virtualY properties and
introduce Qt.application.screens. The latter is an equivalent to
QGuiApplication::screens() and is a JS array the elements of which
can be set as the value of the new Window.targetScreen property.
This means that a call like
window->setScreen(QGuiApplication::screens()[0]) translates to
Window { targetScreen: Qt.application.screens[0]; ... } when using the
Window type from QML. Screen addition or removal can be acted upon via
onScreensChanged.
QQuickScreenAttached has been split into two in order to allow reusing the
QScreen wrapping queries for other purposes as well.
Task-number: QTBUG-56115
Change-Id: I4b2fbd873315b40d0afe878da2fc50966c00e2e0
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'tests/auto/quick/qquickscreen')
-rw-r--r-- | tests/auto/quick/qquickscreen/data/screen.qml | 14 | ||||
-rw-r--r-- | tests/auto/quick/qquickscreen/tst_qquickscreen.cpp | 40 |
2 files changed, 52 insertions, 2 deletions
diff --git a/tests/auto/quick/qquickscreen/data/screen.qml b/tests/auto/quick/qquickscreen/data/screen.qml index c246b3cd83..cf60d0ae40 100644 --- a/tests/auto/quick/qquickscreen/data/screen.qml +++ b/tests/auto/quick/qquickscreen/data/screen.qml @@ -1,5 +1,5 @@ import QtQuick 2.0 -import QtQuick.Window 2.0 as Window +import QtQuick.Window 2.3 as Window Item { width: 100 @@ -10,6 +10,18 @@ Item { property int priOrientation: Window.Screen.primaryOrientation property int updateMask: Window.Screen.orientationUpdateMask property real devicePixelRatio: Window.Screen.devicePixelRatio + property int vx: Window.Screen.virtualX + property int vy: Window.Screen.virtualY Window.Screen.orientationUpdateMask: Qt.LandscapeOrientation | Qt.InvertedLandscapeOrientation + + property int screenCount: Qt.application.screens.length + + property variant allScreens + Component.onCompleted: { + allScreens = []; + var s = Qt.application.screens; + for (var i = 0; i < s.length; ++i) + allScreens.push(s[i]); + } } diff --git a/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp b/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp index 92afdf6864..26b687a4a6 100644 --- a/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp +++ b/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp @@ -33,13 +33,15 @@ #include <QtQuick/QQuickView> #include <QtGui/QScreen> #include "../../shared/util.h" - +#include <QtQuick/private/qquickscreen_p.h> +#include <QDebug> class tst_qquickscreen : public QQmlDataTest { Q_OBJECT private slots: void basicProperties(); void screenOnStartup(); + void fullScreenList(); }; void tst_qquickscreen::basicProperties() @@ -62,6 +64,10 @@ void tst_qquickscreen::basicProperties() QCOMPARE(int(screen->orientationUpdateMask()), root->property("updateMask").toInt()); QCOMPARE(screen->devicePixelRatio(), root->property("devicePixelRatio").toReal()); QVERIFY(screen->devicePixelRatio() >= 1.0); + QCOMPARE(screen->geometry().x(), root->property("vx").toInt()); + QCOMPARE(screen->geometry().y(), root->property("vy").toInt()); + + QVERIFY(root->property("screenCount").toInt() == QGuiApplication::screens().count()); } void tst_qquickscreen::screenOnStartup() @@ -83,6 +89,38 @@ void tst_qquickscreen::screenOnStartup() QCOMPARE(int(screen->orientationUpdateMask()), root->property("updateMask").toInt()); QCOMPARE(screen->devicePixelRatio(), root->property("devicePixelRatio").toReal()); QVERIFY(screen->devicePixelRatio() >= 1.0); + QCOMPARE(screen->geometry().x(), root->property("vx").toInt()); + QCOMPARE(screen->geometry().y(), root->property("vy").toInt()); +} + +void tst_qquickscreen::fullScreenList() +{ + QQuickView view; + view.setSource(testFileUrl("screen.qml")); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + + QQuickItem* root = view.rootObject(); + QVERIFY(root); + + QJSValue screensArray = root->property("allScreens").value<QJSValue>(); + QVERIFY(screensArray.isArray()); + int length = screensArray.property("length").toInt(); + const QList<QScreen *> screenList = QGuiApplication::screens(); + QVERIFY(length == screenList.count()); + + for (int i = 0; i < length; ++i) { + QQuickScreenInfo *info = qobject_cast<QQuickScreenInfo *>(screensArray.property(i).toQObject()); + QVERIFY(info != nullptr); + QCOMPARE(screenList[i]->name(), info->name()); + QCOMPARE(screenList[i]->size().width(), info->width()); + QCOMPARE(screenList[i]->size().height(), info->height()); + QCOMPARE(screenList[i]->availableVirtualGeometry().width(), info->desktopAvailableWidth()); + QCOMPARE(screenList[i]->availableVirtualGeometry().height(), info->desktopAvailableHeight()); + QCOMPARE(screenList[i]->devicePixelRatio(), info->devicePixelRatio()); + QCOMPARE(screenList[i]->geometry().x(), info->virtualX()); + QCOMPARE(screenList[i]->geometry().y(), info->virtualY()); + } } QTEST_MAIN(tst_qquickscreen) |