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