From 7992c2d3a4413082fd40e4099f735d95d522b0f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Wed, 4 Aug 2010 13:48:43 +0200 Subject: Make QWidget::setPlatformWindowFormat recreate platformWindow if the platformWindow is visible. Also had to make sure that the QGLContext of a QGLWidget was recreated. --- src/gui/kernel/qwidget_qpa.cpp | 41 ++++++++++++++-------- src/opengl/qgl_qpa.cpp | 29 +++++++++------ src/plugins/platforms/testlite/qtestlitewindow.cpp | 2 +- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/gui/kernel/qwidget_qpa.cpp b/src/gui/kernel/qwidget_qpa.cpp index ef53004..e11f1fc 100644 --- a/src/gui/kernel/qwidget_qpa.cpp +++ b/src/gui/kernel/qwidget_qpa.cpp @@ -54,22 +54,26 @@ QT_BEGIN_NAMESPACE static QPlatformScreen *qt_screenForWidget(const QWidget *w); -void setParentForChildrenOfWidget(QPlatformWindow *window, const QWidget *widget) +void q_createNativeChildrenAndSetParent(QPlatformWindow *parentWindow, const QWidget *parentWidget) { - QObjectList children = widget->children(); + QObjectList children = parentWidget->children(); for (int i = 0; i < children.size(); i++) { if (children.at(i)->isWidgetType()) { const QWidget *childWidget = qobject_cast(children.at(i)); if (childWidget) { // should not be necessary + if (childWidget->testAttribute(Qt::WA_NativeWindow)) { + if (!childWidget->platformWindow()) + childWidget->winId(); + } if (childWidget->platformWindow()) { - childWidget->platformWindow()->setParent(window); - childWidget->platformWindow()->setWindowFlags(Qt::SubWindow); + childWidget->platformWindow()->setParent(parentWindow); } else { - setParentForChildrenOfWidget(window,childWidget); + q_createNativeChildrenAndSetParent(parentWindow,childWidget); } } } } + } void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow) @@ -79,7 +83,6 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO Q_UNUSED(window); Q_UNUSED(initializeWindow); Q_UNUSED(destroyOldWindow); - // XXX Qt::WindowFlags flags = data.window_flags; @@ -102,12 +105,13 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO setWinId(q->platformWindow()->winId()); - //first check children. then find who for parent. - setParentForChildrenOfWidget(platformWindow,q); + //first check children. and create them if necessary + q_createNativeChildrenAndSetParent(q->platformWindow(),q); + + //if we we have a parent, then set correct parent; if (QWidget *nativeParent = q->nativeParentWidget()) { if (nativeParent->platformWindow()) { platformWindow->setParent(nativeParent->platformWindow()); - platformWindow->setWindowFlags(Qt::SubWindow); } } @@ -143,6 +147,7 @@ void QWidget::destroy(bool destroyWindow, bool destroySubWindows) if (topData) { delete topData->platformWindow; topData->platformWindow = 0; + d->data.winid = 0; } } else { if (parentWidget() && parentWidget()->testAttribute(Qt::WA_WState_Created)) { @@ -176,7 +181,6 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f) QWidget * parentWithWindow = newparent->platformWindow()? newparent : newparent->nativeParentWidget(); if (parentWithWindow && parentWithWindow->platformWindow()) { q->platformWindow()->setParent(parentWithWindow->platformWindow()); - q->platformWindow()->setWindowFlags(Qt::SubWindow); } } @@ -615,7 +619,7 @@ void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) if (isResize) { QResizeEvent e(r.size(), olds); QApplication::sendEvent(q, &e); - if (q->isWindow()) + if (q->platformWindow()) q->update(); } } else { // not visible @@ -743,9 +747,18 @@ QPlatformWindow *QWidget::platformWindow() const void QWidget::setPlatformWindowFormat(const QPlatformWindowFormat &format) { - Q_D(QWidget); - QTLWExtra *topData = d->topData(); - topData->platformWindowFormat = format; + if (isWindow() || testAttribute(Qt::WA_NativeWindow)) { + Q_D(QWidget); + QTLWExtra *topData = d->topData(); + topData->platformWindowFormat = format; + if (testAttribute(Qt::WA_WState_Created)) { + bool wasVisible = testAttribute(Qt::WA_WState_Visible); + destroy(); + d->create_sys(0,true,true); + if (wasVisible) + topData->platformWindow->setVisible(true); + } + } } QPlatformWindowFormat QWidget::platformWindowFormat() const diff --git a/src/opengl/qgl_qpa.cpp b/src/opengl/qgl_qpa.cpp index f859ff1..5e05de1 100644 --- a/src/opengl/qgl_qpa.cpp +++ b/src/opengl/qgl_qpa.cpp @@ -129,11 +129,15 @@ bool QGLContext::chooseContext(const QGLContext* shareContext) if (!widget->platformWindow()){ QGLFormat glformat = format(); QPlatformWindowFormat winFormat = qt_glformat_to_platformwindowformat(glformat); + if (shareContext) { + winFormat.setSharedContext(shareContext->d_func()->platformContext); + } winFormat.setWindowApi(QPlatformWindowFormat::OpenGL); widget->setPlatformWindowFormat(winFormat); widget->winId();//make window } d->platformContext = widget->platformWindow()->glContext(); + Q_ASSERT(d->platformContext); d->glFormat = qt_platformwindowformat_to_glformat(d->platformContext->platformWindowFormat()); d->valid =(bool) d->platformContext; } @@ -147,14 +151,6 @@ void QGLContext::reset() if (!d->valid) return; d->cleanup(); - doneCurrent(); - - if (d->platformContext) { - if (d->paintDevice && d->paintDevice->devType() == QInternal::Widget) { - QWidget *widget = static_cast(d->paintDevice); - widget->destroy(); - } - } d->crWin = false; d->sharing = false; @@ -204,8 +200,6 @@ void QGLWidget::setContext(QGLContext *context, return; } - if (d->glcx) - d->glcx->doneCurrent(); QGLContext* oldcx = d->glcx; d->glcx = context; @@ -286,11 +280,26 @@ void QGLWidget::setMouseTracking(bool enable) bool QGLWidget::event(QEvent *e) { + Q_D(QGLWidget); + if (e->type() == QEvent::WinIdChange) { + if (d->glcx->isValid()) { + if (QGLContext::currentContext() == d->glcx) + QGLContextPrivate::setCurrentContext(0); //Its not valid anymore + setContext(new QGLContext(d->glcx->requestedFormat(), this)); + + } + } return QWidget::event(e); } void QGLWidget::resizeEvent(QResizeEvent *e) { + Q_D(QGLWidget); + if (!isValid()) + return; + if (!d->glcx->initialized()) + glInit(); + resizeGL(width(), height()); return QWidget::resizeEvent(e); } diff --git a/src/plugins/platforms/testlite/qtestlitewindow.cpp b/src/plugins/platforms/testlite/qtestlitewindow.cpp index 67ec97c..fd02bc4 100644 --- a/src/plugins/platforms/testlite/qtestlitewindow.cpp +++ b/src/plugins/platforms/testlite/qtestlitewindow.cpp @@ -206,11 +206,11 @@ QTestLiteWindow::~QTestLiteWindow() #ifdef MYX11_DEBUG qDebug() << "~QTestLiteWindow" << hex << x_window; #endif + delete mGLContext; XFreeGC(xd->display, gc); XDestroyWindow(xd->display, x_window); xd->windowList.removeAll(this); - delete mGLContext; } -- cgit v0.12