macOS: Update qt_on_cocoa manual test
- Add view to contentView, to allow checking parent view interaction - Render via requestUpdate instead of manual timer - Add two windows to check subview interaction Change-Id: Ib028e62f585d45e42c0429e69ea6f45c8a90fe54 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
parent
fefbed5eae
commit
28414f8e3a
@ -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];
|
||||
|
@ -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()
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user