summaryrefslogtreecommitdiffstats
path: root/tests/manual/cocoa/qt_on_cocoa
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/cocoa/qt_on_cocoa')
-rw-r--r--tests/manual/cocoa/qt_on_cocoa/main.mm43
-rw-r--r--tests/manual/cocoa/qt_on_cocoa/rasterwindow.cpp27
-rw-r--r--tests/manual/cocoa/qt_on_cocoa/rasterwindow.h3
3 files changed, 49 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..5e3b8fcd39 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,9 +82,29 @@
[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]];
+
+ window.contentView = contentView;
+
+ // 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];
+
+ [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..dca39839dd 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,15 +135,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;
};