summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios/qiosscreen.mm
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@digia.com>2013-02-26 13:49:03 +0100
committerTor Arne Vestbø <tor.arne.vestbo@digia.com>2013-02-27 23:55:54 +0100
commitd5d3f5ea8e6620e1ae06488a9e35a36550367726 (patch)
tree033b06155761631d19dd5947defaaec8811a626e /src/plugins/platforms/ios/qiosscreen.mm
parent70b21ec3c12c655354676778e087182f20aadbb1 (diff)
iOS: let QIOSScreen change geometry according to interface rotation
Qt expects the screen to change geometry when the "desktop" rotates. On iOS, we interpret this as when the root view controller changes orientation, since after all, this is the surface we place QWindows on top of. Change-Id: Ia00e68c8f9f0a65aefcc60518ee544fb260d4595 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
Diffstat (limited to 'src/plugins/platforms/ios/qiosscreen.mm')
-rw-r--r--src/plugins/platforms/ios/qiosscreen.mm32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm
index 00deaa2fc0..f4cade2e6d 100644
--- a/src/plugins/platforms/ios/qiosscreen.mm
+++ b/src/plugins/platforms/ios/qiosscreen.mm
@@ -88,11 +88,12 @@ QIOSScreen::QIOSScreen(unsigned int screenIndex)
unscaledDpi = 132;
};
- // UIScreen does not report different bounds for different orientations. We
- // match this behavior by staying with a fixed QScreen geometry.
CGRect bounds = [m_uiScreen bounds];
m_geometry = QRect(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height);
+ CGRect frame = m_uiScreen.applicationFrame;
+ m_availableGeometry = QRect(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
+
const qreal millimetersPerInch = 25.4;
m_physicalSize = QSizeF(m_geometry.size()) / unscaledDpi * millimetersPerInch;
@@ -111,8 +112,7 @@ QRect QIOSScreen::geometry() const
QRect QIOSScreen::availableGeometry() const
{
- CGRect frame = m_uiScreen.applicationFrame;
- return QRect(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
+ return m_availableGeometry;
}
int QIOSScreen::depth() const
@@ -150,6 +150,30 @@ void QIOSScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask)
}
}
+void QIOSScreen::setPrimaryOrientation(Qt::ScreenOrientation orientation)
+{
+ // Note that UIScreen never changes orientation, but QScreen should. To work around
+ // this, we let QIOSViewController call us whenever interface orientation changes, and
+ // use that as primary orientation. After all, the viewcontrollers geometry is what we
+ // place QWindows on top of. A problem with this approach is that QIOSViewController is
+ // not in use in a mixed environment, which results in no change to primary orientation.
+ // We see that as acceptable since Qt should most likely not interfere with orientation
+ // for that case anyway.
+ bool portrait = screen()->isPortrait(orientation);
+ if (portrait && m_geometry.width() < m_geometry.height())
+ return;
+
+ // Switching portrait/landscape means swapping width/height (and adjusting x/y):
+ CGRect frame = m_uiScreen.applicationFrame;
+ m_availableGeometry = portrait ? QRect(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height)
+ : QRect(frame.origin.y, m_geometry.width() - frame.size.width - frame.origin.x, frame.size.height, frame.size.width);
+ m_geometry = QRect(0, 0, m_geometry.height(), m_geometry.width());
+ m_physicalSize = QSizeF(m_physicalSize.height(), m_physicalSize.width());
+
+ QWindowSystemInterface::handleScreenGeometryChange(screen(), m_geometry);
+ QWindowSystemInterface::handleScreenAvailableGeometryChange(screen(), m_availableGeometry);
+}
+
UIScreen *QIOSScreen::uiScreen() const
{
return m_uiScreen;