Qt 6.x
The Qt SDK
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_PRIVATE_EXPORT QQuickTapHandler : public QQuickSinglePointHandler
28{
30 Q_PROPERTY(bool pressed READ isPressed NOTIFY pressedChanged FINAL)
31 Q_PROPERTY(int tapCount READ tapCount NOTIFY tapCountChanged FINAL)
32 Q_PROPERTY(qreal timeHeld READ timeHeld NOTIFY timeHeldChanged FINAL)
33 Q_PROPERTY(qreal longPressThreshold READ longPressThreshold WRITE setLongPressThreshold NOTIFY longPressThresholdChanged FINAL)
34 Q_PROPERTY(GesturePolicy gesturePolicy READ gesturePolicy WRITE setGesturePolicy NOTIFY gesturePolicyChanged FINAL)
35 Q_PROPERTY(QQuickTapHandler::ExclusiveSignals exclusiveSignals READ exclusiveSignals WRITE setExclusiveSignals NOTIFY exclusiveSignalsChanged REVISION(6, 5) FINAL)
36
37 QML_NAMED_ELEMENT(TapHandler)
39
40public:
45 DragWithinBounds
46 };
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(ExclusiveSignal)
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
67 GesturePolicy gesturePolicy() const { return m_gesturePolicy; }
68 void setGesturePolicy(GesturePolicy gesturePolicy);
69
70 QQuickTapHandler::ExclusiveSignals exclusiveSignals() const { return m_exclusiveSignals; }
71 void setExclusiveSignals(QQuickTapHandler::ExclusiveSignals newexclusiveSignals);
72
79 Q_REVISION(6, 5) void exclusiveSignalsChanged();
80 // the second argument (Qt::MouseButton) was added in 6.2: avoid name clashes with IDs by not naming it for now
81 void tapped(QEventPoint eventPoint, Qt::MouseButton /* button */);
82 void singleTapped(QEventPoint eventPoint, Qt::MouseButton /* button */);
83 void doubleTapped(QEventPoint eventPoint, Qt::MouseButton /* button */);
84 void longPressed();
85
86protected:
87 void onGrabChanged(QQuickPointerHandler *grabber, QPointingDevice::GrabTransition transition,
88 QPointerEvent *ev, QEventPoint &point) override;
89 void timerEvent(QTimerEvent *event) override;
90 bool wantsEventPoint(const QPointerEvent *event, const QEventPoint &point) override;
91 void handleEventPoint(QPointerEvent *event, QEventPoint &point) override;
92
94 void setPressed(bool press, bool cancel, QPointerEvent *event, QEventPoint &point);
95 int longPressThresholdMilliseconds() const;
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 Qt::MouseButton m_singleTapReleasedButton;
107 int m_tapCount = 0;
108 int m_longPressThreshold = -1;
109 GesturePolicy m_gesturePolicy = GesturePolicy::DragThreshold;
110 ExclusiveSignals m_exclusiveSignals = NotExclusive;
111 bool m_pressed = false;
112
113 static quint64 m_multiTapInterval;
114 static int m_mouseMultiClickDistanceSquared;
115 static int m_touchMultiTapDistanceSquared;
116};
117
119
121
122#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\reentrant
Definition qpoint.h:214
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:64
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:359
Combined button and popup list for selecting options.
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:56
double qreal
Definition qtypes.h:92
future cancel()
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent