Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquicktaphandler_p.h
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKTAPHANDLER_H
5#define QQUICKTAPHANDLER_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qbasictimer.h>
19#include <QtCore/qelapsedtimer.h>
20#include <QtGui/qevent.h>
21#include <QtQuick/qquickitem.h>
22
24
26
27class Q_QUICK_EXPORT QQuickTapHandler : public QQuickSinglePointHandler
28{
30 Q_PROPERTY(bool pressed READ isPressed NOTIFY pressedChanged)
31 Q_PROPERTY(int tapCount READ tapCount NOTIFY tapCountChanged)
32 Q_PROPERTY(qreal timeHeld READ timeHeld NOTIFY timeHeldChanged)
33 Q_PROPERTY(qreal longPressThreshold READ longPressThreshold WRITE setLongPressThreshold NOTIFY longPressThresholdChanged RESET resetLongPressThreshold)
34 Q_PROPERTY(GesturePolicy gesturePolicy READ gesturePolicy WRITE setGesturePolicy NOTIFY gesturePolicyChanged)
35 Q_PROPERTY(QQuickTapHandler::ExclusiveSignals exclusiveSignals READ exclusiveSignals WRITE setExclusiveSignals NOTIFY exclusiveSignalsChanged REVISION(6, 5))
36
37 QML_NAMED_ELEMENT(TapHandler)
39
40public:
47 Q_ENUM(GesturePolicy)
48
50 NotExclusive = 0,
51 SingleTap = 1 << 0,
52 DoubleTap = 1 << 1
53 };
54 Q_DECLARE_FLAGS(ExclusiveSignals, ExclusiveSignal)
55 Q_FLAG(ExclusiveSignals)
56
57 explicit QQuickTapHandler(QQuickItem *parent = nullptr);
58
59 bool isPressed() const { return m_pressed; }
60
61 int tapCount() const { return m_tapCount; }
62 qreal timeHeld() const { return (m_holdTimer.isValid() ? m_holdTimer.elapsed() / 1000.0 : -1.0); }
63
64 qreal longPressThreshold() const;
65 void setLongPressThreshold(qreal longPressThreshold);
66 void resetLongPressThreshold();
67
68 GesturePolicy gesturePolicy() const { return m_gesturePolicy; }
69 void setGesturePolicy(GesturePolicy gesturePolicy);
70
71 QQuickTapHandler::ExclusiveSignals exclusiveSignals() const { return m_exclusiveSignals; }
72 void setExclusiveSignals(QQuickTapHandler::ExclusiveSignals newexclusiveSignals);
73
80 Q_REVISION(6, 5) void exclusiveSignalsChanged();
81 // the second argument (Qt::MouseButton) was added in 6.2: avoid name clashes with IDs by not naming it for now
82 void tapped(QEventPoint eventPoint, Qt::MouseButton /* button */);
83 void singleTapped(QEventPoint eventPoint, Qt::MouseButton /* button */);
84 void doubleTapped(QEventPoint eventPoint, Qt::MouseButton /* button */);
85 void longPressed();
86
87protected:
88 void onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition,
89 QPointerEvent *ev, QEventPoint &point) override;
90 void timerEvent(QTimerEvent *event) override;
91 bool wantsEventPoint(const QPointerEvent *event, const QEventPoint &point) override;
92 void handleEventPoint(QPointerEvent *event, QEventPoint &point) override;
93
95 void setPressed(bool press, bool cancel, QPointerEvent *event, QEventPoint &point);
96 void connectPreRenderSignal(bool conn = true);
97 void updateTimeHeld();
98
100 QPointF m_lastTapPos;
101 quint64 m_lastTapTimestamp = 0;
102 QElapsedTimer m_holdTimer;
103 QBasicTimer m_longPressTimer;
104 QBasicTimer m_doubleTapTimer;
105 QEventPoint m_singleTapReleasedPoint;
106 QMetaObject::Connection m_preRenderSignalConnection;
107 Qt::MouseButton m_singleTapReleasedButton;
108 int m_tapCount = 0;
109 int m_longPressThreshold = -1;
110 GesturePolicy m_gesturePolicy = GesturePolicy::DragThreshold;
111 ExclusiveSignals m_exclusiveSignals = NotExclusive;
112 bool m_pressed = false;
113 bool m_longPressed = false;
114
115 static quint64 m_multiTapInterval;
116 static int m_mouseMultiClickDistanceSquared;
117 static int m_touchMultiTapDistanceSquared;
118};
119
121
123
124#endif // QQUICKTAPHANDLER_H
\inmodule QtCore
Definition qbasictimer.h:18
\inmodule QtCore
The QEventPoint class provides information about a point in a QPointerEvent.
Definition qeventpoint.h:20
\inmodule QtCore Represents a handle to a signal-slot (or signal-functor) connection.
\inmodule QtCore\reentrant
Definition qpoint.h:217
A base class for pointer events.
Definition qevent.h:73
The QPointingDevice class describes a device from which mouse, touch or tablet events originate.
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
Q_REVISION(6, 5) void exclusiveSignalsChanged()
QQuickTapHandler::ExclusiveSignals exclusiveSignals() const
GesturePolicy gesturePolicy() const
qreal timeHeld() const
void tapCountChanged()
void gesturePolicyChanged()
void longPressThresholdChanged()
void timeHeldChanged()
\inmodule QtCore
Definition qcoreevent.h:366
Combined button and popup list for selecting options.
Definition qcompare.h:63
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
struct _cl_event * event
#define QML_NAMED_ELEMENT(NAME)
#define QML_ADDED_IN_VERSION(MAJOR, MINOR)
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_FLAG(x)
#define Q_SIGNALS
unsigned long long quint64
Definition qtypes.h:61
double qreal
Definition qtypes.h:187
future cancel()
\inmodule QtCore