summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2012-01-25 13:41:43 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-26 08:32:28 +0100
commit71db6d654ec4a3166325933ca3a9f5859013c110 (patch)
treecc23527fe27b7324a8ee0ffcb434e990d40de935
parent0bca94cf380a4fc55cf3a46de979d0618f3fa455 (diff)
Made QWindow::currentOrientation() a property.
To match the previous QWindow::orientation() property which can be useful to access from QML. Also, removed the automatic translation of Qt::PrimaryOrientation to QScreen::primaryOrientation() on the QWindow level, as it leads to a lot of complexity regarding the QWindow::contentOrientationChanged() signal, and makes it hard to distinguish between the case where the window's orientation follows that of the screen, and the case where the orientation just happens to be set to that of the screen. Change-Id: I6950d1337b7f929815eff1328181855090d8066b Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
-rw-r--r--src/corelib/global/qnamespace.qdoc3
-rw-r--r--src/gui/kernel/qscreen.cpp2
-rw-r--r--src/gui/kernel/qwindow.cpp14
-rw-r--r--src/gui/kernel/qwindow.h2
-rw-r--r--tests/auto/gui/kernel/qwindow/tst_qwindow.cpp8
5 files changed, 20 insertions, 9 deletions
diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc
index 37be933393..53ad12ed4e 100644
--- a/src/corelib/global/qnamespace.qdoc
+++ b/src/corelib/global/qnamespace.qdoc
@@ -1821,8 +1821,7 @@
This enum type specifies the various orientations a screen might have.
- \value PrimaryOrientation The display's primary orientation. The QWindow and QScreen APIs never return this value,
- instead it will be mapped to the corresponding QScreen's QScreen::primaryOrientation().
+ \value PrimaryOrientation The display's primary orientation.
\value LandscapeOrientation Landscape orientation, display width is greater than display height.
\value PortraitOrientation Portrait orientation, display height is greater than display width,
rotated 90 degree clockwise relative to landscape.
diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp
index 43c2dcc50d..d8413d5cb2 100644
--- a/src/gui/kernel/qscreen.cpp
+++ b/src/gui/kernel/qscreen.cpp
@@ -351,6 +351,8 @@ QRect QScreen::availableVirtualGeometry() const
will change based on the device is being held, and a desktop display
might be rotated so that it's in portrait mode.
+ Qt::PrimaryOrientation is never returned.
+
\sa primaryOrientation(), orientationChanged()
*/
Qt::ScreenOrientation QScreen::orientation() const
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index 65ac5f1539..5bab203abc 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -411,24 +411,26 @@ bool QWindow::isActive() const
void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation)
{
Q_D(QWindow);
+ if (d->contentOrientation == orientation)
+ return;
if (!d->platformWindow)
create();
Q_ASSERT(d->platformWindow);
d->contentOrientation = orientation;
d->platformWindow->handleContentOrientationChange(orientation);
+ emit contentOrientationChanged(orientation);
}
/*!
Returns the actual content orientation.
- This is the last value set with reportContentOrientationChange(),
- except Qt::PrimaryOrientation gets converted to the screen's
- primary orientation.
+ This is the last value set with reportContentOrientationChange(). It defaults
+ to Qt::PrimaryOrientation.
*/
Qt::ScreenOrientation QWindow::contentOrientation() const
{
Q_D(const QWindow);
- return d->contentOrientation == Qt::PrimaryOrientation ? screen()->primaryOrientation() : d->contentOrientation;
+ return d->contentOrientation;
}
/*!
@@ -461,12 +463,14 @@ bool QWindow::requestWindowOrientation(Qt::ScreenOrientation orientation)
/*!
Returns the actual window orientation.
+ The default value is Qt::PrimaryOrientation.
+
\sa requestWindowOrientation()
*/
Qt::ScreenOrientation QWindow::windowOrientation() const
{
Q_D(const QWindow);
- return d->windowOrientation == Qt::PrimaryOrientation ? screen()->primaryOrientation() : d->windowOrientation;
+ return d->windowOrientation;
}
Qt::WindowState QWindow::windowState() const
diff --git a/src/gui/kernel/qwindow.h b/src/gui/kernel/qwindow.h
index 1de5105b1c..be0ca99b8b 100644
--- a/src/gui/kernel/qwindow.h
+++ b/src/gui/kernel/qwindow.h
@@ -90,6 +90,7 @@ class Q_GUI_EXPORT QWindow : public QObject, public QSurface
Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged)
Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged)
+ Q_PROPERTY(Qt::ScreenOrientation contentOrientation READ contentOrientation WRITE reportContentOrientationChange NOTIFY contentOrientationChanged)
public:
enum SurfaceType { RasterSurface, OpenGLSurface };
@@ -259,6 +260,7 @@ Q_SIGNALS:
void heightChanged(int arg);
void visibleChanged(bool arg);
+ void contentOrientationChanged(Qt::ScreenOrientation orientation);
private Q_SLOTS:
void screenDestroyed(QObject *screen);
diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
index d0d2ce1e1d..91f9e4ef49 100644
--- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
+++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
@@ -492,11 +492,15 @@ void tst_QWindow::orientation()
QCOMPARE(window.contentOrientation(), Qt::PortraitOrientation);
window.reportContentOrientationChange(Qt::PrimaryOrientation);
- QCOMPARE(window.contentOrientation(), window.screen()->primaryOrientation());
+ QCOMPARE(window.contentOrientation(), Qt::PrimaryOrientation);
QVERIFY(!window.requestWindowOrientation(Qt::LandscapeOrientation) || window.windowOrientation() == Qt::LandscapeOrientation);
QVERIFY(!window.requestWindowOrientation(Qt::PortraitOrientation) || window.windowOrientation() == Qt::PortraitOrientation);
- QVERIFY(!window.requestWindowOrientation(Qt::PrimaryOrientation) || window.windowOrientation() == window.screen()->primaryOrientation());
+ QVERIFY(!window.requestWindowOrientation(Qt::PrimaryOrientation) || window.windowOrientation() == Qt::PrimaryOrientation);
+
+ QSignalSpy spy(&window, SIGNAL(contentOrientationChanged(Qt::ScreenOrientation)));
+ window.reportContentOrientationChange(Qt::LandscapeOrientation);
+ QCOMPARE(spy.count(), 1);
}
#include <tst_qwindow.moc>