Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | QPanGestureRecognizer::QPanGestureRecognizer() | - |
7 | { | - |
8 | } | - |
9 | | - |
10 | QGesture *QPanGestureRecognizer::create(QObject *target) | - |
11 | { | - |
12 | if (target && target->isWidgetType()) { evaluated: target yes Evaluation Count:5116 | yes Evaluation Count:56 |
partially evaluated: target->isWidgetType() yes Evaluation Count:5116 | no Evaluation Count:0 |
| 0-5116 |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents); | - |
19 | | - |
20 | } executed: } Execution Count:5116 | 5116 |
21 | return new QPanGesture; executed: return new QPanGesture; Execution Count:5172 | 5172 |
22 | } | - |
23 | | - |
24 | QGestureRecognizer::Result QPanGestureRecognizer::recognize(QGesture *state, | - |
25 | QObject *, | - |
26 | QEvent *event) | - |
27 | { | - |
28 | QPanGesture *q = static_cast<QPanGesture *>(state); | - |
29 | QPanGesturePrivate *d = q->d_func(); | - |
30 | | - |
31 | const QTouchEvent *ev = static_cast<const QTouchEvent *>(event); | - |
32 | | - |
33 | QGestureRecognizer::Result result; | - |
34 | switch (event->type()) { | - |
35 | case QEvent::TouchBegin: { | - |
36 | result = QGestureRecognizer::MayBeGesture; | - |
37 | QTouchEvent::TouchPoint p = ev->touchPoints().at(0); | - |
38 | d->lastOffset = d->offset = QPointF(); | - |
39 | break; | 0 |
40 | } | - |
41 | case QEvent::TouchEnd: { | - |
42 | if (q->state() != Qt::NoGesture) { never evaluated: q->state() != Qt::NoGesture | 0 |
43 | if (ev->touchPoints().size() == 2) { never evaluated: ev->touchPoints().size() == 2 | 0 |
44 | QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0); | - |
45 | QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1); | - |
46 | d->lastOffset = d->offset; | - |
47 | d->offset = | - |
48 | QPointF(p1.pos().x() - p1.startPos().x() + p2.pos().x() - p2.startPos().x(), | - |
49 | p1.pos().y() - p1.startPos().y() + p2.pos().y() - p2.startPos().y()) / 2; | - |
50 | } | 0 |
51 | result = QGestureRecognizer::FinishGesture; | - |
52 | } else { | 0 |
53 | result = QGestureRecognizer::CancelGesture; | - |
54 | } | 0 |
55 | break; | 0 |
56 | } | - |
57 | case QEvent::TouchUpdate: { | - |
58 | if (ev->touchPoints().size() >= 2) { never evaluated: ev->touchPoints().size() >= 2 | 0 |
59 | QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0); | - |
60 | QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1); | - |
61 | d->lastOffset = d->offset; | - |
62 | d->offset = | - |
63 | QPointF(p1.pos().x() - p1.startPos().x() + p2.pos().x() - p2.startPos().x(), | - |
64 | p1.pos().y() - p1.startPos().y() + p2.pos().y() - p2.startPos().y()) / 2; | - |
65 | if (d->offset.x() > 10 || d->offset.y() > 10 || never evaluated: d->offset.x() > 10 never evaluated: d->offset.y() > 10 | 0 |
66 | d->offset.x() < -10 || d->offset.y() < -10) { never evaluated: d->offset.x() < -10 never evaluated: d->offset.y() < -10 | 0 |
67 | q->setHotSpot(p1.startScreenPos()); | - |
68 | result = QGestureRecognizer::TriggerGesture; | - |
69 | } else { | 0 |
70 | result = QGestureRecognizer::MayBeGesture; | - |
71 | } | 0 |
72 | } | - |
73 | break; | 0 |
74 | } | - |
75 | case QEvent::MouseButtonPress: | - |
76 | case QEvent::MouseMove: | - |
77 | case QEvent::MouseButtonRelease: | - |
78 | result = QGestureRecognizer::Ignore; | - |
79 | break; executed: break; Execution Count:11613 | 11613 |
80 | default: | - |
81 | result = QGestureRecognizer::Ignore; | - |
82 | break; executed: break; Execution Count:47823 | 47823 |
83 | } | - |
84 | return result; executed: return result; Execution Count:59436 | 59436 |
85 | } | - |
86 | | - |
87 | void QPanGestureRecognizer::reset(QGesture *state) | - |
88 | { | - |
89 | QPanGesture *pan = static_cast<QPanGesture*>(state); | - |
90 | QPanGesturePrivate *d = pan->d_func(); | - |
91 | | - |
92 | d->lastOffset = d->offset = QPointF(); | - |
93 | d->acceleration = 0; | - |
94 | | - |
95 | QGestureRecognizer::reset(state); | - |
96 | } | 0 |
97 | | - |
98 | | - |
99 | | - |
100 | | - |
101 | | - |
102 | | - |
103 | QPinchGestureRecognizer::QPinchGestureRecognizer() | - |
104 | { | - |
105 | } | - |
106 | | - |
107 | QGesture *QPinchGestureRecognizer::create(QObject *target) | - |
108 | { | - |
109 | if (target && target->isWidgetType()) { partially evaluated: target no Evaluation Count:0 | yes Evaluation Count:56 |
never evaluated: target->isWidgetType() | 0-56 |
110 | static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents); | - |
111 | } | 0 |
112 | return new QPinchGesture; executed: return new QPinchGesture; Execution Count:56 | 56 |
113 | } | - |
114 | | - |
115 | QGestureRecognizer::Result QPinchGestureRecognizer::recognize(QGesture *state, | - |
116 | QObject *, | - |
117 | QEvent *event) | - |
118 | { | - |
119 | QPinchGesture *q = static_cast<QPinchGesture *>(state); | - |
120 | QPinchGesturePrivate *d = q->d_func(); | - |
121 | | - |
122 | const QTouchEvent *ev = static_cast<const QTouchEvent *>(event); | - |
123 | | - |
124 | QGestureRecognizer::Result result; | - |
125 | | - |
126 | switch (event->type()) { | - |
127 | case QEvent::TouchBegin: { | - |
128 | result = QGestureRecognizer::MayBeGesture; | - |
129 | break; | 0 |
130 | } | - |
131 | case QEvent::TouchEnd: { | - |
132 | if (q->state() != Qt::NoGesture) { never evaluated: q->state() != Qt::NoGesture | 0 |
133 | result = QGestureRecognizer::FinishGesture; | - |
134 | } else { | 0 |
135 | result = QGestureRecognizer::CancelGesture; | - |
136 | } | 0 |
137 | break; | 0 |
138 | } | - |
139 | case QEvent::TouchUpdate: { | - |
140 | d->changeFlags = 0; | - |
141 | if (ev->touchPoints().size() == 2) { never evaluated: ev->touchPoints().size() == 2 | 0 |
142 | QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0); | - |
143 | QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1); | - |
144 | | - |
145 | d->hotSpot = p1.screenPos(); | - |
146 | d->isHotSpotSet = true; | - |
147 | | - |
148 | QPointF centerPoint = (p1.screenPos() + p2.screenPos()) / 2.0; | - |
149 | if (d->isNewSequence) { never evaluated: d->isNewSequence | 0 |
150 | d->startPosition[0] = p1.screenPos(); | - |
151 | d->startPosition[1] = p2.screenPos(); | - |
152 | d->lastCenterPoint = centerPoint; | - |
153 | } else { | 0 |
154 | d->lastCenterPoint = d->centerPoint; | - |
155 | } | 0 |
156 | d->centerPoint = centerPoint; | - |
157 | | - |
158 | d->changeFlags |= QPinchGesture::CenterPointChanged; | - |
159 | | - |
160 | if (d->isNewSequence) { never evaluated: d->isNewSequence | 0 |
161 | d->scaleFactor = 1.0; | - |
162 | d->lastScaleFactor = 1.0; | - |
163 | } else { | 0 |
164 | d->lastScaleFactor = d->scaleFactor; | - |
165 | QLineF line(p1.screenPos(), p2.screenPos()); | - |
166 | QLineF lastLine(p1.lastScreenPos(), p2.lastScreenPos()); | - |
167 | d->scaleFactor = line.length() / lastLine.length(); | - |
168 | } | 0 |
169 | d->totalScaleFactor = d->totalScaleFactor * d->scaleFactor; | - |
170 | d->changeFlags |= QPinchGesture::ScaleFactorChanged; | - |
171 | | - |
172 | qreal angle = QLineF(p1.screenPos(), p2.screenPos()).angle(); | - |
173 | if (angle > 180) never evaluated: angle > 180 | 0 |
174 | angle -= 360; never executed: angle -= 360; | 0 |
175 | qreal startAngle = QLineF(p1.startScreenPos(), p2.startScreenPos()).angle(); | - |
176 | if (startAngle > 180) never evaluated: startAngle > 180 | 0 |
177 | startAngle -= 360; never executed: startAngle -= 360; | 0 |
178 | const qreal rotationAngle = startAngle - angle; | - |
179 | if (d->isNewSequence) never evaluated: d->isNewSequence | 0 |
180 | d->lastRotationAngle = 0.0; never executed: d->lastRotationAngle = 0.0; | 0 |
181 | else | - |
182 | d->lastRotationAngle = d->rotationAngle; never executed: d->lastRotationAngle = d->rotationAngle; | 0 |
183 | d->rotationAngle = rotationAngle; | - |
184 | d->totalRotationAngle += d->rotationAngle - d->lastRotationAngle; | - |
185 | d->changeFlags |= QPinchGesture::RotationAngleChanged; | - |
186 | | - |
187 | d->totalChangeFlags |= d->changeFlags; | - |
188 | d->isNewSequence = false; | - |
189 | result = QGestureRecognizer::TriggerGesture; | - |
190 | } else { | 0 |
191 | d->isNewSequence = true; | - |
192 | if (q->state() == Qt::NoGesture) never evaluated: q->state() == Qt::NoGesture | 0 |
193 | result = QGestureRecognizer::Ignore; never executed: result = QGestureRecognizer::Ignore; | 0 |
194 | else | - |
195 | result = QGestureRecognizer::FinishGesture; never executed: result = QGestureRecognizer::FinishGesture; | 0 |
196 | } | - |
197 | break; | 0 |
198 | } | - |
199 | case QEvent::MouseButtonPress: | - |
200 | case QEvent::MouseMove: | - |
201 | case QEvent::MouseButtonRelease: | - |
202 | result = QGestureRecognizer::Ignore; | - |
203 | break; | 0 |
204 | default: | - |
205 | result = QGestureRecognizer::Ignore; | - |
206 | break; | 0 |
207 | } | - |
208 | return result; never executed: return result; | 0 |
209 | } | - |
210 | | - |
211 | void QPinchGestureRecognizer::reset(QGesture *state) | - |
212 | { | - |
213 | QPinchGesture *pinch = static_cast<QPinchGesture *>(state); | - |
214 | QPinchGesturePrivate *d = pinch->d_func(); | - |
215 | | - |
216 | d->totalChangeFlags = d->changeFlags = 0; | - |
217 | | - |
218 | d->startCenterPoint = d->lastCenterPoint = d->centerPoint = QPointF(); | - |
219 | d->totalScaleFactor = d->lastScaleFactor = d->scaleFactor = 1; | - |
220 | d->totalRotationAngle = d->lastRotationAngle = d->rotationAngle = 0; | - |
221 | | - |
222 | d->isNewSequence = true; | - |
223 | d->startPosition[0] = d->startPosition[1] = QPointF(); | - |
224 | | - |
225 | QGestureRecognizer::reset(state); | - |
226 | } | 0 |
227 | | - |
228 | | - |
229 | | - |
230 | | - |
231 | | - |
232 | QSwipeGestureRecognizer::QSwipeGestureRecognizer() | - |
233 | { | - |
234 | } | - |
235 | | - |
236 | QGesture *QSwipeGestureRecognizer::create(QObject *target) | - |
237 | { | - |
238 | if (target && target->isWidgetType()) { partially evaluated: target no Evaluation Count:0 | yes Evaluation Count:56 |
never evaluated: target->isWidgetType() | 0-56 |
239 | static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents); | - |
240 | } | 0 |
241 | return new QSwipeGesture; executed: return new QSwipeGesture; Execution Count:56 | 56 |
242 | } | - |
243 | | - |
244 | QGestureRecognizer::Result QSwipeGestureRecognizer::recognize(QGesture *state, | - |
245 | QObject *, | - |
246 | QEvent *event) | - |
247 | { | - |
248 | QSwipeGesture *q = static_cast<QSwipeGesture *>(state); | - |
249 | QSwipeGesturePrivate *d = q->d_func(); | - |
250 | | - |
251 | const QTouchEvent *ev = static_cast<const QTouchEvent *>(event); | - |
252 | | - |
253 | QGestureRecognizer::Result result; | - |
254 | | - |
255 | switch (event->type()) { | - |
256 | case QEvent::TouchBegin: { | - |
257 | d->velocityValue = 1; | - |
258 | d->time.start(); | - |
259 | d->started = true; | - |
260 | result = QGestureRecognizer::MayBeGesture; | - |
261 | break; | 0 |
262 | } | - |
263 | case QEvent::TouchEnd: { | - |
264 | if (q->state() != Qt::NoGesture) { never evaluated: q->state() != Qt::NoGesture | 0 |
265 | result = QGestureRecognizer::FinishGesture; | - |
266 | } else { | 0 |
267 | result = QGestureRecognizer::CancelGesture; | - |
268 | } | 0 |
269 | break; | 0 |
270 | } | - |
271 | case QEvent::TouchUpdate: { | - |
272 | if (!d->started) never evaluated: !d->started | 0 |
273 | result = QGestureRecognizer::CancelGesture; never executed: result = QGestureRecognizer::CancelGesture; | 0 |
274 | else if (ev->touchPoints().size() == 3) { never evaluated: ev->touchPoints().size() == 3 | 0 |
275 | QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0); | - |
276 | QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1); | - |
277 | QTouchEvent::TouchPoint p3 = ev->touchPoints().at(2); | - |
278 | | - |
279 | if (d->lastPositions[0].isNull()) { never evaluated: d->lastPositions[0].isNull() | 0 |
280 | d->lastPositions[0] = p1.startScreenPos().toPoint(); | - |
281 | d->lastPositions[1] = p2.startScreenPos().toPoint(); | - |
282 | d->lastPositions[2] = p3.startScreenPos().toPoint(); | - |
283 | } | 0 |
284 | d->hotSpot = p1.screenPos(); | - |
285 | d->isHotSpotSet = true; | - |
286 | | - |
287 | int xDistance = (p1.screenPos().x() - d->lastPositions[0].x() + | - |
288 | p2.screenPos().x() - d->lastPositions[1].x() + | - |
289 | p3.screenPos().x() - d->lastPositions[2].x()) / 3; | - |
290 | int yDistance = (p1.screenPos().y() - d->lastPositions[0].y() + | - |
291 | p2.screenPos().y() - d->lastPositions[1].y() + | - |
292 | p3.screenPos().y() - d->lastPositions[2].y()) / 3; | - |
293 | | - |
294 | const int distance = xDistance >= yDistance ? xDistance : yDistance; never evaluated: xDistance >= yDistance | 0 |
295 | int elapsedTime = d->time.restart(); | - |
296 | if (!elapsedTime) never evaluated: !elapsedTime | 0 |
297 | elapsedTime = 1; never executed: elapsedTime = 1; | 0 |
298 | d->velocityValue = 0.9 * d->velocityValue + distance / elapsedTime; | - |
299 | d->swipeAngle = QLineF(p1.startScreenPos(), p1.screenPos()).angle(); | - |
300 | | - |
301 | static const int MoveThreshold = 50; | - |
302 | if (xDistance > MoveThreshold || yDistance > MoveThreshold) { never evaluated: xDistance > MoveThreshold never evaluated: yDistance > MoveThreshold | 0 |
303 | | - |
304 | d->lastPositions[0] = p1.screenPos().toPoint(); | - |
305 | d->lastPositions[1] = p2.screenPos().toPoint(); | - |
306 | d->lastPositions[2] = p3.screenPos().toPoint(); | - |
307 | QSwipeGesture::SwipeDirection horizontal = | - |
308 | xDistance > 0 ? QSwipeGesture::Right : QSwipeGesture::Left; never evaluated: xDistance > 0 | 0 |
309 | QSwipeGesture::SwipeDirection vertical = | - |
310 | yDistance > 0 ? QSwipeGesture::Down : QSwipeGesture::Up; never evaluated: yDistance > 0 | 0 |
311 | if (d->verticalDirection == QSwipeGesture::NoDirection) never evaluated: d->verticalDirection == QSwipeGesture::NoDirection | 0 |
312 | d->verticalDirection = vertical; never executed: d->verticalDirection = vertical; | 0 |
313 | if (d->horizontalDirection == QSwipeGesture::NoDirection) never evaluated: d->horizontalDirection == QSwipeGesture::NoDirection | 0 |
314 | d->horizontalDirection = horizontal; never executed: d->horizontalDirection = horizontal; | 0 |
315 | if (d->verticalDirection != vertical || d->horizontalDirection != horizontal) { never evaluated: d->verticalDirection != vertical never evaluated: d->horizontalDirection != horizontal | 0 |
316 | | - |
317 | result = QGestureRecognizer::CancelGesture; | - |
318 | } | 0 |
319 | result = QGestureRecognizer::TriggerGesture; | - |
320 | } else { | 0 |
321 | if (q->state() != Qt::NoGesture) never evaluated: q->state() != Qt::NoGesture | 0 |
322 | result = QGestureRecognizer::TriggerGesture; never executed: result = QGestureRecognizer::TriggerGesture; | 0 |
323 | else | - |
324 | result = QGestureRecognizer::MayBeGesture; never executed: result = QGestureRecognizer::MayBeGesture; | 0 |
325 | } | - |
326 | } else if (ev->touchPoints().size() > 3) { never evaluated: ev->touchPoints().size() > 3 | 0 |
327 | result = QGestureRecognizer::CancelGesture; | - |
328 | } else { | 0 |
329 | if (d->started && (ev->touchPointStates() & Qt::TouchPointPressed)) never evaluated: d->started never evaluated: (ev->touchPointStates() & Qt::TouchPointPressed) | 0 |
330 | result = QGestureRecognizer::CancelGesture; never executed: result = QGestureRecognizer::CancelGesture; | 0 |
331 | else if (d->started) never evaluated: d->started | 0 |
332 | result = QGestureRecognizer::Ignore; never executed: result = QGestureRecognizer::Ignore; | 0 |
333 | else | - |
334 | result = QGestureRecognizer::MayBeGesture; never executed: result = QGestureRecognizer::MayBeGesture; | 0 |
335 | } | - |
336 | break; | 0 |
337 | } | - |
338 | case QEvent::MouseButtonPress: | - |
339 | case QEvent::MouseMove: | - |
340 | case QEvent::MouseButtonRelease: | - |
341 | result = QGestureRecognizer::Ignore; | - |
342 | break; | 0 |
343 | default: | - |
344 | result = QGestureRecognizer::Ignore; | - |
345 | break; | 0 |
346 | } | - |
347 | return result; never executed: return result; | 0 |
348 | } | - |
349 | | - |
350 | void QSwipeGestureRecognizer::reset(QGesture *state) | - |
351 | { | - |
352 | QSwipeGesture *q = static_cast<QSwipeGesture *>(state); | - |
353 | QSwipeGesturePrivate *d = q->d_func(); | - |
354 | | - |
355 | d->verticalDirection = d->horizontalDirection = QSwipeGesture::NoDirection; | - |
356 | d->swipeAngle = 0; | - |
357 | | - |
358 | d->lastPositions[0] = d->lastPositions[1] = d->lastPositions[2] = QPoint(); | - |
359 | d->started = false; | - |
360 | d->velocityValue = 0; | - |
361 | d->time.invalidate(); | - |
362 | | - |
363 | QGestureRecognizer::reset(state); | - |
364 | } | 0 |
365 | | - |
366 | | - |
367 | | - |
368 | | - |
369 | | - |
370 | QTapGestureRecognizer::QTapGestureRecognizer() | - |
371 | { | - |
372 | } | - |
373 | | - |
374 | QGesture *QTapGestureRecognizer::create(QObject *target) | - |
375 | { | - |
376 | if (target && target->isWidgetType()) { evaluated: target yes Evaluation Count:1 | yes Evaluation Count:56 |
partially evaluated: target->isWidgetType() yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-56 |
377 | static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents); | - |
378 | } executed: } Execution Count:1 | 1 |
379 | return new QTapGesture; executed: return new QTapGesture; Execution Count:57 | 57 |
380 | } | - |
381 | | - |
382 | QGestureRecognizer::Result QTapGestureRecognizer::recognize(QGesture *state, | - |
383 | QObject *, | - |
384 | QEvent *event) | - |
385 | { | - |
386 | QTapGesture *q = static_cast<QTapGesture *>(state); | - |
387 | QTapGesturePrivate *d = q->d_func(); | - |
388 | | - |
389 | const QTouchEvent *ev = static_cast<const QTouchEvent *>(event); | - |
390 | | - |
391 | QGestureRecognizer::Result result = QGestureRecognizer::CancelGesture; | - |
392 | | - |
393 | switch (event->type()) { | - |
394 | case QEvent::TouchBegin: { | - |
395 | d->position = ev->touchPoints().at(0).pos(); | - |
396 | q->setHotSpot(ev->touchPoints().at(0).screenPos()); | - |
397 | result = QGestureRecognizer::TriggerGesture; | - |
398 | break; executed: break; Execution Count:2 | 2 |
399 | } | - |
400 | case QEvent::TouchUpdate: | - |
401 | case QEvent::TouchEnd: { | - |
402 | if (q->state() != Qt::NoGesture && ev->touchPoints().size() == 1) { never evaluated: q->state() != Qt::NoGesture never evaluated: ev->touchPoints().size() == 1 | 0 |
403 | QTouchEvent::TouchPoint p = ev->touchPoints().at(0); | - |
404 | QPoint delta = p.pos().toPoint() - p.startPos().toPoint(); | - |
405 | enum { TapRadius = 40 }; | - |
406 | if (delta.manhattanLength() <= TapRadius) { never evaluated: delta.manhattanLength() <= TapRadius | 0 |
407 | if (event->type() == QEvent::TouchEnd) never evaluated: event->type() == QEvent::TouchEnd | 0 |
408 | result = QGestureRecognizer::FinishGesture; never executed: result = QGestureRecognizer::FinishGesture; | 0 |
409 | else | - |
410 | result = QGestureRecognizer::TriggerGesture; never executed: result = QGestureRecognizer::TriggerGesture; | 0 |
411 | } | - |
412 | } | 0 |
413 | break; | 0 |
414 | } | - |
415 | case QEvent::MouseButtonPress: | - |
416 | case QEvent::MouseMove: | - |
417 | case QEvent::MouseButtonRelease: | - |
418 | result = QGestureRecognizer::Ignore; | - |
419 | break; executed: break; Execution Count:1 | 1 |
420 | default: | - |
421 | result = QGestureRecognizer::Ignore; | - |
422 | break; executed: break; Execution Count:24 | 24 |
423 | } | - |
424 | return result; executed: return result; Execution Count:27 | 27 |
425 | } | - |
426 | | - |
427 | void QTapGestureRecognizer::reset(QGesture *state) | - |
428 | { | - |
429 | QTapGesture *q = static_cast<QTapGesture *>(state); | - |
430 | QTapGesturePrivate *d = q->d_func(); | - |
431 | | - |
432 | d->position = QPointF(); | - |
433 | | - |
434 | QGestureRecognizer::reset(state); | - |
435 | } | 0 |
436 | | - |
437 | | - |
438 | | - |
439 | | - |
440 | | - |
441 | QTapAndHoldGestureRecognizer::QTapAndHoldGestureRecognizer() | - |
442 | { | - |
443 | } | - |
444 | | - |
445 | QGesture *QTapAndHoldGestureRecognizer::create(QObject *target) | - |
446 | { | - |
447 | if (target && target->isWidgetType()) { partially evaluated: target no Evaluation Count:0 | yes Evaluation Count:56 |
never evaluated: target->isWidgetType() | 0-56 |
448 | static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents); | - |
449 | } | 0 |
450 | return new QTapAndHoldGesture; executed: return new QTapAndHoldGesture; Execution Count:56 | 56 |
451 | } | - |
452 | | - |
453 | QGestureRecognizer::Result | - |
454 | QTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object, | - |
455 | QEvent *event) | - |
456 | { | - |
457 | QTapAndHoldGesture *q = static_cast<QTapAndHoldGesture *>(state); | - |
458 | QTapAndHoldGesturePrivate *d = q->d_func(); | - |
459 | | - |
460 | if (object == state && event->type() == QEvent::Timer) { never evaluated: object == state never evaluated: event->type() == QEvent::Timer | 0 |
461 | q->killTimer(d->timerId); | - |
462 | d->timerId = 0; | - |
463 | return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint; never executed: return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint; | 0 |
464 | } | - |
465 | | - |
466 | const QTouchEvent *ev = static_cast<const QTouchEvent *>(event); | - |
467 | const QMouseEvent *me = static_cast<const QMouseEvent *>(event); | - |
468 | | - |
469 | const QGraphicsSceneMouseEvent *gsme = static_cast<const QGraphicsSceneMouseEvent *>(event); | - |
470 | | - |
471 | | - |
472 | enum { TapRadius = 40 }; | - |
473 | | - |
474 | switch (event->type()) { | - |
475 | | - |
476 | case QEvent::GraphicsSceneMousePress: | - |
477 | d->position = gsme->screenPos(); | - |
478 | q->setHotSpot(d->position); | - |
479 | if (d->timerId) never evaluated: d->timerId | 0 |
480 | q->killTimer(d->timerId); never executed: q->killTimer(d->timerId); | 0 |
481 | d->timerId = q->startTimer(QTapAndHoldGesturePrivate::Timeout); | - |
482 | return QGestureRecognizer::MayBeGesture; never executed: return QGestureRecognizer::MayBeGesture; | 0 |
483 | | - |
484 | case QEvent::MouseButtonPress: | - |
485 | d->position = me->globalPos(); | - |
486 | q->setHotSpot(d->position); | - |
487 | if (d->timerId) never evaluated: d->timerId | 0 |
488 | q->killTimer(d->timerId); never executed: q->killTimer(d->timerId); | 0 |
489 | d->timerId = q->startTimer(QTapAndHoldGesturePrivate::Timeout); | - |
490 | return QGestureRecognizer::MayBeGesture; never executed: return QGestureRecognizer::MayBeGesture; | 0 |
491 | case QEvent::TouchBegin: | - |
492 | d->position = ev->touchPoints().at(0).startScreenPos(); | - |
493 | q->setHotSpot(d->position); | - |
494 | if (d->timerId) never evaluated: d->timerId | 0 |
495 | q->killTimer(d->timerId); never executed: q->killTimer(d->timerId); | 0 |
496 | d->timerId = q->startTimer(QTapAndHoldGesturePrivate::Timeout); | - |
497 | return QGestureRecognizer::MayBeGesture; never executed: return QGestureRecognizer::MayBeGesture; | 0 |
498 | | - |
499 | case QEvent::GraphicsSceneMouseRelease: | - |
500 | | - |
501 | case QEvent::MouseButtonRelease: | - |
502 | case QEvent::TouchEnd: | - |
503 | return QGestureRecognizer::CancelGesture; never executed: return QGestureRecognizer::CancelGesture; | 0 |
504 | case QEvent::TouchUpdate: | - |
505 | if (d->timerId && ev->touchPoints().size() == 1) { never evaluated: d->timerId never evaluated: ev->touchPoints().size() == 1 | 0 |
506 | QTouchEvent::TouchPoint p = ev->touchPoints().at(0); | - |
507 | QPoint delta = p.pos().toPoint() - p.startPos().toPoint(); | - |
508 | if (delta.manhattanLength() <= TapRadius) never evaluated: delta.manhattanLength() <= TapRadius | 0 |
509 | return QGestureRecognizer::MayBeGesture; never executed: return QGestureRecognizer::MayBeGesture; | 0 |
510 | } | 0 |
511 | return QGestureRecognizer::CancelGesture; never executed: return QGestureRecognizer::CancelGesture; | 0 |
512 | case QEvent::MouseMove: { | - |
513 | QPoint delta = me->globalPos() - d->position.toPoint(); | - |
514 | if (d->timerId && delta.manhattanLength() <= TapRadius) never evaluated: d->timerId never evaluated: delta.manhattanLength() <= TapRadius | 0 |
515 | return QGestureRecognizer::MayBeGesture; never executed: return QGestureRecognizer::MayBeGesture; | 0 |
516 | return QGestureRecognizer::CancelGesture; never executed: return QGestureRecognizer::CancelGesture; | 0 |
517 | } | - |
518 | | - |
519 | case QEvent::GraphicsSceneMouseMove: { | - |
520 | QPoint delta = gsme->screenPos() - d->position.toPoint(); | - |
521 | if (d->timerId && delta.manhattanLength() <= TapRadius) never evaluated: d->timerId never evaluated: delta.manhattanLength() <= TapRadius | 0 |
522 | return QGestureRecognizer::MayBeGesture; never executed: return QGestureRecognizer::MayBeGesture; | 0 |
523 | return QGestureRecognizer::CancelGesture; never executed: return QGestureRecognizer::CancelGesture; | 0 |
524 | } | - |
525 | | - |
526 | default: | - |
527 | return QGestureRecognizer::Ignore; never executed: return QGestureRecognizer::Ignore; | 0 |
528 | } | - |
529 | } | 0 |
530 | | - |
531 | void QTapAndHoldGestureRecognizer::reset(QGesture *state) | - |
532 | { | - |
533 | QTapAndHoldGesture *q = static_cast<QTapAndHoldGesture *>(state); | - |
534 | QTapAndHoldGesturePrivate *d = q->d_func(); | - |
535 | | - |
536 | d->position = QPointF(); | - |
537 | if (d->timerId) never evaluated: d->timerId | 0 |
538 | q->killTimer(d->timerId); never executed: q->killTimer(d->timerId); | 0 |
539 | d->timerId = 0; | - |
540 | | - |
541 | QGestureRecognizer::reset(state); | - |
542 | } | 0 |
543 | | - |
544 | | - |
545 | | - |
| | |