summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@digia.com>2015-01-16 17:50:34 +0100
committerTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2015-01-23 03:05:17 +0100
commitd24cfc8b86898ffcee7fcd05f4b29476497c9176 (patch)
tree3eec656cd558df7fe5d90fe73e196d3db2d1156e
parentd4fd619b1088f885878381508918d933c7c226e1 (diff)
iOS: Decouple screen geometry calculations from UIWindow geometry
At startup or when a new UIWindow has been created but not associated with a UIScreen yet, its geometry will be invalid, and cause the wrong geometry for its corresponding QScreen when we use it to map geometry. Instead we explicitly use the status bar orientation to map to the correct geometry. Change-Id: If37b3ab2ad5db65e20a7e3af5c3854b3e3ddff0d Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@theqtcompany.com> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
-rw-r--r--src/plugins/platforms/ios/qiosscreen.mm31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm
index a7d8149fb7..9087cc0ec5 100644
--- a/src/plugins/platforms/ios/qiosscreen.mm
+++ b/src/plugins/platforms/ios/qiosscreen.mm
@@ -230,22 +230,31 @@ void QIOSScreen::updateProperties()
QRect previousGeometry = m_geometry;
QRect previousAvailableGeometry = m_availableGeometry;
- UIView *rootView = m_uiWindow.rootViewController.view;
+ m_geometry = fromCGRect(m_uiScreen.bounds).toRect();
+ m_availableGeometry = fromCGRect(m_uiScreen.applicationFrame).toRect();
- m_geometry = fromCGRect([rootView convertRect:m_uiScreen.bounds fromView:m_uiWindow]).toRect();
- m_availableGeometry = fromCGRect([rootView convertRect:m_uiScreen.applicationFrame fromView:m_uiWindow]).toRect();
+ Qt::ScreenOrientation statusBarOrientation = toQtScreenOrientation(UIDeviceOrientation([UIApplication sharedApplication].statusBarOrientation));
- if (QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_8_0 && ![m_uiWindow.rootViewController shouldAutorotate]) {
- // Setting the statusbar orientation (content orientation) on iOS8+ will result in the UIScreen
- // updating its geometry and available geometry, which in the case of content orientation is not
- // what we want. We want to reflect the screen geometry based on the locked orientation, and
- // adjust the available geometry based on the repositioned status bar for the current status
+ if (QSysInfo::MacintoshVersion < QSysInfo::MV_IOS_8_0) {
+ // On iOS < 8.0 the UIScreen geometry is always in portait, and the system applies
+ // the screen rotation to the root view-controller's view instead of directly to the
+ // screen, like iOS 8 and above does.
+ m_geometry = mapBetween(Qt::PortraitOrientation, statusBarOrientation, m_geometry);
+ m_availableGeometry = transformBetween(Qt::PortraitOrientation, statusBarOrientation, m_geometry).mapRect(m_availableGeometry);
+ }
+
+ if (![m_uiWindow.rootViewController shouldAutorotate]) {
+ // Setting the statusbar orientation (content orientation) on will affect the screen geometry,
+ // which is not what we want. We want to reflect the screen geometry based on the locked orientation,
+ // and adjust the available geometry based on the repositioned status bar for the current status
// bar orientation.
- Qt::ScreenOrientation lockedOrientation = toQtScreenOrientation(UIDeviceOrientation(rootView.qtViewController.lockedOrientation));
- Qt::ScreenOrientation contenOrientation = toQtScreenOrientation(UIDeviceOrientation([UIApplication sharedApplication].statusBarOrientation));
+ // FIXME: Handle hybrid apps by eg. observing changes to the shouldAutorotate property
+ Q_ASSERT([m_uiWindow.rootViewController isKindOfClass:[QIOSViewController class]]);
+ QIOSViewController *qtViewController = static_cast<QIOSViewController *>(m_uiWindow.rootViewController);
- QTransform transform = screen()->transformBetween(lockedOrientation, contenOrientation, m_geometry).inverted();
+ Qt::ScreenOrientation lockedOrientation = toQtScreenOrientation(UIDeviceOrientation(qtViewController.lockedOrientation));
+ QTransform transform = transformBetween(lockedOrientation, statusBarOrientation, m_geometry).inverted();
m_geometry = transform.mapRect(m_geometry);
m_availableGeometry = transform.mapRect(m_availableGeometry);