Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/handlers/qquicktaphandler.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2017 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtQuick module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||
16 | ** | - | ||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
24 | ** | - | ||||||||||||||||||
25 | ** GNU General Public License Usage | - | ||||||||||||||||||
26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
35 | ** | - | ||||||||||||||||||
36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
37 | ** | - | ||||||||||||||||||
38 | ****************************************************************************/ | - | ||||||||||||||||||
39 | - | |||||||||||||||||||
40 | #include "qquicktaphandler_p.h" | - | ||||||||||||||||||
41 | #include <qpa/qplatformtheme.h> | - | ||||||||||||||||||
42 | #include <private/qguiapplication_p.h> | - | ||||||||||||||||||
43 | #include <QtGui/qstylehints.h> | - | ||||||||||||||||||
44 | - | |||||||||||||||||||
45 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
46 | - | |||||||||||||||||||
47 | Q_LOGGING_CATEGORY(lcTapHandler, "qt.quick.handler.tap") executed 358 times by 3 tests: return category; Executed by:
| 358 | ||||||||||||||||||
48 | - | |||||||||||||||||||
49 | qreal QQuickTapHandler::m_multiTapInterval(0.0); | - | ||||||||||||||||||
50 | // single tap distance is the same as the drag threshold | - | ||||||||||||||||||
51 | int QQuickTapHandler::m_mouseMultiClickDistanceSquared(-1); | - | ||||||||||||||||||
52 | int QQuickTapHandler::m_touchMultiTapDistanceSquared(-1); | - | ||||||||||||||||||
53 | - | |||||||||||||||||||
54 | /*! | - | ||||||||||||||||||
55 | \qmltype TapHandler | - | ||||||||||||||||||
56 | \instantiates QQuickTapHandler | - | ||||||||||||||||||
57 | \inherits SinglePointHandler | - | ||||||||||||||||||
58 | \inqmlmodule Qt.labs.handlers | - | ||||||||||||||||||
59 | \ingroup qtquick-handlers | - | ||||||||||||||||||
60 | \brief Handler for taps and clicks. | - | ||||||||||||||||||
61 | - | |||||||||||||||||||
62 | TapHandler is a handler for taps on a touchscreen or clicks on a mouse. | - | ||||||||||||||||||
63 | - | |||||||||||||||||||
64 | Detection of a valid tap gesture depends on \l gesturePolicy. The default | - | ||||||||||||||||||
65 | value is DragThreshold, which requires the press and release to be close | - | ||||||||||||||||||
66 | together in both space and time. In this case, DragHandler is able to | - | ||||||||||||||||||
67 | function using only a passive grab, and therefore does not interfere with | - | ||||||||||||||||||
68 | event delivery to any other Items or Pointer Handlers. So the default | - | ||||||||||||||||||
69 | gesturePolicy is useful when you want to modify behavior of an existing | - | ||||||||||||||||||
70 | control or Item by adding a TapHandler with bindings and/or JavaScript | - | ||||||||||||||||||
71 | callbacks. | - | ||||||||||||||||||
72 | - | |||||||||||||||||||
73 | Note that buttons (such as QPushButton) are often implemented not to care | - | ||||||||||||||||||
74 | whether the press and release occur close together: if you press the button | - | ||||||||||||||||||
75 | and then change your mind, you need to drag all the way off the edge of the | - | ||||||||||||||||||
76 | button in order to cancel the click. For this use case, set the | - | ||||||||||||||||||
77 | \l gesturePolicy to \c TapHandler.ReleaseWithinBounds. | - | ||||||||||||||||||
78 | - | |||||||||||||||||||
79 | For multi-tap gestures (double-tap, triple-tap etc.), the distance moved | - | ||||||||||||||||||
80 | must not exceed QPlatformTheme::MouseDoubleClickDistance with mouse and | - | ||||||||||||||||||
81 | QPlatformTheme::TouchDoubleTapDistance with touch, and the time between | - | ||||||||||||||||||
82 | taps must not exceed QStyleHints::mouseDoubleClickInterval(). | - | ||||||||||||||||||
83 | - | |||||||||||||||||||
84 | \sa MouseArea | - | ||||||||||||||||||
85 | */ | - | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | QQuickTapHandler::QQuickTapHandler(QObject *parent) | - | ||||||||||||||||||
88 | : QQuickSinglePointHandler(parent) | - | ||||||||||||||||||
89 | , m_pressed(false) | - | ||||||||||||||||||
90 | , m_gesturePolicy(DragThreshold) | - | ||||||||||||||||||
91 | , m_tapCount(0) | - | ||||||||||||||||||
92 | , m_longPressThreshold(-1) | - | ||||||||||||||||||
93 | , m_lastTapTimestamp(0.0) | - | ||||||||||||||||||
94 | { | - | ||||||||||||||||||
95 | if (m_mouseMultiClickDistanceSquared < 0) {
| 8-596 | ||||||||||||||||||
96 | m_multiTapInterval = qApp->styleHints()->mouseDoubleClickInterval() / 1000.0; | - | ||||||||||||||||||
97 | m_mouseMultiClickDistanceSquared = QGuiApplicationPrivate::platformTheme()-> | - | ||||||||||||||||||
98 | themeHint(QPlatformTheme::MouseDoubleClickDistance).toInt(); | - | ||||||||||||||||||
99 | m_mouseMultiClickDistanceSquared *= m_mouseMultiClickDistanceSquared; | - | ||||||||||||||||||
100 | m_touchMultiTapDistanceSquared = QGuiApplicationPrivate::platformTheme()-> | - | ||||||||||||||||||
101 | themeHint(QPlatformTheme::TouchDoubleTapDistance).toInt(); | - | ||||||||||||||||||
102 | m_touchMultiTapDistanceSquared *= m_touchMultiTapDistanceSquared; | - | ||||||||||||||||||
103 | } executed 8 times by 4 tests: end of block Executed by:
| 8 | ||||||||||||||||||
104 | } executed 604 times by 4 tests: end of block Executed by:
| 604 | ||||||||||||||||||
105 | - | |||||||||||||||||||
106 | QQuickTapHandler::~QQuickTapHandler() | - | ||||||||||||||||||
107 | { | - | ||||||||||||||||||
108 | } | - | ||||||||||||||||||
109 | - | |||||||||||||||||||
110 | static bool dragOverThreshold(const QQuickEventPoint *point) | - | ||||||||||||||||||
111 | { | - | ||||||||||||||||||
112 | QPointF delta = point->scenePosition() - point->scenePressPosition(); | - | ||||||||||||||||||
113 | return (QQuickWindowPrivate::dragOverThreshold(delta.x(), Qt::XAxis, point) || executed 2496 times by 3 tests: return (QQuickWindowPrivate::dragOverThreshold(delta.x(), Qt::XAxis, point) || QQuickWindowPrivate::dragOverThreshold(delta.y(), Qt::YAxis, point)); Executed by:
| 2496 | ||||||||||||||||||
114 | QQuickWindowPrivate::dragOverThreshold(delta.y(), Qt::YAxis, point)); executed 2496 times by 3 tests: return (QQuickWindowPrivate::dragOverThreshold(delta.x(), Qt::XAxis, point) || QQuickWindowPrivate::dragOverThreshold(delta.y(), Qt::YAxis, point)); Executed by:
| 2496 | ||||||||||||||||||
115 | } | - | ||||||||||||||||||
116 | - | |||||||||||||||||||
117 | bool QQuickTapHandler::wantsEventPoint(QQuickEventPoint *point) | - | ||||||||||||||||||
118 | { | - | ||||||||||||||||||
119 | // If the user has not violated any constraint, it could be a tap. | - | ||||||||||||||||||
120 | // Otherwise we want to give up the grab so that a competing handler | - | ||||||||||||||||||
121 | // (e.g. DragHandler) gets a chance to take over. | - | ||||||||||||||||||
122 | // Don't forget to emit released in case of a cancel. | - | ||||||||||||||||||
123 | bool ret = false; | - | ||||||||||||||||||
124 | switch (point->state()) { | - | ||||||||||||||||||
125 | case QQuickEventPoint::Pressed: executed 1168 times by 3 tests: case QQuickEventPoint::Pressed: Executed by:
| 1168 | ||||||||||||||||||
126 | case QQuickEventPoint::Released: executed 1546 times by 3 tests: case QQuickEventPoint::Released: Executed by:
| 1546 | ||||||||||||||||||
127 | ret = parentContains(point); | - | ||||||||||||||||||
128 | break; executed 2714 times by 3 tests: break; Executed by:
| 2714 | ||||||||||||||||||
129 | case QQuickEventPoint::Updated: executed 2816 times by 3 tests: case QQuickEventPoint::Updated: Executed by:
| 2816 | ||||||||||||||||||
130 | switch (m_gesturePolicy) { | - | ||||||||||||||||||
131 | case DragThreshold: executed 2496 times by 3 tests: case DragThreshold: Executed by:
| 2496 | ||||||||||||||||||
132 | ret = !dragOverThreshold(point); | - | ||||||||||||||||||
133 | break; executed 2496 times by 3 tests: break; Executed by:
| 2496 | ||||||||||||||||||
134 | case WithinBounds: executed 156 times by 2 tests: case WithinBounds: Executed by:
| 156 | ||||||||||||||||||
135 | ret = parentContains(point); | - | ||||||||||||||||||
136 | break; executed 156 times by 2 tests: break; Executed by:
| 156 | ||||||||||||||||||
137 | case ReleaseWithinBounds: executed 164 times by 2 tests: case ReleaseWithinBounds: Executed by:
| 164 | ||||||||||||||||||
138 | ret = point->pointId() == this->point().id(); | - | ||||||||||||||||||
139 | break; executed 164 times by 2 tests: break; Executed by:
| 164 | ||||||||||||||||||
140 | } | - | ||||||||||||||||||
141 | break; executed 2816 times by 3 tests: break; Executed by:
| 2816 | ||||||||||||||||||
142 | case QQuickEventPoint::Stationary: executed 262 times by 2 tests: case QQuickEventPoint::Stationary: Executed by:
| 262 | ||||||||||||||||||
143 | // Never react in any way when the point hasn't moved. | - | ||||||||||||||||||
144 | // In autotests, the point's position may not even be correct, because | - | ||||||||||||||||||
145 | // QTest::touchEvent(window, touchDevice).stationary(1) | - | ||||||||||||||||||
146 | // provides no opportunity to give a position, so it ends up being random. | - | ||||||||||||||||||
147 | break; executed 262 times by 2 tests: break; Executed by:
| 262 | ||||||||||||||||||
148 | } | - | ||||||||||||||||||
149 | // If this is the grabber, returning false from this function will cancel the grab, | - | ||||||||||||||||||
150 | // so onGrabChanged(this, CancelGrabExclusive, point) and setPressed(false) will be called. | - | ||||||||||||||||||
151 | // But when m_gesturePolicy is DragThreshold, we don't get an exclusive grab, but | - | ||||||||||||||||||
152 | // we still don't want to be pressed anymore. | - | ||||||||||||||||||
153 | if (!ret && point->pointId() == this->point().id() && point->state() != QQuickEventPoint::Stationary)
| 58-3442 | ||||||||||||||||||
154 | setPressed(false, true, point); executed 538 times by 3 tests: setPressed(false, true, point); Executed by:
| 538 | ||||||||||||||||||
155 | return ret; executed 5792 times by 3 tests: return ret; Executed by:
| 5792 | ||||||||||||||||||
156 | } | - | ||||||||||||||||||
157 | - | |||||||||||||||||||
158 | void QQuickTapHandler::handleEventPoint(QQuickEventPoint *point) | - | ||||||||||||||||||
159 | { | - | ||||||||||||||||||
160 | switch (point->state()) { | - | ||||||||||||||||||
161 | case QQuickEventPoint::Pressed: executed 156 times by 3 tests: case QQuickEventPoint::Pressed: Executed by:
| 156 | ||||||||||||||||||
162 | setPressed(true, false, point); | - | ||||||||||||||||||
163 | break; executed 156 times by 3 tests: break; Executed by:
| 156 | ||||||||||||||||||
164 | case QQuickEventPoint::Released: executed 120 times by 3 tests: case QQuickEventPoint::Released: Executed by:
| 120 | ||||||||||||||||||
165 | if ((point->pointerEvent()->buttons() & acceptedButtons()) == Qt::NoButton)
| 0-120 | ||||||||||||||||||
166 | setPressed(false, false, point); executed 120 times by 3 tests: setPressed(false, false, point); Executed by:
| 120 | ||||||||||||||||||
167 | break; executed 120 times by 3 tests: break; Executed by:
| 120 | ||||||||||||||||||
168 | default: executed 680 times by 3 tests: default: Executed by:
| 680 | ||||||||||||||||||
169 | break; executed 680 times by 3 tests: break; Executed by:
| 680 | ||||||||||||||||||
170 | } | - | ||||||||||||||||||
171 | } | - | ||||||||||||||||||
172 | - | |||||||||||||||||||
173 | /*! | - | ||||||||||||||||||
174 | \qmlproperty real QtQuick::TapHandler::longPressThreshold | - | ||||||||||||||||||
175 | - | |||||||||||||||||||
176 | The time in seconds that an event point must be pressed in order to | - | ||||||||||||||||||
177 | trigger a long press gesture and emit the \l longPressed() signal. | - | ||||||||||||||||||
178 | If the point is released before this time limit, a tap can be detected | - | ||||||||||||||||||
179 | if the \l gesturePolicy constraint is satisfied. The default value is | - | ||||||||||||||||||
180 | QStyleHints::mousePressAndHoldInterval() converted to seconds. | - | ||||||||||||||||||
181 | */ | - | ||||||||||||||||||
182 | qreal QQuickTapHandler::longPressThreshold() const | - | ||||||||||||||||||
183 | { | - | ||||||||||||||||||
184 | return longPressThresholdMilliseconds() / 1000.0; executed 64 times by 2 tests: return longPressThresholdMilliseconds() / 1000.0; Executed by:
| 64 | ||||||||||||||||||
185 | } | - | ||||||||||||||||||
186 | - | |||||||||||||||||||
187 | void QQuickTapHandler::setLongPressThreshold(qreal longPressThreshold) | - | ||||||||||||||||||
188 | { | - | ||||||||||||||||||
189 | int ms = qRound(longPressThreshold * 1000); | - | ||||||||||||||||||
190 | if (m_longPressThreshold == ms)
| 0-222 | ||||||||||||||||||
191 | return; never executed: return; | 0 | ||||||||||||||||||
192 | - | |||||||||||||||||||
193 | m_longPressThreshold = ms; | - | ||||||||||||||||||
194 | emit longPressThresholdChanged(); | - | ||||||||||||||||||
195 | } executed 222 times by 2 tests: end of block Executed by:
| 222 | ||||||||||||||||||
196 | - | |||||||||||||||||||
197 | int QQuickTapHandler::longPressThresholdMilliseconds() const | - | ||||||||||||||||||
198 | { | - | ||||||||||||||||||
199 | return (m_longPressThreshold < 0 ? QGuiApplication::styleHints()->mousePressAndHoldInterval() : m_longPressThreshold); executed 212 times by 3 tests: return (m_longPressThreshold < 0 ? QGuiApplication::styleHints()->mousePressAndHoldInterval() : m_longPressThreshold); Executed by:
| 212 | ||||||||||||||||||
200 | } | - | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | void QQuickTapHandler::timerEvent(QTimerEvent *event) | - | ||||||||||||||||||
203 | { | - | ||||||||||||||||||
204 | if (event->timerId() == m_longPressTimer.timerId()) {
| 0-4 | ||||||||||||||||||
205 | m_longPressTimer.stop(); | - | ||||||||||||||||||
206 | qCDebug(lcTapHandler) << objectName() << "longPressed"; never executed: QMessageLogger(__FILE__, 206, __PRETTY_FUNCTION__, lcTapHandler().categoryName()).debug() << objectName() << "longPressed";
| 0-4 | ||||||||||||||||||
207 | emit longPressed(); | - | ||||||||||||||||||
208 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
209 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
210 | - | |||||||||||||||||||
211 | /*! | - | ||||||||||||||||||
212 | \qmlsignal QtQuick::TapHandler::tapped() | - | ||||||||||||||||||
213 | - | |||||||||||||||||||
214 | This signal is emitted when the pointer device taps the item. | - | ||||||||||||||||||
215 | */ | - | ||||||||||||||||||
216 | - | |||||||||||||||||||
217 | /*! | - | ||||||||||||||||||
218 | \qmlsignal QtQuick::TapHandler::longPressed() | - | ||||||||||||||||||
219 | - | |||||||||||||||||||
220 | This signal is emitted when a press occurs that is longer than the | - | ||||||||||||||||||
221 | \l {TapHandler::longPressThreshold} {long press threshold}. | - | ||||||||||||||||||
222 | */ | - | ||||||||||||||||||
223 | - | |||||||||||||||||||
224 | /*! | - | ||||||||||||||||||
225 | \qmlproperty enumeration QtQuick::TapHandler::gesturePolicy | - | ||||||||||||||||||
226 | - | |||||||||||||||||||
227 | The spatial constraint for a tap or long press gesture to be recognized, | - | ||||||||||||||||||
228 | in addition to the constraint that the release must occur before | - | ||||||||||||||||||
229 | \l longPressThreshold has elapsed. If these constraints are not satisfied, | - | ||||||||||||||||||
230 | the \l tapped signal is not emitted, and \l tapCount is not incremented. | - | ||||||||||||||||||
231 | If the spatial constraint is violated, \l pressed transitions immediately | - | ||||||||||||||||||
232 | from true to false, regardless of the time held. | - | ||||||||||||||||||
233 | - | |||||||||||||||||||
234 | \value TapHandler.DragThreshold | - | ||||||||||||||||||
235 | (the default value) The event point must not move significantly. | - | ||||||||||||||||||
236 | If the mouse, finger or stylus moves past the system-wide drag | - | ||||||||||||||||||
237 | threshold (QStyleHints::startDragDistance), the tap gesture is | - | ||||||||||||||||||
238 | canceled, even if the button or finger is still pressed. This policy | - | ||||||||||||||||||
239 | can be useful whenever TapHandler needs to cooperate with other | - | ||||||||||||||||||
240 | pointer handlers (for example \l DragHandler) or event-handling Items | - | ||||||||||||||||||
241 | (for example QtQuick Controls), because in this case TapHandler | - | ||||||||||||||||||
242 | will not take the exclusive grab, but merely a passive grab. | - | ||||||||||||||||||
243 | - | |||||||||||||||||||
244 | \value TapHandler.WithinBounds | - | ||||||||||||||||||
245 | If the event point leaves the bounds of the \l target item, the tap | - | ||||||||||||||||||
246 | gesture is canceled. The TapHandler will take the exclusive grab on | - | ||||||||||||||||||
247 | press, but will release the grab as soon as the boundary constraint | - | ||||||||||||||||||
248 | is no longer satisfied. | - | ||||||||||||||||||
249 | - | |||||||||||||||||||
250 | \value TapHandler.ReleaseWithinBounds | - | ||||||||||||||||||
251 | At the time of release (the mouse button is released or the finger | - | ||||||||||||||||||
252 | is lifted), if the event point is outside the bounds of the | - | ||||||||||||||||||
253 | \l target item, a tap gesture is not recognized. This corresponds to | - | ||||||||||||||||||
254 | typical behavior for button widgets: you can cancel a click by | - | ||||||||||||||||||
255 | dragging outside the button, and you can also change your mind by | - | ||||||||||||||||||
256 | dragging back inside the button before release. Note that it's | - | ||||||||||||||||||
257 | necessary for TapHandler take the exclusive grab on press and retain | - | ||||||||||||||||||
258 | it until release in order to detect this gesture. | - | ||||||||||||||||||
259 | */ | - | ||||||||||||||||||
260 | void QQuickTapHandler::setGesturePolicy(QQuickTapHandler::GesturePolicy gesturePolicy) | - | ||||||||||||||||||
261 | { | - | ||||||||||||||||||
262 | if (m_gesturePolicy == gesturePolicy)
| 146-448 | ||||||||||||||||||
263 | return; executed 448 times by 3 tests: return; Executed by:
| 448 | ||||||||||||||||||
264 | - | |||||||||||||||||||
265 | m_gesturePolicy = gesturePolicy; | - | ||||||||||||||||||
266 | emit gesturePolicyChanged(); | - | ||||||||||||||||||
267 | } executed 146 times by 2 tests: end of block Executed by:
| 146 | ||||||||||||||||||
268 | - | |||||||||||||||||||
269 | /*! | - | ||||||||||||||||||
270 | \qmlproperty bool QtQuick::TapHandler::pressed | - | ||||||||||||||||||
271 | \readonly | - | ||||||||||||||||||
272 | - | |||||||||||||||||||
273 | Holds true whenever the mouse or touch point is pressed, | - | ||||||||||||||||||
274 | and any movement since the press is compliant with the current | - | ||||||||||||||||||
275 | \l gesturePolicy. When the event point is released or the policy is | - | ||||||||||||||||||
276 | violated, \e pressed will change to false. | - | ||||||||||||||||||
277 | */ | - | ||||||||||||||||||
278 | void QQuickTapHandler::setPressed(bool press, bool cancel, QQuickEventPoint *point) | - | ||||||||||||||||||
279 | { | - | ||||||||||||||||||
280 | if (m_pressed != press) {
| 290-614 | ||||||||||||||||||
281 | qCDebug(lcTapHandler) << objectName() << "pressed" << m_pressed << "->" << press << (cancel ? "CANCEL" : "") << point; never executed: QMessageLogger(__FILE__, 281, __PRETTY_FUNCTION__, lcTapHandler().categoryName()).debug() << objectName() << "pressed" << m_pressed << "->" << press << (cancel ? "CANCEL" : "") << point;
| 0-290 | ||||||||||||||||||
282 | m_pressed = press; | - | ||||||||||||||||||
283 | connectPreRenderSignal(press); | - | ||||||||||||||||||
284 | updateTimeHeld(); | - | ||||||||||||||||||
285 | if (press) {
| 142-148 | ||||||||||||||||||
286 | m_longPressTimer.start(longPressThresholdMilliseconds(), this); | - | ||||||||||||||||||
287 | m_holdTimer.start(); | - | ||||||||||||||||||
288 | } else { executed 148 times by 3 tests: end of block Executed by:
| 148 | ||||||||||||||||||
289 | m_longPressTimer.stop(); | - | ||||||||||||||||||
290 | m_holdTimer.invalidate(); | - | ||||||||||||||||||
291 | } executed 142 times by 3 tests: end of block Executed by:
| 142 | ||||||||||||||||||
292 | if (press) {
| 142-148 | ||||||||||||||||||
293 | // on press, grab before emitting changed signals | - | ||||||||||||||||||
294 | if (m_gesturePolicy == DragThreshold)
| 50-98 | ||||||||||||||||||
295 | setPassiveGrab(point, press); executed 98 times by 3 tests: setPassiveGrab(point, press); Executed by:
| 98 | ||||||||||||||||||
296 | else | - | ||||||||||||||||||
297 | setExclusiveGrab(point, press); executed 50 times by 2 tests: setExclusiveGrab(point, press); Executed by:
| 50 | ||||||||||||||||||
298 | } | - | ||||||||||||||||||
299 | if (!cancel && !press && parentContains(point)) {
| 0-212 | ||||||||||||||||||
300 | if (point->timeHeld() < longPressThreshold()) {
| 4-60 | ||||||||||||||||||
301 | // Assuming here that pointerEvent()->timestamp() is in ms. | - | ||||||||||||||||||
302 | qreal ts = point->pointerEvent()->timestamp() / 1000.0; | - | ||||||||||||||||||
303 | if (ts - m_lastTapTimestamp < m_multiTapInterval &&
| 16-44 | ||||||||||||||||||
304 | QVector2D(point->scenePosition() - m_lastTapPos).lengthSquared() <
| 2-14 | ||||||||||||||||||
305 | (point->pointerEvent()->device()->type() == QQuickPointerDevice::Mouse ?
| 2-14 | ||||||||||||||||||
306 | m_mouseMultiClickDistanceSquared : m_touchMultiTapDistanceSquared))
| 2-14 | ||||||||||||||||||
307 | ++m_tapCount; executed 2 times by 1 test: ++m_tapCount; Executed by:
| 2 | ||||||||||||||||||
308 | else | - | ||||||||||||||||||
309 | m_tapCount = 1; executed 58 times by 2 tests: m_tapCount = 1; Executed by:
| 58 | ||||||||||||||||||
310 | qCDebug(lcTapHandler) << objectName() << "tapped" << m_tapCount << "times"; never executed: QMessageLogger(__FILE__, 310, __PRETTY_FUNCTION__, lcTapHandler().categoryName()).debug() << objectName() << "tapped" << m_tapCount << "times";
| 0-60 | ||||||||||||||||||
311 | emit tapped(); | - | ||||||||||||||||||
312 | emit tapCountChanged(); | - | ||||||||||||||||||
313 | if (m_tapCount == 1)
| 2-58 | ||||||||||||||||||
314 | emit singleTapped(); executed 58 times by 2 tests: singleTapped(); Executed by:
| 58 | ||||||||||||||||||
315 | else if (m_tapCount == 2)
| 0-2 | ||||||||||||||||||
316 | emit doubleTapped(); executed 2 times by 1 test: doubleTapped(); Executed by:
| 2 | ||||||||||||||||||
317 | m_lastTapTimestamp = ts; | - | ||||||||||||||||||
318 | m_lastTapPos = point->scenePosition(); | - | ||||||||||||||||||
319 | } else { executed 60 times by 2 tests: end of block Executed by:
| 60 | ||||||||||||||||||
320 | qCDebug(lcTapHandler) << objectName() << "tap threshold" << longPressThreshold() << "exceeded:" << point->timeHeld(); never executed: QMessageLogger(__FILE__, 320, __PRETTY_FUNCTION__, lcTapHandler().categoryName()).debug() << objectName() << "tap threshold" << longPressThreshold() << "exceeded:" << point->timeHeld();
| 0-4 | ||||||||||||||||||
321 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
322 | } | - | ||||||||||||||||||
323 | emit pressedChanged(); | - | ||||||||||||||||||
324 | if (!press && m_gesturePolicy != DragThreshold) {
| 46-148 | ||||||||||||||||||
325 | // on release, ungrab after emitting changed signals | - | ||||||||||||||||||
326 | setExclusiveGrab(point, press); | - | ||||||||||||||||||
327 | } executed 46 times by 2 tests: end of block Executed by:
| 46 | ||||||||||||||||||
328 | if (cancel)
| 78-212 | ||||||||||||||||||
329 | emit canceled(point); executed 78 times by 3 tests: canceled(point); Executed by:
| 78 | ||||||||||||||||||
330 | } executed 290 times by 3 tests: end of block Executed by:
| 290 | ||||||||||||||||||
331 | } executed 904 times by 3 tests: end of block Executed by:
| 904 | ||||||||||||||||||
332 | - | |||||||||||||||||||
333 | void QQuickTapHandler::onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabState stateChange, QQuickEventPoint *point) | - | ||||||||||||||||||
334 | { | - | ||||||||||||||||||
335 | QQuickSinglePointHandler::onGrabChanged(grabber, stateChange, point); | - | ||||||||||||||||||
336 | bool isCanceled = stateChange == QQuickEventPoint::CancelGrabExclusive || stateChange == QQuickEventPoint::CancelGrabPassive;
| 8-268 | ||||||||||||||||||
337 | if (grabber == this && (isCanceled || point->state() == QQuickEventPoint::Released))
| 22-254 | ||||||||||||||||||
338 | setPressed(false, isCanceled, point); executed 90 times by 3 tests: setPressed(false, isCanceled, point); Executed by:
| 90 | ||||||||||||||||||
339 | } executed 276 times by 3 tests: end of block Executed by:
| 276 | ||||||||||||||||||
340 | - | |||||||||||||||||||
341 | void QQuickTapHandler::connectPreRenderSignal(bool conn) | - | ||||||||||||||||||
342 | { | - | ||||||||||||||||||
343 | if (conn)
| 142-148 | ||||||||||||||||||
344 | connect(parentItem()->window(), &QQuickWindow::beforeSynchronizing, this, &QQuickTapHandler::updateTimeHeld); executed 148 times by 3 tests: connect(parentItem()->window(), &QQuickWindow::beforeSynchronizing, this, &QQuickTapHandler::updateTimeHeld); Executed by:
| 148 | ||||||||||||||||||
345 | else | - | ||||||||||||||||||
346 | disconnect(parentItem()->window(), &QQuickWindow::beforeSynchronizing, this, &QQuickTapHandler::updateTimeHeld); executed 142 times by 3 tests: disconnect(parentItem()->window(), &QQuickWindow::beforeSynchronizing, this, &QQuickTapHandler::updateTimeHeld); Executed by:
| 142 | ||||||||||||||||||
347 | } | - | ||||||||||||||||||
348 | - | |||||||||||||||||||
349 | void QQuickTapHandler::updateTimeHeld() | - | ||||||||||||||||||
350 | { | - | ||||||||||||||||||
351 | emit timeHeldChanged(); | - | ||||||||||||||||||
352 | } executed 594 times by 3 tests: end of block Executed by:
| 594 | ||||||||||||||||||
353 | - | |||||||||||||||||||
354 | /*! | - | ||||||||||||||||||
355 | \qmlproperty int QtQuick::TapHandler::tapCount | - | ||||||||||||||||||
356 | \readonly | - | ||||||||||||||||||
357 | - | |||||||||||||||||||
358 | The number of taps which have occurred within the time and space | - | ||||||||||||||||||
359 | constraints to be considered a single gesture. For example, to detect | - | ||||||||||||||||||
360 | a triple-tap, you can write: | - | ||||||||||||||||||
361 | - | |||||||||||||||||||
362 | \qml | - | ||||||||||||||||||
363 | Rectangle { | - | ||||||||||||||||||
364 | width: 100; height: 30 | - | ||||||||||||||||||
365 | signal tripleTap | - | ||||||||||||||||||
366 | TapHandler { | - | ||||||||||||||||||
367 | acceptedButtons: Qt.AllButtons | - | ||||||||||||||||||
368 | onTapped: if (tapCount == 3) tripleTap() | - | ||||||||||||||||||
369 | } | - | ||||||||||||||||||
370 | } | - | ||||||||||||||||||
371 | \endqml | - | ||||||||||||||||||
372 | */ | - | ||||||||||||||||||
373 | - | |||||||||||||||||||
374 | /*! | - | ||||||||||||||||||
375 | \qmlproperty real QtQuick::TapHandler::timeHeld | - | ||||||||||||||||||
376 | \readonly | - | ||||||||||||||||||
377 | - | |||||||||||||||||||
378 | The amount of time in seconds that a pressed point has been held, without | - | ||||||||||||||||||
379 | moving beyond the drag threshold. It will be updated at least once per | - | ||||||||||||||||||
380 | frame rendered, which enables rendering an animation showing the progress | - | ||||||||||||||||||
381 | towards an action which will be triggered by a long-press. It is also | - | ||||||||||||||||||
382 | possible to trigger one of a series of actions depending on how long the | - | ||||||||||||||||||
383 | press is held. | - | ||||||||||||||||||
384 | - | |||||||||||||||||||
385 | A value of less than zero means no point is being held within this | - | ||||||||||||||||||
386 | handler's \l [QML] Item. | - | ||||||||||||||||||
387 | */ | - | ||||||||||||||||||
388 | - | |||||||||||||||||||
389 | /*! | - | ||||||||||||||||||
390 | \qmlsignal TapHandler::singleTapped | - | ||||||||||||||||||
391 | \since 5.11 | - | ||||||||||||||||||
392 | - | |||||||||||||||||||
393 | This signal is emitted when the \l target is tapped once. After an amount | - | ||||||||||||||||||
394 | of time greater than QStyleHints::mouseDoubleClickInterval, it can be | - | ||||||||||||||||||
395 | tapped again; but if the time until the next tap is less, \l tapCount | - | ||||||||||||||||||
396 | will increase. | - | ||||||||||||||||||
397 | */ | - | ||||||||||||||||||
398 | - | |||||||||||||||||||
399 | /*! | - | ||||||||||||||||||
400 | \qmlsignal TapHandler::doubleTapped | - | ||||||||||||||||||
401 | \since 5.11 | - | ||||||||||||||||||
402 | - | |||||||||||||||||||
403 | This signal is emitted when the \l target is tapped twice within a short | - | ||||||||||||||||||
404 | span of time (QStyleHints::mouseDoubleClickInterval) and distance | - | ||||||||||||||||||
405 | (QPlatformTheme::MouseDoubleClickDistance or | - | ||||||||||||||||||
406 | QPlatformTheme::TouchDoubleTapDistance). This signal always occurs | - | ||||||||||||||||||
407 | after singleTapped, tapped and tapCountChanged. | - | ||||||||||||||||||
408 | */ | - | ||||||||||||||||||
409 | QT_END_NAMESPACE | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |