diff options
author | Morten Johan Sørvig <morten.sorvig@digia.com> | 2015-01-27 14:13:39 +0100 |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@theqtcompany.com> | 2015-04-30 05:04:07 +0000 |
commit | 795400d1e5bc73769de990c69d6c864f7b148b85 (patch) | |
tree | 5e8bce58074679fac3568caccfb6338d0f458ec0 /tests/manual/cocoa/qt_on_cocoa/main.mm | |
parent | 737eccf1ef3c0d8811aecdbccf8eead210e76335 (diff) |
Clean up qt_on_cocoa manual test.
Focus the test on embedding QWindow: Remove the
NSToolBar code. Use standard NSApplication startup
code. Use winId() to access the NSView instead of
QPlatformNativeInterface (which is gui-private).
Rename Window -> RasterWindow.
Change-Id: Ie98cb73020d2721743bb665b89b17f07f2bf984b
Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
Diffstat (limited to 'tests/manual/cocoa/qt_on_cocoa/main.mm')
-rw-r--r-- | tests/manual/cocoa/qt_on_cocoa/main.mm | 168 |
1 files changed, 31 insertions, 137 deletions
diff --git a/tests/manual/cocoa/qt_on_cocoa/main.mm b/tests/manual/cocoa/qt_on_cocoa/main.mm index 5dd546479e..23370b0305 100644 --- a/tests/manual/cocoa/qt_on_cocoa/main.mm +++ b/tests/manual/cocoa/qt_on_cocoa/main.mm @@ -31,123 +31,35 @@ ** ****************************************************************************/ -#include <QtGui> -#include <QtDeclarative> +#include "rasterwindow.h" +#include <QtGui> #include <QtWidgets/QtWidgets> -#include <private/qwidgetwindow_p.h> -#include <QtGui/qpa/qplatformnativeinterface.h> - -#include <QtGui/QPixmap> - -#include "window.h" #include <Cocoa/Cocoa.h> - -@interface FilledView : NSView -{ - +@interface AppDelegate : NSObject <NSApplicationDelegate> { + QGuiApplication *m_app; + QWindow *m_window; } +- (AppDelegate *) initWithArgc:(int)argc argv:(const char **)argv; +- (void) applicationWillFinishLaunching: (NSNotification *)notification; +- (void)applicationWillTerminate:(NSNotification *)notification; @end -@implementation FilledView - -- (void)drawRect:(NSRect)dirtyRect { - // set any NSColor for filling, say white: - [[NSColor redColor] setFill]; - NSRectFill(dirtyRect); -} - -@end - -@interface QtMacToolbarDelegate : NSObject <NSToolbarDelegate> +@implementation AppDelegate +- (AppDelegate *) initWithArgc:(int)argc argv:(const char **)argv { -@public - NSToolbar *toolbar; -} - -- (id)init; -- (NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier: (NSString *) itemIdent willBeInsertedIntoToolbar:(BOOL) willBeInserted; -- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)tb; -- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar; -- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar; -@end - -@implementation QtMacToolbarDelegate - -- (id)init -{ - self = [super init]; - if (self) { - } + m_app = new QGuiApplication(argc, const_cast<char **>(argv)); return self; } -- (void)dealloc -{ - [super dealloc]; -} - -- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)tb -{ - Q_UNUSED(tb); - NSMutableArray *array = [[[NSMutableArray alloc] init] autorelease]; -// [array addObject : NSToolbarPrintItemIdentifier]; -// [array addObject : NSToolbarShowColorsItemIdentifier]; - [array addObject : @"filledView"]; - return array; -} - -- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)tb -{ - Q_UNUSED(tb); - NSMutableArray *array = [[[NSMutableArray alloc] init] autorelease]; -// [array addObject : NSToolbarPrintItemIdentifier]; -// [array addObject : NSToolbarShowColorsItemIdentifier]; - [array addObject : @"filledView"]; - return array; -} - -- (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar *)tb -{ - Q_UNUSED(tb); - NSMutableArray *array = [[[NSMutableArray alloc] init] autorelease]; - return array; -} - -- (IBAction)itemClicked:(id)sender +- (void) applicationWillFinishLaunching: (NSNotification *)notification { + Q_UNUSED(notification); -} - -- (NSToolbarItem *) toolbar: (NSToolbar *)tb itemForItemIdentifier: (NSString *) itemIdentifier willBeInsertedIntoToolbar:(BOOL) willBeInserted -{ - Q_UNUSED(tb); - Q_UNUSED(willBeInserted); - //const QString identifier = toQString(itemIdentifier); - //NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdentifier] autorelease]; - //return toolbarItem; - - //NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdentifier] autorelease]; - NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdentifier] autorelease]; - FilledView *theView = [[FilledView alloc] init]; - [toolbarItem setView : theView]; - [toolbarItem setMinSize : NSMakeSize(400, 40)]; - [toolbarItem setMaxSize : NSMakeSize(4000, 40)]; - return toolbarItem; -} -@end - -@interface WindowAndViewAndQtCreator : NSObject {} -- (void)createWindowAndViewAndQt; -@end - -@implementation WindowAndViewAndQtCreator -- (void)createWindowAndViewAndQt { - - // Create the window + // Create the NSWindow NSRect frame = NSMakeRect(500, 500, 500, 500); NSWindow* window = [[NSWindow alloc] initWithContentRect:frame styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask @@ -156,49 +68,31 @@ NSString *title = @"This the NSWindow window"; [window setTitle:title]; - [window setBackgroundColor:[NSColor blueColor]]; - // Create a tool bar, set Qt delegate - NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier : @"foobartoolbar"]; - QtMacToolbarDelegate *delegate = [[QtMacToolbarDelegate alloc] init]; - [toolbar setDelegate : delegate]; - [window setToolbar : toolbar]; - - // Create the QWindow, don't show it. - Window *qtWindow = new Window(); - qtWindow->create(); - - //QSGView *qtWindow = new QSGView(); - //qtWindow->setSource(QUrl::fromLocalFile("/Users/msorvig/code/qt5/qtdeclarative/examples/declarative/samegame/samegame.qml")); - // qtWindow->setWindowFlags(Qt::WindowType(13)); // 13: NativeEmbeddedWindow - - // Get the nsview from the QWindow, set it as the content view - // on the NSWindow created above. - QPlatformNativeInterface *platformNativeInterface = QGuiApplication::platformNativeInterface(); - NSView *qtView = (NSView *)platformNativeInterface->nativeResourceForWindow("nsview", qtWindow); - [window setContentView:qtView]; + // Create the QWindow, use its NSView as the content view + m_window = new RasterWindow(); + [window setContentView:reinterpret_cast<NSView *>(m_window->winId())]; + + // Show the NSWindow [window makeKeyAndOrderFront:NSApp]; } -@end -int main(int argc, char *argv[]) +- (void)applicationWillTerminate:(NSNotification *)notification { - QGuiApplication app(argc, argv); - - // fake NSApplicationMain() implementation follows: - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - [NSApplication sharedApplication]; + Q_UNUSED(notification); + delete m_window; + delete m_app; +} - // schedule call to create the UI. - WindowAndViewAndQtCreator *windowAndViewAndQtCreator= [WindowAndViewAndQtCreator alloc]; - [NSTimer scheduledTimerWithTimeInterval:0 target:windowAndViewAndQtCreator selector:@selector(createWindowAndViewAndQt) userInfo:nil repeats:NO]; +@end - [(NSApplication *)NSApp run]; - [NSApp release]; - [pool release]; - exit(0); - return 0; +int main(int argc, const char *argv[]) +{ + // Create NSApplicaiton with delgate + NSApplication *app =[NSApplication sharedApplication]; + app.delegate = [[AppDelegate alloc] initWithArgc:argc argv:argv]; + return NSApplicationMain (argc, argv); } |