summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qscreen.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/qscreen.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/qscreen.cpp')
-rw-r--r--src/gui/kernel/qscreen.cpp111
1 files changed, 86 insertions, 25 deletions
diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp
index 0a7d22c6c8..43c2dcc50d 100644
--- a/src/gui/kernel/qscreen.cpp
+++ b/src/gui/kernel/qscreen.cpp
@@ -343,35 +343,36 @@ QRect QScreen::availableVirtualGeometry() const
}
/*!
- \property QScreen::primaryOrientation
- \brief the primary screen orientation
+ \property QScreen::orientation
+ \brief the screen orientation
+
+ The screen orientation represents the physical orientation
+ of the display. For example, the screen orientation of a mobile device
+ will change based on the device is being held, and a desktop display
+ might be rotated so that it's in portrait mode.
- The primary screen orientation is the orientation that corresponds
- to an un-rotated screen buffer. When the current orientation is equal
- to the primary orientation no rotation needs to be done by the
- application.
+ \sa primaryOrientation(), orientationChanged()
*/
-Qt::ScreenOrientation QScreen::primaryOrientation() const
+Qt::ScreenOrientation QScreen::orientation() const
{
Q_D(const QScreen);
- return d->platformScreen->primaryOrientation();
+ return d->orientation == Qt::PrimaryOrientation ? primaryOrientation() : d->orientation;
}
/*!
\property QScreen::primaryOrientation
- \brief the current screen orientation
+ \brief the primary screen orientation
- The current orientation is a hint to the application saying
- what the preferred application orientation should be, based on the
- current orientation of the physical display and / or other factors.
+ The primary screen orientation is Qt::LandscapeOrientation
+ if the screen geometry's width is greater than or equal to its
+ height, or Qt::PortraitOrientation otherwise.
- \sa primaryOrientation()
- \sa currentOrientationChanged()
+ \sa primaryOrientationChanged()
*/
-Qt::ScreenOrientation QScreen::currentOrientation() const
+Qt::ScreenOrientation QScreen::primaryOrientation() const
{
Q_D(const QScreen);
- return d->currentOrientation;
+ return d->primaryOrientation;
}
// i must be power of two
@@ -393,10 +394,18 @@ static int log2(uint i)
rotation \a a to rotation \a b.
The result will be 0, 90, 180, or 270.
+
+ Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation().
*/
int QScreen::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b)
{
- if (a == Qt::UnknownOrientation || b == Qt::UnknownOrientation || a == b)
+ if (a == Qt::PrimaryOrientation)
+ a = primaryOrientation();
+
+ if (b == Qt::PrimaryOrientation)
+ b = primaryOrientation();
+
+ if (a == b)
return 0;
int ia = log2(uint(a));
@@ -420,10 +429,18 @@ int QScreen::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b)
the resulting transform will be such that the point QPoint(0, 0) is mapped to QPoint(0, w),
and QPoint(h, w) is mapped to QPoint(0, h). Thus, the landscape coordinate system QRect(0, 0, h, w)
is mapped (with a 90 degree rotation) into the portrait coordinate system QRect(0, 0, w, h).
+
+ Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation().
*/
QTransform QScreen::transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &target)
{
- if (a == Qt::UnknownOrientation || b == Qt::UnknownOrientation || a == b)
+ if (a == Qt::PrimaryOrientation)
+ a = primaryOrientation();
+
+ if (b == Qt::PrimaryOrientation)
+ b = primaryOrientation();
+
+ if (a == b)
return QTransform();
int angle = angleBetween(a, b);
@@ -453,10 +470,18 @@ QTransform QScreen::transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientat
This will flip the x and y dimensions of the rectangle if orientation \a is
Qt::PortraitOrientation or Qt::InvertedPortraitOrientation and orientation \b is
Qt::LandscapeOrientation or Qt::InvertedLandscapeOrientation, or vice versa.
+
+ Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation().
*/
QRect QScreen::mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &rect)
{
- if (a == Qt::UnknownOrientation || b == Qt::UnknownOrientation || a == b)
+ if (a == Qt::PrimaryOrientation)
+ a = primaryOrientation();
+
+ if (b == Qt::PrimaryOrientation)
+ b = primaryOrientation();
+
+ if (a == b)
return rect;
if ((a == Qt::PortraitOrientation || a == Qt::InvertedPortraitOrientation)
@@ -469,14 +494,50 @@ QRect QScreen::mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, cons
}
/*!
- \fn QScreen::currentOrientationChanged(Qt::ScreenOrientation orientation)
+ Convenience function to check if a screen orientation is either portrait
+ or inverted portrait.
- This signal is emitted when the current orientation of the screen
- changes. The current orientation is a hint to the application saying
- what the preferred application orientation should be, based on the
- current orientation of the physical display and / or other factors.
+ Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation().
+*/
+bool QScreen::isPortrait(Qt::ScreenOrientation o)
+{
+ return o == Qt::PortraitOrientation || o == Qt::InvertedPortraitOrientation
+ || (o == Qt::PrimaryOrientation && primaryOrientation() == Qt::PortraitOrientation);
+}
- \sa currentOrientation()
+/*!
+ Convenience function to check if a screen orientation is either landscape
+ or inverted landscape.
+
+ Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation().
+*/
+bool QScreen::isLandscape(Qt::ScreenOrientation o)
+{
+ return o == Qt::LandscapeOrientation || o == Qt::InvertedLandscapeOrientation
+ || (o == Qt::PrimaryOrientation && primaryOrientation() == Qt::LandscapeOrientation);
+}
+
+/*!
+ \fn QScreen::orientationChanged(Qt::ScreenOrientation orientation)
+
+ This signal is emitted when the orientation of the screen
+ changes.
+
+ \sa orientation()
*/
+/*!
+ \fn QScreen::primaryOrientationChanged(Qt::ScreenOrientation orientation)
+
+ This signal is emitted when the primary orientation of the screen
+ changes.
+
+ \sa primaryOrientation()
+*/
+
+void QScreenPrivate::updatePrimaryOrientation()
+{
+ primaryOrientation = geometry.width() >= geometry.height() ? Qt::LandscapeOrientation : Qt::PortraitOrientation;
+}
+
QT_END_NAMESPACE