diff options
Diffstat (limited to 'tests/manual/cocoa/qt_on_cocoa')
-rw-r--r-- | tests/manual/cocoa/qt_on_cocoa/main.mm | 27 | ||||
-rw-r--r-- | tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp | 26 | ||||
-rw-r--r-- | tests/manual/cocoa/qt_on_cocoa/rasterwindow.h | 3 |
3 files changed, 32 insertions, 24 deletions
diff --git a/tests/manual/cocoa/qt_on_cocoa/main.mm b/tests/manual/cocoa/qt_on_cocoa/main.mm index 4ec1ce1e0d..f99406f619 100644 --- a/tests/manual/cocoa/qt_on_cocoa/main.mm +++ b/tests/manual/cocoa/qt_on_cocoa/main.mm @@ -33,6 +33,17 @@ #include <AppKit/AppKit.h> + +@interface ContentView : NSView +@end + +@implementation ContentView +- (void)drawRect:(NSRect)dirtyRect { + [[NSColor whiteColor] setFill]; + NSRectFill(dirtyRect); +} +@end + @interface AppDelegate : NSObject <NSApplicationDelegate> { QGuiApplication *m_app; QWindow *m_window; @@ -65,9 +76,19 @@ [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())]; + window.contentView = [[[ContentView alloc] initWithFrame:frame] autorelease]; + + // Create the QWindow, add its NSView to the content view + m_window = new RasterWindow; + m_window->setObjectName("RasterWindow"); + m_window->setGeometry(QRect(0, 0, 300, 300)); + + QWindow *childWindow = new RasterWindow; + childWindow->setObjectName("RasterWindowChild"); + childWindow->setParent(m_window); + childWindow->setGeometry(50, 50, 100, 100); + + [window.contentView addSubview:reinterpret_cast<NSView *>(m_window->winId())]; // Show the NSWindow [window makeKeyAndOrderFront:NSApp]; diff --git a/tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp b/tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp index ca09af9964..8a451d5f7c 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,7 +59,6 @@ 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) @@ -104,7 +92,7 @@ void RasterWindow::mouseReleaseEvent(QMouseEvent *event) void RasterWindow::exposeEvent(QExposeEvent *) { - scheduleRender(); + render(); } void RasterWindow::resizeEvent(QResizeEvent *) @@ -146,15 +134,15 @@ 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() 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; }; |