aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickwidgets
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@digia.com>2014-09-11 10:44:17 +0200
committerOswald Buddenhagen <oswald.buddenhagen@digia.com>2014-09-11 10:44:17 +0200
commit22fcb0efbe0644f5bd29e9538ebb76fa0dbc37b3 (patch)
tree523582d6d950035b90bddbfb778302abe3fb2599 /src/quickwidgets
parent57459d769e10170aea4e084917c1fb7267278aa2 (diff)
parentc6a71e297447e27d49fce6a3ec3e28c303ec7042 (diff)
Merge remote-tracking branch 'origin/5.4' into dev
Conflicts: src/quick/items/qquickpainteditem.h src/quick/items/qquickshadereffectsource.cpp src/quick/items/qquickshadereffectsource_p.h Change-Id: If98096443afe85fc4370cef971eace050006a61b
Diffstat (limited to 'src/quickwidgets')
-rw-r--r--src/quickwidgets/qquickwidget.cpp170
-rw-r--r--src/quickwidgets/qquickwidget.h32
-rw-r--r--src/quickwidgets/qquickwidget_p.h30
-rw-r--r--src/quickwidgets/qtquickwidgetsglobal.h30
4 files changed, 153 insertions, 109 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp
index 2541359fdd..8d93bf389b 100644
--- a/src/quickwidgets/qquickwidget.cpp
+++ b/src/quickwidgets/qquickwidget.cpp
@@ -1,40 +1,32 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtQuick module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
+** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
+** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -218,7 +210,7 @@ void QQuickWidgetPrivate::renderSceneGraph()
QOpenGLContext *context = offscreenWindow->openglContext();
if (!context) {
- qWarning("QQuickWidget: render scenegraph with no context");
+ qWarning("QQuickWidget: Attempted to render scene with no context");
return;
}
@@ -302,6 +294,26 @@ QImage QQuickWidgetPrivate::grabFramebuffer()
some of the benefits of threaded rendering, for example \l Animator classes and vsync driven
animations, will not be available.
+ \section1 Limitations
+
+ Putting other widgets underneath and making the QQuickWidget transparent will not lead
+ to the expected results: the widgets underneath will not be visible. This is because
+ in practice the QQuickWidget is drawn before all other regular, non-OpenGL widgets,
+ and so see-through types of solutions are not feasible. Other type of layouts, like
+ having widgets on top of the QQuickWidget, will function as expected.
+
+ When absolutely necessary, this limitation can be overcome by setting the
+ Qt::WA_AlwaysStackOnTop attribute on the QQuickWidget. Be aware, however that this
+ breaks stacking order. For example it will not be possible to have other widgets on
+ top of the QQuickWidget, so it should only be used in situations where a
+ semi-transparent QQuickWidget with other widgets visible underneath is required.
+
+ This limitation only applies when there are other widgets underneath the QQuickWidget
+ inside the same window. Making the window semi-transparent, with other applications
+ and the desktop visible in the background, is done in the traditional way: Set
+ Qt::WA_TranslucentBackground and change the Qt Quick Scenegraph's clear color to
+ Qt::transparent via setClearColor().
+
\sa {Exposing Attributes of C++ Types to QML}, {Qt Quick Widgets Example}, QQuickView
*/
@@ -634,33 +646,40 @@ void QQuickWidgetPrivate::handleContextCreationFailure(const QSurfaceFormat &for
void QQuickWidgetPrivate::createContext()
{
- if (context)
- return;
-
- context = new QOpenGLContext;
- context->setFormat(offscreenWindow->requestedFormat());
+ // On hide-show we invalidate() but our context is kept.
+ // We nonetheless need to initialize() again.
+ const bool reinit = context && !offscreenWindow->openglContext();
+
+ if (!reinit) {
+ if (context)
+ return;
+
+ context = new QOpenGLContext;
+ context->setFormat(offscreenWindow->requestedFormat());
+
+ if (qt_gl_global_share_context())
+ context->setShareContext(qt_gl_global_share_context());
+
+ if (!context->create()) {
+ const bool isEs = context->isOpenGLES();
+ delete context;
+ context = 0;
+ handleContextCreationFailure(offscreenWindow->requestedFormat(), isEs);
+ return;
+ }
- if (qt_gl_global_share_context())
- context->setShareContext(qt_gl_global_share_context());
- if (!context->create()) {
- const bool isEs = context->isOpenGLES();
- delete context;
- context = 0;
- handleContextCreationFailure(offscreenWindow->requestedFormat(), isEs);
- return;
+ offscreenSurface = new QOffscreenSurface;
+ // Pass the context's format(), which, now that the underlying platform context is created,
+ // contains a QSurfaceFormat representing the _actual_ format of the underlying
+ // configuration. This is essential to get a surface that is compatible with the context.
+ offscreenSurface->setFormat(context->format());
+ offscreenSurface->create();
}
- offscreenSurface = new QOffscreenSurface;
- // Pass the context's format(), which, now that the underlying platform context is created,
- // contains a QSurfaceFormat representing the _actual_ format of the underlying
- // configuration. This is essential to get a surface that is compatible with the context.
- offscreenSurface->setFormat(context->format());
- offscreenSurface->create();
-
if (context->makeCurrent(offscreenSurface))
renderControl->initialize(context);
else
- qWarning("QQuickWidget: failed to make window surface current");
+ qWarning("QQuickWidget: Failed to make context current");
}
void QQuickWidgetPrivate::destroyContext()
@@ -675,6 +694,11 @@ void QQuickWidget::createFramebufferObject()
{
Q_D(QQuickWidget);
+ // Could come from Show -> createContext -> sceneGraphInitialized in which case the size may
+ // still be invalid on some platforms. Bail out. A resize will come later on.
+ if (size().isEmpty())
+ return;
+
QOpenGLContext *context = d->offscreenWindow->openglContext();
if (!context) {
@@ -699,8 +723,13 @@ void QQuickWidget::createFramebufferObject()
QSize fboSize = size() * window()->devicePixelRatio();
- delete d->fbo;
- d->fbo = new QOpenGLFramebufferObject(fboSize, format);
+ // Could be a simple hide - show, in which case the previous fbo is just fine.
+ if (!d->fbo || d->fbo->size() != fboSize) {
+ delete d->fbo;
+ d->fbo = new QOpenGLFramebufferObject(fboSize, format);
+ }
+
+ d->offscreenWindow->setGeometry(0, 0, width(), height());
d->offscreenWindow->setRenderTarget(d->fbo);
if (samples > 0)
@@ -878,16 +907,29 @@ void QQuickWidget::resizeEvent(QResizeEvent *e)
d->fakeHidden = true;
return;
}
- if (d->fakeHidden && d->context) {
+
+ bool needsSync = false;
+ if (d->fakeHidden) {
//restart rendering
d->fakeHidden = false;
- d->renderControl->sync();
+ needsSync = true;
}
- d->createContext();
- createFramebufferObject();
- QCoreApplication::sendEvent(d->offscreenWindow, e);
- d->offscreenWindow->setGeometry(0, 0, e->size().width(), e->size().height());
+ if (d->context) {
+ // Bail out when receiving a resize after scenegraph invalidation. This can happen
+ // during hide - resize - show sequences and also during application exit.
+ if (!d->fbo && !d->offscreenWindow->openglContext())
+ return;
+ if (!d->fbo || d->fbo->size() != size() * devicePixelRatio()) {
+ needsSync = true;
+ createFramebufferObject();
+ }
+ } else {
+ // This will result in a scenegraphInitialized() signal which
+ // is connected to createFramebufferObject().
+ needsSync = true;
+ d->createContext();
+ }
QOpenGLContext *context = d->offscreenWindow->openglContext();
if (!context) {
@@ -897,14 +939,19 @@ void QQuickWidget::resizeEvent(QResizeEvent *e)
context->makeCurrent(d->offscreenSurface);
- if (d->fakeHidden) {
- d->fakeHidden = false;
+ if (needsSync) {
+ d->renderControl->polishItems();
d->renderControl->sync();
}
d->renderControl->render();
-
context->functions()->glFlush();
+
+ if (d->resolvedFbo) {
+ QRect rect(QPoint(0, 0), d->fbo->size());
+ QOpenGLFramebufferObject::blitFramebuffer(d->resolvedFbo, rect, d->fbo, rect);
+ }
+
context->doneCurrent();
}
@@ -938,6 +985,7 @@ void QQuickWidget::mouseMoveEvent(QMouseEvent *e)
// because QQuickWindow thinks of itself as a top-level window always.
QMouseEvent mappedEvent(e->type(), e->localPos(), e->screenPos(), e->button(), e->buttons(), e->modifiers());
QCoreApplication::sendEvent(d->offscreenWindow, &mappedEvent);
+ e->setAccepted(mappedEvent.isAccepted());
}
/*! \reimp */
@@ -951,6 +999,7 @@ void QQuickWidget::mouseDoubleClickEvent(QMouseEvent *e)
QMouseEvent pressEvent(QEvent::MouseButtonPress, e->localPos(), e->screenPos(), e->button(),
e->buttons(), e->modifiers());
QCoreApplication::sendEvent(d->offscreenWindow, &pressEvent);
+ e->setAccepted(pressEvent.isAccepted());
QMouseEvent mappedEvent(e->type(), e->localPos(), e->screenPos(), e->button(), e->buttons(),
e->modifiers());
QCoreApplication::sendEvent(d->offscreenWindow, &mappedEvent);
@@ -980,6 +1029,7 @@ void QQuickWidget::mousePressEvent(QMouseEvent *e)
QMouseEvent mappedEvent(e->type(), e->localPos(), e->screenPos(), e->button(), e->buttons(), e->modifiers());
QCoreApplication::sendEvent(d->offscreenWindow, &mappedEvent);
+ e->setAccepted(mappedEvent.isAccepted());
}
/*! \reimp */
@@ -990,6 +1040,7 @@ void QQuickWidget::mouseReleaseEvent(QMouseEvent *e)
QMouseEvent mappedEvent(e->type(), e->localPos(), e->screenPos(), e->button(), e->buttons(), e->modifiers());
QCoreApplication::sendEvent(d->offscreenWindow, &mappedEvent);
+ e->setAccepted(mappedEvent.isAccepted());
}
#ifndef QT_NO_WHEELEVENT
@@ -1115,4 +1166,19 @@ QImage QQuickWidget::grabFramebuffer() const
return const_cast<QQuickWidgetPrivate *>(d_func())->grabFramebuffer();
}
+/*!
+ Sets the clear \a color. By default this is an opaque color.
+
+ To get a semi- or fully transparent QQuickWidget, call this function with \a
+ color set to Qt::transparent and set the Qt::WA_TranslucentBackground widget
+ attribute.
+
+ \sa QQuickWindow::setColor()
+ */
+void QQuickWidget::setClearColor(const QColor &color)
+{
+ Q_D(QQuickWidget);
+ d->offscreenWindow->setColor(color);
+}
+
QT_END_NAMESPACE
diff --git a/src/quickwidgets/qquickwidget.h b/src/quickwidgets/qquickwidget.h
index df0fa5a54a..87f688c11a 100644
--- a/src/quickwidgets/qquickwidget.h
+++ b/src/quickwidgets/qquickwidget.h
@@ -1,40 +1,32 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtQuick module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
+** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
+** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -96,6 +88,8 @@ public:
QImage grabFramebuffer() const;
+ void setClearColor(const QColor &color);
+
public Q_SLOTS:
void setSource(const QUrl&);
void setContent(const QUrl& url, QQmlComponent *component, QObject *item);
diff --git a/src/quickwidgets/qquickwidget_p.h b/src/quickwidgets/qquickwidget_p.h
index 755acb969d..2289b18d72 100644
--- a/src/quickwidgets/qquickwidget_p.h
+++ b/src/quickwidgets/qquickwidget_p.h
@@ -1,40 +1,32 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtQuick module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
+** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
+** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
** $QT_END_LICENSE$
**
****************************************************************************/
diff --git a/src/quickwidgets/qtquickwidgetsglobal.h b/src/quickwidgets/qtquickwidgetsglobal.h
index 2524150ed1..f0b1caeb1b 100644
--- a/src/quickwidgets/qtquickwidgetsglobal.h
+++ b/src/quickwidgets/qtquickwidgetsglobal.h
@@ -1,40 +1,32 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtQuick module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
+** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
+** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
** $QT_END_LICENSE$
**
****************************************************************************/