aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Olav Tvete <paul.tvete@digia.com>2014-03-06 13:57:39 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-07 16:55:12 +0100
commitfdefb96476847a8fd8b7a074016b6de25f87eb95 (patch)
treeba86e527d0d8f64f4156a27893bcb8136fd8bde8 /src
parentb287d58b3937160b30388f29410df0f14bb0d778 (diff)
QQuickWidget: handle windowChange
When the toplevel window changes, QQuickWidget needs to recreate the context so it is compatible with the new window. Change-Id: Ic7c3410061a33f223e20e3d1f93437917abcff18 Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/quickwidgets/qquickwidget.cpp29
-rw-r--r--src/quickwidgets/qquickwidget_p.h4
2 files changed, 28 insertions, 5 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp
index cc8c616d26..f25f9a2f35 100644
--- a/src/quickwidgets/qquickwidget.cpp
+++ b/src/quickwidgets/qquickwidget.cpp
@@ -82,6 +82,12 @@ void QQuickWidgetPrivate::init(QQmlEngine* e)
QObject::connect(renderControl, SIGNAL(sceneChanged()), q, SLOT(triggerUpdate()));
}
+void QQuickWidgetPrivate::handleWindowChange()
+{
+ renderControl->stop();
+ destroyContext();
+}
+
QQuickWidgetPrivate::QQuickWidgetPrivate()
: root(0)
, component(0)
@@ -521,6 +527,15 @@ void QQuickWidgetPrivate::createContext()
qWarning("QQuickWidget: failed to make window surface current");
}
+void QQuickWidgetPrivate::destroyContext()
+{
+ if (!context)
+ return;
+ renderControl->invalidate();
+ delete context;
+ context = 0;
+}
+
void QQuickWidget::createFramebufferObject()
{
Q_D(QQuickWidget);
@@ -768,6 +783,7 @@ void QQuickWidget::showEvent(QShowEvent *)
QQuickWindowPrivate::get(d->offscreenWindow)->forceRendering = true;
d->updatePending = false;
+ d->createContext();
triggerUpdate();
}
@@ -776,12 +792,15 @@ void QQuickWidget::hideEvent(QHideEvent *)
Q_D(QQuickWidget);
QQuickWindowPrivate::get(d->offscreenWindow)->forceRendering = false;
- QOpenGLContext *context = d->offscreenWindow->openglContext();
- if (!context) {
+ if (!d->context) {
qWarning("QQuickWidget::hideEvent with no context");
return;
}
- context->makeCurrent(d->offscreenWindow);
+ bool success = d->context->makeCurrent(d->offscreenSurface);
+ if (!success) {
+ qWarning("QQuickWidget::hideEvent could not make context current");
+ return;
+ }
d->renderControl->stop();
}
@@ -837,7 +856,9 @@ bool QQuickWidget::event(QEvent *e)
case QEvent::TouchCancel:
// Touch events only have local and global positions, no need to map.
return d->offscreenWindow->event(e);
-
+ case QEvent::WindowChangeInternal:
+ d->handleWindowChange();
+ break;
default:
break;
}
diff --git a/src/quickwidgets/qquickwidget_p.h b/src/quickwidgets/qquickwidget_p.h
index c75e5f08ad..1d0b4e1bbe 100644
--- a/src/quickwidgets/qquickwidget_p.h
+++ b/src/quickwidgets/qquickwidget_p.h
@@ -85,10 +85,12 @@ public:
void setRootObject(QObject *);
void renderSceneGraph();
void createContext();
+ void destroyContext();
- GLuint textureId() const;
+ GLuint textureId() const Q_DECL_OVERRIDE;
void init(QQmlEngine* e = 0);
+ void handleWindowChange();
QSize rootObjectSize() const;