aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2016-08-15 15:01:14 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2016-08-25 15:51:15 +0000
commita2dd1ee46ccdff16d5ba589cdce03e36ca93497e (patch)
tree0c1ad4b08e2468b243f1c8ed3421635da0d442c9 /src/quick
parent400322244093979f42846a8547a6416a1c857868 (diff)
add QQuickPointerSingleHandler
An intermediate class for convenience in implementing handlers which are only interested in single points. Such handlers grab the first point which occurs inside the target item, and ignore all other points. Change-Id: Ib4cdd8c12c0e74dbfdcf701d3ec06e0429f2bcc9 Reviewed-by: Jan Arve Sæther <jan-arve.saether@theqtcompany.com>
Diffstat (limited to 'src/quick')
-rw-r--r--src/quick/handlers/handlers.pri2
-rw-r--r--src/quick/handlers/qquickpointersinglehandler.cpp105
-rw-r--r--src/quick/handlers/qquickpointersinglehandler_p.h83
3 files changed, 190 insertions, 0 deletions
diff --git a/src/quick/handlers/handlers.pri b/src/quick/handlers/handlers.pri
index 2eed3855d3..c91b259107 100644
--- a/src/quick/handlers/handlers.pri
+++ b/src/quick/handlers/handlers.pri
@@ -1,9 +1,11 @@
HEADERS += \
$$PWD/qquickpointerhandler_p.h \
$$PWD/qquickpointerdevicehandler_p.h \
+ $$PWD/qquickpointersinglehandler_p.h \
$$PWD/qquickhandlersmodule_p.h \
SOURCES += \
$$PWD/qquickpointerhandler.cpp \
$$PWD/qquickpointerdevicehandler.cpp \
+ $$PWD/qquickpointersinglehandler.cpp \
$$PWD/qquickhandlersmodule.cpp \
diff --git a/src/quick/handlers/qquickpointersinglehandler.cpp b/src/quick/handlers/qquickpointersinglehandler.cpp
new file mode 100644
index 0000000000..135726105b
--- /dev/null
+++ b/src/quick/handlers/qquickpointersinglehandler.cpp
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** 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 "qquickpointersinglehandler_p.h"
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ An intermediate class (not registered as a QML type)
+ for the most common handlers: those which expect only a single point.
+ wantsPointerEvent() will choose the first point which is inside the
+ \l target item, and return true as long as the event contains that point.
+ Override handleEventPoint() to implement a single-point handler.
+*/
+
+QQuickPointerSingleHandler::QQuickPointerSingleHandler(QObject *parent)
+ : QQuickPointerDeviceHandler(parent)
+ , m_currentPoint(nullptr)
+ , m_currentPointId(0)
+{
+}
+
+bool QQuickPointerSingleHandler::wantsPointerEvent(QQuickPointerEvent *event)
+{
+ if (!QQuickPointerDeviceHandler::wantsPointerEvent(event))
+ return false;
+ int c = event->pointCount();
+ for (int i = 0; i < c; ++i) {
+ QQuickEventPoint *p = event->point(i);
+ if (m_currentPointId) {
+ if (m_currentPointId == p->pointId()) {
+ m_currentPoint = p;
+ return true;
+ }
+ } else {
+ if (p->grabber()) {
+ if (p->grabber() == target())
+ setCurrentPoint(p);
+ else
+ continue;
+ } else {
+ if (targetContains(p))
+ setCurrentPoint(p);
+ }
+ if (m_currentPoint)
+ return true;
+ }
+ }
+ // If we didn't return yet, there are no interesting points
+ setCurrentPoint(nullptr);
+ return false;
+}
+
+void QQuickPointerSingleHandler::handlePointerEventImpl(QQuickPointerEvent *event)
+{
+ QQuickPointerDeviceHandler::handlePointerEventImpl(event);
+ handleEventPoint(m_currentPoint);
+ // If the point is released or was rejected, this handler is done handling that point.
+ if (m_currentPoint->state() == QQuickEventPoint::Released || !m_currentPoint->grabber())
+ setCurrentPoint(nullptr);
+}
+
+void QQuickPointerSingleHandler::setCurrentPoint(QQuickEventPoint *p)
+{
+ m_currentPoint = p;
+ m_currentPointId = p ? p->pointId() : 0;
+}
+
+QT_END_NAMESPACE
diff --git a/src/quick/handlers/qquickpointersinglehandler_p.h b/src/quick/handlers/qquickpointersinglehandler_p.h
new file mode 100644
index 0000000000..c05a5cfc62
--- /dev/null
+++ b/src/quick/handlers/qquickpointersinglehandler_p.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** 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 QQUICKPOINTERSINGLEHANDLER_H
+#define QQUICKPOINTERSINGLEHANDLER_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 "qquickpointerdevicehandler_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class Q_QUICK_PRIVATE_EXPORT QQuickPointerSingleHandler : public QQuickPointerDeviceHandler
+{
+ Q_OBJECT
+
+public:
+ QQuickPointerSingleHandler(QObject *parent = 0);
+ virtual ~QQuickPointerSingleHandler() { }
+
+protected:
+ bool wantsPointerEvent(QQuickPointerEvent *event) Q_DECL_OVERRIDE;
+ void handlePointerEventImpl(QQuickPointerEvent *event) Q_DECL_OVERRIDE;
+ virtual void handleEventPoint(QQuickEventPoint *point) = 0;
+
+private:
+ void setCurrentPoint(QQuickEventPoint *p);
+
+private:
+ QQuickEventPoint *m_currentPoint;
+ quint64 m_currentPointId;
+};
+
+QT_END_NAMESPACE
+
+QML_DECLARE_TYPE(QQuickPointerSingleHandler)
+
+#endif // QQUICKPOINTERSINGLEHANDLER_H