From 55f0bce0945a2f2b28e2454fbc03b1efd61819e4 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Fri, 16 Nov 2012 11:14:34 +0100 Subject: iOS: implement requestWindowOrientation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The application is normally supposed to rotate the content on its own, but can call requestWindowOrientation to ask the window manager to do it instead. This way of integrating orientation with the OS is fragile, because: 1. In some cases, you cannot stop the OS from rotating at all (tablets). 2. It would be more safe to inform the window manager up-front which orientations it could rotate into, rather that relying on a function you call call to force this later on. 3. When the QML application starts, its a bit late to inform the platform plugin that it supports e.g landscape. If the OS is in landscape already, the plugin must still assume that the app operates in portrait (doing rotating on its own) until requestWindowOrientation is called. This might cause the app to first start up in portrait, just to rotate into landscape. On iOS, it seems like we can handle the first two cases. The third need some more investigation. We should anyway investigate if we need some adjustment to the Qt API. Change-Id: I50638b78d469ab70820a787de86a2f1981470786 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qiosviewcontroller.h | 8 +++++++- src/plugins/platforms/ios/qiosviewcontroller.mm | 26 ++++++++++++++++++++++--- src/plugins/platforms/ios/qioswindow.h | 1 + src/plugins/platforms/ios/qioswindow.mm | 17 ++++++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) (limited to 'src/plugins/platforms/ios') diff --git a/src/plugins/platforms/ios/qiosviewcontroller.h b/src/plugins/platforms/ios/qiosviewcontroller.h index d5a61cb3f4..780ec7adab 100644 --- a/src/plugins/platforms/ios/qiosviewcontroller.h +++ b/src/plugins/platforms/ios/qiosviewcontroller.h @@ -40,7 +40,13 @@ ****************************************************************************/ #import +#import -@interface QIOSViewController : UIViewController +@interface QIOSViewController : UIViewController { +@public + bool m_shouldAutorotate; +} + +-(bool)rotateToDeviceOrientation; @end diff --git a/src/plugins/platforms/ios/qiosviewcontroller.mm b/src/plugins/platforms/ios/qiosviewcontroller.mm index 5381b3a21e..8b1a085cc5 100644 --- a/src/plugins/platforms/ios/qiosviewcontroller.mm +++ b/src/plugins/platforms/ios/qiosviewcontroller.mm @@ -43,12 +43,32 @@ @implementation QIOSViewController -- (BOOL)shouldAutorotate +-(id)init { - return NO; + self = [super init]; + if (self) { + m_shouldAutorotate = NO; + } + return self; } -- (NSUInteger)supportedInterfaceOrientations +-(bool)rotateToDeviceOrientation +{ + if ([UIViewController respondsToSelector:@selector(attemptRotationToDeviceOrientation)]) { + m_shouldAutorotate = YES; + [UIViewController attemptRotationToDeviceOrientation]; + m_shouldAutorotate = NO; + return true; + } + return false; +} + +-(BOOL)shouldAutorotate +{ + return m_shouldAutorotate; +} + +-(NSUInteger)supportedInterfaceOrientations { // We need to tell iOS that we support all orientations in order to set // status bar orientation when application content orientation changes. diff --git a/src/plugins/platforms/ios/qioswindow.h b/src/plugins/platforms/ios/qioswindow.h index b20c1c4fc5..e4c3a6a17c 100644 --- a/src/plugins/platforms/ios/qioswindow.h +++ b/src/plugins/platforms/ios/qioswindow.h @@ -87,6 +87,7 @@ public: void setWindowState(Qt::WindowState state); void handleContentOrientationChange(Qt::ScreenOrientation orientation); + Qt::ScreenOrientation requestWindowOrientation(Qt::ScreenOrientation orientation); GLuint framebufferObject(const QIOSContext &context) const; diff --git a/src/plugins/platforms/ios/qioswindow.mm b/src/plugins/platforms/ios/qioswindow.mm index e220312d15..c1f14f22ef 100644 --- a/src/plugins/platforms/ios/qioswindow.mm +++ b/src/plugins/platforms/ios/qioswindow.mm @@ -44,6 +44,7 @@ #include "qiosscreen.h" #include "qiosapplicationdelegate.h" #include "qiosorientationlistener.h" +#include "qiosviewcontroller.h" #import @@ -257,6 +258,22 @@ void QIOSWindow::handleContentOrientationChange(Qt::ScreenOrientation orientatio [[UIApplication sharedApplication] setStatusBarOrientation:uiOrientation animated:NO]; } +Qt::ScreenOrientation QIOSWindow::requestWindowOrientation(Qt::ScreenOrientation orientation) +{ + if (!m_view.window) + return Qt::PortraitOrientation; + UIViewController *viewController = m_view.window.rootViewController; + if (!viewController || [viewController isKindOfClass:[QIOSViewController class]] == false) { + return convertToQtOrientation(viewController.interfaceOrientation); + } else { + QIOSViewController *qiosViewController = static_cast(viewController); + if ([qiosViewController rotateToDeviceOrientation]) + return orientation; + else + return convertToQtOrientation(viewController.interfaceOrientation); + } +} + GLuint QIOSWindow::framebufferObject(const QIOSContext &context) const { static GLuint framebuffer = 0; -- cgit v1.2.3