summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qwindow.cpp
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2012-01-13 10:31:11 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-24 15:38:48 +0100
commitb39df8bf92a530783144dbcf5cae939742ff2d23 (patch)
tree0560985d33f59a48693acadbdfbb59b328131499 /src/gui/kernel/qwindow.cpp
parentb0a0403daf81e82ea732aa91ec92cf94553a7935 (diff)
Made window orientation API more flexible.
Previously we only had QWindow::setOrientation() which was a hint about the orientation the window's contents were rendered in. However, it's necessary to separate between the orientation corresponding to the window buffer layout and orientation of the contents. A game for example might typically want to use a landscape buffer even on a portrait device. Thus, we replace QWindow::orientation() with QWindow::reportContentOrientationChange() and QWindow::requestWindowOrientation(). Change-Id: I1f07362192daf36c45519cb05b43ac352f1945b5 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/gui/kernel/qwindow.cpp')
-rw-r--r--src/gui/kernel/qwindow.cpp102
1 files changed, 79 insertions, 23 deletions
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index 2893273ce0..65ac5f1539 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -72,8 +72,24 @@ QT_BEGIN_NAMESPACE
to support double and triple buffering. To release a windows memory
resources, the destroy() function.
- */
-
+ \section1 Window and content orientation
+
+ QWindow has reportContentOrientationChange() and
+ requestWindowOrientation() that can be used to specify the
+ layout of the window contents in relation to the screen. The
+ window orientation determines the actual buffer layout of the
+ window, and the windowing system uses this value to rotate the
+ window before it ends up on the display, and to ensure that input
+ coordinates are in the correct coordinate space relative to the
+ application.
+
+ On the other hand, the content orientation is simply a hint to the
+ windowing system about which orientation the window contents are in.
+ It's useful when you wish to keep the same buffer layout, but rotate
+ the contents instead, especially when doing rotation animations
+ between different orientations. The windowing system might use this
+ value to determine the layout of system popups or dialogs.
+*/
QWindow::QWindow(QScreen *targetScreen)
: QObject(*new QWindowPrivate(), 0)
, QSurface(QSurface::Window)
@@ -375,42 +391,82 @@ bool QWindow::isActive() const
}
/*!
- Returns the window's currently set orientation.
+ Reports that the orientation of the window's contents have changed.
+
+ This is a hint to the window manager in case it needs to display
+ additional content like popups, dialogs, status bars, or similar
+ in relation to the window.
+
+ The recommended orientation is QScreen::orientation() but
+ an application doesn't have to support all possible orientations,
+ and thus can opt to ignore the current screen orientation.
+
+ The difference between the window and the content orientation
+ determines how much to rotate the content by. QScreen::angleBetween(),
+ QScreen::transformBetween(), and QScreen::mapBetween() can be used
+ to compute the necessary transform.
+
+ \sa requestWindowOrientation(), QScreen::orientation()
+*/
+void QWindow::reportContentOrientationChange(Qt::ScreenOrientation orientation)
+{
+ Q_D(QWindow);
+ if (!d->platformWindow)
+ create();
+ Q_ASSERT(d->platformWindow);
+ d->contentOrientation = orientation;
+ d->platformWindow->handleContentOrientationChange(orientation);
+}
- The default value is Qt::UnknownOrientation.
+/*!
+ Returns the actual content orientation.
- \sa setOrientation(), QScreen::currentOrientation()
+ This is the last value set with reportContentOrientationChange(),
+ except Qt::PrimaryOrientation gets converted to the screen's
+ primary orientation.
*/
-Qt::ScreenOrientation QWindow::orientation() const
+Qt::ScreenOrientation QWindow::contentOrientation() const
{
Q_D(const QWindow);
- return d->orientation;
+ return d->contentOrientation == Qt::PrimaryOrientation ? screen()->primaryOrientation() : d->contentOrientation;
}
/*!
- Set the orientation of the window's contents.
+ Requests the given window orientation.
- This is a hint to the window manager in case it needs to display
- additional content like popups, dialogs, status bars, or similar
- in relation to the window.
+ The window orientation specifies how the window should be rotated
+ by the window manager in order to be displayed. Input events will
+ be correctly mapped to the given orientation.
- The recommended orientation is QScreen::currentOrientation() but
- an application doesn't have to support all possible orientations,
- and thus can opt to ignore the current screen orientation.
+ The return value is false if the system doesn't support the given
+ orientation (for example when requesting a portrait orientation
+ on a device that only handles landscape buffers, typically a desktop
+ system).
+
+ If the return value is false, call windowOrientation() to get the actual
+ supported orientation.
- \sa QScreen::currentOrientation()
+ \sa windowOrientation(), reportContentOrientationChange(), QScreen::orientation()
*/
-void QWindow::setOrientation(Qt::ScreenOrientation orientation)
+bool QWindow::requestWindowOrientation(Qt::ScreenOrientation orientation)
{
Q_D(QWindow);
- if (orientation == d->orientation)
- return;
+ if (!d->platformWindow)
+ create();
+ Q_ASSERT(d->platformWindow);
+ d->windowOrientation = d->platformWindow->requestWindowOrientation(orientation);
+ return d->windowOrientation == orientation;
+}
- d->orientation = orientation;
- if (d->platformWindow) {
- d->platformWindow->setOrientation(orientation);
- }
- emit orientationChanged(orientation);
+/*!
+ Returns the actual window orientation.
+
+ \sa requestWindowOrientation()
+*/
+Qt::ScreenOrientation QWindow::windowOrientation() const
+{
+ Q_D(const QWindow);
+ return d->windowOrientation == Qt::PrimaryOrientation ? screen()->primaryOrientation() : d->windowOrientation;
}
Qt::WindowState QWindow::windowState() const