diff options
author | Norwegian Rock Cat <qt-info@nokia.com> | 2009-04-15 10:11:39 (GMT) |
---|---|---|
committer | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-04-15 16:14:17 (GMT) |
commit | aa082287ab51dd42c749e92431527c69f6adc078 (patch) | |
tree | 5e49e37c1eb4411ed03b6ceec7af1543937c44ba /src | |
parent | 87a19963529a3974ae5fda3822c49cdc9a973a93 (diff) | |
download | Qt-aa082287ab51dd42c749e92431527c69f6adc078.zip Qt-aa082287ab51dd42c749e92431527c69f6adc078.tar.gz Qt-aa082287ab51dd42c749e92431527c69f6adc078.tar.bz2 |
BT: Fix Cocoa bug w/OpenGL widgets in dock widgets would disappear.
The NSOpenGLContext seems to be tied to the window. So if the view
changes from one window to another, the OpenGL context needs to be
cleared. We can do this by hooking into the viewWillChangeWindow and
viewDidChangeWindow events and clear and reset the drawable
respectively. We also found out that QCocoaOpenGLView was not being used
at all, so just remove it to get rid of any confusion.
Task-number: 250066
Reviewed-by: Trond
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qcoreevent.h | 1 | ||||
-rw-r--r-- | src/gui/kernel/qcocoaview_mac.mm | 21 | ||||
-rw-r--r-- | src/opengl/qgl.cpp | 4 | ||||
-rw-r--r-- | src/opengl/qgl_mac.mm | 28 | ||||
-rw-r--r-- | src/opengl/qgl_p.h | 1 |
5 files changed, 32 insertions, 23 deletions
diff --git a/src/corelib/kernel/qcoreevent.h b/src/corelib/kernel/qcoreevent.h index 5487703..fa472e6 100644 --- a/src/corelib/kernel/qcoreevent.h +++ b/src/corelib/kernel/qcoreevent.h @@ -264,6 +264,7 @@ public: GrabKeyboard = 188, UngrabKeyboard = 189, CocoaRequestModal = 190, // Internal for requesting an application modal Cocoa Window + MacGLClearDrawable = 191, // Internal Cocoa, the window has changed, so we must clear // 512 reserved for Qt Jambi's MetaCall event // 513 reserved for Qt Jambi's DeleteOnMainThread event diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm index 118d54c..670226b 100644 --- a/src/gui/kernel/qcocoaview_mac.mm +++ b/src/gui/kernel/qcocoaview_mac.mm @@ -946,6 +946,27 @@ extern "C" { } } +- (void)viewWillMoveToWindow:(NSWindow *)window +{ + if (qwidget->windowFlags() & Qt::MSWindowsOwnDC + && (window != [self window])) { // OpenGL Widget + // Create a stupid ClearDrawable Event + QEvent event(QEvent::MacGLClearDrawable); + qApp->sendEvent(qwidget, &event); + } +} + +- (void)viewDidMoveToWindow +{ + if (qwidget->windowFlags() & Qt::MSWindowsOwnDC && [self window]) { + // call update paint event + qwidgetprivate->needWindowChange = true; + QEvent event(QEvent::MacGLWindowChange); + qApp->sendEvent(qwidget, &event); + } +} + + // NSTextInput Protocol implementation - (void) insertText:(id)aString diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 303b5e2..99df658 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -3235,6 +3235,10 @@ bool QGLWidget::event(QEvent *e) update(); } return true; +# if defined(QT_MAC_USE_COCOA) + } else if (e->type() == QEvent::MacGLClearDrawable) { + d->glcx->d_ptr->clearDrawable(); +# endif } #endif diff --git a/src/opengl/qgl_mac.mm b/src/opengl/qgl_mac.mm index 314c659..3dbdaec 100644 --- a/src/opengl/qgl_mac.mm +++ b/src/opengl/qgl_mac.mm @@ -87,29 +87,6 @@ QT_FORWARD_DECLARE_CLASS(QWidget) QT_FORWARD_DECLARE_CLASS(QWidgetPrivate) QT_FORWARD_DECLARE_CLASS(QGLWidgetPrivate) -@interface QT_MANGLE_NAMESPACE(QCocoaOpenGLView) : QT_MANGLE_NAMESPACE(QCocoaView) -{ -} -- (id)initWithQWidget:(QWidget *)widget widgetPrivate:(QWidgetPrivate *)widgetprivate; -@end - -@implementation QT_MANGLE_NAMESPACE(QCocoaOpenGLView) -- (id)initWithQWidget:(QWidget *)widget widgetPrivate:(QWidgetPrivate *)widgetprivate -{ - self = [super initWithQWidget:widget widgetPrivate:widgetprivate]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(_surfaceNeedsUpdate:) - name:NSViewGlobalFrameDidChangeNotification - object:self]; - return self; -} - -- (void) _surfaceNeedsUpdate:(NSNotification*)notification -{ - Q_UNUSED(notification); - static_cast<QGLWidgetPrivate *>(qwidgetprivate)->glcx->updatePaintDevice(); -} -@end QT_BEGIN_NAMESPACE void *qt_current_nsopengl_context() @@ -435,6 +412,11 @@ void *QGLContextPrivate::tryFormat(const QGLFormat &format) #endif } +void QGLContextPrivate::clearDrawable() +{ + [static_cast<NSOpenGLContext *>(cx) clearDrawable]; +} + /*! \bold{Mac OS X only:} This virtual function tries to find a visual that matches the format, reducing the demands if the original request diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index b15eebc..1214f20 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -234,6 +234,7 @@ public: #if defined(Q_WS_MAC) bool update; void *tryFormat(const QGLFormat &format); + void clearDrawable(); #endif QGLFormat glFormat; QGLFormat reqFormat; |