iOS: create top-level UIWindow and UIViewController

Create a UIWIndow with a view controller and a view
where we can reparent our QIOSWindow views inside.

Change-Id: Ic90707d3ebe1af970a3aa2aa0f8c0f4be192456a
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
bb10
Richard Moe Gustavsen 2012-11-07 09:31:00 +01:00 committed by Tor Arne Vestbø
parent 09187f602c
commit 19de726725
2 changed files with 24 additions and 0 deletions

View File

@ -40,6 +40,7 @@
****************************************************************************/
#import "qiosapplicationdelegate.h"
#include "qioswindow.h"
#include <QtCore/QtCore>
@implementation QIOSApplicationDelegate
@ -48,7 +49,24 @@
{
Q_UNUSED(application)
Q_UNUSED(launchOptions)
// If this application delegate is instanciated, it means that
// this plugin also created UIApplication. We then also create a
// window with a view controller, and set all QWindow views
// as children of the controller view:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *controller = [[UIViewController alloc] init];
self.window.rootViewController = controller;
controller.view = [[UIView alloc] init];
QWindowList windows = QGuiApplication::topLevelWindows();
for (int i=0; i<windows.size(); ++i) {
if (QIOSWindow *w = static_cast<QIOSWindow *>(windows[i]->handle())) {
UIView *winView = w->nativeView();
if (winView && !winView.superview)
[controller.view addSubview:winView];
}
}
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];

View File

@ -42,6 +42,7 @@
#include "qioswindow.h"
#include "qioscontext.h"
#include "qiosscreen.h"
#include "qiosapplicationdelegate.h"
#import <QuartzCore/CAEAGLLayer.h>
@ -170,6 +171,11 @@ QIOSWindow::QIOSWindow(QWindow *window)
: QPlatformWindow(window)
, m_view([[EAGLView alloc] init])
{
UIApplication *uiApplication = [UIApplication sharedApplication];
if (uiApplication) {
if ([uiApplication.delegate isMemberOfClass:[QIOSApplicationDelegate class]])
[uiApplication.delegate.window.rootViewController.view addSubview:m_view];
}
}
QIOSWindow::~QIOSWindow()