From c75bc5b532479e8dbe6b7f07dcc5f9fcc915f5c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Thu, 14 Feb 2013 14:08:09 +0100 Subject: iOS: Don't crash on landscape mode startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fromPortraitToPrimary is called from the QIOSScreen constructor. This is probably to early to call QGuiApplication functions. Change-Id: I882304fd641df13dc530491990245ba9ad495377 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qiosglobal.h | 4 +++- src/plugins/platforms/ios/qiosglobal.mm | 4 ++-- src/plugins/platforms/ios/qiosinputcontext.mm | 2 +- src/plugins/platforms/ios/qiosscreen.mm | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/plugins/platforms/ios/qiosglobal.h b/src/plugins/platforms/ios/qiosglobal.h index cd265c0603..3be9f8bb21 100644 --- a/src/plugins/platforms/ios/qiosglobal.h +++ b/src/plugins/platforms/ios/qiosglobal.h @@ -49,6 +49,8 @@ QT_BEGIN_NAMESPACE +class QPlatformScreen; + bool isQtApplication(); QIOSViewController *rootViewController(); @@ -58,7 +60,7 @@ CGPoint toCGPoint(const QPoint &point); QPoint fromCGPoint(const CGPoint &point); Qt::ScreenOrientation toQtScreenOrientation(UIDeviceOrientation uiDeviceOrientation); UIDeviceOrientation fromQtScreenOrientation(Qt::ScreenOrientation qtOrientation); -QRect fromPortraitToPrimary(const QRect &rect); +QRect fromPortraitToPrimary(const QRect &rect, QPlatformScreen *screen); QT_END_NAMESPACE diff --git a/src/plugins/platforms/ios/qiosglobal.mm b/src/plugins/platforms/ios/qiosglobal.mm index 4657b73a10..5860078372 100644 --- a/src/plugins/platforms/ios/qiosglobal.mm +++ b/src/plugins/platforms/ios/qiosglobal.mm @@ -131,11 +131,11 @@ UIDeviceOrientation fromQtScreenOrientation(Qt::ScreenOrientation qtOrientation) return uiOrientation; } -QRect fromPortraitToPrimary(const QRect &rect) +QRect fromPortraitToPrimary(const QRect &rect, QPlatformScreen *screen) { // UIScreen is always in portrait. Use this function to convert CGRects // aligned with UIScreen into whatever is the current orientation of QScreen. - QRect geometry = QGuiApplication::primaryScreen()->handle()->geometry(); + QRect geometry = screen->geometry(); return geometry.width() < geometry.height() ? rect : QRect(rect.y(), geometry.width() - rect.width() - rect.x(), rect.height(), rect.width()); } diff --git a/src/plugins/platforms/ios/qiosinputcontext.mm b/src/plugins/platforms/ios/qiosinputcontext.mm index c0ff3b2531..1d3ab12de9 100644 --- a/src/plugins/platforms/ios/qiosinputcontext.mm +++ b/src/plugins/platforms/ios/qiosinputcontext.mm @@ -83,7 +83,7 @@ CGRect frame; [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&frame]; - m_keyboardRect = fromPortraitToPrimary(fromCGRect(frame)); + m_keyboardRect = fromPortraitToPrimary(fromCGRect(frame), QGuiApplication::primaryScreen()->handle()); m_context->emitKeyboardRectChanged(); BOOL visible = CGRectIntersectsRect(frame, [UIScreen mainScreen].bounds); diff --git a/src/plugins/platforms/ios/qiosscreen.mm b/src/plugins/platforms/ios/qiosscreen.mm index 5cee5a3362..3265ed8e37 100644 --- a/src/plugins/platforms/ios/qiosscreen.mm +++ b/src/plugins/platforms/ios/qiosscreen.mm @@ -224,7 +224,7 @@ void QIOSScreen::setPrimaryOrientation(Qt::ScreenOrientation orientation) // Switching portrait/landscape means swapping width/height (and adjusting x/y): m_geometry = QRect(0, 0, m_geometry.height(), m_geometry.width()); m_physicalSize = QSizeF(m_physicalSize.height(), m_physicalSize.width()); - m_availableGeometry = fromPortraitToPrimary(fromCGRect(m_uiScreen.applicationFrame)); + m_availableGeometry = fromPortraitToPrimary(fromCGRect(m_uiScreen.applicationFrame), this); QWindowSystemInterface::handleScreenGeometryChange(screen(), m_geometry); QWindowSystemInterface::handleScreenAvailableGeometryChange(screen(), m_availableGeometry); -- cgit v1.2.3