From d2d53dffbc3ba52333e559e2c0391bd73e5b840c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Samuel=20R=C3=B8dal?= Date: Tue, 24 Jan 2012 10:04:45 +0100 Subject: [PATCH] Adapted QQuickScreenAttached to orientation API changes in QScreen. Change-Id: Ic2cb008b989780e297f03ddd5bdef466bb230c74 Reviewed-by: Lars Knoll --- examples/declarative/calculator/calculator.qml | 2 +- examples/declarative/window/screen/screenInfo.qml | 2 +- src/quick/items/qquickscreen.cpp | 31 +++++++++++++--------- src/quick/items/qquickscreen_p.h | 6 ++--- tests/auto/qtquick2/qquickscreen/data/screen.qml | 2 +- .../qtquick2/qquickscreen/tst_qquickscreen.cpp | 2 +- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/examples/declarative/calculator/calculator.qml b/examples/declarative/calculator/calculator.qml index cfec9c1..82fa1c1 100644 --- a/examples/declarative/calculator/calculator.qml +++ b/examples/declarative/calculator/calculator.qml @@ -62,7 +62,7 @@ Rectangle { Item { id: main - state: "orientation " + Screen.currentOrientation + state: "orientation " + Screen.orientation property bool landscapeWindow: window.width > window.height property real baseWidth: landscapeWindow ? window.height : window.width diff --git a/examples/declarative/window/screen/screenInfo.qml b/examples/declarative/window/screen/screenInfo.qml index 53028a4..9a97276 100644 --- a/examples/declarative/window/screen/screenInfo.qml +++ b/examples/declarative/window/screen/screenInfo.qml @@ -47,7 +47,7 @@ Item { height: 200 Item { id: main - state: "orientation " + Window.Screen.currentOrientation + state: "orientation " + Window.Screen.orientation property bool landscapeWindow: Window.Screen.primaryOrientation == Qt.LandscapeOrientation property real baseWidth: landscapeWindow ? root.height : root.width diff --git a/src/quick/items/qquickscreen.cpp b/src/quick/items/qquickscreen.cpp index dc9a3d3..3769f4e 100644 --- a/src/quick/items/qquickscreen.cpp +++ b/src/quick/items/qquickscreen.cpp @@ -74,10 +74,10 @@ QT_BEGIN_NAMESPACE \qmlattachedproperty Qt::ScreenOrientation QtQuickWindow2::Screen::primaryOrientation \readonly - This contains the primary orientation of the screen. This can only change if the screen changes. + This contains the primary orientation of the screen. */ /*! - \qmlattachedproperty Qt::ScreenOrientation QtQuickWindow2::Screen::currentOrientation + \qmlattachedproperty Qt::ScreenOrientation QtQuickWindow2::Screen::orientation \readonly This contains the current orientation of the screen. @@ -119,20 +119,20 @@ int QQuickScreenAttached::height() const Qt::ScreenOrientation QQuickScreenAttached::primaryOrientation() const { if (!m_screen) - return Qt::UnknownOrientation; + return Qt::PrimaryOrientation; return m_screen->primaryOrientation(); } -Qt::ScreenOrientation QQuickScreenAttached::currentOrientation() const +Qt::ScreenOrientation QQuickScreenAttached::orientation() const { if (!m_screen) - return Qt::UnknownOrientation; - return m_screen->currentOrientation(); + return Qt::PrimaryOrientation; + return m_screen->orientation(); } int QQuickScreenAttached::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b) { - return QScreen::angleBetween(a,b); + return m_screen->angleBetween(a,b); } void QQuickScreenAttached::canvasChanged(QQuickCanvas* c)//Called by QQuickItemPrivate::initCanvas @@ -147,8 +147,10 @@ void QQuickScreenAttached::canvasChanged(QQuickCanvas* c)//Called by QQuickItemP this, SIGNAL(widthChanged())); disconnect(oldScreen, SIGNAL(sizeChanged(QSize)), this, SIGNAL(heightChanged())); - disconnect(oldScreen, SIGNAL(currentOrientationChanged(Qt::ScreenOrientation)), - this, SIGNAL(currentOrientationChanged())); + disconnect(oldScreen, SIGNAL(orientationChanged(Qt::ScreenOrientation)), + this, SIGNAL(orientationChanged())); + disconnect(oldScreen, SIGNAL(primaryOrientationChanged(Qt::ScreenOrientation)), + this, SIGNAL(primaryOrientationChanged())); } if (!screen) @@ -158,8 +160,9 @@ void QQuickScreenAttached::canvasChanged(QQuickCanvas* c)//Called by QQuickItemP emit widthChanged(); emit heightChanged(); } - if (!oldScreen || screen->currentOrientation() != oldScreen->currentOrientation()) - emit currentOrientationChanged(); + + if (!oldScreen || screen->orientation() != oldScreen->orientation()) + emit orientationChanged(); if (!oldScreen || screen->primaryOrientation() != oldScreen->primaryOrientation()) emit primaryOrientationChanged(); @@ -168,8 +171,10 @@ void QQuickScreenAttached::canvasChanged(QQuickCanvas* c)//Called by QQuickItemP this, SIGNAL(widthChanged())); connect(screen, SIGNAL(sizeChanged(QSize)), this, SIGNAL(heightChanged())); - connect(screen, SIGNAL(currentOrientationChanged(Qt::ScreenOrientation)), - this, SIGNAL(currentOrientationChanged())); + connect(screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)), + this, SIGNAL(orientationChanged())); + connect(screen, SIGNAL(primaryOrientationChanged(Qt::ScreenOrientation)), + this, SIGNAL(primaryOrientationChanged())); } } diff --git a/src/quick/items/qquickscreen_p.h b/src/quick/items/qquickscreen_p.h index 5a67952..672607f 100644 --- a/src/quick/items/qquickscreen_p.h +++ b/src/quick/items/qquickscreen_p.h @@ -63,7 +63,7 @@ class Q_AUTOTEST_EXPORT QQuickScreenAttached : public QObject Q_PROPERTY(int width READ width NOTIFY widthChanged) Q_PROPERTY(int height READ height NOTIFY heightChanged) Q_PROPERTY(Qt::ScreenOrientation primaryOrientation READ primaryOrientation NOTIFY primaryOrientationChanged) - Q_PROPERTY(Qt::ScreenOrientation currentOrientation READ currentOrientation NOTIFY currentOrientationChanged) + Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation NOTIFY orientationChanged) public: QQuickScreenAttached(QObject* attachee); @@ -71,7 +71,7 @@ public: int width() const; int height() const; Qt::ScreenOrientation primaryOrientation() const; - Qt::ScreenOrientation currentOrientation() const; + Qt::ScreenOrientation orientation() const; Q_INVOKABLE int angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b); @@ -81,7 +81,7 @@ Q_SIGNALS: void widthChanged(); void heightChanged(); void primaryOrientationChanged(); - void currentOrientationChanged(); + void orientationChanged(); private: QScreen* m_screen; diff --git a/tests/auto/qtquick2/qquickscreen/data/screen.qml b/tests/auto/qtquick2/qquickscreen/data/screen.qml index 971975f..780b22f 100644 --- a/tests/auto/qtquick2/qquickscreen/data/screen.qml +++ b/tests/auto/qtquick2/qquickscreen/data/screen.qml @@ -6,6 +6,6 @@ Item { height: 100 property int w: Window.Screen.width property int h: Window.Screen.height - property int curOrientation: Window.Screen.currentOrientation + property int curOrientation: Window.Screen.orientation property int priOrientation: Window.Screen.primaryOrientation } diff --git a/tests/auto/qtquick2/qquickscreen/tst_qquickscreen.cpp b/tests/auto/qtquick2/qquickscreen/tst_qquickscreen.cpp index 8e32284..fdb2730 100644 --- a/tests/auto/qtquick2/qquickscreen/tst_qquickscreen.cpp +++ b/tests/auto/qtquick2/qquickscreen/tst_qquickscreen.cpp @@ -68,7 +68,7 @@ void tst_qquickscreen::basicProperties() QCOMPARE(screen->size().width(), root->property("w").toInt()); QCOMPARE(screen->size().height(), root->property("h").toInt()); - QCOMPARE(int(screen->currentOrientation()), root->property("curOrientation").toInt()); + QCOMPARE(int(screen->orientation()), root->property("curOrientation").toInt()); QCOMPARE(int(screen->primaryOrientation()), root->property("priOrientation").toInt()); } -- 2.7.4