diff options
Diffstat (limited to 'src/quickwidgets/qquickwidget.cpp')
-rw-r--r-- | src/quickwidgets/qquickwidget.cpp | 79 |
1 files changed, 49 insertions, 30 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp index 1a840b44bd..2f43582529 100644 --- a/src/quickwidgets/qquickwidget.cpp +++ b/src/quickwidgets/qquickwidget.cpp @@ -1,31 +1,37 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtQuick module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL21$ +** $QT_BEGIN_LICENSE:LGPL$ ** 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 The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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 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. +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company 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 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** @@ -96,10 +102,6 @@ void QQuickWidgetPrivate::init(QQmlEngine* e) if (!engine.data()->incubationController()) engine.data()->setIncubationController(offscreenWindow->incubationController()); - QQmlInspectorService *service = QQmlDebugConnector::service<QQmlInspectorService>(); - if (service) - service->addView(q); - #ifndef QT_NO_DRAGANDDROP q->setAcceptDrops(true); #endif @@ -150,10 +152,6 @@ QQuickWidgetPrivate::QQuickWidgetPrivate() QQuickWidgetPrivate::~QQuickWidgetPrivate() { - QQmlInspectorService *service = QQmlDebugConnector::service<QQmlInspectorService>(); - if (service) - service->removeView(q_func()); - invalidateRenderControl(); // context and offscreenSurface are current at this stage, if the context was created. @@ -988,7 +986,9 @@ QSize QQuickWidget::initialSize() const } /*! - Returns the view's root \l {QQuickItem} {item}. + Returns the view's root \l {QQuickItem} {item}. Can be null + when setContents/setSource has not been called, if they were called with + broken QtQuick code or while the QtQuick contents are being created. */ QQuickItem *QQuickWidget::rootObject() const { @@ -1049,7 +1049,8 @@ void QQuickWidget::resizeEvent(QResizeEvent *e) void QQuickWidget::keyPressEvent(QKeyEvent *e) { Q_D(QQuickWidget); - Q_QUICK_INPUT_PROFILE(addEvent<QQuickProfiler::Key>()); + Q_QUICK_INPUT_PROFILE(QQuickProfiler::Key, QQuickProfiler::InputKeyPress, e->key(), + e->modifiers()); QCoreApplication::sendEvent(d->offscreenWindow, e); } @@ -1058,7 +1059,8 @@ void QQuickWidget::keyPressEvent(QKeyEvent *e) void QQuickWidget::keyReleaseEvent(QKeyEvent *e) { Q_D(QQuickWidget); - Q_QUICK_INPUT_PROFILE(addEvent<QQuickProfiler::Key>()); + Q_QUICK_INPUT_PROFILE(QQuickProfiler::Key, QQuickProfiler::InputKeyRelease, e->key(), + e->modifiers()); QCoreApplication::sendEvent(d->offscreenWindow, e); } @@ -1067,7 +1069,8 @@ void QQuickWidget::keyReleaseEvent(QKeyEvent *e) void QQuickWidget::mouseMoveEvent(QMouseEvent *e) { Q_D(QQuickWidget); - Q_QUICK_INPUT_PROFILE(addEvent<QQuickProfiler::Mouse>()); + Q_QUICK_INPUT_PROFILE(QQuickProfiler::Mouse, QQuickProfiler::InputMouseMove, e->localPos().x(), + e->localPos().y()); // Use the constructor taking localPos and screenPos. That puts localPos into the // event's localPos and windowPos, and screenPos into the event's screenPos. This way @@ -1082,7 +1085,8 @@ void QQuickWidget::mouseMoveEvent(QMouseEvent *e) void QQuickWidget::mouseDoubleClickEvent(QMouseEvent *e) { Q_D(QQuickWidget); - Q_QUICK_INPUT_PROFILE(addEvent<QQuickProfiler::Mouse>()); + Q_QUICK_INPUT_PROFILE(QQuickProfiler::Mouse, QQuickProfiler::InputMouseDoubleClick, + e->button(), e->buttons()); // As the second mouse press is suppressed in widget windows we emulate it here for QML. // See QTBUG-25831 @@ -1115,6 +1119,8 @@ void QQuickWidget::showEvent(QShowEvent *) emit d->offscreenWindow->visibleChanged(true); offscreenPrivate->updateVisibility(); } + if (QQmlInspectorService *service = QQmlDebugConnector::service<QQmlInspectorService>()) + service->setParentWindow(d->offscreenWindow, window()->windowHandle()); } /*! \reimp */ @@ -1128,13 +1134,16 @@ void QQuickWidget::hideEvent(QHideEvent *) emit d->offscreenWindow->visibleChanged(false); offscreenPrivate->updateVisibility(); } + if (QQmlInspectorService *service = QQmlDebugConnector::service<QQmlInspectorService>()) + service->setParentWindow(d->offscreenWindow, d->offscreenWindow); } /*! \reimp */ void QQuickWidget::mousePressEvent(QMouseEvent *e) { Q_D(QQuickWidget); - Q_QUICK_INPUT_PROFILE(addEvent<QQuickProfiler::Mouse>()); + Q_QUICK_INPUT_PROFILE(QQuickProfiler::Mouse, QQuickProfiler::InputMousePress, e->button(), + e->buttons()); QMouseEvent mappedEvent(e->type(), e->localPos(), e->screenPos(), e->button(), e->buttons(), e->modifiers()); QCoreApplication::sendEvent(d->offscreenWindow, &mappedEvent); @@ -1145,7 +1154,8 @@ void QQuickWidget::mousePressEvent(QMouseEvent *e) void QQuickWidget::mouseReleaseEvent(QMouseEvent *e) { Q_D(QQuickWidget); - Q_QUICK_INPUT_PROFILE(addEvent<QQuickProfiler::Mouse>()); + Q_QUICK_INPUT_PROFILE(QQuickProfiler::Mouse, QQuickProfiler::InputMouseRelease, e->button(), + e->buttons()); QMouseEvent mappedEvent(e->type(), e->localPos(), e->screenPos(), e->button(), e->buttons(), e->modifiers()); QCoreApplication::sendEvent(d->offscreenWindow, &mappedEvent); @@ -1157,7 +1167,8 @@ void QQuickWidget::mouseReleaseEvent(QMouseEvent *e) void QQuickWidget::wheelEvent(QWheelEvent *e) { Q_D(QQuickWidget); - Q_QUICK_INPUT_PROFILE(addEvent<QQuickProfiler::Mouse>()); + Q_QUICK_INPUT_PROFILE(QQuickProfiler::Mouse, QQuickProfiler::InputMouseWheel, + e->angleDelta().x(), e->angleDelta().y()); // Wheel events only have local and global positions, no need to map. QCoreApplication::sendEvent(d->offscreenWindow, e); @@ -1286,6 +1297,14 @@ void QQuickWidget::triggerUpdate() Q_D(QQuickWidget); d->updatePending = true; if (!d->eventPending) { + // There's no sense in immediately kicking a render off now, as + // there may be a number of triggerUpdate calls to come from a multitude + // of different sources (network, touch/mouse/keyboard, timers, + // animations, ...), and we want to batch them all into single frames as + // much as possible for the sake of interactivity and responsiveness. + // + // To achieve this, we set a timer and only perform the rendering when + // this is complete. const int exhaustDelay = 5; d->updateTimer.start(exhaustDelay, Qt::PreciseTimer, this); d->eventPending = true; |