summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qwidget.cpp
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@digia.com>2014-06-20 11:58:34 +0200
committerLaszlo Agocs <laszlo.agocs@digia.com>2014-08-01 17:13:59 +0200
commite453484bca5add5973602044ff0fbc224f819a07 (patch)
tree67f8b2afcb6622fee78f45959980324eeaf4accf /src/widgets/kernel/qwidget.cpp
parent718f248a8921ad310cbb9e099b16f5ffa0c860c1 (diff)
Make QOpenGLWidget public
QOpenGLWidget is now public. In addition Qt::WA_AlwaysStackOnTop is introduced to support the special case of semi-transparent QOpenGLWidget or QQuickWidget on top of regular widgets. hellogl_es2 becomes the qopenglwidget example. This example performs painting both via QPainter and native GL commands and has the OpenGL widget combined with other, normal widgets. The widget stack receives some changes when it comes to renderToTexture widgets like QQuickWidget and QOpenGLWidget. Calling update() will now result in a paint event, which is essential for QOpenGLWidget since we want it to behave like a regular widget. The dirty region handling is extended specially for such widgets due to performance reasons. (an OpenGL content update must not result in any backingstore painting, and is thus handled as a different kind of dirtiness) [ChangeLog] Added QOpenGLWidget. This widget serves as a replacement for QGLWidget. Task-number: QTBUG-36899 Task-number: QTBUG-40086 Change-Id: Ibf7f82fea99b39edfffd2fc088e7e0eadbca25cf Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
Diffstat (limited to 'src/widgets/kernel/qwidget.cpp')
-rw-r--r--src/widgets/kernel/qwidget.cpp63
1 files changed, 49 insertions, 14 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index e692a985eb..43ce9a82f7 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -5492,18 +5492,22 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP
//paint the background
if ((asRoot || q->autoFillBackground() || onScreen || q->testAttribute(Qt::WA_StyledBackground))
&& !q->testAttribute(Qt::WA_OpaquePaintEvent) && !q->testAttribute(Qt::WA_NoSystemBackground)) {
+ beginBackingStorePainting();
QPainter p(q);
paintBackground(&p, toBePainted, (asRoot || onScreen) ? flags | DrawAsRoot : 0);
+ endBackingStorePainting();
}
if (!sharedPainter)
setSystemClip(pdev, toBePainted.translated(offset));
if (!onScreen && !asRoot && !isOpaque && q->testAttribute(Qt::WA_TintedBackground)) {
+ beginBackingStorePainting();
QPainter p(q);
QColor tint = q->palette().window().color();
tint.setAlphaF(qreal(.6));
p.fillRect(toBePainted.boundingRect(), tint);
+ endBackingStorePainting();
}
}
@@ -5513,24 +5517,30 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP
<< "geometry ==" << QRect(q->mapTo(q->window(), QPoint(0, 0)), q->size());
#endif
+ bool grabbed = false;
+#ifndef QT_NO_OPENGL
if (renderToTexture) {
// This widget renders into a texture which is composed later. We just need to
// punch a hole in the backingstore, so the texture will be visible.
-#ifndef QT_NO_OPENGL
- QPainter p(q);
-
- if (backingStore) {
- p.setCompositionMode(QPainter::CompositionMode_Source);
- p.fillRect(q->rect(), Qt::transparent);
- } else {
- // We are not drawing to a backingstore: fall back to QImage
- p.drawImage(q->rect(), grabFramebuffer());
+ if (!q->testAttribute(Qt::WA_AlwaysStackOnTop)) {
+ beginBackingStorePainting();
+ QPainter p(q);
+ if (backingStore) {
+ p.setCompositionMode(QPainter::CompositionMode_Source);
+ p.fillRect(q->rect(), Qt::transparent);
+ } else {
+ // We are not drawing to a backingstore: fall back to QImage
+ p.drawImage(q->rect(), grabFramebuffer());
+ grabbed = true;
+ }
+ endBackingStorePainting();
}
-#endif
- } else {
+ }
+#endif // QT_NO_OPENGL
+
+ if (!grabbed) {
//actually send the paint event
- QPaintEvent e(toBePainted);
- QCoreApplication::sendSpontaneousEvent(q, &e);
+ sendPaintEvent(toBePainted);
}
// Native widgets need to be marked dirty on screen so painting will be done in correct context
@@ -5586,6 +5596,13 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP
}
}
+void QWidgetPrivate::sendPaintEvent(const QRegion &toBePainted)
+{
+ Q_Q(QWidget);
+ QPaintEvent e(toBePainted);
+ QCoreApplication::sendSpontaneousEvent(q, &e);
+}
+
void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset,
const QRegion &sourceRegion, QWidget::RenderFlags renderFlags)
{
@@ -11968,7 +11985,7 @@ QOpenGLContext *QWidgetPrivate::shareContext() const
}
QWidgetPrivate *that = const_cast<QWidgetPrivate *>(this);
if (!extra->topextra->shareContext) {
- QOpenGLContext *ctx = new QOpenGLContext();
+ QOpenGLContext *ctx = new QOpenGLContext;
ctx->setShareContext(QOpenGLContextPrivate::globalShareContext());
ctx->setFormat(extra->topextra->window->format());
ctx->create();
@@ -11978,6 +11995,24 @@ QOpenGLContext *QWidgetPrivate::shareContext() const
#endif // QT_NO_OPENGL
}
+#ifndef QT_NO_OPENGL
+void QWidgetPrivate::sendComposeStatus(QWidget *w, bool end)
+{
+ QWidgetPrivate *wd = QWidgetPrivate::get(w);
+ if (!wd->textureChildSeen)
+ return;
+ if (end)
+ wd->endCompose();
+ else
+ wd->beginCompose();
+ for (int i = 0; i < wd->children.size(); ++i) {
+ w = qobject_cast<QWidget *>(wd->children.at(i));
+ if (w && !w->isWindow() && !w->isHidden() && QWidgetPrivate::get(w)->textureChildSeen)
+ sendComposeStatus(w, end);
+ }
+}
+#endif // QT_NO_OPENGL
+
Q_WIDGETS_EXPORT QWidgetData *qt_qwidget_data(QWidget *widget)
{
return widget->data;