iOS: add convenience function to get to the root QIOSViewController

It seems that we need to access our view controller from many
places, and the syntax to do so is tricky to remember. So lets
just add it to our global functions, with the added bonus of a
using a little cache.

Note: many of these functions could be made inline, but since one
concern of the plugin will be the end size of the app, I prefer
to trade size for speed at this point. We can always change this
later.

Change-Id: I578ea9ae8218d23d635b7728a930763ca53c4eaa
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
bb10
Richard Moe Gustavsen 2012-12-19 09:15:27 +01:00 committed by Tor Arne Vestbø
parent ac0f6d1a34
commit 2dea9fdc3a
4 changed files with 15 additions and 3 deletions

View File

@ -47,9 +47,13 @@
#import <QtGui/qguiapplication.h>
#import "qiosscreen.h"
@class QIOSViewController;
QT_BEGIN_NAMESPACE
bool isQtApplication();
QIOSViewController *rootViewController();
CGRect toCGRect(const QRect &rect);
QRect fromCGRect(const CGRect &rect);
Qt::ScreenOrientation toQtScreenOrientation(UIDeviceOrientation uiDeviceOrientation);

View File

@ -41,6 +41,7 @@
#include "qiosglobal.h"
#include "qiosapplicationdelegate.h"
#include "qiosviewcontroller.h"
#include <QtGui/qscreen.h>
QT_BEGIN_NAMESPACE
@ -57,6 +58,13 @@ bool isQtApplication()
return isQt;
}
QIOSViewController *rootViewController()
{
static QIOSViewController *c = isQtApplication() ?
static_cast<QIOSViewController *>([UIApplication sharedApplication].delegate.window.rootViewController) : nil;
return c;
}
CGRect toCGRect(const QRect &rect)
{
return CGRectMake(rect.x(), rect.y(), rect.width(), rect.height());

View File

@ -44,6 +44,7 @@
#include "qioswindow.h"
#include <qpa/qwindowsysteminterface.h>
#include "qiosapplicationdelegate.h"
#include "qiosviewcontroller.h"
#include <sys/sysctl.h>
@ -141,8 +142,7 @@ QIOSScreen::QIOSScreen(unsigned int screenIndex)
if (isQtApplication()) {
// When in a non-mixed environment, let QScreen follow the current interface orientation:
UIViewController *controller = [UIApplication sharedApplication].delegate.window.rootViewController;
setPrimaryOrientation(toQtScreenOrientation(controller.interfaceOrientation));
setPrimaryOrientation(toQtScreenOrientation(rootViewController().interfaceOrientation));
}
[pool release];

View File

@ -197,7 +197,7 @@ QIOSWindow::QIOSWindow(QWindow *window)
, m_devicePixelRatio(1.0)
{
if (isQtApplication())
[[UIApplication sharedApplication].delegate.window.rootViewController.view addSubview:m_view];
[rootViewController().view addSubview:m_view];
setWindowState(window->windowState());