diff options
author | Shawn Rutledge <shawn.rutledge@theqtcompany.com> | 2015-06-01 17:49:37 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2016-08-15 15:21:19 +0000 |
commit | 54eab024611c6b9675ef6d48a15e7d69ed28df87 (patch) | |
tree | faff31d691c3c0f66f0fc0261eac9afb96a4d20f | |
parent | 076640e0e7ac31574c41bd6298a89b0cb5d7f9a7 (diff) |
Introduce QQuickPointerHandler: base class for nested event handlers
They will be Tech Preview in 5.8, so they shouldn't be available
unless you explicitly import them.
Task-number: QTBUG-54824
Change-Id: I290854a4e2b76e2cdfef5c216c7fdeb47fbcd390
Reviewed-by: Jan Arve Sæther <jan-arve.saether@theqtcompany.com>
-rw-r--r-- | src/imports/handlers/handlers.pro | 11 | ||||
-rw-r--r-- | src/imports/handlers/plugin.cpp | 88 | ||||
-rw-r--r-- | src/imports/handlers/qmldir | 5 | ||||
-rw-r--r-- | src/imports/imports.pro | 1 | ||||
-rw-r--r-- | src/quick/handlers/handlers.pri | 7 | ||||
-rw-r--r-- | src/quick/handlers/qquickhandlersmodule.cpp | 90 | ||||
-rw-r--r-- | src/quick/handlers/qquickhandlersmodule_p.h | 68 | ||||
-rw-r--r-- | src/quick/handlers/qquickpointerhandler.cpp | 120 | ||||
-rw-r--r-- | src/quick/handlers/qquickpointerhandler_p.h | 101 | ||||
-rw-r--r-- | src/quick/items/qquickflickable.cpp | 3 | ||||
-rw-r--r-- | src/quick/items/qquickitem.cpp | 17 | ||||
-rw-r--r-- | src/quick/items/qquickitem_p.h | 4 | ||||
-rw-r--r-- | src/quick/items/qquickwindow.cpp | 13 | ||||
-rw-r--r-- | src/quick/quick.pro | 1 |
14 files changed, 527 insertions, 2 deletions
diff --git a/src/imports/handlers/handlers.pro b/src/imports/handlers/handlers.pro new file mode 100644 index 0000000000..0e32644773 --- /dev/null +++ b/src/imports/handlers/handlers.pro @@ -0,0 +1,11 @@ +CXX_MODULE = qml +TARGET = handlersplugin +TARGETPATH = Qt/labs/handlers +IMPORT_VERSION = 1.0 + +SOURCES += \ + plugin.cpp + +QT += quick-private qml-private + +load(qml_plugin) diff --git a/src/imports/handlers/plugin.cpp b/src/imports/handlers/plugin.cpp new file mode 100644 index 0000000000..21b9764611 --- /dev/null +++ b/src/imports/handlers/plugin.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $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 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 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. +** +** 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$ +** +****************************************************************************/ + +#include <QtQml/qqmlextensionplugin.h> + +#include <private/qquickhandlersmodule_p.h> + +static void initResources() +{ +#ifdef QT_STATIC + Q_INIT_RESOURCE(qmake_Qt_labs_handlers_1); +#endif +} + +QT_BEGIN_NAMESPACE + +/*! + \qmlmodule Qt.labs.handlers 1.0 + \title Qt Quick Pointer Handlers + \ingroup qmlmodules + \brief Provides QML types for handling pointer events. + + This QML module contains types for handling pointer events, which are an abstraction + of mouse, touch and tablet events. + + To use the types in this module, import the module with the following line: + + \code + import Qt.labs.handlers 1.0 + \endcode +*/ + + +//![class decl] +class QtQuickHandlersPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) +public: + QtQuickHandlersPlugin(QObject *parent = 0) : QQmlExtensionPlugin(parent) { initResources(); } + void registerTypes(const char *uri) Q_DECL_OVERRIDE + { + Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.labs.handlers")); + Q_UNUSED(uri); + QQuickHandlersModule::defineModule(); + } +}; +//![class decl] + +QT_END_NAMESPACE + +#include "plugin.moc" diff --git a/src/imports/handlers/qmldir b/src/imports/handlers/qmldir new file mode 100644 index 0000000000..4896348c2e --- /dev/null +++ b/src/imports/handlers/qmldir @@ -0,0 +1,5 @@ +module Qt.labs.handlers +plugin handlersplugin +classname QtQuickHandlersPlugin +typeinfo plugins.qmltypes + diff --git a/src/imports/imports.pro b/src/imports/imports.pro index 9e3cdf3f42..ade744ec19 100644 --- a/src/imports/imports.pro +++ b/src/imports/imports.pro @@ -11,6 +11,7 @@ SUBDIRS += \ qtHaveModule(quick) { SUBDIRS += \ + handlers \ layouts \ qtquick2 \ window \ diff --git a/src/quick/handlers/handlers.pri b/src/quick/handlers/handlers.pri new file mode 100644 index 0000000000..0c6bd2ab17 --- /dev/null +++ b/src/quick/handlers/handlers.pri @@ -0,0 +1,7 @@ +HEADERS += \ + $$PWD/qquickpointerhandler_p.h \ + $$PWD/qquickhandlersmodule_p.h \ + +SOURCES += \ + $$PWD/qquickpointerhandler.cpp \ + $$PWD/qquickhandlersmodule.cpp \ diff --git a/src/quick/handlers/qquickhandlersmodule.cpp b/src/quick/handlers/qquickhandlersmodule.cpp new file mode 100644 index 0000000000..dd50c367ec --- /dev/null +++ b/src/quick/handlers/qquickhandlersmodule.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** 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: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 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 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. +** +** 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$ +** +****************************************************************************/ + +#include "qquickhandlersmodule_p.h" +#include "qquickpointerhandler_p.h" + +static void initResources() +{ +#ifdef QT_STATIC + Q_INIT_RESOURCE(qmake_Qt_labs_handlers); +#endif +} + +QT_BEGIN_NAMESPACE + +static QQmlPrivate::AutoParentResult handler_autoParent(QObject *obj, QObject *parent) +{ + if (QQuickItem *parentItem = qmlobject_cast<QQuickItem *>(parent)) { + QQuickPointerHandler *handler = qmlobject_cast<QQuickPointerHandler *>(obj); + if (handler && !handler->target()) { + handler->setTarget(parentItem); + return QQmlPrivate::Parented; + } + } + return QQmlPrivate::IncompatibleObject; +} + +static void qt_quickhandlers_defineModule(const char *uri, int major, int minor) +{ + QQmlPrivate::RegisterAutoParent autoparent = { 0, &handler_autoParent }; + QQmlPrivate::qmlregister(QQmlPrivate::AutoParentRegistration, &autoparent); + qmlRegisterUncreatableType<QQuickPointerEvent>(uri, major, minor, "PointerEvent", + QQuickPointerHandler::tr("PointerEvent is only available as a parameter of several signals in PointerHandler")); + qmlRegisterUncreatableType<QQuickPointerDevice>(uri, major, minor, "PointerDevice", + QQuickPointerHandler::tr("PointerDevice is only available as a property of PointerEvent")); + qRegisterMetaType<QPointerUniqueId>("QPointerUniqueId"); + qmlRegisterUncreatableType<QPointerUniqueId>(uri, major, minor, "PointerUniqueId", + QQuickPointerHandler::tr("PointerUniqueId is only available as a property of PointerEvent")); + + qmlRegisterType<QQuickPointerHandler>(uri,major,minor,"PointerHandler"); +} + +void QQuickHandlersModule::defineModule() +{ + initResources(); + + const char uri[] = "Qt.labs.handlers"; + int majorVersion = 1; + int minorVersion = 0; + + qt_quickhandlers_defineModule(uri, majorVersion, minorVersion); +} + +QT_END_NAMESPACE diff --git a/src/quick/handlers/qquickhandlersmodule_p.h b/src/quick/handlers/qquickhandlersmodule_p.h new file mode 100644 index 0000000000..7eb8d39b98 --- /dev/null +++ b/src/quick/handlers/qquickhandlersmodule_p.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** 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: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 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 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. +** +** 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$ +** +****************************************************************************/ + +#ifndef QQUICKHANDLERSMODULE_P_H +#define QQUICKHANDLERSMODULE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <qqml.h> +#include <private/qtquickglobal_p.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICK_PRIVATE_EXPORT QQuickHandlersModule +{ +public: + static void defineModule(); +}; + +QT_END_NAMESPACE + +#endif // QQUICKHANDLERSMODULE_P_H + diff --git a/src/quick/handlers/qquickpointerhandler.cpp b/src/quick/handlers/qquickpointerhandler.cpp new file mode 100644 index 0000000000..9964d8f465 --- /dev/null +++ b/src/quick/handlers/qquickpointerhandler.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** 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: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 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 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. +** +** 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$ +** +****************************************************************************/ + +#include "qquickpointerhandler_p.h" + +QT_BEGIN_NAMESPACE + +Q_LOGGING_CATEGORY(lcPointerHandlerDispatch, "qt.quick.handler.dispatch") + +/*! + \qmltype PointerHandler + \instantiates QQuickPointerHandler + \inqmlmodule QtQuick + \ingroup qtquick-handlers + \brief Handler for pointer events + + PointerHandler is a handler for pointer events regardless of source. + They may represent events from a touch, mouse or tablet device. +*/ + +QQuickPointerHandler::QQuickPointerHandler(QObject *parent) + : QObject(parent) + , m_currentEvent(nullptr) + , m_target(nullptr) + , m_enabled(true) +{ +} + +void QQuickPointerHandler::setGrab(QQuickEventPoint *point, bool grab) +{ + // TODO eventually the handler itself should be the grabber, instead of the target Item + if (grab) + point->setGrabber(m_target); + else if (point->grabber() == m_target) + point->setGrabber(nullptr); +} + +/*! + \qmlproperty QQuickPointerHandler::enabled + + If a PointerHandler is disabled, it will reject all events + and no signals will be emitted. + + TODO is it too extreme not even to emit pressed/updated/released? + or should we disable only the higher-level interpretation, in subclasses? +*/ +void QQuickPointerHandler::setEnabled(bool enabled) +{ + if (m_enabled == enabled) + return; + + m_enabled = enabled; + emit enabledChanged(); +} + +void QQuickPointerHandler::setTarget(QQuickItem *target) +{ + if (m_target == target) + return; + + if (m_target) { + QQuickItemPrivate *p = QQuickItemPrivate::get(m_target); + p->extra.value().pointerHandlers.removeOne(this); + } + + m_target = target; + if (m_target) { + QQuickItemPrivate *p = QQuickItemPrivate::get(m_target); + p->extra.value().pointerHandlers.append(this); + // Accept all buttons, and leave filtering to pointerEvent() and/or user JS, + // because there can be multiple handlers... + m_target->setAcceptedMouseButtons(Qt::AllButtons); + } + emit targetChanged(); +} + +void QQuickPointerHandler::handlePointerEventImpl(QQuickPointerEvent *event) +{ + if (!m_enabled) + return; + m_currentEvent = event; +} + +QT_END_NAMESPACE diff --git a/src/quick/handlers/qquickpointerhandler_p.h b/src/quick/handlers/qquickpointerhandler_p.h new file mode 100644 index 0000000000..b20f20d8f9 --- /dev/null +++ b/src/quick/handlers/qquickpointerhandler_p.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** 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: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 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 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. +** +** 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$ +** +****************************************************************************/ + +#ifndef QQUICKPOINTERHANDLER_H +#define QQUICKPOINTERHANDLER_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qevent.h" + +#include <QtQuick/private/qquickevents_p_p.h> +#include <QtQuick/private/qquickitem_p.h> + +QT_BEGIN_NAMESPACE + +Q_DECLARE_LOGGING_CATEGORY(lcPointerHandlerDispatch) + +class Q_QUICK_PRIVATE_EXPORT QQuickPointerHandler : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) + Q_PROPERTY(QQuickItem * target READ target WRITE setTarget NOTIFY targetChanged) + +public: + QQuickPointerHandler(QObject *parent = 0); + virtual ~QQuickPointerHandler() { } + +public: + bool enabled() const { return m_enabled; } + void setEnabled(bool enabled); + + QQuickItem *target() const { return m_target; } + void setTarget(QQuickItem *target); + + void handlePointerEvent(QQuickPointerEvent *event) { handlePointerEventImpl(event); } + +Q_SIGNALS: + void enabledChanged(); + void targetChanged(); + +protected: + QQuickPointerEvent *currentEvent() { return m_currentEvent; } + virtual void handlePointerEventImpl(QQuickPointerEvent *event); + void setGrab(QQuickEventPoint *point, bool grab); + +private: + QQuickPointerEvent *m_currentEvent; + QQuickItem *m_target; + bool m_enabled; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQuickPointerHandler) + +#endif // QQUICKPOINTERHANDLER_H diff --git a/src/quick/items/qquickflickable.cpp b/src/quick/items/qquickflickable.cpp index dcba5c2d71..b4650a215a 100644 --- a/src/quick/items/qquickflickable.cpp +++ b/src/quick/items/qquickflickable.cpp @@ -44,6 +44,7 @@ #include "qquickwindow_p.h" #include "qquickevents_p_p.h" +#include <QtQuick/private/qquickpointerhandler_p.h> #include <QtQuick/private/qquicktransition_p.h> #include <private/qqmlglobal_p.h> @@ -1763,6 +1764,8 @@ void QQuickFlickablePrivate::data_append(QQmlListProperty<QObject> *prop, QObjec i->setParentItem(static_cast<QQuickFlickablePrivate*>(prop->data)->contentItem); } else { o->setParent(prop->object); // XXX todo - do we want this? + if (QQuickPointerHandler *pointerHandler = qmlobject_cast<QQuickPointerHandler *>(o)) + pointerHandler->setTarget(static_cast<QQuickItem *>(prop->object)); } } diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp index 84f9b0f169..a4be47380e 100644 --- a/src/quick/items/qquickitem.cpp +++ b/src/quick/items/qquickitem.cpp @@ -68,6 +68,7 @@ #include <private/qquickitem_p.h> #include <private/qqmlaccessors_p.h> #include <QtQuick/private/qquickaccessibleattached_p.h> +#include <QtQuick/private/qquickpointerhandler_p.h> #include <private/qv4engine_p.h> #include <private/qv4object_p.h> @@ -87,6 +88,7 @@ QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(DBG_MOUSE_TARGET) Q_DECLARE_LOGGING_CATEGORY(DBG_HOVER_TRACE) +Q_DECLARE_LOGGING_CATEGORY(lcPointerHandlerDispatch) void debugFocusTree(QQuickItem *item, QQuickItem *scope = 0, int depth = 1) { @@ -3187,7 +3189,9 @@ void QQuickItemPrivate::data_append(QQmlListProperty<QObject> *prop, QObject *o) } else { if (o->inherits("QGraphicsItem")) qWarning("Cannot add a QtQuick 1.0 item (%s) into a QtQuick 2.0 scene!", o->metaObject()->className()); - else { + else if (QQuickPointerHandler *pointerHandler = qmlobject_cast<QQuickPointerHandler *>(o)) { + pointerHandler->setTarget(that); + } else { QQuickWindow *thisWindow = qmlobject_cast<QQuickWindow *>(o); QQuickItem *item = that; QQuickWindow *itemWindow = that->window(); @@ -4964,6 +4968,17 @@ void QQuickItemPrivate::deliverInputMethodEvent(QInputMethodEvent *e) } #endif // QT_NO_IM +void QQuickItemPrivate::handlePointerEvent(QQuickPointerEvent *event) +{ + Q_Q(QQuickItem); + if (extra.isAllocated()) { + for (QQuickPointerHandler *handler : extra->pointerHandlers) { + qCDebug(lcPointerHandlerDispatch) << " delivering" << event << "to" << handler << "on" << q; + handler->handlePointerEvent(event); + } + } +} + /*! Called when \a change occurs for this item. diff --git a/src/quick/items/qquickitem_p.h b/src/quick/items/qquickitem_p.h index 9ea2712e18..94180309a3 100644 --- a/src/quick/items/qquickitem_p.h +++ b/src/quick/items/qquickitem_p.h @@ -85,6 +85,7 @@ class QQuickItemKeyFilter; class QQuickLayoutMirroringAttached; class QQuickEnterKeyAttached; class QQuickScreenAttached; +class QQuickPointerHandler; class QQuickContents : public QQuickItemChangeListener { @@ -340,6 +341,7 @@ public: QQuickLayoutMirroringAttached* layoutDirectionAttached; QQuickEnterKeyAttached *enterKeyAttached; QQuickItemKeyFilter *keyHandler; + QVector<QQuickPointerHandler *> pointerHandlers; mutable QQuickItemLayer *layer; #ifndef QT_NO_CURSOR QCursor cursor; @@ -555,6 +557,8 @@ public: void deliverInputMethodEvent(QInputMethodEvent *); #endif + virtual void handlePointerEvent(QQuickPointerEvent *); + bool isTransparentForPositioner() const; void setTransparentForPositioner(bool trans); diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 16cbb2aa2f..d73f8cd2c4 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -1618,6 +1618,12 @@ void QQuickWindowPrivate::deliverMouseEvent(QQuickPointerMouseEvent *pointerEven return; } + // Let the Item's handlers (if any) have the event first. + QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(grabber); + itemPrivate->handlePointerEvent(pointerEvent); + if (pointerEvent->allPointsAccepted()) + return; + // send update QPointF localPos = grabber->mapFromScene(lastMousePosition); auto me = pointerEvent->asMouseEvent(localPos); @@ -2232,6 +2238,12 @@ bool QQuickWindowPrivate::deliverPressEvent(QQuickPointerEvent *event, QSet<QQui bool QQuickWindowPrivate::deliverMatchingPointsToItem(QQuickItem *item, QQuickPointerEvent *pointerEvent, QSet<QQuickItem *> *hasFiltered) { Q_Q(QQuickWindow); + QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); + + // Let the Item's handlers (if any) have the event first. + itemPrivate->handlePointerEvent(pointerEvent); + if (pointerEvent->allPointsAccepted()) + return true; // TODO: unite this mouse point delivery with the synthetic mouse event below if (auto event = pointerEvent->asPointerMouseEvent()) { @@ -2283,7 +2295,6 @@ bool QQuickWindowPrivate::deliverMatchingPointsToItem(QQuickItem *item, QQuickPo eventAccepted = touchEvent->isAccepted(); // If the touch event wasn't accepted, synthesize a mouse event and see if the item wants it. - QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item); if (!eventAccepted && (itemPrivate->acceptedMouseButtons() & Qt::LeftButton)) { // send mouse event if (deliverTouchAsMouse(item, event)) diff --git a/src/quick/quick.pro b/src/quick/quick.pro index f74a554aa9..e89db182f3 100644 --- a/src/quick/quick.pro +++ b/src/quick/quick.pro @@ -32,6 +32,7 @@ ANDROID_BUNDLED_FILES += \ include(util/util.pri) include(scenegraph/scenegraph.pri) include(items/items.pri) +include(handlers/handlers.pri) include(designer/designer.pri) contains(QT_CONFIG, accessibility) { include(accessible/accessible.pri) |