qstandardgestures.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qstandardgestures.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets 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 "qstandardgestures_p.h"-
41#include "qgesture.h"-
42#include "qgesture_p.h"-
43#include "qevent.h"-
44#include "qwidget.h"-
45#include "qabstractscrollarea.h"-
46#include <qgraphicssceneevent.h>-
47#include "qdebug.h"-
48-
49#ifndef QT_NO_GESTURES-
50-
51QT_BEGIN_NAMESPACE-
52-
53// If the change in scale for a single touch event is out of this range,-
54// we consider it to be spurious.-
55static const qreal kSingleStepScaleMax = 2.0;-
56static const qreal kSingleStepScaleMin = 0.1;-
57-
58QGesture *QPanGestureRecognizer::create(QObject *target)-
59{-
60 if (target && target->isWidgetType()) {
targetDescription
TRUEnever evaluated
FALSEnever evaluated
target->isWidgetType()Description
TRUEnever evaluated
FALSEnever evaluated
0
61#if (defined(Q_OS_MACX) || defined(Q_OS_WIN)) && !defined(QT_NO_NATIVE_GESTURES)-
62 // for scroll areas on Windows and OS X we want to use native gestures instead-
63 if (!qobject_cast<QAbstractScrollArea *>(target->parent()))-
64 static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);-
65#else-
66 static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);-
67#endif-
68 }
never executed: end of block
0
69 return new QPanGesture;
never executed: return new QPanGesture;
0
70}-
71-
72static QPointF panOffset(const QList<QTouchEvent::TouchPoint> &touchPoints, int maxCount)-
73{-
74 QPointF result;-
75 const int count = qMin(touchPoints.size(), maxCount);-
76 for (int p = 0; p < count; ++p)
p < countDescription
TRUEnever evaluated
FALSEnever evaluated
0
77 result += touchPoints.at(p).pos() - touchPoints.at(p).startPos();
never executed: result += touchPoints.at(p).pos() - touchPoints.at(p).startPos();
0
78 return result / qreal(count);
never executed: return result / qreal(count);
0
79}-
80-
81QGestureRecognizer::Result QPanGestureRecognizer::recognize(QGesture *state,-
82 QObject *,-
83 QEvent *event)-
84{-
85 QPanGesture *q = static_cast<QPanGesture *>(state);-
86 QPanGesturePrivate *d = q->d_func();-
87-
88 QGestureRecognizer::Result result = QGestureRecognizer::Ignore;-
89 switch (event->type()) {-
90 case QEvent::TouchBegin: {
never executed: case QEvent::TouchBegin:
0
91 const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);-
92 result = QGestureRecognizer::MayBeGesture;-
93 QTouchEvent::TouchPoint p = ev->touchPoints().at(0);-
94 d->lastOffset = d->offset = QPointF();-
95 d->pointCount = m_pointCount;-
96 break;
never executed: break;
0
97 }-
98 case QEvent::TouchEnd: {
never executed: case QEvent::TouchEnd:
0
99 if (q->state() != Qt::NoGesture) {
q->state() != Qt::NoGestureDescription
TRUEnever evaluated
FALSEnever evaluated
0
100 const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);-
101 if (ev->touchPoints().size() == d->pointCount) {
ev->touchPoint... d->pointCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
102 d->lastOffset = d->offset;-
103 d->offset = panOffset(ev->touchPoints(), d->pointCount);-
104 }
never executed: end of block
0
105 result = QGestureRecognizer::FinishGesture;-
106 } else {
never executed: end of block
0
107 result = QGestureRecognizer::CancelGesture;-
108 }
never executed: end of block
0
109 break;
never executed: break;
0
110 }-
111 case QEvent::TouchUpdate: {
never executed: case QEvent::TouchUpdate:
0
112 const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);-
113 if (ev->touchPoints().size() >= d->pointCount) {
ev->touchPoint... d->pointCountDescription
TRUEnever evaluated
FALSEnever evaluated
0
114 d->lastOffset = d->offset;-
115 d->offset = panOffset(ev->touchPoints(), d->pointCount);-
116 if (d->offset.x() > 10 || d->offset.y() > 10 ||
d->offset.x() > 10Description
TRUEnever evaluated
FALSEnever evaluated
d->offset.y() > 10Description
TRUEnever evaluated
FALSEnever evaluated
0
117 d->offset.x() < -10 || d->offset.y() < -10) {
d->offset.x() < -10Description
TRUEnever evaluated
FALSEnever evaluated
d->offset.y() < -10Description
TRUEnever evaluated
FALSEnever evaluated
0
118 q->setHotSpot(ev->touchPoints().first().startScreenPos());-
119 result = QGestureRecognizer::TriggerGesture;-
120 } else {
never executed: end of block
0
121 result = QGestureRecognizer::MayBeGesture;-
122 }
never executed: end of block
0
123 }-
124 break;
never executed: break;
0
125 }-
126 default:
never executed: default:
0
127 break;
never executed: break;
0
128 }-
129 return result;
never executed: return result;
0
130}-
131-
132void QPanGestureRecognizer::reset(QGesture *state)-
133{-
134 QPanGesture *pan = static_cast<QPanGesture*>(state);-
135 QPanGesturePrivate *d = pan->d_func();-
136-
137 d->lastOffset = d->offset = QPointF();-
138 d->acceleration = 0;-
139-
140 QGestureRecognizer::reset(state);-
141}
never executed: end of block
0
142-
143-
144//-
145// QPinchGestureRecognizer-
146//-
147-
148QPinchGestureRecognizer::QPinchGestureRecognizer()-
149{-
150}-
151-
152QGesture *QPinchGestureRecognizer::create(QObject *target)-
153{-
154 if (target && target->isWidgetType()) {
targetDescription
TRUEnever evaluated
FALSEnever evaluated
target->isWidgetType()Description
TRUEnever evaluated
FALSEnever evaluated
0
155 static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);-
156 }
never executed: end of block
0
157 return new QPinchGesture;
never executed: return new QPinchGesture;
0
158}-
159-
160QGestureRecognizer::Result QPinchGestureRecognizer::recognize(QGesture *state,-
161 QObject *,-
162 QEvent *event)-
163{-
164 QPinchGesture *q = static_cast<QPinchGesture *>(state);-
165 QPinchGesturePrivate *d = q->d_func();-
166-
167 QGestureRecognizer::Result result = QGestureRecognizer::Ignore;-
168-
169 switch (event->type()) {-
170 case QEvent::TouchBegin: {
never executed: case QEvent::TouchBegin:
0
171 result = QGestureRecognizer::MayBeGesture;-
172 break;
never executed: break;
0
173 }-
174 case QEvent::TouchEnd: {
never executed: case QEvent::TouchEnd:
0
175 if (q->state() != Qt::NoGesture) {
q->state() != Qt::NoGestureDescription
TRUEnever evaluated
FALSEnever evaluated
0
176 result = QGestureRecognizer::FinishGesture;-
177 } else {
never executed: end of block
0
178 result = QGestureRecognizer::CancelGesture;-
179 }
never executed: end of block
0
180 break;
never executed: break;
0
181 }-
182 case QEvent::TouchUpdate: {
never executed: case QEvent::TouchUpdate:
0
183 const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);-
184 d->changeFlags = 0;-
185 if (ev->touchPoints().size() == 2) {
ev->touchPoints().size() == 2Description
TRUEnever evaluated
FALSEnever evaluated
0
186 QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0);-
187 QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);-
188-
189 d->hotSpot = p1.screenPos();-
190 d->isHotSpotSet = true;-
191-
192 QPointF centerPoint = (p1.screenPos() + p2.screenPos()) / 2.0;-
193 if (d->isNewSequence) {
d->isNewSequenceDescription
TRUEnever evaluated
FALSEnever evaluated
0
194 d->startPosition[0] = p1.screenPos();-
195 d->startPosition[1] = p2.screenPos();-
196 d->lastCenterPoint = centerPoint;-
197 } else {
never executed: end of block
0
198 d->lastCenterPoint = d->centerPoint;-
199 }
never executed: end of block
0
200 d->centerPoint = centerPoint;-
201-
202 d->changeFlags |= QPinchGesture::CenterPointChanged;-
203-
204 if (d->isNewSequence) {
d->isNewSequenceDescription
TRUEnever evaluated
FALSEnever evaluated
0
205 d->scaleFactor = 1.0;-
206 d->lastScaleFactor = 1.0;-
207 } else {
never executed: end of block
0
208 d->lastScaleFactor = d->scaleFactor;-
209 QLineF line(p1.screenPos(), p2.screenPos());-
210 QLineF lastLine(p1.lastScreenPos(), p2.lastScreenPos());-
211 qreal newScaleFactor = line.length() / lastLine.length();-
212 if (newScaleFactor > kSingleStepScaleMax || newScaleFactor < kSingleStepScaleMin)
newScaleFactor...leStepScaleMaxDescription
TRUEnever evaluated
FALSEnever evaluated
newScaleFactor...leStepScaleMinDescription
TRUEnever evaluated
FALSEnever evaluated
0
213 return QGestureRecognizer::Ignore;
never executed: return QGestureRecognizer::Ignore;
0
214 d->scaleFactor = newScaleFactor;-
215 }
never executed: end of block
0
216 d->totalScaleFactor = d->totalScaleFactor * d->scaleFactor;-
217 d->changeFlags |= QPinchGesture::ScaleFactorChanged;-
218-
219 qreal angle = QLineF(p1.screenPos(), p2.screenPos()).angle();-
220 if (angle > 180)
angle > 180Description
TRUEnever evaluated
FALSEnever evaluated
0
221 angle -= 360;
never executed: angle -= 360;
0
222 qreal startAngle = QLineF(p1.startScreenPos(), p2.startScreenPos()).angle();-
223 if (startAngle > 180)
startAngle > 180Description
TRUEnever evaluated
FALSEnever evaluated
0
224 startAngle -= 360;
never executed: startAngle -= 360;
0
225 const qreal rotationAngle = startAngle - angle;-
226 if (d->isNewSequence)
d->isNewSequenceDescription
TRUEnever evaluated
FALSEnever evaluated
0
227 d->lastRotationAngle = 0.0;
never executed: d->lastRotationAngle = 0.0;
0
228 else-
229 d->lastRotationAngle = d->rotationAngle;
never executed: d->lastRotationAngle = d->rotationAngle;
0
230 d->rotationAngle = rotationAngle;-
231 d->totalRotationAngle += d->rotationAngle - d->lastRotationAngle;-
232 d->changeFlags |= QPinchGesture::RotationAngleChanged;-
233-
234 d->totalChangeFlags |= d->changeFlags;-
235 d->isNewSequence = false;-
236 result = QGestureRecognizer::TriggerGesture;-
237 } else {
never executed: end of block
0
238 d->isNewSequence = true;-
239 if (q->state() == Qt::NoGesture)
q->state() == Qt::NoGestureDescription
TRUEnever evaluated
FALSEnever evaluated
0
240 result = QGestureRecognizer::Ignore;
never executed: result = QGestureRecognizer::Ignore;
0
241 else-
242 result = QGestureRecognizer::FinishGesture;
never executed: result = QGestureRecognizer::FinishGesture;
0
243 }-
244 break;
never executed: break;
0
245 }-
246 default:
never executed: default:
0
247 break;
never executed: break;
0
248 }-
249 return result;
never executed: return result;
0
250}-
251-
252void QPinchGestureRecognizer::reset(QGesture *state)-
253{-
254 QPinchGesture *pinch = static_cast<QPinchGesture *>(state);-
255 QPinchGesturePrivate *d = pinch->d_func();-
256-
257 d->totalChangeFlags = d->changeFlags = 0;-
258-
259 d->startCenterPoint = d->lastCenterPoint = d->centerPoint = QPointF();-
260 d->totalScaleFactor = d->lastScaleFactor = d->scaleFactor = 1;-
261 d->totalRotationAngle = d->lastRotationAngle = d->rotationAngle = 0;-
262-
263 d->isNewSequence = true;-
264 d->startPosition[0] = d->startPosition[1] = QPointF();-
265-
266 QGestureRecognizer::reset(state);-
267}
never executed: end of block
0
268-
269//-
270// QSwipeGestureRecognizer-
271//-
272-
273QSwipeGestureRecognizer::QSwipeGestureRecognizer()-
274{-
275}-
276-
277QGesture *QSwipeGestureRecognizer::create(QObject *target)-
278{-
279 if (target && target->isWidgetType()) {
targetDescription
TRUEnever evaluated
FALSEnever evaluated
target->isWidgetType()Description
TRUEnever evaluated
FALSEnever evaluated
0
280 static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);-
281 }
never executed: end of block
0
282 return new QSwipeGesture;
never executed: return new QSwipeGesture;
0
283}-
284-
285QGestureRecognizer::Result QSwipeGestureRecognizer::recognize(QGesture *state,-
286 QObject *,-
287 QEvent *event)-
288{-
289 QSwipeGesture *q = static_cast<QSwipeGesture *>(state);-
290 QSwipeGesturePrivate *d = q->d_func();-
291-
292 QGestureRecognizer::Result result = QGestureRecognizer::Ignore;-
293-
294 switch (event->type()) {-
295 case QEvent::TouchBegin: {
never executed: case QEvent::TouchBegin:
0
296 d->velocityValue = 1;-
297 d->time.start();-
298 d->state = QSwipeGesturePrivate::Started;-
299 result = QGestureRecognizer::MayBeGesture;-
300 break;
never executed: break;
0
301 }-
302 case QEvent::TouchEnd: {
never executed: case QEvent::TouchEnd:
0
303 if (q->state() != Qt::NoGesture) {
q->state() != Qt::NoGestureDescription
TRUEnever evaluated
FALSEnever evaluated
0
304 result = QGestureRecognizer::FinishGesture;-
305 } else {
never executed: end of block
0
306 result = QGestureRecognizer::CancelGesture;-
307 }
never executed: end of block
0
308 break;
never executed: break;
0
309 }-
310 case QEvent::TouchUpdate: {
never executed: case QEvent::TouchUpdate:
0
311 const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);-
312 if (d->state == QSwipeGesturePrivate::NoGesture)
d->state == QS...ate::NoGestureDescription
TRUEnever evaluated
FALSEnever evaluated
0
313 result = QGestureRecognizer::CancelGesture;
never executed: result = QGestureRecognizer::CancelGesture;
0
314 else if (ev->touchPoints().size() == 3) {
ev->touchPoints().size() == 3Description
TRUEnever evaluated
FALSEnever evaluated
0
315 d->state = QSwipeGesturePrivate::ThreePointsReached;-
316 QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0);-
317 QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);-
318 QTouchEvent::TouchPoint p3 = ev->touchPoints().at(2);-
319-
320 if (d->lastPositions[0].isNull()) {
d->lastPositions[0].isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
321 d->lastPositions[0] = p1.startScreenPos().toPoint();-
322 d->lastPositions[1] = p2.startScreenPos().toPoint();-
323 d->lastPositions[2] = p3.startScreenPos().toPoint();-
324 }
never executed: end of block
0
325 d->hotSpot = p1.screenPos();-
326 d->isHotSpotSet = true;-
327-
328 int xDistance = (p1.screenPos().x() - d->lastPositions[0].x() +-
329 p2.screenPos().x() - d->lastPositions[1].x() +-
330 p3.screenPos().x() - d->lastPositions[2].x()) / 3;-
331 int yDistance = (p1.screenPos().y() - d->lastPositions[0].y() +-
332 p2.screenPos().y() - d->lastPositions[1].y() +-
333 p3.screenPos().y() - d->lastPositions[2].y()) / 3;-
334-
335 const int distance = xDistance >= yDistance ? xDistance : yDistance;
xDistance >= yDistanceDescription
TRUEnever evaluated
FALSEnever evaluated
0
336 int elapsedTime = d->time.restart();-
337 if (!elapsedTime)
!elapsedTimeDescription
TRUEnever evaluated
FALSEnever evaluated
0
338 elapsedTime = 1;
never executed: elapsedTime = 1;
0
339 d->velocityValue = 0.9 * d->velocityValue + (qreal) distance / elapsedTime;-
340 d->swipeAngle = QLineF(p1.startScreenPos(), p1.screenPos()).angle();-
341-
342 static const int MoveThreshold = 50;-
343 static const int directionChangeThreshold = MoveThreshold / 8;-
344 if (qAbs(xDistance) > MoveThreshold || qAbs(yDistance) > MoveThreshold) {
qAbs(xDistance... MoveThresholdDescription
TRUEnever evaluated
FALSEnever evaluated
qAbs(yDistance... MoveThresholdDescription
TRUEnever evaluated
FALSEnever evaluated
0
345 // measure the distance to check if the direction changed-
346 d->lastPositions[0] = p1.screenPos().toPoint();-
347 d->lastPositions[1] = p2.screenPos().toPoint();-
348 d->lastPositions[2] = p3.screenPos().toPoint();-
349 result = QGestureRecognizer::TriggerGesture;-
350 // QTBUG-46195, small changes in direction should not cause the gesture to be canceled.-
351 if (d->verticalDirection == QSwipeGesture::NoDirection || qAbs(yDistance) > directionChangeThreshold) {
d->verticalDir...e::NoDirectionDescription
TRUEnever evaluated
FALSEnever evaluated
qAbs(yDistance...hangeThresholdDescription
TRUEnever evaluated
FALSEnever evaluated
0
352 const QSwipeGesture::SwipeDirection vertical = yDistance > 0
yDistance > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
353 ? QSwipeGesture::Down : QSwipeGesture::Up;-
354 if (d->verticalDirection != QSwipeGesture::NoDirection && d->verticalDirection != vertical)
d->verticalDir...e::NoDirectionDescription
TRUEnever evaluated
FALSEnever evaluated
d->verticalDir...on != verticalDescription
TRUEnever evaluated
FALSEnever evaluated
0
355 result = QGestureRecognizer::CancelGesture;
never executed: result = QGestureRecognizer::CancelGesture;
0
356 d->verticalDirection = vertical;-
357 }
never executed: end of block
0
358 if (d->horizontalDirection == QSwipeGesture::NoDirection || qAbs(xDistance) > directionChangeThreshold) {
d->horizontalD...e::NoDirectionDescription
TRUEnever evaluated
FALSEnever evaluated
qAbs(xDistance...hangeThresholdDescription
TRUEnever evaluated
FALSEnever evaluated
0
359 const QSwipeGesture::SwipeDirection horizontal = xDistance > 0
xDistance > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
360 ? QSwipeGesture::Right : QSwipeGesture::Left;-
361 if (d->horizontalDirection != QSwipeGesture::NoDirection && d->horizontalDirection != horizontal)
d->horizontalD...e::NoDirectionDescription
TRUEnever evaluated
FALSEnever evaluated
d->horizontalD... != horizontalDescription
TRUEnever evaluated
FALSEnever evaluated
0
362 result = QGestureRecognizer::CancelGesture;
never executed: result = QGestureRecognizer::CancelGesture;
0
363 d->horizontalDirection = horizontal;-
364 }
never executed: end of block
0
365 } else {
never executed: end of block
0
366 if (q->state() != Qt::NoGesture)
q->state() != Qt::NoGestureDescription
TRUEnever evaluated
FALSEnever evaluated
0
367 result = QGestureRecognizer::TriggerGesture;
never executed: result = QGestureRecognizer::TriggerGesture;
0
368 else-
369 result = QGestureRecognizer::MayBeGesture;
never executed: result = QGestureRecognizer::MayBeGesture;
0
370 }-
371 } else if (ev->touchPoints().size() > 3) {
ev->touchPoints().size() > 3Description
TRUEnever evaluated
FALSEnever evaluated
0
372 result = QGestureRecognizer::CancelGesture;-
373 } else { // less than 3 touch points
never executed: end of block
0
374 switch (d->state) {-
375 case QSwipeGesturePrivate::NoGesture:
never executed: case QSwipeGesturePrivate::NoGesture:
0
376 result = QGestureRecognizer::MayBeGesture;-
377 break;
never executed: break;
0
378 case QSwipeGesturePrivate::Started:
never executed: case QSwipeGesturePrivate::Started:
0
379 result = QGestureRecognizer::Ignore;-
380 break;
never executed: break;
0
381 case QSwipeGesturePrivate::ThreePointsReached:
never executed: case QSwipeGesturePrivate::ThreePointsReached:
0
382 result = (ev->touchPointStates() & Qt::TouchPointPressed)
(ev->touchPoin...hPointPressed)Description
TRUEnever evaluated
FALSEnever evaluated
0
383 ? QGestureRecognizer::CancelGesture : QGestureRecognizer::Ignore;-
384 break;
never executed: break;
0
385 }-
386 }
never executed: end of block
0
387 break;
never executed: break;
0
388 }-
389 default:
never executed: default:
0
390 break;
never executed: break;
0
391 }-
392 return result;
never executed: return result;
0
393}-
394-
395void QSwipeGestureRecognizer::reset(QGesture *state)-
396{-
397 QSwipeGesture *q = static_cast<QSwipeGesture *>(state);-
398 QSwipeGesturePrivate *d = q->d_func();-
399-
400 d->verticalDirection = d->horizontalDirection = QSwipeGesture::NoDirection;-
401 d->swipeAngle = 0;-
402-
403 d->lastPositions[0] = d->lastPositions[1] = d->lastPositions[2] = QPoint();-
404 d->state = QSwipeGesturePrivate::NoGesture;-
405 d->velocityValue = 0;-
406 d->time.invalidate();-
407-
408 QGestureRecognizer::reset(state);-
409}
never executed: end of block
0
410-
411//-
412// QTapGestureRecognizer-
413//-
414-
415QTapGestureRecognizer::QTapGestureRecognizer()-
416{-
417}-
418-
419QGesture *QTapGestureRecognizer::create(QObject *target)-
420{-
421 if (target && target->isWidgetType()) {
targetDescription
TRUEnever evaluated
FALSEnever evaluated
target->isWidgetType()Description
TRUEnever evaluated
FALSEnever evaluated
0
422 static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);-
423 }
never executed: end of block
0
424 return new QTapGesture;
never executed: return new QTapGesture;
0
425}-
426-
427QGestureRecognizer::Result QTapGestureRecognizer::recognize(QGesture *state,-
428 QObject *,-
429 QEvent *event)-
430{-
431 QTapGesture *q = static_cast<QTapGesture *>(state);-
432 QTapGesturePrivate *d = q->d_func();-
433-
434 const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);-
435-
436 QGestureRecognizer::Result result = QGestureRecognizer::CancelGesture;-
437-
438 switch (event->type()) {-
439 case QEvent::TouchBegin: {
never executed: case QEvent::TouchBegin:
0
440 d->position = ev->touchPoints().at(0).pos();-
441 q->setHotSpot(ev->touchPoints().at(0).screenPos());-
442 result = QGestureRecognizer::TriggerGesture;-
443 break;
never executed: break;
0
444 }-
445 case QEvent::TouchUpdate:
never executed: case QEvent::TouchUpdate:
0
446 case QEvent::TouchEnd: {
never executed: case QEvent::TouchEnd:
0
447 if (q->state() != Qt::NoGesture && ev->touchPoints().size() == 1) {
q->state() != Qt::NoGestureDescription
TRUEnever evaluated
FALSEnever evaluated
ev->touchPoints().size() == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
448 QTouchEvent::TouchPoint p = ev->touchPoints().at(0);-
449 QPoint delta = p.pos().toPoint() - p.startPos().toPoint();-
450 enum { TapRadius = 40 };-
451 if (delta.manhattanLength() <= TapRadius) {
delta.manhatta...) <= TapRadiusDescription
TRUEnever evaluated
FALSEnever evaluated
0
452 if (event->type() == QEvent::TouchEnd)
event->type() ...vent::TouchEndDescription
TRUEnever evaluated
FALSEnever evaluated
0
453 result = QGestureRecognizer::FinishGesture;
never executed: result = QGestureRecognizer::FinishGesture;
0
454 else-
455 result = QGestureRecognizer::TriggerGesture;
never executed: result = QGestureRecognizer::TriggerGesture;
0
456 }-
457 }
never executed: end of block
0
458 break;
never executed: break;
0
459 }-
460 case QEvent::MouseButtonPress:
never executed: case QEvent::MouseButtonPress:
0
461 case QEvent::MouseMove:
never executed: case QEvent::MouseMove:
0
462 case QEvent::MouseButtonRelease:
never executed: case QEvent::MouseButtonRelease:
0
463 result = QGestureRecognizer::Ignore;-
464 break;
never executed: break;
0
465 default:
never executed: default:
0
466 result = QGestureRecognizer::Ignore;-
467 break;
never executed: break;
0
468 }-
469 return result;
never executed: return result;
0
470}-
471-
472void QTapGestureRecognizer::reset(QGesture *state)-
473{-
474 QTapGesture *q = static_cast<QTapGesture *>(state);-
475 QTapGesturePrivate *d = q->d_func();-
476-
477 d->position = QPointF();-
478-
479 QGestureRecognizer::reset(state);-
480}
never executed: end of block
0
481-
482//-
483// QTapAndHoldGestureRecognizer-
484//-
485-
486QTapAndHoldGestureRecognizer::QTapAndHoldGestureRecognizer()-
487{-
488}-
489-
490QGesture *QTapAndHoldGestureRecognizer::create(QObject *target)-
491{-
492 if (target && target->isWidgetType()) {
targetDescription
TRUEnever evaluated
FALSEnever evaluated
target->isWidgetType()Description
TRUEnever evaluated
FALSEnever evaluated
0
493 static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);-
494 }
never executed: end of block
0
495 return new QTapAndHoldGesture;
never executed: return new QTapAndHoldGesture;
0
496}-
497-
498QGestureRecognizer::Result-
499QTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object,-
500 QEvent *event)-
501{-
502 QTapAndHoldGesture *q = static_cast<QTapAndHoldGesture *>(state);-
503 QTapAndHoldGesturePrivate *d = q->d_func();-
504-
505 if (object == state && event->type() == QEvent::Timer) {
object == stateDescription
TRUEnever evaluated
FALSEnever evaluated
event->type() == QEvent::TimerDescription
TRUEnever evaluated
FALSEnever evaluated
0
506 q->killTimer(d->timerId);-
507 d->timerId = 0;-
508 return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint;
never executed: return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint;
0
509 }-
510-
511 enum { TapRadius = 40 };-
512-
513 switch (event->type()) {-
514#ifndef QT_NO_GRAPHICSVIEW-
515 case QEvent::GraphicsSceneMousePress: {
never executed: case QEvent::GraphicsSceneMousePress:
0
516 const QGraphicsSceneMouseEvent *gsme = static_cast<const QGraphicsSceneMouseEvent *>(event);-
517 d->position = gsme->screenPos();-
518 q->setHotSpot(d->position);-
519 if (d->timerId)
d->timerIdDescription
TRUEnever evaluated
FALSEnever evaluated
0
520 q->killTimer(d->timerId);
never executed: q->killTimer(d->timerId);
0
521 d->timerId = q->startTimer(QTapAndHoldGesturePrivate::Timeout);-
522 return QGestureRecognizer::MayBeGesture; // we don't show a sign of life until the timeout
never executed: return QGestureRecognizer::MayBeGesture;
0
523 }-
524#endif-
525 case QEvent::MouseButtonPress: {
never executed: case QEvent::MouseButtonPress:
0
526 const QMouseEvent *me = static_cast<const QMouseEvent *>(event);-
527 d->position = me->globalPos();-
528 q->setHotSpot(d->position);-
529 if (d->timerId)
d->timerIdDescription
TRUEnever evaluated
FALSEnever evaluated
0
530 q->killTimer(d->timerId);
never executed: q->killTimer(d->timerId);
0
531 d->timerId = q->startTimer(QTapAndHoldGesturePrivate::Timeout);-
532 return QGestureRecognizer::MayBeGesture; // we don't show a sign of life until the timeout
never executed: return QGestureRecognizer::MayBeGesture;
0
533 }-
534 case QEvent::TouchBegin: {
never executed: case QEvent::TouchBegin:
0
535 const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);-
536 d->position = ev->touchPoints().at(0).startScreenPos();-
537 q->setHotSpot(d->position);-
538 if (d->timerId)
d->timerIdDescription
TRUEnever evaluated
FALSEnever evaluated
0
539 q->killTimer(d->timerId);
never executed: q->killTimer(d->timerId);
0
540 d->timerId = q->startTimer(QTapAndHoldGesturePrivate::Timeout);-
541 return QGestureRecognizer::MayBeGesture; // we don't show a sign of life until the timeout
never executed: return QGestureRecognizer::MayBeGesture;
0
542 }-
543#ifndef QT_NO_GRAPHICSVIEW-
544 case QEvent::GraphicsSceneMouseRelease:
never executed: case QEvent::GraphicsSceneMouseRelease:
0
545#endif-
546 case QEvent::MouseButtonRelease:
never executed: case QEvent::MouseButtonRelease:
0
547 case QEvent::TouchEnd:
never executed: case QEvent::TouchEnd:
0
548 return QGestureRecognizer::CancelGesture; // get out of the MayBeGesture state
never executed: return QGestureRecognizer::CancelGesture;
0
549 case QEvent::TouchUpdate: {
never executed: case QEvent::TouchUpdate:
0
550 const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);-
551 if (d->timerId && ev->touchPoints().size() == 1) {
d->timerIdDescription
TRUEnever evaluated
FALSEnever evaluated
ev->touchPoints().size() == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
552 QTouchEvent::TouchPoint p = ev->touchPoints().at(0);-
553 QPoint delta = p.pos().toPoint() - p.startPos().toPoint();-
554 if (delta.manhattanLength() <= TapRadius)
delta.manhatta...) <= TapRadiusDescription
TRUEnever evaluated
FALSEnever evaluated
0
555 return QGestureRecognizer::MayBeGesture;
never executed: return QGestureRecognizer::MayBeGesture;
0
556 }
never executed: end of block
0
557 return QGestureRecognizer::CancelGesture;
never executed: return QGestureRecognizer::CancelGesture;
0
558 }-
559 case QEvent::MouseMove: {
never executed: case QEvent::MouseMove:
0
560 const QMouseEvent *me = static_cast<const QMouseEvent *>(event);-
561 QPoint delta = me->globalPos() - d->position.toPoint();-
562 if (d->timerId && delta.manhattanLength() <= TapRadius)
d->timerIdDescription
TRUEnever evaluated
FALSEnever evaluated
delta.manhatta...) <= TapRadiusDescription
TRUEnever evaluated
FALSEnever evaluated
0
563 return QGestureRecognizer::MayBeGesture;
never executed: return QGestureRecognizer::MayBeGesture;
0
564 return QGestureRecognizer::CancelGesture;
never executed: return QGestureRecognizer::CancelGesture;
0
565 }-
566#ifndef QT_NO_GRAPHICSVIEW-
567 case QEvent::GraphicsSceneMouseMove: {
never executed: case QEvent::GraphicsSceneMouseMove:
0
568 const QGraphicsSceneMouseEvent *gsme = static_cast<const QGraphicsSceneMouseEvent *>(event);-
569 QPoint delta = gsme->screenPos() - d->position.toPoint();-
570 if (d->timerId && delta.manhattanLength() <= TapRadius)
d->timerIdDescription
TRUEnever evaluated
FALSEnever evaluated
delta.manhatta...) <= TapRadiusDescription
TRUEnever evaluated
FALSEnever evaluated
0
571 return QGestureRecognizer::MayBeGesture;
never executed: return QGestureRecognizer::MayBeGesture;
0
572 return QGestureRecognizer::CancelGesture;
never executed: return QGestureRecognizer::CancelGesture;
0
573 }-
574#endif-
575 default:
never executed: default:
0
576 return QGestureRecognizer::Ignore;
never executed: return QGestureRecognizer::Ignore;
0
577 }-
578}-
579-
580void QTapAndHoldGestureRecognizer::reset(QGesture *state)-
581{-
582 QTapAndHoldGesture *q = static_cast<QTapAndHoldGesture *>(state);-
583 QTapAndHoldGesturePrivate *d = q->d_func();-
584-
585 d->position = QPointF();-
586 if (d->timerId)
d->timerIdDescription
TRUEnever evaluated
FALSEnever evaluated
0
587 q->killTimer(d->timerId);
never executed: q->killTimer(d->timerId);
0
588 d->timerId = 0;-
589-
590 QGestureRecognizer::reset(state);-
591}
never executed: end of block
0
592-
593QT_END_NAMESPACE-
594-
595#endif // QT_NO_GESTURES-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9