diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-09-24 12:08:10 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@digia.com> | 2014-09-30 09:57:04 +0200 |
commit | 536ead429648f40b874f8d6927bb8f98e8f47a37 (patch) | |
tree | e419d5eaf01c0a363b609574261f6c3ad6a45efd | |
parent | d5b10eda96e2b00a11a2346cb2374af053a5c5af (diff) |
Add orientationUpdateMask to QQuickScreen
Task-number: QTBUG-38699
Change-Id: I173b7e53c27dba336351572859f7c9aeafe07ef9
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
-rw-r--r-- | src/quick/items/qquickscreen.cpp | 34 | ||||
-rw-r--r-- | src/quick/items/qquickscreen_p.h | 10 | ||||
-rw-r--r-- | tests/auto/quick/qquickscreen/data/screen.qml | 3 | ||||
-rw-r--r-- | tests/auto/quick/qquickscreen/tst_qquickscreen.cpp | 1 |
4 files changed, 47 insertions, 1 deletions
diff --git a/src/quick/items/qquickscreen.cpp b/src/quick/items/qquickscreen.cpp index 0d9226d77f..926ac7b4ee 100644 --- a/src/quick/items/qquickscreen.cpp +++ b/src/quick/items/qquickscreen.cpp @@ -171,6 +171,9 @@ QT_BEGIN_NAMESPACE change, then probably you are using a device which does not rotate its own display. In that case you may need to use \l {Item::rotation}{Item.rotation} or \l {Item::transform}{Item.transform} to rotate your content. + + \note This property does not update unless a Screen::orientationUpdateMask + is set to a value other than \c 0. */ /*! \qmlattachedmethod int Screen::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b) @@ -178,10 +181,21 @@ QT_BEGIN_NAMESPACE Returns the rotation angle, in degrees, between the two specified angles. */ +/*! + \qmlattachedproperty Qt::ScreenOrientations Screen::orientationUpdateMask + \since 5.4 + + This contains the update mask for the orientation. Screen::orientation + only emits changes for the screen orientations matching this mask. + + The default, \c 0, means Screen::orientation never updates. +*/ + QQuickScreenAttached::QQuickScreenAttached(QObject* attachee) : QObject(attachee) , m_screen(NULL) , m_window(NULL) + , m_updateMask(0) { m_attachee = qobject_cast<QQuickItem*>(attachee); @@ -260,6 +274,24 @@ Qt::ScreenOrientation QQuickScreenAttached::orientation() const return m_screen->orientation(); } +Qt::ScreenOrientations QQuickScreenAttached::orientationUpdateMask() const +{ + return m_updateMask; +} + +void QQuickScreenAttached::setOrientationUpdateMask(Qt::ScreenOrientations mask) +{ + if (m_updateMask == mask) + return; + + m_updateMask = mask; + + if (m_screen) + m_screen->setOrientationUpdateMask(m_updateMask); + + emit orientationUpdateMaskChanged(); +} + int QQuickScreenAttached::angleBetween(int a, int b) { if (!m_screen) @@ -290,6 +322,8 @@ void QQuickScreenAttached::screenChanged(QScreen *screen) if (!screen) return; //Don't bother emitting signals, because the new values are garbage anyways + screen->setOrientationUpdateMask(m_updateMask); + if (!oldScreen || screen->size() != oldScreen->size()) { emit widthChanged(); emit heightChanged(); diff --git a/src/quick/items/qquickscreen_p.h b/src/quick/items/qquickscreen_p.h index 884995a67e..d661cc6f56 100644 --- a/src/quick/items/qquickscreen_p.h +++ b/src/quick/items/qquickscreen_p.h @@ -50,15 +50,19 @@ class Q_AUTOTEST_EXPORT QQuickScreenAttached : public QObject { Q_OBJECT - Q_PROPERTY(QString name READ name NOTIFY nameChanged); + Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(int width READ width NOTIFY widthChanged) Q_PROPERTY(int height READ height NOTIFY heightChanged) Q_PROPERTY(int desktopAvailableWidth READ desktopAvailableWidth NOTIFY desktopGeometryChanged) Q_PROPERTY(int desktopAvailableHeight READ desktopAvailableHeight NOTIFY desktopGeometryChanged) Q_PROPERTY(qreal logicalPixelDensity READ logicalPixelDensity NOTIFY logicalPixelDensityChanged) Q_PROPERTY(qreal pixelDensity READ pixelDensity NOTIFY pixelDensityChanged) + // TODO Qt 6 Rename primaryOrientation to orientation Q_PROPERTY(Qt::ScreenOrientation primaryOrientation READ primaryOrientation NOTIFY primaryOrientationChanged) + // TODO Qt 6 Remove this orientation -> incomplete device orientation -> better use OrientationSensor Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation NOTIFY orientationChanged) + Q_PROPERTY(Qt::ScreenOrientations orientationUpdateMask READ orientationUpdateMask + WRITE setOrientationUpdateMask NOTIFY orientationUpdateMaskChanged) public: QQuickScreenAttached(QObject* attachee); @@ -72,6 +76,8 @@ public: qreal pixelDensity() const; Qt::ScreenOrientation primaryOrientation() const; Qt::ScreenOrientation orientation() const; + Qt::ScreenOrientations orientationUpdateMask() const; + void setOrientationUpdateMask(Qt::ScreenOrientations mask); //Treats int as Qt::ScreenOrientation, due to QTBUG-20639 Q_INVOKABLE int angleBetween(int a, int b); @@ -87,6 +93,7 @@ Q_SIGNALS: void pixelDensityChanged(); void primaryOrientationChanged(); void orientationChanged(); + void orientationUpdateMaskChanged(); protected Q_SLOTS: void screenChanged(QScreen*); @@ -95,6 +102,7 @@ private: QScreen* m_screen; QQuickWindow* m_window; QQuickItem* m_attachee; + Qt::ScreenOrientations m_updateMask; }; class Q_AUTOTEST_EXPORT QQuickScreen : public QObject diff --git a/tests/auto/quick/qquickscreen/data/screen.qml b/tests/auto/quick/qquickscreen/data/screen.qml index 780b22f23d..dc3803f4e3 100644 --- a/tests/auto/quick/qquickscreen/data/screen.qml +++ b/tests/auto/quick/qquickscreen/data/screen.qml @@ -8,4 +8,7 @@ Item { property int h: Window.Screen.height property int curOrientation: Window.Screen.orientation property int priOrientation: Window.Screen.primaryOrientation + property int updateMask: Window.Screen.orientationUpdateMask + + Window.Screen.orientationUpdateMask: Qt.LandscapeOrientation | Qt.InvertedLandscapeOrientation } diff --git a/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp b/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp index dc6fe061c3..be543e8022 100644 --- a/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp +++ b/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp @@ -62,6 +62,7 @@ void tst_qquickscreen::basicProperties() QCOMPARE(screen->size().height(), root->property("h").toInt()); QCOMPARE(int(screen->orientation()), root->property("curOrientation").toInt()); QCOMPARE(int(screen->primaryOrientation()), root->property("priOrientation").toInt()); + QCOMPARE(int(screen->orientationUpdateMask()), root->property("updateMask").toInt()); } QTEST_MAIN(tst_qquickscreen) |