diff options
Diffstat (limited to 'tests/manual/cocoa')
-rw-r--r-- | tests/manual/cocoa/qt_on_cocoa/main.mm | 50 | ||||
-rw-r--r-- | tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp | 32 | ||||
-rw-r--r-- | tests/manual/cocoa/qt_on_cocoa/rasterwindow.h | 3 |
3 files changed, 59 insertions, 26 deletions
diff --git a/tests/manual/cocoa/qt_on_cocoa/main.mm b/tests/manual/cocoa/qt_on_cocoa/main.mm index 4ec1ce1e0d..805ef0d7c2 100644 --- a/tests/manual/cocoa/qt_on_cocoa/main.mm +++ b/tests/manual/cocoa/qt_on_cocoa/main.mm @@ -33,6 +33,23 @@ #include <AppKit/AppKit.h> + +@interface ContentView : NSView +@end + +@implementation ContentView +- (void)drawRect:(NSRect)dirtyRect { + [[NSColor whiteColor] setFill]; + NSRectFill(dirtyRect); +} + +- (void)cursorUpdate:(NSEvent *)theEvent +{ + Q_UNUSED(theEvent); + [[NSCursor pointingHandCursor] set]; +} +@end + @interface AppDelegate : NSObject <NSApplicationDelegate> { QGuiApplication *m_app; QWindow *m_window; @@ -65,12 +82,35 @@ [window setTitle:title]; [window setBackgroundColor:[NSColor blueColor]]; - // Create the QWindow, use its NSView as the content view - m_window = new RasterWindow(); - [window setContentView:reinterpret_cast<NSView *>(m_window->winId())]; + NSView *contentView = [[[ContentView alloc] initWithFrame:frame] autorelease]; + [contentView addTrackingArea:[[NSTrackingArea alloc] initWithRect:[contentView frame] + options:NSTrackingActiveInActiveApp | NSTrackingInVisibleRect | NSTrackingCursorUpdate + owner:contentView userInfo:nil]]; + + // Create the QWindow, add its NSView to the content view + m_window = new RasterWindow; + m_window->setObjectName("RasterWindow"); + m_window->setCursor(Qt::CrossCursor); + m_window->setGeometry(QRect(0, 0, 300, 300)); + + QWindow *childWindow = new RasterWindow; + childWindow->setObjectName("RasterWindowChild"); + childWindow->setParent(m_window); + childWindow->setCursor(Qt::BusyCursor); + childWindow->setGeometry(50, 50, 100, 100); + + NSTextField *textField = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 10, 80, 25)]; + [(NSView*)childWindow->winId() addSubview:textField]; + + [contentView addSubview:reinterpret_cast<NSView *>(m_window->winId())]; + + window.contentView = contentView; - // Show the NSWindow - [window makeKeyAndOrderFront:NSApp]; + // Show the NSWindow delayed, so that we can verify that Qt picks up the right + // notifications to expose the window when it does become visible. + dispatch_async(dispatch_get_main_queue(), ^{ + [window makeKeyAndOrderFront:NSApp]; + }); } - (void)applicationWillTerminate:(NSNotification *)notification diff --git a/tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp b/tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp index ca09af9964..6d7cb3e305 100644 --- a/tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp +++ b/tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp @@ -52,17 +52,6 @@ RasterWindow::RasterWindow(QRasterWindow *parent) void RasterWindow::initialize() { - if (parent()) - setGeometry(QRect(160, 120, 320, 240)); - else { - setGeometry(QRect(10, 10, 640, 480)); - - setSizeIncrement(QSize(10, 10)); - setBaseSize(QSize(640, 480)); - setMinimumSize(QSize(240, 160)); - setMaximumSize(QSize(800, 600)); - } - create(); m_backingStore = new QBackingStore(this); @@ -70,12 +59,12 @@ void RasterWindow::initialize() m_image.fill(colorTable[m_backgroundColorIndex % (sizeof(colorTable) / sizeof(colorTable[0]))].rgba()); m_lastPos = QPoint(-1, -1); - m_renderTimer = 0; } void RasterWindow::mousePressEvent(QMouseEvent *event) { m_lastPos = event->pos(); + unsetCursor(); } void RasterWindow::mouseMoveEvent(QMouseEvent *event) @@ -104,7 +93,7 @@ void RasterWindow::mouseReleaseEvent(QMouseEvent *event) void RasterWindow::exposeEvent(QExposeEvent *) { - scheduleRender(); + render(); } void RasterWindow::resizeEvent(QResizeEvent *) @@ -146,19 +135,24 @@ void RasterWindow::keyPressEvent(QKeyEvent *event) void RasterWindow::scheduleRender() { - if (!m_renderTimer) - m_renderTimer = startTimer(1); + requestUpdate(); } -void RasterWindow::timerEvent(QTimerEvent *) +bool RasterWindow::event(QEvent *e) { - render(); - killTimer(m_renderTimer); - m_renderTimer = 0; + if (e->type() == QEvent::UpdateRequest) + render(); + + return QWindow::event(e); } void RasterWindow::render() { + if (!isExposed()) { + qDebug() << "Skipping render, not exposed"; + return; + } + QRect rect(QPoint(), geometry().size()); m_backingStore->resize(rect.size()); diff --git a/tests/manual/cocoa/qt_on_cocoa/rasterwindow.h b/tests/manual/cocoa/qt_on_cocoa/rasterwindow.h index eff2addb70..5262300b12 100644 --- a/tests/manual/cocoa/qt_on_cocoa/rasterwindow.h +++ b/tests/manual/cocoa/qt_on_cocoa/rasterwindow.h @@ -44,7 +44,7 @@ protected: void exposeEvent(QExposeEvent *); void resizeEvent(QResizeEvent *); - void timerEvent(QTimerEvent *); + bool event(QEvent *); private: void render(); @@ -56,5 +56,4 @@ private: QPoint m_lastPos; int m_backgroundColorIndex; QBackingStore *m_backingStore; - int m_renderTimer; }; |