aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/handlers
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2018-03-22 21:49:39 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2018-12-05 12:11:39 +0000
commit2fa9c254f34a7b1ad019fd8b71ceb5d6fffdea59 (patch)
treef69a401ace036a48bdd06dbd0eb72a1a2c21652d /src/quick/handlers
parent74d23ca548b47c85c4b8cdde5fd5a9026e4eb08c (diff)
Refactor QQuickSinglePointHandler into public and private classes
Change-Id: Idf861ce4286e24cecd81f802032243b467950c5e Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/quick/handlers')
-rw-r--r--src/quick/handlers/handlers.pri1
-rw-r--r--src/quick/handlers/qquicksinglepointhandler.cpp62
-rw-r--r--src/quick/handlers/qquicksinglepointhandler_p.h16
-rw-r--r--src/quick/handlers/qquicksinglepointhandler_p_p.h79
4 files changed, 131 insertions, 27 deletions
diff --git a/src/quick/handlers/handlers.pri b/src/quick/handlers/handlers.pri
index 1258822f40..226cca22cb 100644
--- a/src/quick/handlers/handlers.pri
+++ b/src/quick/handlers/handlers.pri
@@ -10,6 +10,7 @@ HEADERS += \
$$PWD/qquickpointerhandler_p_p.h \
$$PWD/qquickpointhandler_p.h \
$$PWD/qquicksinglepointhandler_p.h \
+ $$PWD/qquicksinglepointhandler_p_p.h \
$$PWD/qquicktaphandler_p.h \
$$PWD/qquickdragaxis_p.h
diff --git a/src/quick/handlers/qquicksinglepointhandler.cpp b/src/quick/handlers/qquicksinglepointhandler.cpp
index 82e5b1b05d..8f2f403975 100644
--- a/src/quick/handlers/qquicksinglepointhandler.cpp
+++ b/src/quick/handlers/qquicksinglepointhandler.cpp
@@ -38,6 +38,7 @@
****************************************************************************/
#include "qquicksinglepointhandler_p.h"
+#include "qquicksinglepointhandler_p_p.h"
QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(DBG_TOUCH_TARGET)
@@ -59,19 +60,25 @@ Q_DECLARE_LOGGING_CATEGORY(DBG_TOUCH_TARGET)
*/
QQuickSinglePointHandler::QQuickSinglePointHandler(QQuickItem *parent)
- : QQuickPointerDeviceHandler(parent)
+ : QQuickPointerDeviceHandler(*(new QQuickSinglePointHandlerPrivate), parent)
+{
+}
+
+QQuickSinglePointHandler::QQuickSinglePointHandler(QQuickSinglePointHandlerPrivate &dd, QQuickItem *parent)
+ : QQuickPointerDeviceHandler(dd, parent)
{
}
bool QQuickSinglePointHandler::wantsPointerEvent(QQuickPointerEvent *event)
{
+ Q_D(QQuickSinglePointHandler);
if (!QQuickPointerDeviceHandler::wantsPointerEvent(event))
return false;
if (event->device()->pointerType() != QQuickPointerDevice::Finger &&
(event->buttons() & acceptedButtons()) == 0 && (event->button() & acceptedButtons()) == 0)
return false;
- if (m_pointInfo.m_id) {
+ if (d->pointInfo.id()) {
// We already know which one we want, so check whether it's there.
// It's expected to be an update or a release.
// If we no longer want it, cancel the grab.
@@ -81,7 +88,7 @@ bool QQuickSinglePointHandler::wantsPointerEvent(QQuickPointerEvent *event)
int c = event->pointCount();
for (int i = 0; i < c; ++i) {
QQuickEventPoint *p = event->point(i);
- const bool found = (p->pointId() == m_pointInfo.m_id);
+ const bool found = (p->pointId() == d->pointInfo.id());
if (found)
missing = false;
if (wantsEventPoint(p)) {
@@ -91,10 +98,10 @@ bool QQuickSinglePointHandler::wantsPointerEvent(QQuickPointerEvent *event)
}
}
if (missing)
- qCWarning(DBG_TOUCH_TARGET) << this << "pointId" << hex << m_pointInfo.m_id
+ qCWarning(DBG_TOUCH_TARGET) << this << "pointId" << hex << d->pointInfo.id()
<< "is missing from current event, but was neither canceled nor released";
if (point) {
- if (candidatePointCount == 1 || (candidatePointCount > 1 && m_ignoreAdditionalPoints)) {
+ if (candidatePointCount == 1 || (candidatePointCount > 1 && d->ignoreAdditionalPoints)) {
point->setAccepted();
return true;
} else {
@@ -121,35 +128,37 @@ bool QQuickSinglePointHandler::wantsPointerEvent(QQuickPointerEvent *event)
chosen->setAccepted();
}
}
- return m_pointInfo.m_id;
+ return d->pointInfo.id();
}
void QQuickSinglePointHandler::handlePointerEventImpl(QQuickPointerEvent *event)
{
+ Q_D(QQuickSinglePointHandler);
QQuickPointerDeviceHandler::handlePointerEventImpl(event);
- QQuickEventPoint *currentPoint = event->pointById(m_pointInfo.m_id);
+ QQuickEventPoint *currentPoint = event->pointById(d->pointInfo.id());
Q_ASSERT(currentPoint);
- m_pointInfo.reset(currentPoint);
+ d->pointInfo.reset(currentPoint);
handleEventPoint(currentPoint);
if (currentPoint->state() == QQuickEventPoint::Released && (event->buttons() & acceptedButtons()) == Qt::NoButton) {
setExclusiveGrab(currentPoint, false);
- reset();
+ d->reset();
}
emit pointChanged();
}
void QQuickSinglePointHandler::onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point)
{
+ Q_D(QQuickSinglePointHandler);
if (grabber != this)
return;
switch (transition) {
case QQuickEventPoint::GrabExclusive:
- m_pointInfo.m_sceneGrabPosition = point->sceneGrabPosition();
+ d->pointInfo.m_sceneGrabPosition = point->sceneGrabPosition();
setActive(true);
QQuickPointerHandler::onGrabChanged(grabber, transition, point);
break;
case QQuickEventPoint::GrabPassive:
- m_pointInfo.m_sceneGrabPosition = point->sceneGrabPosition();
+ d->pointInfo.m_sceneGrabPosition = point->sceneGrabPosition();
QQuickPointerHandler::onGrabChanged(grabber, transition, point);
break;
case QQuickEventPoint::OverrideGrabPassive:
@@ -160,32 +169,35 @@ void QQuickSinglePointHandler::onGrabChanged(QQuickPointerHandler *grabber, QQui
case QQuickEventPoint::CancelGrabExclusive:
// the grab is lost or relinquished, so the point is no longer relevant
QQuickPointerHandler::onGrabChanged(grabber, transition, point);
- reset();
+ d->reset();
break;
}
}
void QQuickSinglePointHandler::setIgnoreAdditionalPoints(bool v)
{
- m_ignoreAdditionalPoints = v;
+ Q_D(QQuickSinglePointHandler);
+ d->ignoreAdditionalPoints = v;
}
void QQuickSinglePointHandler::moveTarget(QPointF pos, QQuickEventPoint *point)
{
+ Q_D(QQuickSinglePointHandler);
target()->setPosition(pos);
- m_pointInfo.m_scenePosition = point->scenePosition();
- m_pointInfo.m_position = target()->mapFromScene(m_pointInfo.m_scenePosition);
+ d->pointInfo.m_scenePosition = point->scenePosition();
+ d->pointInfo.m_position = target()->mapFromScene(d->pointInfo.m_scenePosition);
}
void QQuickSinglePointHandler::setPointId(int id)
{
- m_pointInfo.m_id = id;
+ Q_D(QQuickSinglePointHandler);
+ d->pointInfo.m_id = id;
}
-void QQuickSinglePointHandler::reset()
+QQuickHandlerPoint QQuickSinglePointHandler::point() const
{
- setActive(false);
- m_pointInfo.reset();
+ Q_D(const QQuickSinglePointHandler);
+ return d->pointInfo;
}
/*!
@@ -196,4 +208,16 @@ void QQuickSinglePointHandler::reset()
handled, this object is reset to default values (all coordinates are 0).
*/
+QQuickSinglePointHandlerPrivate::QQuickSinglePointHandlerPrivate()
+ : QQuickPointerDeviceHandlerPrivate()
+{
+}
+
+void QQuickSinglePointHandlerPrivate::reset()
+{
+ Q_Q(QQuickSinglePointHandler);
+ q->setActive(false);
+ pointInfo.reset();
+}
+
QT_END_NAMESPACE
diff --git a/src/quick/handlers/qquicksinglepointhandler_p.h b/src/quick/handlers/qquicksinglepointhandler_p.h
index b9e5b12224..edc55aaaf6 100644
--- a/src/quick/handlers/qquicksinglepointhandler_p.h
+++ b/src/quick/handlers/qquicksinglepointhandler_p.h
@@ -56,24 +56,29 @@
QT_BEGIN_NAMESPACE
+class QQuickSinglePointHandlerPrivate;
+
class Q_QUICK_PRIVATE_EXPORT QQuickSinglePointHandler : public QQuickPointerDeviceHandler
{
Q_OBJECT
Q_PROPERTY(QQuickHandlerPoint point READ point NOTIFY pointChanged)
+
public:
explicit QQuickSinglePointHandler(QQuickItem *parent = nullptr);
- QQuickHandlerPoint point() const { return m_pointInfo; }
+ QQuickHandlerPoint point() const;
Q_SIGNALS:
void pointChanged();
protected:
+ QQuickSinglePointHandler(QQuickSinglePointHandlerPrivate &dd, QQuickItem *parent);
+
bool wantsPointerEvent(QQuickPointerEvent *event) override;
void handlePointerEventImpl(QQuickPointerEvent *event) override;
virtual void handleEventPoint(QQuickEventPoint *point) = 0;
- QQuickEventPoint *currentPoint(QQuickPointerEvent *ev) { return ev->pointById(m_pointInfo.m_id); }
+ QQuickEventPoint *currentPoint(QQuickPointerEvent *ev);
void onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point) override;
void setIgnoreAdditionalPoints(bool v = true);
@@ -82,12 +87,7 @@ protected:
void setPointId(int id);
-private:
- void reset();
-
-private:
- QQuickHandlerPoint m_pointInfo;
- bool m_ignoreAdditionalPoints = false;
+ Q_DECLARE_PRIVATE(QQuickSinglePointHandler)
};
QT_END_NAMESPACE
diff --git a/src/quick/handlers/qquicksinglepointhandler_p_p.h b/src/quick/handlers/qquicksinglepointhandler_p_p.h
new file mode 100644
index 0000000000..1e66c25e14
--- /dev/null
+++ b/src/quick/handlers/qquicksinglepointhandler_p_p.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 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_P_H
+#define QQUICKPOINTERSINGLEHANDLER_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 "qquickhandlerpoint_p.h"
+#include "qquickpointerdevicehandler_p_p.h"
+#include "qquicksinglepointhandler_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class Q_QUICK_PRIVATE_EXPORT QQuickSinglePointHandlerPrivate : public QQuickPointerDeviceHandlerPrivate
+{
+ Q_DECLARE_PUBLIC(QQuickSinglePointHandler)
+
+public:
+ static QQuickSinglePointHandlerPrivate* get(QQuickSinglePointHandler *q) { return q->d_func(); }
+ static const QQuickSinglePointHandlerPrivate* get(const QQuickSinglePointHandler *q) { return q->d_func(); }
+
+ QQuickSinglePointHandlerPrivate();
+
+ void reset();
+
+ QQuickHandlerPoint pointInfo;
+ bool ignoreAdditionalPoints = false;
+};
+
+QT_END_NAMESPACE
+
+#endif // QQUICKPOINTERSINGLEHANDLER_P_H
+