Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/handlers/qquicktaphandler.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | const QLoggingCategory &lcTapHandler() { static const QLoggingCategory category("qt.quick.handler.tap"); return executed 358 times by 3 tests: category;return category; Executed by:
executed 358 times by 3 tests: }return category; Executed by:
| 358 | ||||||||||||||||||
5 | - | |||||||||||||||||||
6 | qreal QQuickTapHandler::m_multiTapInterval(0.0); | - | ||||||||||||||||||
7 | - | |||||||||||||||||||
8 | int QQuickTapHandler::m_mouseMultiClickDistanceSquared(-1); | - | ||||||||||||||||||
9 | int QQuickTapHandler::m_touchMultiTapDistanceSquared(-1); | - | ||||||||||||||||||
10 | QQuickTapHandler::QQuickTapHandler(QObject *parent) | - | ||||||||||||||||||
11 | : QQuickSinglePointHandler(parent) | - | ||||||||||||||||||
12 | , m_pressed(false) | - | ||||||||||||||||||
13 | , m_gesturePolicy(DragThreshold) | - | ||||||||||||||||||
14 | , m_tapCount(0) | - | ||||||||||||||||||
15 | , m_longPressThreshold(-1) | - | ||||||||||||||||||
16 | , m_lastTapTimestamp(0.0) | - | ||||||||||||||||||
17 | { | - | ||||||||||||||||||
18 | if (m_mouseMultiClickDistanceSquared < 0
| 8-596 | ||||||||||||||||||
19 | m_multiTapInterval = (static_cast<QGuiApplication *>(QCoreApplication::instance()))->styleHints()->mouseDoubleClickInterval() / 1000.0; | - | ||||||||||||||||||
20 | m_mouseMultiClickDistanceSquared = QGuiApplicationPrivate::platformTheme()-> | - | ||||||||||||||||||
21 | themeHint(QPlatformTheme::MouseDoubleClickDistance).toInt(); | - | ||||||||||||||||||
22 | m_mouseMultiClickDistanceSquared *= m_mouseMultiClickDistanceSquared; | - | ||||||||||||||||||
23 | m_touchMultiTapDistanceSquared = QGuiApplicationPrivate::platformTheme()-> | - | ||||||||||||||||||
24 | themeHint(QPlatformTheme::TouchDoubleTapDistance).toInt(); | - | ||||||||||||||||||
25 | m_touchMultiTapDistanceSquared *= m_touchMultiTapDistanceSquared; | - | ||||||||||||||||||
26 | } executed 8 times by 4 tests: end of block Executed by:
| 8 | ||||||||||||||||||
27 | } executed 604 times by 4 tests: end of block Executed by:
| 604 | ||||||||||||||||||
28 | - | |||||||||||||||||||
29 | QQuickTapHandler::~QQuickTapHandler() | - | ||||||||||||||||||
30 | { | - | ||||||||||||||||||
31 | } | - | ||||||||||||||||||
32 | - | |||||||||||||||||||
33 | static bool dragOverThreshold(const QQuickEventPoint *point) | - | ||||||||||||||||||
34 | { | - | ||||||||||||||||||
35 | QPointF delta = point->scenePosition() - point->scenePressPosition(); | - | ||||||||||||||||||
36 | return executed 2496 times by 3 tests: (QQuickWindowPrivate::dragOverThreshold(delta.x(), Qt::XAxis, point) ||return (QQuickWindowPrivate::dragOverThreshold(delta.x(), Qt::XAxis, point) || QQuickWindowPrivate::dragOverThreshold(delta.y(), Qt::YAxis, point)); Executed by:
executed 2496 times by 3 tests: return (QQuickWindowPrivate::dragOverThreshold(delta.x(), Qt::XAxis, point) || QQuickWindowPrivate::dragOverThreshold(delta.y(), Qt::YAxis, point)); Executed by:
| 2496 | ||||||||||||||||||
37 | 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 | ||||||||||||||||||
38 | } | - | ||||||||||||||||||
39 | - | |||||||||||||||||||
40 | bool QQuickTapHandler::wantsEventPoint(QQuickEventPoint *point) | - | ||||||||||||||||||
41 | { | - | ||||||||||||||||||
42 | - | |||||||||||||||||||
43 | - | |||||||||||||||||||
44 | - | |||||||||||||||||||
45 | - | |||||||||||||||||||
46 | bool ret = false; | - | ||||||||||||||||||
47 | switch (point->state()) { | - | ||||||||||||||||||
48 | case executed 1168 times by 3 tests: QQuickEventPoint::Pressed:case QQuickEventPoint::Pressed: Executed by:
executed 1168 times by 3 tests: case QQuickEventPoint::Pressed: Executed by:
| 1168 | ||||||||||||||||||
49 | case executed 1546 times by 3 tests: QQuickEventPoint::Released:case QQuickEventPoint::Released: Executed by:
executed 1546 times by 3 tests: case QQuickEventPoint::Released: Executed by:
| 1546 | ||||||||||||||||||
50 | ret = parentContains(point); | - | ||||||||||||||||||
51 | break; executed 2714 times by 3 tests: break; Executed by:
| 2714 | ||||||||||||||||||
52 | case executed 2816 times by 3 tests: QQuickEventPoint::Updated:case QQuickEventPoint::Updated: Executed by:
executed 2816 times by 3 tests: case QQuickEventPoint::Updated: Executed by:
| 2816 | ||||||||||||||||||
53 | switch (m_gesturePolicy) { | - | ||||||||||||||||||
54 | case executed 2496 times by 3 tests: DragThreshold:case DragThreshold: Executed by:
executed 2496 times by 3 tests: case DragThreshold: Executed by:
| 2496 | ||||||||||||||||||
55 | ret = !dragOverThreshold(point); | - | ||||||||||||||||||
56 | break; executed 2496 times by 3 tests: break; Executed by:
| 2496 | ||||||||||||||||||
57 | case executed 156 times by 2 tests: WithinBounds:case WithinBounds: Executed by:
executed 156 times by 2 tests: case WithinBounds: Executed by:
| 156 | ||||||||||||||||||
58 | ret = parentContains(point); | - | ||||||||||||||||||
59 | break; executed 156 times by 2 tests: break; Executed by:
| 156 | ||||||||||||||||||
60 | case executed 164 times by 2 tests: ReleaseWithinBounds:case ReleaseWithinBounds: Executed by:
executed 164 times by 2 tests: case ReleaseWithinBounds: Executed by:
| 164 | ||||||||||||||||||
61 | ret = point->pointId() == this->point().id(); | - | ||||||||||||||||||
62 | break; executed 164 times by 2 tests: break; Executed by:
| 164 | ||||||||||||||||||
63 | } | - | ||||||||||||||||||
64 | break; executed 2816 times by 3 tests: break; Executed by:
| 2816 | ||||||||||||||||||
65 | case executed 262 times by 2 tests: QQuickEventPoint::Stationary:case QQuickEventPoint::Stationary: Executed by:
executed 262 times by 2 tests: case QQuickEventPoint::Stationary: Executed by:
| 262 | ||||||||||||||||||
66 | - | |||||||||||||||||||
67 | - | |||||||||||||||||||
68 | - | |||||||||||||||||||
69 | - | |||||||||||||||||||
70 | break; executed 262 times by 2 tests: break; Executed by:
| 262 | ||||||||||||||||||
71 | } | - | ||||||||||||||||||
72 | - | |||||||||||||||||||
73 | - | |||||||||||||||||||
74 | - | |||||||||||||||||||
75 | - | |||||||||||||||||||
76 | if (!ret
| 58-3442 | ||||||||||||||||||
77 | setPressed(false, true, point); executed 538 times by 3 tests: setPressed(false, true, point); Executed by:
| 538 | ||||||||||||||||||
78 | return executed 5792 times by 3 tests: ret;return ret; Executed by:
executed 5792 times by 3 tests: return ret; Executed by:
| 5792 | ||||||||||||||||||
79 | } | - | ||||||||||||||||||
80 | - | |||||||||||||||||||
81 | void QQuickTapHandler::handleEventPoint(QQuickEventPoint *point) | - | ||||||||||||||||||
82 | { | - | ||||||||||||||||||
83 | switch (point->state()) { | - | ||||||||||||||||||
84 | case executed 156 times by 3 tests: QQuickEventPoint::Pressed:case QQuickEventPoint::Pressed: Executed by:
executed 156 times by 3 tests: case QQuickEventPoint::Pressed: Executed by:
| 156 | ||||||||||||||||||
85 | setPressed(true, false, point); | - | ||||||||||||||||||
86 | break; executed 156 times by 3 tests: break; Executed by:
| 156 | ||||||||||||||||||
87 | case executed 120 times by 3 tests: QQuickEventPoint::Released:case QQuickEventPoint::Released: Executed by:
executed 120 times by 3 tests: case QQuickEventPoint::Released: Executed by:
| 120 | ||||||||||||||||||
88 | if ((
| 0-120 | ||||||||||||||||||
89 | setPressed(false, false, point); executed 120 times by 3 tests: setPressed(false, false, point); Executed by:
| 120 | ||||||||||||||||||
90 | break; executed 120 times by 3 tests: break; Executed by:
| 120 | ||||||||||||||||||
91 | default executed 680 times by 3 tests: :default: Executed by:
executed 680 times by 3 tests: default: Executed by:
| 680 | ||||||||||||||||||
92 | break; executed 680 times by 3 tests: break; Executed by:
| 680 | ||||||||||||||||||
93 | } | - | ||||||||||||||||||
94 | } | - | ||||||||||||||||||
95 | qreal QQuickTapHandler::longPressThreshold() const | - | ||||||||||||||||||
96 | { | - | ||||||||||||||||||
97 | return executed 64 times by 2 tests: longPressThresholdMilliseconds() / 1000.0;return longPressThresholdMilliseconds() / 1000.0; Executed by:
executed 64 times by 2 tests: return longPressThresholdMilliseconds() / 1000.0; Executed by:
| 64 | ||||||||||||||||||
98 | } | - | ||||||||||||||||||
99 | - | |||||||||||||||||||
100 | void QQuickTapHandler::setLongPressThreshold(qreal longPressThreshold) | - | ||||||||||||||||||
101 | { | - | ||||||||||||||||||
102 | int ms = qRound(longPressThreshold * 1000); | - | ||||||||||||||||||
103 | if (m_longPressThreshold == ms
| 0-222 | ||||||||||||||||||
104 | return; never executed: return; | 0 | ||||||||||||||||||
105 | - | |||||||||||||||||||
106 | m_longPressThreshold = ms; | - | ||||||||||||||||||
107 | longPressThresholdChanged(); | - | ||||||||||||||||||
108 | } executed 222 times by 2 tests: end of block Executed by:
| 222 | ||||||||||||||||||
109 | - | |||||||||||||||||||
110 | int QQuickTapHandler::longPressThresholdMilliseconds() const | - | ||||||||||||||||||
111 | { | - | ||||||||||||||||||
112 | return executed 212 times by 3 tests: (m_longPressThreshold < 0 ? QGuiApplication::styleHints()->mousePressAndHoldInterval() : m_longPressThreshold);return (m_longPressThreshold < 0 ? QGuiApplication::styleHints()->mousePressAndHoldInterval() : m_longPressThreshold); Executed by:
executed 212 times by 3 tests: return (m_longPressThreshold < 0 ? QGuiApplication::styleHints()->mousePressAndHoldInterval() : m_longPressThreshold); Executed by:
| 212 | ||||||||||||||||||
113 | } | - | ||||||||||||||||||
114 | - | |||||||||||||||||||
115 | void QQuickTapHandler::timerEvent(QTimerEvent *event) | - | ||||||||||||||||||
116 | { | - | ||||||||||||||||||
117 | if (event->timerId() == m_longPressTimer.timerId()
| 0-4 | ||||||||||||||||||
118 | m_longPressTimer.stop(); | - | ||||||||||||||||||
119 | for (bool qt_category_enabled = lcTapHandler().isDebugEnabled(); qt_category_enabled
never executed: QMessageLogger(__FILE__, 206, __PRETTY_FUNCTION__, lcTapHandler().categoryName()).debug() << objectName() << "longPressed"; | 0-4 | ||||||||||||||||||
120 | longPressed(); | - | ||||||||||||||||||
121 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
122 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
123 | void QQuickTapHandler::setGesturePolicy(QQuickTapHandler::GesturePolicy gesturePolicy) | - | ||||||||||||||||||
124 | { | - | ||||||||||||||||||
125 | if (m_gesturePolicy == gesturePolicy
| 146-448 | ||||||||||||||||||
126 | return; executed 448 times by 3 tests: return; Executed by:
| 448 | ||||||||||||||||||
127 | - | |||||||||||||||||||
128 | m_gesturePolicy = gesturePolicy; | - | ||||||||||||||||||
129 | gesturePolicyChanged(); | - | ||||||||||||||||||
130 | } executed 146 times by 2 tests: end of block Executed by:
| 146 | ||||||||||||||||||
131 | void QQuickTapHandler::setPressed(bool press, bool cancel, QQuickEventPoint *point) | - | ||||||||||||||||||
132 | { | - | ||||||||||||||||||
133 | if (m_pressed != press
| 290-614 | ||||||||||||||||||
134 | for (bool qt_category_enabled = lcTapHandler().isDebugEnabled(); qt_category_enabled
never executed: QMessageLogger(__FILE__, 281, __PRETTY_FUNCTION__, lcTapHandler().categoryName()).debug() << objectName() << "pressed" << m_pressed << "->" << press << (cancel ? "CANCEL" : "") << point; | 0-290 | ||||||||||||||||||
135 | m_pressed = press; | - | ||||||||||||||||||
136 | connectPreRenderSignal(press); | - | ||||||||||||||||||
137 | updateTimeHeld(); | - | ||||||||||||||||||
138 | if (press
| 142-148 | ||||||||||||||||||
139 | m_longPressTimer.start(longPressThresholdMilliseconds(), this); | - | ||||||||||||||||||
140 | m_holdTimer.start(); | - | ||||||||||||||||||
141 | } executed 148 times by 3 tests: else {end of block Executed by:
| 148 | ||||||||||||||||||
142 | m_longPressTimer.stop(); | - | ||||||||||||||||||
143 | m_holdTimer.invalidate(); | - | ||||||||||||||||||
144 | } executed 142 times by 3 tests: end of block Executed by:
| 142 | ||||||||||||||||||
145 | if (press
| 142-148 | ||||||||||||||||||
146 | - | |||||||||||||||||||
147 | if (m_gesturePolicy == DragThreshold
| 50-98 | ||||||||||||||||||
148 | setPassiveGrab(point, press); executed 98 times by 3 tests: setPassiveGrab(point, press); Executed by:
| 98 | ||||||||||||||||||
149 | else | - | ||||||||||||||||||
150 | setExclusiveGrab(point, press); executed 50 times by 2 tests: setExclusiveGrab(point, press); Executed by:
| 50 | ||||||||||||||||||
151 | } | - | ||||||||||||||||||
152 | if (!cancel
| 0-212 | ||||||||||||||||||
153 | if (point->timeHeld() < longPressThreshold()
| 4-60 | ||||||||||||||||||
154 | - | |||||||||||||||||||
155 | qreal ts = point->pointerEvent()->timestamp() / 1000.0; | - | ||||||||||||||||||
156 | if (ts - m_lastTapTimestamp < m_multiTapInterval
| 16-44 | ||||||||||||||||||
157 | QVector2D(point->scenePosition() - m_lastTapPos).lengthSquared() <
| 2-14 | ||||||||||||||||||
158 | (point->pointerEvent()->device()->type() == QQuickPointerDevice::Mouse ?
| 2-14 | ||||||||||||||||||
159 | m_mouseMultiClickDistanceSquared : m_touchMultiTapDistanceSquared)
| 2-14 | ||||||||||||||||||
160 | ++ executed 2 times by 1 test: m_tapCount;++m_tapCount; Executed by:
executed 2 times by 1 test: ++m_tapCount; Executed by:
| 2 | ||||||||||||||||||
161 | else | - | ||||||||||||||||||
162 | m_tapCount = 1; executed 58 times by 2 tests: m_tapCount = 1; Executed by:
| 58 | ||||||||||||||||||
163 | for (bool qt_category_enabled = lcTapHandler().isDebugEnabled(); qt_category_enabled
never executed: QMessageLogger(__FILE__, 310, __PRETTY_FUNCTION__, lcTapHandler().categoryName()).debug() << objectName() << "tapped" << m_tapCount << "times"; | 0-60 | ||||||||||||||||||
164 | tapped(); | - | ||||||||||||||||||
165 | tapCountChanged(); | - | ||||||||||||||||||
166 | if (m_tapCount == 1
| 2-58 | ||||||||||||||||||
167 | singleTapped(); executed 58 times by 2 tests: singleTapped(); Executed by:
| 58 | ||||||||||||||||||
168 | else if (m_tapCount == 2
| 0-2 | ||||||||||||||||||
169 | doubleTapped(); executed 2 times by 1 test: doubleTapped(); Executed by:
| 2 | ||||||||||||||||||
170 | m_lastTapTimestamp = ts; | - | ||||||||||||||||||
171 | m_lastTapPos = point->scenePosition(); | - | ||||||||||||||||||
172 | } executed 60 times by 2 tests: else {end of block Executed by:
| 60 | ||||||||||||||||||
173 | for (bool qt_category_enabled = lcTapHandler().isDebugEnabled(); qt_category_enabled
never executed: QMessageLogger(__FILE__, 320, __PRETTY_FUNCTION__, lcTapHandler().categoryName()).debug() << objectName() << "tap threshold" << longPressThreshold() << "exceeded:" << point->timeHeld(); | 0-4 | ||||||||||||||||||
174 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
175 | } | - | ||||||||||||||||||
176 | pressedChanged(); | - | ||||||||||||||||||
177 | if (!press
| 46-148 | ||||||||||||||||||
178 | - | |||||||||||||||||||
179 | setExclusiveGrab(point, press); | - | ||||||||||||||||||
180 | } executed 46 times by 2 tests: end of block Executed by:
| 46 | ||||||||||||||||||
181 | if (cancel
| 78-212 | ||||||||||||||||||
182 | canceled(point); executed 78 times by 3 tests: canceled(point); Executed by:
| 78 | ||||||||||||||||||
183 | } executed 290 times by 3 tests: end of block Executed by:
| 290 | ||||||||||||||||||
184 | } executed 904 times by 3 tests: end of block Executed by:
| 904 | ||||||||||||||||||
185 | - | |||||||||||||||||||
186 | void QQuickTapHandler::onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabState stateChange, QQuickEventPoint *point) | - | ||||||||||||||||||
187 | { | - | ||||||||||||||||||
188 | QQuickSinglePointHandler::onGrabChanged(grabber, stateChange, point); | - | ||||||||||||||||||
189 | bool isCanceled = stateChange == QQuickEventPoint::CancelGrabExclusive
| 8-268 | ||||||||||||||||||
190 | if (grabber == this
| 22-254 | ||||||||||||||||||
191 | setPressed(false, isCanceled, point); executed 90 times by 3 tests: setPressed(false, isCanceled, point); Executed by:
| 90 | ||||||||||||||||||
192 | } executed 276 times by 3 tests: end of block Executed by:
| 276 | ||||||||||||||||||
193 | - | |||||||||||||||||||
194 | void QQuickTapHandler::connectPreRenderSignal(bool conn) | - | ||||||||||||||||||
195 | { | - | ||||||||||||||||||
196 | if (conn
| 142-148 | ||||||||||||||||||
197 | 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 | ||||||||||||||||||
198 | else | - | ||||||||||||||||||
199 | 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 | ||||||||||||||||||
200 | } | - | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | void QQuickTapHandler::updateTimeHeld() | - | ||||||||||||||||||
203 | { | - | ||||||||||||||||||
204 | timeHeldChanged(); | - | ||||||||||||||||||
205 | } executed 594 times by 3 tests: end of block Executed by:
| 594 | ||||||||||||||||||
206 | - | |||||||||||||||||||
Switch to Source code | Preprocessed file |