kernel/qstandardgestures.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtGui 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 Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qstandardgestures_p.h" -
43#include "qgesture.h" -
44#include "qgesture_p.h" -
45#include "qevent.h" -
46#include "qwidget.h" -
47#include "qabstractscrollarea.h" -
48#include <qgraphicssceneevent.h> -
49#include "qdebug.h" -
50 -
51#ifndef QT_NO_GESTURES -
52 -
53QT_BEGIN_NAMESPACE -
54 -
55QPanGestureRecognizer::QPanGestureRecognizer() -
56{ -
57} -
58 -
59QGesture *QPanGestureRecognizer::create(QObject *target) -
60{ -
61 if (target && target->isWidgetType()) {
evaluated: target
TRUEFALSE
yes
Evaluation Count:5116
yes
Evaluation Count:56
partially evaluated: target->isWidgetType()
TRUEFALSE
yes
Evaluation Count:5116
no
Evaluation Count:0
0-5116
62#if defined(Q_OS_WIN) && !defined(QT_NO_NATIVE_GESTURES) -
63 // for scroll areas on Windows we want to use native gestures instead -
64 if (!qobject_cast<QAbstractScrollArea *>(target->parent())) -
65 static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents); -
66#else -
67 static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);
executed (the execution status of this line is deduced): static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);
-
68#endif -
69 }
executed: }
Execution Count:5116
5116
70 return new QPanGesture;
executed: return new QPanGesture;
Execution Count:5172
5172
71} -
72 -
73QGestureRecognizer::Result QPanGestureRecognizer::recognize(QGesture *state, -
74 QObject *, -
75 QEvent *event) -
76{ -
77 QPanGesture *q = static_cast<QPanGesture *>(state);
executed (the execution status of this line is deduced): QPanGesture *q = static_cast<QPanGesture *>(state);
-
78 QPanGesturePrivate *d = q->d_func();
executed (the execution status of this line is deduced): QPanGesturePrivate *d = q->d_func();
-
79 -
80 const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
executed (the execution status of this line is deduced): const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
-
81 -
82 QGestureRecognizer::Result result;
executed (the execution status of this line is deduced): QGestureRecognizer::Result result;
-
83 switch (event->type()) { -
84 case QEvent::TouchBegin: { -
85 result = QGestureRecognizer::MayBeGesture;
never executed (the execution status of this line is deduced): result = QGestureRecognizer::MayBeGesture;
-
86 QTouchEvent::TouchPoint p = ev->touchPoints().at(0);
never executed (the execution status of this line is deduced): QTouchEvent::TouchPoint p = ev->touchPoints().at(0);
-
87 d->lastOffset = d->offset = QPointF();
never executed (the execution status of this line is deduced): d->lastOffset = d->offset = QPointF();
-
88 break;
never executed: break;
0
89 } -
90 case QEvent::TouchEnd: { -
91 if (q->state() != Qt::NoGesture) {
never evaluated: q->state() != Qt::NoGesture
0
92 if (ev->touchPoints().size() == 2) {
never evaluated: ev->touchPoints().size() == 2
0
93 QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0);
never executed (the execution status of this line is deduced): QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0);
-
94 QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);
never executed (the execution status of this line is deduced): QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);
-
95 d->lastOffset = d->offset;
never executed (the execution status of this line is deduced): d->lastOffset = d->offset;
-
96 d->offset =
never executed (the execution status of this line is deduced): d->offset =
-
97 QPointF(p1.pos().x() - p1.startPos().x() + p2.pos().x() - p2.startPos().x(),
never executed (the execution status of this line is deduced): QPointF(p1.pos().x() - p1.startPos().x() + p2.pos().x() - p2.startPos().x(),
-
98 p1.pos().y() - p1.startPos().y() + p2.pos().y() - p2.startPos().y()) / 2;
never executed (the execution status of this line is deduced): p1.pos().y() - p1.startPos().y() + p2.pos().y() - p2.startPos().y()) / 2;
-
99 }
never executed: }
0
100 result = QGestureRecognizer::FinishGesture;
never executed (the execution status of this line is deduced): result = QGestureRecognizer::FinishGesture;
-
101 } else {
never executed: }
0
102 result = QGestureRecognizer::CancelGesture;
never executed (the execution status of this line is deduced): result = QGestureRecognizer::CancelGesture;
-
103 }
never executed: }
0
104 break;
never executed: break;
0
105 } -
106 case QEvent::TouchUpdate: { -
107 if (ev->touchPoints().size() >= 2) {
never evaluated: ev->touchPoints().size() >= 2
0
108 QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0);
never executed (the execution status of this line is deduced): QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0);
-
109 QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);
never executed (the execution status of this line is deduced): QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);
-
110 d->lastOffset = d->offset;
never executed (the execution status of this line is deduced): d->lastOffset = d->offset;
-
111 d->offset =
never executed (the execution status of this line is deduced): d->offset =
-
112 QPointF(p1.pos().x() - p1.startPos().x() + p2.pos().x() - p2.startPos().x(),
never executed (the execution status of this line is deduced): QPointF(p1.pos().x() - p1.startPos().x() + p2.pos().x() - p2.startPos().x(),
-
113 p1.pos().y() - p1.startPos().y() + p2.pos().y() - p2.startPos().y()) / 2;
never executed (the execution status of this line is deduced): p1.pos().y() - p1.startPos().y() + p2.pos().y() - p2.startPos().y()) / 2;
-
114 if (d->offset.x() > 10 || d->offset.y() > 10 ||
never evaluated: d->offset.x() > 10
never evaluated: d->offset.y() > 10
0
115 d->offset.x() < -10 || d->offset.y() < -10) {
never evaluated: d->offset.x() < -10
never evaluated: d->offset.y() < -10
0
116 q->setHotSpot(p1.startScreenPos());
never executed (the execution status of this line is deduced): q->setHotSpot(p1.startScreenPos());
-
117 result = QGestureRecognizer::TriggerGesture;
never executed (the execution status of this line is deduced): result = QGestureRecognizer::TriggerGesture;
-
118 } else {
never executed: }
0
119 result = QGestureRecognizer::MayBeGesture;
never executed (the execution status of this line is deduced): result = QGestureRecognizer::MayBeGesture;
-
120 }
never executed: }
0
121 } -
122 break;
never executed: break;
0
123 } -
124 case QEvent::MouseButtonPress: -
125 case QEvent::MouseMove: -
126 case QEvent::MouseButtonRelease: -
127 result = QGestureRecognizer::Ignore;
executed (the execution status of this line is deduced): result = QGestureRecognizer::Ignore;
-
128 break;
executed: break;
Execution Count:11613
11613
129 default: -
130 result = QGestureRecognizer::Ignore;
executed (the execution status of this line is deduced): result = QGestureRecognizer::Ignore;
-
131 break;
executed: break;
Execution Count:47823
47823
132 } -
133 return result;
executed: return result;
Execution Count:59436
59436
134} -
135 -
136void QPanGestureRecognizer::reset(QGesture *state) -
137{ -
138 QPanGesture *pan = static_cast<QPanGesture*>(state);
never executed (the execution status of this line is deduced): QPanGesture *pan = static_cast<QPanGesture*>(state);
-
139 QPanGesturePrivate *d = pan->d_func();
never executed (the execution status of this line is deduced): QPanGesturePrivate *d = pan->d_func();
-
140 -
141 d->lastOffset = d->offset = QPointF();
never executed (the execution status of this line is deduced): d->lastOffset = d->offset = QPointF();
-
142 d->acceleration = 0;
never executed (the execution status of this line is deduced): d->acceleration = 0;
-
143 -
144 QGestureRecognizer::reset(state);
never executed (the execution status of this line is deduced): QGestureRecognizer::reset(state);
-
145}
never executed: }
0
146 -
147 -
148// -
149// QPinchGestureRecognizer -
150// -
151 -
152QPinchGestureRecognizer::QPinchGestureRecognizer() -
153{ -
154} -
155 -
156QGesture *QPinchGestureRecognizer::create(QObject *target) -
157{ -
158 if (target && target->isWidgetType()) {
partially evaluated: target
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:56
never evaluated: target->isWidgetType()
0-56
159 static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);
never executed (the execution status of this line is deduced): static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);
-
160 }
never executed: }
0
161 return new QPinchGesture;
executed: return new QPinchGesture;
Execution Count:56
56
162} -
163 -
164QGestureRecognizer::Result QPinchGestureRecognizer::recognize(QGesture *state, -
165 QObject *, -
166 QEvent *event) -
167{ -
168 QPinchGesture *q = static_cast<QPinchGesture *>(state);
never executed (the execution status of this line is deduced): QPinchGesture *q = static_cast<QPinchGesture *>(state);
-
169 QPinchGesturePrivate *d = q->d_func();
never executed (the execution status of this line is deduced): QPinchGesturePrivate *d = q->d_func();
-
170 -
171 const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
never executed (the execution status of this line is deduced): const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
-
172 -
173 QGestureRecognizer::Result result;
never executed (the execution status of this line is deduced): QGestureRecognizer::Result result;
-
174 -
175 switch (event->type()) { -
176 case QEvent::TouchBegin: { -
177 result = QGestureRecognizer::MayBeGesture;
never executed (the execution status of this line is deduced): result = QGestureRecognizer::MayBeGesture;
-
178 break;
never executed: break;
0
179 } -
180 case QEvent::TouchEnd: { -
181 if (q->state() != Qt::NoGesture) {
never evaluated: q->state() != Qt::NoGesture
0
182 result = QGestureRecognizer::FinishGesture;
never executed (the execution status of this line is deduced): result = QGestureRecognizer::FinishGesture;
-
183 } else {
never executed: }
0
184 result = QGestureRecognizer::CancelGesture;
never executed (the execution status of this line is deduced): result = QGestureRecognizer::CancelGesture;
-
185 }
never executed: }
0
186 break;
never executed: break;
0
187 } -
188 case QEvent::TouchUpdate: { -
189 d->changeFlags = 0;
never executed (the execution status of this line is deduced): d->changeFlags = 0;
-
190 if (ev->touchPoints().size() == 2) {
never evaluated: ev->touchPoints().size() == 2
0
191 QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0);
never executed (the execution status of this line is deduced): QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0);
-
192 QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);
never executed (the execution status of this line is deduced): QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);
-
193 -
194 d->hotSpot = p1.screenPos();
never executed (the execution status of this line is deduced): d->hotSpot = p1.screenPos();
-
195 d->isHotSpotSet = true;
never executed (the execution status of this line is deduced): d->isHotSpotSet = true;
-
196 -
197 QPointF centerPoint = (p1.screenPos() + p2.screenPos()) / 2.0;
never executed (the execution status of this line is deduced): QPointF centerPoint = (p1.screenPos() + p2.screenPos()) / 2.0;
-
198 if (d->isNewSequence) {
never evaluated: d->isNewSequence
0
199 d->startPosition[0] = p1.screenPos();
never executed (the execution status of this line is deduced): d->startPosition[0] = p1.screenPos();
-
200 d->startPosition[1] = p2.screenPos();
never executed (the execution status of this line is deduced): d->startPosition[1] = p2.screenPos();
-
201 d->lastCenterPoint = centerPoint;
never executed (the execution status of this line is deduced): d->lastCenterPoint = centerPoint;
-
202 } else {
never executed: }
0
203 d->lastCenterPoint = d->centerPoint;
never executed (the execution status of this line is deduced): d->lastCenterPoint = d->centerPoint;
-
204 }
never executed: }
0
205 d->centerPoint = centerPoint;
never executed (the execution status of this line is deduced): d->centerPoint = centerPoint;
-
206 -
207 d->changeFlags |= QPinchGesture::CenterPointChanged;
never executed (the execution status of this line is deduced): d->changeFlags |= QPinchGesture::CenterPointChanged;
-
208 -
209 if (d->isNewSequence) {
never evaluated: d->isNewSequence
0
210 d->scaleFactor = 1.0;
never executed (the execution status of this line is deduced): d->scaleFactor = 1.0;
-
211 d->lastScaleFactor = 1.0;
never executed (the execution status of this line is deduced): d->lastScaleFactor = 1.0;
-
212 } else {
never executed: }
0
213 d->lastScaleFactor = d->scaleFactor;
never executed (the execution status of this line is deduced): d->lastScaleFactor = d->scaleFactor;
-
214 QLineF line(p1.screenPos(), p2.screenPos());
never executed (the execution status of this line is deduced): QLineF line(p1.screenPos(), p2.screenPos());
-
215 QLineF lastLine(p1.lastScreenPos(), p2.lastScreenPos());
never executed (the execution status of this line is deduced): QLineF lastLine(p1.lastScreenPos(), p2.lastScreenPos());
-
216 d->scaleFactor = line.length() / lastLine.length();
never executed (the execution status of this line is deduced): d->scaleFactor = line.length() / lastLine.length();
-
217 }
never executed: }
0
218 d->totalScaleFactor = d->totalScaleFactor * d->scaleFactor;
never executed (the execution status of this line is deduced): d->totalScaleFactor = d->totalScaleFactor * d->scaleFactor;
-
219 d->changeFlags |= QPinchGesture::ScaleFactorChanged;
never executed (the execution status of this line is deduced): d->changeFlags |= QPinchGesture::ScaleFactorChanged;
-
220 -
221 qreal angle = QLineF(p1.screenPos(), p2.screenPos()).angle();
never executed (the execution status of this line is deduced): qreal angle = QLineF(p1.screenPos(), p2.screenPos()).angle();
-
222 if (angle > 180)
never evaluated: angle > 180
0
223 angle -= 360;
never executed: angle -= 360;
0
224 qreal startAngle = QLineF(p1.startScreenPos(), p2.startScreenPos()).angle();
never executed (the execution status of this line is deduced): qreal startAngle = QLineF(p1.startScreenPos(), p2.startScreenPos()).angle();
-
225 if (startAngle > 180)
never evaluated: startAngle > 180
0
226 startAngle -= 360;
never executed: startAngle -= 360;
0
227 const qreal rotationAngle = startAngle - angle;
never executed (the execution status of this line is deduced): const qreal rotationAngle = startAngle - angle;
-
228 if (d->isNewSequence)
never evaluated: d->isNewSequence
0
229 d->lastRotationAngle = 0.0;
never executed: d->lastRotationAngle = 0.0;
0
230 else -
231 d->lastRotationAngle = d->rotationAngle;
never executed: d->lastRotationAngle = d->rotationAngle;
0
232 d->rotationAngle = rotationAngle;
never executed (the execution status of this line is deduced): d->rotationAngle = rotationAngle;
-
233 d->totalRotationAngle += d->rotationAngle - d->lastRotationAngle;
never executed (the execution status of this line is deduced): d->totalRotationAngle += d->rotationAngle - d->lastRotationAngle;
-
234 d->changeFlags |= QPinchGesture::RotationAngleChanged;
never executed (the execution status of this line is deduced): d->changeFlags |= QPinchGesture::RotationAngleChanged;
-
235 -
236 d->totalChangeFlags |= d->changeFlags;
never executed (the execution status of this line is deduced): d->totalChangeFlags |= d->changeFlags;
-
237 d->isNewSequence = false;
never executed (the execution status of this line is deduced): d->isNewSequence = false;
-
238 result = QGestureRecognizer::TriggerGesture;
never executed (the execution status of this line is deduced): result = QGestureRecognizer::TriggerGesture;
-
239 } else {
never executed: }
0
240 d->isNewSequence = true;
never executed (the execution status of this line is deduced): d->isNewSequence = true;
-
241 if (q->state() == Qt::NoGesture)
never evaluated: q->state() == Qt::NoGesture
0
242 result = QGestureRecognizer::Ignore;
never executed: result = QGestureRecognizer::Ignore;
0
243 else -
244 result = QGestureRecognizer::FinishGesture;
never executed: result = QGestureRecognizer::FinishGesture;
0
245 } -
246 break;
never executed: break;
0
247 } -
248 case QEvent::MouseButtonPress: -
249 case QEvent::MouseMove: -
250 case QEvent::MouseButtonRelease: -
251 result = QGestureRecognizer::Ignore;
never executed (the execution status of this line is deduced): result = QGestureRecognizer::Ignore;
-
252 break;
never executed: break;
0
253 default: -
254 result = QGestureRecognizer::Ignore;
never executed (the execution status of this line is deduced): result = QGestureRecognizer::Ignore;
-
255 break;
never executed: break;
0
256 } -
257 return result;
never executed: return result;
0
258} -
259 -
260void QPinchGestureRecognizer::reset(QGesture *state) -
261{ -
262 QPinchGesture *pinch = static_cast<QPinchGesture *>(state);
never executed (the execution status of this line is deduced): QPinchGesture *pinch = static_cast<QPinchGesture *>(state);
-
263 QPinchGesturePrivate *d = pinch->d_func();
never executed (the execution status of this line is deduced): QPinchGesturePrivate *d = pinch->d_func();
-
264 -
265 d->totalChangeFlags = d->changeFlags = 0;
never executed (the execution status of this line is deduced): d->totalChangeFlags = d->changeFlags = 0;
-
266 -
267 d->startCenterPoint = d->lastCenterPoint = d->centerPoint = QPointF();
never executed (the execution status of this line is deduced): d->startCenterPoint = d->lastCenterPoint = d->centerPoint = QPointF();
-
268 d->totalScaleFactor = d->lastScaleFactor = d->scaleFactor = 1;
never executed (the execution status of this line is deduced): d->totalScaleFactor = d->lastScaleFactor = d->scaleFactor = 1;
-
269 d->totalRotationAngle = d->lastRotationAngle = d->rotationAngle = 0;
never executed (the execution status of this line is deduced): d->totalRotationAngle = d->lastRotationAngle = d->rotationAngle = 0;
-
270 -
271 d->isNewSequence = true;
never executed (the execution status of this line is deduced): d->isNewSequence = true;
-
272 d->startPosition[0] = d->startPosition[1] = QPointF();
never executed (the execution status of this line is deduced): d->startPosition[0] = d->startPosition[1] = QPointF();
-
273 -
274 QGestureRecognizer::reset(state);
never executed (the execution status of this line is deduced): QGestureRecognizer::reset(state);
-
275}
never executed: }
0
276 -
277// -
278// QSwipeGestureRecognizer -
279// -
280 -
281QSwipeGestureRecognizer::QSwipeGestureRecognizer() -
282{ -
283} -
284 -
285QGesture *QSwipeGestureRecognizer::create(QObject *target) -
286{ -
287 if (target && target->isWidgetType()) {
partially evaluated: target
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:56
never evaluated: target->isWidgetType()
0-56
288 static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);
never executed (the execution status of this line is deduced): static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);
-
289 }
never executed: }
0
290 return new QSwipeGesture;
executed: return new QSwipeGesture;
Execution Count:56
56
291} -
292 -
293QGestureRecognizer::Result QSwipeGestureRecognizer::recognize(QGesture *state, -
294 QObject *, -
295 QEvent *event) -
296{ -
297 QSwipeGesture *q = static_cast<QSwipeGesture *>(state);
never executed (the execution status of this line is deduced): QSwipeGesture *q = static_cast<QSwipeGesture *>(state);
-
298 QSwipeGesturePrivate *d = q->d_func();
never executed (the execution status of this line is deduced): QSwipeGesturePrivate *d = q->d_func();
-
299 -
300 const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
never executed (the execution status of this line is deduced): const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
-
301 -
302 QGestureRecognizer::Result result;
never executed (the execution status of this line is deduced): QGestureRecognizer::Result result;
-
303 -
304 switch (event->type()) { -
305 case QEvent::TouchBegin: { -
306 d->velocityValue = 1;
never executed (the execution status of this line is deduced): d->velocityValue = 1;
-
307 d->time.start();
never executed (the execution status of this line is deduced): d->time.start();
-
308 d->started = true;
never executed (the execution status of this line is deduced): d->started = true;
-
309 result = QGestureRecognizer::MayBeGesture;
never executed (the execution status of this line is deduced): result = QGestureRecognizer::MayBeGesture;
-
310 break;
never executed: break;
0
311 } -
312 case QEvent::TouchEnd: { -
313 if (q->state() != Qt::NoGesture) {
never evaluated: q->state() != Qt::NoGesture
0
314 result = QGestureRecognizer::FinishGesture;
never executed (the execution status of this line is deduced): result = QGestureRecognizer::FinishGesture;
-
315 } else {
never executed: }
0
316 result = QGestureRecognizer::CancelGesture;
never executed (the execution status of this line is deduced): result = QGestureRecognizer::CancelGesture;
-
317 }
never executed: }
0
318 break;
never executed: break;
0
319 } -
320 case QEvent::TouchUpdate: { -
321 if (!d->started)
never evaluated: !d->started
0
322 result = QGestureRecognizer::CancelGesture;
never executed: result = QGestureRecognizer::CancelGesture;
0
323 else if (ev->touchPoints().size() == 3) {
never evaluated: ev->touchPoints().size() == 3
0
324 QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0);
never executed (the execution status of this line is deduced): QTouchEvent::TouchPoint p1 = ev->touchPoints().at(0);
-
325 QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);
never executed (the execution status of this line is deduced): QTouchEvent::TouchPoint p2 = ev->touchPoints().at(1);
-
326 QTouchEvent::TouchPoint p3 = ev->touchPoints().at(2);
never executed (the execution status of this line is deduced): QTouchEvent::TouchPoint p3 = ev->touchPoints().at(2);
-
327 -
328 if (d->lastPositions[0].isNull()) {
never evaluated: d->lastPositions[0].isNull()
0
329 d->lastPositions[0] = p1.startScreenPos().toPoint();
never executed (the execution status of this line is deduced): d->lastPositions[0] = p1.startScreenPos().toPoint();
-
330 d->lastPositions[1] = p2.startScreenPos().toPoint();
never executed (the execution status of this line is deduced): d->lastPositions[1] = p2.startScreenPos().toPoint();
-
331 d->lastPositions[2] = p3.startScreenPos().toPoint();
never executed (the execution status of this line is deduced): d->lastPositions[2] = p3.startScreenPos().toPoint();
-
332 }
never executed: }
0
333 d->hotSpot = p1.screenPos();
never executed (the execution status of this line is deduced): d->hotSpot = p1.screenPos();
-
334 d->isHotSpotSet = true;
never executed (the execution status of this line is deduced): d->isHotSpotSet = true;
-
335 -
336 int xDistance = (p1.screenPos().x() - d->lastPositions[0].x() +
never executed (the execution status of this line is deduced): int xDistance = (p1.screenPos().x() - d->lastPositions[0].x() +
-
337 p2.screenPos().x() - d->lastPositions[1].x() +
never executed (the execution status of this line is deduced): p2.screenPos().x() - d->lastPositions[1].x() +
-
338 p3.screenPos().x() - d->lastPositions[2].x()) / 3;
never executed (the execution status of this line is deduced): p3.screenPos().x() - d->lastPositions[2].x()) / 3;
-
339 int yDistance = (p1.screenPos().y() - d->lastPositions[0].y() +
never executed (the execution status of this line is deduced): int yDistance = (p1.screenPos().y() - d->lastPositions[0].y() +
-
340 p2.screenPos().y() - d->lastPositions[1].y() +
never executed (the execution status of this line is deduced): p2.screenPos().y() - d->lastPositions[1].y() +
-
341 p3.screenPos().y() - d->lastPositions[2].y()) / 3;
never executed (the execution status of this line is deduced): p3.screenPos().y() - d->lastPositions[2].y()) / 3;
-
342 -
343 const int distance = xDistance >= yDistance ? xDistance : yDistance;
never evaluated: xDistance >= yDistance
0
344 int elapsedTime = d->time.restart();
never executed (the execution status of this line is deduced): int elapsedTime = d->time.restart();
-
345 if (!elapsedTime)
never evaluated: !elapsedTime
0
346 elapsedTime = 1;
never executed: elapsedTime = 1;
0
347 d->velocityValue = 0.9 * d->velocityValue + distance / elapsedTime;
never executed (the execution status of this line is deduced): d->velocityValue = 0.9 * d->velocityValue + distance / elapsedTime;
-
348 d->swipeAngle = QLineF(p1.startScreenPos(), p1.screenPos()).angle();
never executed (the execution status of this line is deduced): d->swipeAngle = QLineF(p1.startScreenPos(), p1.screenPos()).angle();
-
349 -
350 static const int MoveThreshold = 50; -
351 if (xDistance > MoveThreshold || yDistance > MoveThreshold) {
never evaluated: xDistance > MoveThreshold
never evaluated: yDistance > MoveThreshold
0
352 // measure the distance to check if the direction changed -
353 d->lastPositions[0] = p1.screenPos().toPoint();
never executed (the execution status of this line is deduced): d->lastPositions[0] = p1.screenPos().toPoint();
-
354 d->lastPositions[1] = p2.screenPos().toPoint();
never executed (the execution status of this line is deduced): d->lastPositions[1] = p2.screenPos().toPoint();
-
355 d->lastPositions[2] = p3.screenPos().toPoint();
never executed (the execution status of this line is deduced): d->lastPositions[2] = p3.screenPos().toPoint();
-
356 QSwipeGesture::SwipeDirection horizontal =
never executed (the execution status of this line is deduced): QSwipeGesture::SwipeDirection horizontal =
-
357 xDistance > 0 ? QSwipeGesture::Right : QSwipeGesture::Left;
never evaluated: xDistance > 0
0
358 QSwipeGesture::SwipeDirection vertical =
never executed (the execution status of this line is deduced): QSwipeGesture::SwipeDirection vertical =
-
359 yDistance > 0 ? QSwipeGesture::Down : QSwipeGesture::Up;
never evaluated: yDistance > 0
0
360 if (d->verticalDirection == QSwipeGesture::NoDirection)
never evaluated: d->verticalDirection == QSwipeGesture::NoDirection
0
361 d->verticalDirection = vertical;
never executed: d->verticalDirection = vertical;
0
362 if (d->horizontalDirection == QSwipeGesture::NoDirection)
never evaluated: d->horizontalDirection == QSwipeGesture::NoDirection
0
363 d->horizontalDirection = horizontal;
never executed: d->horizontalDirection = horizontal;
0
364 if (d->verticalDirection != vertical || d->horizontalDirection != horizontal) {
never evaluated: d->verticalDirection != vertical
never evaluated: d->horizontalDirection != horizontal
0
365 // the user has changed the direction! -
366 result = QGestureRecognizer::CancelGesture;
never executed (the execution status of this line is deduced): result = QGestureRecognizer::CancelGesture;
-
367 }
never executed: }
0
368 result = QGestureRecognizer::TriggerGesture;
never executed (the execution status of this line is deduced): result = QGestureRecognizer::TriggerGesture;
-
369 } else {
never executed: }
0
370 if (q->state() != Qt::NoGesture)
never evaluated: q->state() != Qt::NoGesture
0
371 result = QGestureRecognizer::TriggerGesture;
never executed: result = QGestureRecognizer::TriggerGesture;
0
372 else -
373 result = QGestureRecognizer::MayBeGesture;
never executed: result = QGestureRecognizer::MayBeGesture;
0
374 } -
375 } else if (ev->touchPoints().size() > 3) {
never evaluated: ev->touchPoints().size() > 3
0
376 result = QGestureRecognizer::CancelGesture;
never executed (the execution status of this line is deduced): result = QGestureRecognizer::CancelGesture;
-
377 } else { // less than 3 touch points
never executed: }
0
378 if (d->started && (ev->touchPointStates() & Qt::TouchPointPressed))
never evaluated: d->started
never evaluated: (ev->touchPointStates() & Qt::TouchPointPressed)
0
379 result = QGestureRecognizer::CancelGesture;
never executed: result = QGestureRecognizer::CancelGesture;
0
380 else if (d->started)
never evaluated: d->started
0
381 result = QGestureRecognizer::Ignore;
never executed: result = QGestureRecognizer::Ignore;
0
382 else -
383 result = QGestureRecognizer::MayBeGesture;
never executed: result = QGestureRecognizer::MayBeGesture;
0
384 } -
385 break;
never executed: break;
0
386 } -
387 case QEvent::MouseButtonPress: -
388 case QEvent::MouseMove: -
389 case QEvent::MouseButtonRelease: -
390 result = QGestureRecognizer::Ignore;
never executed (the execution status of this line is deduced): result = QGestureRecognizer::Ignore;
-
391 break;
never executed: break;
0
392 default: -
393 result = QGestureRecognizer::Ignore;
never executed (the execution status of this line is deduced): result = QGestureRecognizer::Ignore;
-
394 break;
never executed: break;
0
395 } -
396 return result;
never executed: return result;
0
397} -
398 -
399void QSwipeGestureRecognizer::reset(QGesture *state) -
400{ -
401 QSwipeGesture *q = static_cast<QSwipeGesture *>(state);
never executed (the execution status of this line is deduced): QSwipeGesture *q = static_cast<QSwipeGesture *>(state);
-
402 QSwipeGesturePrivate *d = q->d_func();
never executed (the execution status of this line is deduced): QSwipeGesturePrivate *d = q->d_func();
-
403 -
404 d->verticalDirection = d->horizontalDirection = QSwipeGesture::NoDirection;
never executed (the execution status of this line is deduced): d->verticalDirection = d->horizontalDirection = QSwipeGesture::NoDirection;
-
405 d->swipeAngle = 0;
never executed (the execution status of this line is deduced): d->swipeAngle = 0;
-
406 -
407 d->lastPositions[0] = d->lastPositions[1] = d->lastPositions[2] = QPoint();
never executed (the execution status of this line is deduced): d->lastPositions[0] = d->lastPositions[1] = d->lastPositions[2] = QPoint();
-
408 d->started = false;
never executed (the execution status of this line is deduced): d->started = false;
-
409 d->velocityValue = 0;
never executed (the execution status of this line is deduced): d->velocityValue = 0;
-
410 d->time.invalidate();
never executed (the execution status of this line is deduced): d->time.invalidate();
-
411 -
412 QGestureRecognizer::reset(state);
never executed (the execution status of this line is deduced): QGestureRecognizer::reset(state);
-
413}
never executed: }
0
414 -
415// -
416// QTapGestureRecognizer -
417// -
418 -
419QTapGestureRecognizer::QTapGestureRecognizer() -
420{ -
421} -
422 -
423QGesture *QTapGestureRecognizer::create(QObject *target) -
424{ -
425 if (target && target->isWidgetType()) {
evaluated: target
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:56
partially evaluated: target->isWidgetType()
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-56
426 static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);
executed (the execution status of this line is deduced): static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);
-
427 }
executed: }
Execution Count:1
1
428 return new QTapGesture;
executed: return new QTapGesture;
Execution Count:57
57
429} -
430 -
431QGestureRecognizer::Result QTapGestureRecognizer::recognize(QGesture *state, -
432 QObject *, -
433 QEvent *event) -
434{ -
435 QTapGesture *q = static_cast<QTapGesture *>(state);
executed (the execution status of this line is deduced): QTapGesture *q = static_cast<QTapGesture *>(state);
-
436 QTapGesturePrivate *d = q->d_func();
executed (the execution status of this line is deduced): QTapGesturePrivate *d = q->d_func();
-
437 -
438 const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
executed (the execution status of this line is deduced): const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
-
439 -
440 QGestureRecognizer::Result result = QGestureRecognizer::CancelGesture;
executed (the execution status of this line is deduced): QGestureRecognizer::Result result = QGestureRecognizer::CancelGesture;
-
441 -
442 switch (event->type()) { -
443 case QEvent::TouchBegin: { -
444 d->position = ev->touchPoints().at(0).pos();
executed (the execution status of this line is deduced): d->position = ev->touchPoints().at(0).pos();
-
445 q->setHotSpot(ev->touchPoints().at(0).screenPos());
executed (the execution status of this line is deduced): q->setHotSpot(ev->touchPoints().at(0).screenPos());
-
446 result = QGestureRecognizer::TriggerGesture;
executed (the execution status of this line is deduced): result = QGestureRecognizer::TriggerGesture;
-
447 break;
executed: break;
Execution Count:2
2
448 } -
449 case QEvent::TouchUpdate: -
450 case QEvent::TouchEnd: { -
451 if (q->state() != Qt::NoGesture && ev->touchPoints().size() == 1) {
never evaluated: q->state() != Qt::NoGesture
never evaluated: ev->touchPoints().size() == 1
0
452 QTouchEvent::TouchPoint p = ev->touchPoints().at(0);
never executed (the execution status of this line is deduced): QTouchEvent::TouchPoint p = ev->touchPoints().at(0);
-
453 QPoint delta = p.pos().toPoint() - p.startPos().toPoint();
never executed (the execution status of this line is deduced): QPoint delta = p.pos().toPoint() - p.startPos().toPoint();
-
454 enum { TapRadius = 40 };
never executed (the execution status of this line is deduced): enum { TapRadius = 40 };
-
455 if (delta.manhattanLength() <= TapRadius) {
never evaluated: delta.manhattanLength() <= TapRadius
0
456 if (event->type() == QEvent::TouchEnd)
never evaluated: event->type() == QEvent::TouchEnd
0
457 result = QGestureRecognizer::FinishGesture;
never executed: result = QGestureRecognizer::FinishGesture;
0
458 else -
459 result = QGestureRecognizer::TriggerGesture;
never executed: result = QGestureRecognizer::TriggerGesture;
0
460 } -
461 }
never executed: }
0
462 break;
never executed: break;
0
463 } -
464 case QEvent::MouseButtonPress: -
465 case QEvent::MouseMove: -
466 case QEvent::MouseButtonRelease: -
467 result = QGestureRecognizer::Ignore;
executed (the execution status of this line is deduced): result = QGestureRecognizer::Ignore;
-
468 break;
executed: break;
Execution Count:1
1
469 default: -
470 result = QGestureRecognizer::Ignore;
executed (the execution status of this line is deduced): result = QGestureRecognizer::Ignore;
-
471 break;
executed: break;
Execution Count:24
24
472 } -
473 return result;
executed: return result;
Execution Count:27
27
474} -
475 -
476void QTapGestureRecognizer::reset(QGesture *state) -
477{ -
478 QTapGesture *q = static_cast<QTapGesture *>(state);
never executed (the execution status of this line is deduced): QTapGesture *q = static_cast<QTapGesture *>(state);
-
479 QTapGesturePrivate *d = q->d_func();
never executed (the execution status of this line is deduced): QTapGesturePrivate *d = q->d_func();
-
480 -
481 d->position = QPointF();
never executed (the execution status of this line is deduced): d->position = QPointF();
-
482 -
483 QGestureRecognizer::reset(state);
never executed (the execution status of this line is deduced): QGestureRecognizer::reset(state);
-
484}
never executed: }
0
485 -
486// -
487// QTapAndHoldGestureRecognizer -
488// -
489 -
490QTapAndHoldGestureRecognizer::QTapAndHoldGestureRecognizer() -
491{ -
492} -
493 -
494QGesture *QTapAndHoldGestureRecognizer::create(QObject *target) -
495{ -
496 if (target && target->isWidgetType()) {
partially evaluated: target
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:56
never evaluated: target->isWidgetType()
0-56
497 static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);
never executed (the execution status of this line is deduced): static_cast<QWidget *>(target)->setAttribute(Qt::WA_AcceptTouchEvents);
-
498 }
never executed: }
0
499 return new QTapAndHoldGesture;
executed: return new QTapAndHoldGesture;
Execution Count:56
56
500} -
501 -
502QGestureRecognizer::Result -
503QTapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *object, -
504 QEvent *event) -
505{ -
506 QTapAndHoldGesture *q = static_cast<QTapAndHoldGesture *>(state);
never executed (the execution status of this line is deduced): QTapAndHoldGesture *q = static_cast<QTapAndHoldGesture *>(state);
-
507 QTapAndHoldGesturePrivate *d = q->d_func();
never executed (the execution status of this line is deduced): QTapAndHoldGesturePrivate *d = q->d_func();
-
508 -
509 if (object == state && event->type() == QEvent::Timer) {
never evaluated: object == state
never evaluated: event->type() == QEvent::Timer
0
510 q->killTimer(d->timerId);
never executed (the execution status of this line is deduced): q->killTimer(d->timerId);
-
511 d->timerId = 0;
never executed (the execution status of this line is deduced): d->timerId = 0;
-
512 return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint;
never executed: return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint;
0
513 } -
514 -
515 const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
never executed (the execution status of this line is deduced): const QTouchEvent *ev = static_cast<const QTouchEvent *>(event);
-
516 const QMouseEvent *me = static_cast<const QMouseEvent *>(event);
never executed (the execution status of this line is deduced): const QMouseEvent *me = static_cast<const QMouseEvent *>(event);
-
517#ifndef QT_NO_GRAPHICSVIEW -
518 const QGraphicsSceneMouseEvent *gsme = static_cast<const QGraphicsSceneMouseEvent *>(event);
never executed (the execution status of this line is deduced): const QGraphicsSceneMouseEvent *gsme = static_cast<const QGraphicsSceneMouseEvent *>(event);
-
519#endif -
520 -
521 enum { TapRadius = 40 };
never executed (the execution status of this line is deduced): enum { TapRadius = 40 };
-
522 -
523 switch (event->type()) { -
524#ifndef QT_NO_GRAPHICSVIEW -
525 case QEvent::GraphicsSceneMousePress: -
526 d->position = gsme->screenPos();
never executed (the execution status of this line is deduced): d->position = gsme->screenPos();
-
527 q->setHotSpot(d->position);
never executed (the execution status of this line is deduced): q->setHotSpot(d->position);
-
528 if (d->timerId)
never evaluated: d->timerId
0
529 q->killTimer(d->timerId);
never executed: q->killTimer(d->timerId);
0
530 d->timerId = q->startTimer(QTapAndHoldGesturePrivate::Timeout);
never executed (the execution status of this line is deduced): d->timerId = q->startTimer(QTapAndHoldGesturePrivate::Timeout);
-
531 return QGestureRecognizer::MayBeGesture; // we don't show a sign of life until the timeout
never executed: return QGestureRecognizer::MayBeGesture;
0
532#endif -
533 case QEvent::MouseButtonPress: -
534 d->position = me->globalPos();
never executed (the execution status of this line is deduced): d->position = me->globalPos();
-
535 q->setHotSpot(d->position);
never executed (the execution status of this line is deduced): q->setHotSpot(d->position);
-
536 if (d->timerId)
never evaluated: d->timerId
0
537 q->killTimer(d->timerId);
never executed: q->killTimer(d->timerId);
0
538 d->timerId = q->startTimer(QTapAndHoldGesturePrivate::Timeout);
never executed (the execution status of this line is deduced): d->timerId = q->startTimer(QTapAndHoldGesturePrivate::Timeout);
-
539 return QGestureRecognizer::MayBeGesture; // we don't show a sign of life until the timeout
never executed: return QGestureRecognizer::MayBeGesture;
0
540 case QEvent::TouchBegin: -
541 d->position = ev->touchPoints().at(0).startScreenPos();
never executed (the execution status of this line is deduced): d->position = ev->touchPoints().at(0).startScreenPos();
-
542 q->setHotSpot(d->position);
never executed (the execution status of this line is deduced): q->setHotSpot(d->position);
-
543 if (d->timerId)
never evaluated: d->timerId
0
544 q->killTimer(d->timerId);
never executed: q->killTimer(d->timerId);
0
545 d->timerId = q->startTimer(QTapAndHoldGesturePrivate::Timeout);
never executed (the execution status of this line is deduced): d->timerId = q->startTimer(QTapAndHoldGesturePrivate::Timeout);
-
546 return QGestureRecognizer::MayBeGesture; // we don't show a sign of life until the timeout
never executed: return QGestureRecognizer::MayBeGesture;
0
547#ifndef QT_NO_GRAPHICSVIEW -
548 case QEvent::GraphicsSceneMouseRelease: -
549#endif -
550 case QEvent::MouseButtonRelease: -
551 case QEvent::TouchEnd: -
552 return QGestureRecognizer::CancelGesture; // get out of the MayBeGesture state
never executed: return QGestureRecognizer::CancelGesture;
0
553 case QEvent::TouchUpdate: -
554 if (d->timerId && ev->touchPoints().size() == 1) {
never evaluated: d->timerId
never evaluated: ev->touchPoints().size() == 1
0
555 QTouchEvent::TouchPoint p = ev->touchPoints().at(0);
never executed (the execution status of this line is deduced): QTouchEvent::TouchPoint p = ev->touchPoints().at(0);
-
556 QPoint delta = p.pos().toPoint() - p.startPos().toPoint();
never executed (the execution status of this line is deduced): QPoint delta = p.pos().toPoint() - p.startPos().toPoint();
-
557 if (delta.manhattanLength() <= TapRadius)
never evaluated: delta.manhattanLength() <= TapRadius
0
558 return QGestureRecognizer::MayBeGesture;
never executed: return QGestureRecognizer::MayBeGesture;
0
559 }
never executed: }
0
560 return QGestureRecognizer::CancelGesture;
never executed: return QGestureRecognizer::CancelGesture;
0
561 case QEvent::MouseMove: { -
562 QPoint delta = me->globalPos() - d->position.toPoint();
never executed (the execution status of this line is deduced): QPoint delta = me->globalPos() - d->position.toPoint();
-
563 if (d->timerId && delta.manhattanLength() <= TapRadius)
never evaluated: d->timerId
never evaluated: delta.manhattanLength() <= TapRadius
0
564 return QGestureRecognizer::MayBeGesture;
never executed: return QGestureRecognizer::MayBeGesture;
0
565 return QGestureRecognizer::CancelGesture;
never executed: return QGestureRecognizer::CancelGesture;
0
566 } -
567#ifndef QT_NO_GRAPHICSVIEW -
568 case QEvent::GraphicsSceneMouseMove: { -
569 QPoint delta = gsme->screenPos() - d->position.toPoint();
never executed (the execution status of this line is deduced): QPoint delta = gsme->screenPos() - d->position.toPoint();
-
570 if (d->timerId && delta.manhattanLength() <= TapRadius)
never evaluated: d->timerId
never evaluated: delta.manhattanLength() <= TapRadius
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: -
576 return QGestureRecognizer::Ignore;
never executed: return QGestureRecognizer::Ignore;
0
577 } -
578}
never executed: }
0
579 -
580void QTapAndHoldGestureRecognizer::reset(QGesture *state) -
581{ -
582 QTapAndHoldGesture *q = static_cast<QTapAndHoldGesture *>(state);
never executed (the execution status of this line is deduced): QTapAndHoldGesture *q = static_cast<QTapAndHoldGesture *>(state);
-
583 QTapAndHoldGesturePrivate *d = q->d_func();
never executed (the execution status of this line is deduced): QTapAndHoldGesturePrivate *d = q->d_func();
-
584 -
585 d->position = QPointF();
never executed (the execution status of this line is deduced): d->position = QPointF();
-
586 if (d->timerId)
never evaluated: d->timerId
0
587 q->killTimer(d->timerId);
never executed: q->killTimer(d->timerId);
0
588 d->timerId = 0;
never executed (the execution status of this line is deduced): d->timerId = 0;
-
589 -
590 QGestureRecognizer::reset(state);
never executed (the execution status of this line is deduced): QGestureRecognizer::reset(state);
-
591}
never executed: }
0
592 -
593QT_END_NAMESPACE -
594 -
595#endif // QT_NO_GESTURES -
596 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial