OpenCoverage

qflickgesture.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/util/qflickgesture.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 "qgesture.h"-
41#include "qapplication.h"-
42#include "qevent.h"-
43#include "qwidget.h"-
44#include "qgraphicsitem.h"-
45#include "qgraphicsscene.h"-
46#include "qgraphicssceneevent.h"-
47#include "qgraphicsview.h"-
48#include "qscroller.h"-
49#include <QtGui/qtouchdevice.h>-
50#include "private/qapplication_p.h"-
51#include "private/qevent_p.h"-
52#include "private/qflickgesture_p.h"-
53#include "qdebug.h"-
54-
55#ifndef QT_NO_GESTURES-
56-
57QT_BEGIN_NAMESPACE-
58-
59//#define QFLICKGESTURE_DEBUG-
60-
61#ifdef QFLICKGESTURE_DEBUG-
62# define qFGDebug qDebug-
63#else-
64# define qFGDebug while (false) qDebug-
65#endif-
66-
67extern bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event);-
68-
69static QMouseEvent *copyMouseEvent(QEvent *e)-
70{-
71 switch (e->type()) {-
72 case QEvent::MouseButtonPress:
never executed: case QEvent::MouseButtonPress:
0
73 case QEvent::MouseButtonRelease:
never executed: case QEvent::MouseButtonRelease:
0
74 case QEvent::MouseMove: {
never executed: case QEvent::MouseMove:
0
75 QMouseEvent *me = static_cast<QMouseEvent *>(e);-
76 QMouseEvent *cme = new QMouseEvent(me->type(), QPoint(0, 0), me->windowPos(), me->screenPos(),-
77 me->button(), me->buttons(), me->modifiers(), me->source());-
78 return cme;
never executed: return cme;
0
79 }-
80#ifndef QT_NO_GRAPHICSVIEW-
81 case QEvent::GraphicsSceneMousePress:
never executed: case QEvent::GraphicsSceneMousePress:
0
82 case QEvent::GraphicsSceneMouseRelease:
never executed: case QEvent::GraphicsSceneMouseRelease:
0
83 case QEvent::GraphicsSceneMouseMove: {
never executed: case QEvent::GraphicsSceneMouseMove:
0
84 QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent *>(e);-
85#if 1-
86 QEvent::Type met = me->type() == QEvent::GraphicsSceneMousePress ? QEvent::MouseButtonPress :
me->type() == ...ceneMousePressDescription
TRUEnever evaluated
FALSEnever evaluated
0
87 (me->type() == QEvent::GraphicsSceneMouseRelease ? QEvent::MouseButtonRelease : QEvent::MouseMove);
me->type() == ...neMouseReleaseDescription
TRUEnever evaluated
FALSEnever evaluated
0
88 QMouseEvent *cme = new QMouseEvent(met, QPoint(0, 0), QPoint(0, 0), me->screenPos(),-
89 me->button(), me->buttons(), me->modifiers(), me->source());-
90 return cme;
never executed: return cme;
0
91#else-
92 QGraphicsSceneMouseEvent *copy = new QGraphicsSceneMouseEvent(me->type());-
93 copy->setPos(me->pos());-
94 copy->setScenePos(me->scenePos());-
95 copy->setScreenPos(me->screenPos());-
96 for (int i = 0x1; i <= 0x10; i <<= 1) {-
97 Qt::MouseButton button = Qt::MouseButton(i);-
98 copy->setButtonDownPos(button, me->buttonDownPos(button));-
99 copy->setButtonDownScenePos(button, me->buttonDownScenePos(button));-
100 copy->setButtonDownScreenPos(button, me->buttonDownScreenPos(button));-
101 }-
102 copy->setLastPos(me->lastPos());-
103 copy->setLastScenePos(me->lastScenePos());-
104 copy->setLastScreenPos(me->lastScreenPos());-
105 copy->setButtons(me->buttons());-
106 copy->setButton(me->button());-
107 copy->setModifiers(me->modifiers());-
108 copy->setSource(me->source());-
109 copy->setFlags(me->flags());-
110 return copy;-
111#endif-
112 }-
113#endif // QT_NO_GRAPHICSVIEW-
114 default:
never executed: default:
0
115 return 0;
never executed: return 0;
0
116 }-
117}-
118-
119class PressDelayHandler : public QObject-
120{-
121private:-
122 PressDelayHandler(QObject *parent = 0)-
123 : QObject(parent)-
124 , pressDelayTimer(0)-
125 , sendingEvent(false)-
126 , mouseButton(Qt::NoButton)-
127 , mouseTarget(0)-
128 , mouseEventSource(Qt::MouseEventNotSynthesized)-
129 { }
never executed: end of block
0
130-
131 static PressDelayHandler *inst;-
132-
133public:-
134 enum {-
135 UngrabMouseBefore = 1,-
136 RegrabMouseAfterwards = 2-
137 };-
138-
139 static PressDelayHandler *instance()-
140 {-
141 static PressDelayHandler *inst = 0;-
142 if (!inst)
!instDescription
TRUEnever evaluated
FALSEnever evaluated
0
143 inst = new PressDelayHandler(QCoreApplication::instance());
never executed: inst = new PressDelayHandler(QCoreApplication::instance());
0
144 return inst;
never executed: return inst;
0
145 }-
146-
147 bool shouldEventBeIgnored(QEvent *) const-
148 {-
149 return sendingEvent;
never executed: return sendingEvent;
0
150 }-
151-
152 bool isDelaying() const-
153 {-
154 return !pressDelayEvent.isNull();
never executed: return !pressDelayEvent.isNull();
0
155 }-
156-
157 void pressed(QEvent *e, int delay)-
158 {-
159 if (!pressDelayEvent) {
!pressDelayEventDescription
TRUEnever evaluated
FALSEnever evaluated
0
160 pressDelayEvent.reset(copyMouseEvent(e));-
161 pressDelayTimer = startTimer(delay);-
162 mouseTarget = QApplication::widgetAt(pressDelayEvent->globalPos());-
163 mouseButton = pressDelayEvent->button();-
164 mouseEventSource = pressDelayEvent->source();-
165 qFGDebug("QFG: consuming/delaying mouse press");
dead code: QMessageLogger(__FILE__, 165, __PRETTY_FUNCTION__).debug("QFG: consuming/delaying mouse press");
-
166 } else {
never executed: end of block
0
167 qFGDebug("QFG: NOT consuming/delaying mouse press");
dead code: QMessageLogger(__FILE__, 167, __PRETTY_FUNCTION__).debug("QFG: NOT consuming/delaying mouse press");
-
168 }
never executed: end of block
0
169 e->setAccepted(true);-
170 }
never executed: end of block
0
171-
172 bool released(QEvent *e, bool scrollerWasActive, bool scrollerIsActive)-
173 {-
174 // consume this event if the scroller was or is active-
175 bool result = scrollerWasActive || scrollerIsActive;
scrollerWasActiveDescription
TRUEnever evaluated
FALSEnever evaluated
scrollerIsActiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
176-
177 // stop the timer-
178 if (pressDelayTimer) {
pressDelayTimerDescription
TRUEnever evaluated
FALSEnever evaluated
0
179 killTimer(pressDelayTimer);-
180 pressDelayTimer = 0;-
181 }
never executed: end of block
0
182 // we still haven't even sent the press, so do it now-
183 if (pressDelayEvent && mouseTarget && !scrollerIsActive) {
pressDelayEventDescription
TRUEnever evaluated
FALSEnever evaluated
mouseTargetDescription
TRUEnever evaluated
FALSEnever evaluated
!scrollerIsActiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
184 QScopedPointer<QMouseEvent> releaseEvent(copyMouseEvent(e));-
185-
186 qFGDebug() << "QFG: re-sending mouse press (due to release) for " << mouseTarget;
dead code: QMessageLogger(__FILE__, 186, __PRETTY_FUNCTION__).debug() << "QFG: re-sending mouse press (due to release) for " << mouseTarget;
-
187 sendMouseEvent(pressDelayEvent.data(), UngrabMouseBefore);-
188-
189 qFGDebug() << "QFG: faking mouse release (due to release) for " << mouseTarget;
dead code: QMessageLogger(__FILE__, 189, __PRETTY_FUNCTION__).debug() << "QFG: faking mouse release (due to release) for " << mouseTarget;
-
190 sendMouseEvent(releaseEvent.data());-
191-
192 result = true; // consume this event-
193 } else if (mouseTarget && scrollerIsActive) {
never executed: end of block
mouseTargetDescription
TRUEnever evaluated
FALSEnever evaluated
scrollerIsActiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
194 // we grabbed the mouse expicitly when the scroller became active, so undo that now-
195 sendMouseEvent(0, UngrabMouseBefore);-
196 }
never executed: end of block
0
197 pressDelayEvent.reset(0);-
198 mouseTarget = 0;-
199 return result;
never executed: return result;
0
200 }-
201-
202 void scrollerWasIntercepted()-
203 {-
204 qFGDebug("QFG: deleting delayed mouse press, since scroller was only intercepted");
dead code: QMessageLogger(__FILE__, 204, __PRETTY_FUNCTION__).debug("QFG: deleting delayed mouse press, since scroller was only intercepted");
-
205 if (pressDelayEvent) {
pressDelayEventDescription
TRUEnever evaluated
FALSEnever evaluated
0
206 // we still haven't even sent the press, so just throw it away now-
207 if (pressDelayTimer) {
pressDelayTimerDescription
TRUEnever evaluated
FALSEnever evaluated
0
208 killTimer(pressDelayTimer);-
209 pressDelayTimer = 0;-
210 }
never executed: end of block
0
211 pressDelayEvent.reset(0);-
212 }
never executed: end of block
0
213 mouseTarget = 0;-
214 }
never executed: end of block
0
215-
216 void scrollerBecameActive()-
217 {-
218 if (pressDelayEvent) {
pressDelayEventDescription
TRUEnever evaluated
FALSEnever evaluated
0
219 // we still haven't even sent the press, so just throw it away now-
220 qFGDebug("QFG: deleting delayed mouse press, since scroller is active now");
dead code: QMessageLogger(__FILE__, 220, __PRETTY_FUNCTION__).debug("QFG: deleting delayed mouse press, since scroller is active now");
-
221 if (pressDelayTimer) {
pressDelayTimerDescription
TRUEnever evaluated
FALSEnever evaluated
0
222 killTimer(pressDelayTimer);-
223 pressDelayTimer = 0;-
224 }
never executed: end of block
0
225 pressDelayEvent.reset(0);-
226 mouseTarget = 0;-
227 } else if (mouseTarget) {
never executed: end of block
mouseTargetDescription
TRUEnever evaluated
FALSEnever evaluated
0
228 // we did send a press, so we need to fake a release now-
229-
230 // release all pressed mouse buttons-
231 /* Qt::MouseButtons mouseButtons = QApplication::mouseButtons();-
232 for (int i = 0; i < 32; ++i) {-
233 if (mouseButtons & (1 << i)) {-
234 Qt::MouseButton b = static_cast<Qt::MouseButton>(1 << i);-
235 mouseButtons &= ~b;-
236 QPoint farFarAway(-QWIDGETSIZE_MAX, -QWIDGETSIZE_MAX);-
237-
238 qFGDebug() << "QFG: sending a fake mouse release at far-far-away to " << mouseTarget;-
239 QMouseEvent re(QEvent::MouseButtonRelease, QPoint(), farFarAway,-
240 b, mouseButtons, QApplication::keyboardModifiers());-
241 sendMouseEvent(&re);-
242 }-
243 }*/-
244-
245 QPoint farFarAway(-QWIDGETSIZE_MAX, -QWIDGETSIZE_MAX);-
246-
247 qFGDebug() << "QFG: sending a fake mouse release at far-far-away to " << mouseTarget;
dead code: QMessageLogger(__FILE__, 247, __PRETTY_FUNCTION__).debug() << "QFG: sending a fake mouse release at far-far-away to " << mouseTarget;
-
248 QMouseEvent re(QEvent::MouseButtonRelease, QPoint(), farFarAway, farFarAway,-
249 mouseButton, QApplication::mouseButtons() & ~mouseButton,-
250 QApplication::keyboardModifiers(), mouseEventSource);-
251 sendMouseEvent(&re, RegrabMouseAfterwards);-
252 // don't clear the mouseTarget just yet, since we need to explicitly ungrab the mouse on release!-
253 }
never executed: end of block
0
254 }
never executed: end of block
0
255-
256protected:-
257 void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE-
258 {-
259 if (e->timerId() == pressDelayTimer) {
e->timerId() =...ressDelayTimerDescription
TRUEnever evaluated
FALSEnever evaluated
0
260 if (pressDelayEvent && mouseTarget) {
pressDelayEventDescription
TRUEnever evaluated
FALSEnever evaluated
mouseTargetDescription
TRUEnever evaluated
FALSEnever evaluated
0
261 qFGDebug() << "QFG: timer event: re-sending mouse press to " << mouseTarget;
dead code: QMessageLogger(__FILE__, 261, __PRETTY_FUNCTION__).debug() << "QFG: timer event: re-sending mouse press to " << mouseTarget;
-
262 sendMouseEvent(pressDelayEvent.data(), UngrabMouseBefore);-
263 }
never executed: end of block
0
264 pressDelayEvent.reset(0);-
265-
266 if (pressDelayTimer) {
pressDelayTimerDescription
TRUEnever evaluated
FALSEnever evaluated
0
267 killTimer(pressDelayTimer);-
268 pressDelayTimer = 0;-
269 }
never executed: end of block
0
270 }
never executed: end of block
0
271 }
never executed: end of block
0
272-
273 void sendMouseEvent(QMouseEvent *me, int flags = 0)-
274 {-
275 if (mouseTarget) {
mouseTargetDescription
TRUEnever evaluated
FALSEnever evaluated
0
276 sendingEvent = true;-
277-
278#ifndef QT_NO_GRAPHICSVIEW-
279 QGraphicsItem *grabber = 0;-
280 if (mouseTarget->parentWidget()) {
mouseTarget->parentWidget()Description
TRUEnever evaluated
FALSEnever evaluated
0
281 if (QGraphicsView *gv = qobject_cast<QGraphicsView *>(mouseTarget->parentWidget())) {
QGraphicsView ...arentWidget())Description
TRUEnever evaluated
FALSEnever evaluated
0
282 if (gv->scene())
gv->scene()Description
TRUEnever evaluated
FALSEnever evaluated
0
283 grabber = gv->scene()->mouseGrabberItem();
never executed: grabber = gv->scene()->mouseGrabberItem();
0
284 }
never executed: end of block
0
285 }
never executed: end of block
0
286-
287 if (grabber && (flags & UngrabMouseBefore)) {
grabberDescription
TRUEnever evaluated
FALSEnever evaluated
(flags & UngrabMouseBefore)Description
TRUEnever evaluated
FALSEnever evaluated
0
288 // GraphicsView Mouse Handling Workaround #1:-
289 // we need to ungrab the mouse before re-sending the press,-
290 // since the scene had already set the mouse grabber to the-
291 // original (and consumed) event's receiver-
292 qFGDebug() << "QFG: ungrabbing" << grabber;
dead code: QMessageLogger(__FILE__, 292, __PRETTY_FUNCTION__).debug() << "QFG: ungrabbing" << grabber;
-
293 grabber->ungrabMouse();-
294 }
never executed: end of block
0
295#endif // QT_NO_GRAPHICSVIEW-
296-
297 if (me) {
meDescription
TRUEnever evaluated
FALSEnever evaluated
0
298 QMouseEvent copy(me->type(), mouseTarget->mapFromGlobal(me->globalPos()),-
299 mouseTarget->topLevelWidget()->mapFromGlobal(me->globalPos()), me->screenPos(),-
300 me->button(), me->buttons(), me->modifiers(), me->source());-
301 qt_sendSpontaneousEvent(mouseTarget, &copy);-
302 }
never executed: end of block
0
303-
304#ifndef QT_NO_GRAPHICSVIEW-
305 if (grabber && (flags & RegrabMouseAfterwards)) {
grabberDescription
TRUEnever evaluated
FALSEnever evaluated
(flags & Regra...useAfterwards)Description
TRUEnever evaluated
FALSEnever evaluated
0
306 // GraphicsView Mouse Handling Workaround #2:-
307 // we need to re-grab the mouse after sending a faked mouse-
308 // release, since we still need the mouse moves for the gesture-
309 // (the scene will clear the item's mouse grabber status on-
310 // release).-
311 qFGDebug() << "QFG: re-grabbing" << grabber;
dead code: QMessageLogger(__FILE__, 311, __PRETTY_FUNCTION__).debug() << "QFG: re-grabbing" << grabber;
-
312 grabber->grabMouse();-
313 }
never executed: end of block
0
314#endif-
315 sendingEvent = false;-
316 }
never executed: end of block
0
317 }
never executed: end of block
0
318-
319-
320private:-
321 int pressDelayTimer;-
322 QScopedPointer<QMouseEvent> pressDelayEvent;-
323 bool sendingEvent;-
324 Qt::MouseButton mouseButton;-
325 QPointer<QWidget> mouseTarget;-
326 Qt::MouseEventSource mouseEventSource;-
327};-
328-
329-
330/*!-
331 \internal-
332 \class QFlickGesture-
333 \since 4.8-
334 \brief The QFlickGesture class describes a flicking gesture made by the user.-
335 \ingroup gestures-
336 The QFlickGesture is more complex than the QPanGesture that uses QScroller and QScrollerProperties-
337 to decide if it is triggered.-
338 This gesture is reacting on touch event as compared to the QMouseFlickGesture.-
339-
340 \sa {Gestures in Widgets and Graphics View}, QScroller, QScrollerProperties, QMouseFlickGesture-
341*/-
342-
343/*!-
344 \internal-
345*/-
346QFlickGesture::QFlickGesture(QObject *receiver, Qt::MouseButton button, QObject *parent)-
347 : QGesture(*new QFlickGesturePrivate, parent)-
348{-
349 d_func()->q_ptr = this;-
350 d_func()->receiver = receiver;-
351 d_func()->receiverScroller = (receiver && QScroller::hasScroller(receiver)) ? QScroller::scroller(receiver) : 0;
receiverDescription
TRUEnever evaluated
FALSEnever evaluated
QScroller::has...ller(receiver)Description
TRUEnever evaluated
FALSEnever evaluated
0
352 d_func()->button = button;-
353}
never executed: end of block
0
354-
355QFlickGesture::~QFlickGesture()-
356{ }-
357-
358QFlickGesturePrivate::QFlickGesturePrivate()-
359 : receiverScroller(0), button(Qt::NoButton), macIgnoreWheel(false)-
360{
never executed: end of block
}
never executed: end of block
0
361-
362-
363//-
364// QFlickGestureRecognizer-
365//-
366-
367-
368QFlickGestureRecognizer::QFlickGestureRecognizer(Qt::MouseButton button)-
369{-
370 this->button = button;-
371}
never executed: end of block
0
372-
373/*! \reimp-
374 */-
375QGesture *QFlickGestureRecognizer::create(QObject *target)-
376{-
377#ifndef QT_NO_GRAPHICSVIEW-
378 QGraphicsObject *go = qobject_cast<QGraphicsObject*>(target);-
379 if (go && button == Qt::NoButton) {
goDescription
TRUEnever evaluated
FALSEnever evaluated
button == Qt::NoButtonDescription
TRUEnever evaluated
FALSEnever evaluated
0
380 go->setAcceptTouchEvents(true);-
381 }
never executed: end of block
0
382#endif-
383 return new QFlickGesture(target, button);
never executed: return new QFlickGesture(target, button);
0
384}-
385-
386/*! \internal-
387 The recognize function detects a touch event suitable to start the attached QScroller.-
388 The QFlickGesture will be triggered as soon as the scroller is no longer in the state-
389 QScroller::Inactive or QScroller::Pressed. It will be finished or canceled-
390 at the next QEvent::TouchEnd.-
391 Note that the QScroller might continue scrolling (kinetically) at this point.-
392 */-
393QGestureRecognizer::Result QFlickGestureRecognizer::recognize(QGesture *state,-
394 QObject *watched,-
395 QEvent *event)-
396{-
397 Q_UNUSED(watched);-
398-
399 static QElapsedTimer monotonicTimer;-
400 if (!monotonicTimer.isValid())
!monotonicTimer.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
401 monotonicTimer.start();
never executed: monotonicTimer.start();
0
402-
403 QFlickGesture *q = static_cast<QFlickGesture *>(state);-
404 QFlickGesturePrivate *d = q->d_func();-
405-
406 QScroller *scroller = d->receiverScroller;-
407 if (!scroller)
!scrollerDescription
TRUEnever evaluated
FALSEnever evaluated
0
408 return Ignore; // nothing to do without a scroller?
never executed: return Ignore;
0
409-
410 QWidget *receiverWidget = qobject_cast<QWidget *>(d->receiver);-
411#ifndef QT_NO_GRAPHICSVIEW-
412 QGraphicsObject *receiverGraphicsObject = qobject_cast<QGraphicsObject *>(d->receiver);-
413#endif-
414-
415 // this is only set for events that we inject into the event loop via sendEvent()-
416 if (PressDelayHandler::instance()->shouldEventBeIgnored(event)) {
PressDelayHand...Ignored(event)Description
TRUEnever evaluated
FALSEnever evaluated
0
417 //qFGDebug() << state << "QFG: ignored event: " << event->type();-
418 return Ignore;
never executed: return Ignore;
0
419 }-
420-
421 const QMouseEvent *me = 0;-
422#ifndef QT_NO_GRAPHICSVIEW-
423 const QGraphicsSceneMouseEvent *gsme = 0;-
424#endif-
425 const QTouchEvent *te = 0;-
426 QPoint globalPos;-
427-
428 // qFGDebug() << "FlickGesture "<<state<<"watched:"<<watched<<"receiver"<<d->receiver<<"event"<<event->type()<<"button"<<button;-
429-
430 switch (event->type()) {-
431 case QEvent::MouseButtonPress:
never executed: case QEvent::MouseButtonPress:
0
432 case QEvent::MouseButtonRelease:
never executed: case QEvent::MouseButtonRelease:
0
433 case QEvent::MouseMove:
never executed: case QEvent::MouseMove:
0
434 if (!receiverWidget)
!receiverWidgetDescription
TRUEnever evaluated
FALSEnever evaluated
0
435 return Ignore;
never executed: return Ignore;
0
436 if (button != Qt::NoButton) {
button != Qt::NoButtonDescription
TRUEnever evaluated
FALSEnever evaluated
0
437 me = static_cast<const QMouseEvent *>(event);-
438 globalPos = me->globalPos();-
439 }
never executed: end of block
0
440 break;
never executed: break;
0
441#ifndef QT_NO_GRAPHICSVIEW-
442 case QEvent::GraphicsSceneMousePress:
never executed: case QEvent::GraphicsSceneMousePress:
0
443 case QEvent::GraphicsSceneMouseRelease:
never executed: case QEvent::GraphicsSceneMouseRelease:
0
444 case QEvent::GraphicsSceneMouseMove:
never executed: case QEvent::GraphicsSceneMouseMove:
0
445 if (!receiverGraphicsObject)
!receiverGraphicsObjectDescription
TRUEnever evaluated
FALSEnever evaluated
0
446 return Ignore;
never executed: return Ignore;
0
447 if (button != Qt::NoButton) {
button != Qt::NoButtonDescription
TRUEnever evaluated
FALSEnever evaluated
0
448 gsme = static_cast<const QGraphicsSceneMouseEvent *>(event);-
449 globalPos = gsme->screenPos();-
450 }
never executed: end of block
0
451 break;
never executed: break;
0
452#endif-
453 case QEvent::TouchBegin:
never executed: case QEvent::TouchBegin:
0
454 case QEvent::TouchEnd:
never executed: case QEvent::TouchEnd:
0
455 case QEvent::TouchUpdate:
never executed: case QEvent::TouchUpdate:
0
456 if (button == Qt::NoButton) {
button == Qt::NoButtonDescription
TRUEnever evaluated
FALSEnever evaluated
0
457 te = static_cast<const QTouchEvent *>(event);-
458 if (!te->touchPoints().isEmpty())
!te->touchPoints().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
459 globalPos = te->touchPoints().at(0).screenPos().toPoint();
never executed: globalPos = te->touchPoints().at(0).screenPos().toPoint();
0
460 }
never executed: end of block
0
461 break;
never executed: break;
0
462-
463#if defined(Q_DEAD_CODE_FROM_QT4_MAC)-
464 // the only way to distinguish between real mouse wheels and wheel-
465 // events generated by the native 2 finger swipe gesture is to listen-
466 // for these events (according to Apple's Cocoa Event-Handling Guide)-
467-
468 case QEvent::NativeGesture: {-
469 QNativeGestureEvent *nge = static_cast<QNativeGestureEvent *>(event);-
470 if (nge->gestureType == QNativeGestureEvent::GestureBegin)-
471 d->macIgnoreWheel = true;-
472 else if (nge->gestureType == QNativeGestureEvent::GestureEnd)-
473 d->macIgnoreWheel = false;-
474 break;-
475 }-
476#endif-
477-
478 // consume all wheel events if the scroller is active-
479 case QEvent::Wheel:
never executed: case QEvent::Wheel:
0
480 if (d->macIgnoreWheel || (scroller->state() != QScroller::Inactive))
d->macIgnoreWheelDescription
TRUEnever evaluated
FALSEnever evaluated
(scroller->sta...ler::Inactive)Description
TRUEnever evaluated
FALSEnever evaluated
0
481 return Ignore | ConsumeEventHint;
never executed: return Ignore | ConsumeEventHint;
0
482 break;
never executed: break;
0
483-
484 // consume all dbl click events if the scroller is active-
485 case QEvent::MouseButtonDblClick:
never executed: case QEvent::MouseButtonDblClick:
0
486 if (scroller->state() != QScroller::Inactive)
scroller->stat...ller::InactiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
487 return Ignore | ConsumeEventHint;
never executed: return Ignore | ConsumeEventHint;
0
488 break;
never executed: break;
0
489-
490 default:
never executed: default:
0
491 break;
never executed: break;
0
492 }-
493-
494 if (!me
!meDescription
TRUEnever evaluated
FALSEnever evaluated
0
495#ifndef QT_NO_GRAPHICSVIEW-
496 && !gsme
!gsmeDescription
TRUEnever evaluated
FALSEnever evaluated
0
497#endif-
498 && !te) // Neither mouse nor touch
!teDescription
TRUEnever evaluated
FALSEnever evaluated
0
499 return Ignore;
never executed: return Ignore;
0
500-
501 // get the current pointer position in local coordinates.-
502 QPointF point;-
503 QScroller::Input inputType = (QScroller::Input) 0;-
504-
505 switch (event->type()) {-
506 case QEvent::MouseButtonPress:
never executed: case QEvent::MouseButtonPress:
0
507 if (me && me->button() == button && me->buttons() == button) {
meDescription
TRUEnever evaluated
FALSEnever evaluated
me->button() == buttonDescription
TRUEnever evaluated
FALSEnever evaluated
me->buttons() == buttonDescription
TRUEnever evaluated
FALSEnever evaluated
0
508 point = me->globalPos();-
509 inputType = QScroller::InputPress;-
510 } else if (me) {
never executed: end of block
meDescription
TRUEnever evaluated
FALSEnever evaluated
0
511 scroller->stop();-
512 return CancelGesture;
never executed: return CancelGesture;
0
513 }-
514 break;
never executed: break;
0
515 case QEvent::MouseButtonRelease:
never executed: case QEvent::MouseButtonRelease:
0
516 if (me && me->button() == button) {
meDescription
TRUEnever evaluated
FALSEnever evaluated
me->button() == buttonDescription
TRUEnever evaluated
FALSEnever evaluated
0
517 point = me->globalPos();-
518 inputType = QScroller::InputRelease;-
519 }
never executed: end of block
0
520 break;
never executed: break;
0
521 case QEvent::MouseMove:
never executed: case QEvent::MouseMove:
0
522 if (me && me->buttons() == button) {
meDescription
TRUEnever evaluated
FALSEnever evaluated
me->buttons() == buttonDescription
TRUEnever evaluated
FALSEnever evaluated
0
523 point = me->globalPos();-
524 inputType = QScroller::InputMove;-
525 }
never executed: end of block
0
526 break;
never executed: break;
0
527-
528#ifndef QT_NO_GRAPHICSVIEW-
529 case QEvent::GraphicsSceneMousePress:
never executed: case QEvent::GraphicsSceneMousePress:
0
530 if (gsme && gsme->button() == button && gsme->buttons() == button) {
gsmeDescription
TRUEnever evaluated
FALSEnever evaluated
gsme->button() == buttonDescription
TRUEnever evaluated
FALSEnever evaluated
gsme->buttons() == buttonDescription
TRUEnever evaluated
FALSEnever evaluated
0
531 point = gsme->scenePos();-
532 inputType = QScroller::InputPress;-
533 } else if (gsme) {
never executed: end of block
gsmeDescription
TRUEnever evaluated
FALSEnever evaluated
0
534 scroller->stop();-
535 return CancelGesture;
never executed: return CancelGesture;
0
536 }-
537 break;
never executed: break;
0
538 case QEvent::GraphicsSceneMouseRelease:
never executed: case QEvent::GraphicsSceneMouseRelease:
0
539 if (gsme && gsme->button() == button) {
gsmeDescription
TRUEnever evaluated
FALSEnever evaluated
gsme->button() == buttonDescription
TRUEnever evaluated
FALSEnever evaluated
0
540 point = gsme->scenePos();-
541 inputType = QScroller::InputRelease;-
542 }
never executed: end of block
0
543 break;
never executed: break;
0
544 case QEvent::GraphicsSceneMouseMove:
never executed: case QEvent::GraphicsSceneMouseMove:
0
545 if (gsme && gsme->buttons() == button) {
gsmeDescription
TRUEnever evaluated
FALSEnever evaluated
gsme->buttons() == buttonDescription
TRUEnever evaluated
FALSEnever evaluated
0
546 point = gsme->scenePos();-
547 inputType = QScroller::InputMove;-
548 }
never executed: end of block
0
549 break;
never executed: break;
0
550#endif-
551-
552 case QEvent::TouchBegin:
never executed: case QEvent::TouchBegin:
0
553 inputType = QScroller::InputPress;-
554 // fall through-
555 case QEvent::TouchEnd:
code before this statement never executed: case QEvent::TouchEnd:
never executed: case QEvent::TouchEnd:
0
556 if (!inputType)
!inputTypeDescription
TRUEnever evaluated
FALSEnever evaluated
0
557 inputType = QScroller::InputRelease;
never executed: inputType = QScroller::InputRelease;
0
558 // fallthrough-
559 case QEvent::TouchUpdate:
code before this statement never executed: case QEvent::TouchUpdate:
never executed: case QEvent::TouchUpdate:
0
560 if (!inputType)
!inputTypeDescription
TRUEnever evaluated
FALSEnever evaluated
0
561 inputType = QScroller::InputMove;
never executed: inputType = QScroller::InputMove;
0
562-
563 if (te->device()->type() == QTouchDevice::TouchPad) {
te->device()->...vice::TouchPadDescription
TRUEnever evaluated
FALSEnever evaluated
0
564 if (te->touchPoints().count() != 2) // 2 fingers on pad
te->touchPoints().count() != 2Description
TRUEnever evaluated
FALSEnever evaluated
0
565 return Ignore;
never executed: return Ignore;
0
566-
567 point = te->touchPoints().at(0).startScenePos() +-
568 ((te->touchPoints().at(0).scenePos() - te->touchPoints().at(0).startScenePos()) +-
569 (te->touchPoints().at(1).scenePos() - te->touchPoints().at(1).startScenePos())) / 2;-
570 } else { // TouchScreen
never executed: end of block
0
571 if (te->touchPoints().count() != 1) // 1 finger on screen
te->touchPoints().count() != 1Description
TRUEnever evaluated
FALSEnever evaluated
0
572 return Ignore;
never executed: return Ignore;
0
573-
574 point = te->touchPoints().at(0).scenePos();-
575 }
never executed: end of block
0
576 break;
never executed: break;
0
577-
578 default:
never executed: default:
0
579 break;
never executed: break;
0
580 }-
581-
582 // Check for an active scroller at globalPos-
583 if (inputType == QScroller::InputPress) {
inputType == Q...er::InputPressDescription
TRUEnever evaluated
FALSEnever evaluated
0
584 const auto activeScrollers = QScroller::activeScrollers();-
585 for (QScroller *as : activeScrollers) {-
586 if (as != scroller) {
as != scrollerDescription
TRUEnever evaluated
FALSEnever evaluated
0
587 QRegion scrollerRegion;-
588-
589 if (QWidget *w = qobject_cast<QWidget *>(as->target())) {
QWidget *w = q...(as->target())Description
TRUEnever evaluated
FALSEnever evaluated
0
590 scrollerRegion = QRect(w->mapToGlobal(QPoint(0, 0)), w->size());-
591#ifndef QT_NO_GRAPHICSVIEW-
592 } else if (QGraphicsObject *go = qobject_cast<QGraphicsObject *>(as->target())) {
never executed: end of block
QGraphicsObjec...(as->target())Description
TRUEnever evaluated
FALSEnever evaluated
0
593 if (const auto *scene = go->scene()) {
const auto *sc... = go->scene()Description
TRUEnever evaluated
FALSEnever evaluated
0
594 const auto goBoundingRectMappedToScene = go->mapToScene(go->boundingRect());-
595 const auto views = scene->views();-
596 for (QGraphicsView *gv : views) {-
597 scrollerRegion |= gv->mapFromScene(goBoundingRectMappedToScene)-
598 .translated(gv->mapToGlobal(QPoint(0, 0)));-
599 }
never executed: end of block
0
600 }
never executed: end of block
0
601#endif-
602 }
never executed: end of block
0
603 // active scrollers always have priority-
604 if (scrollerRegion.contains(globalPos))
scrollerRegion...ins(globalPos)Description
TRUEnever evaluated
FALSEnever evaluated
0
605 return Ignore;
never executed: return Ignore;
0
606 }
never executed: end of block
0
607 }
never executed: end of block
0
608 }
never executed: end of block
0
609-
610 bool scrollerWasDragging = (scroller->state() == QScroller::Dragging);-
611 bool scrollerWasScrolling = (scroller->state() == QScroller::Scrolling);-
612-
613 if (inputType) {
inputTypeDescription
TRUEnever evaluated
FALSEnever evaluated
0
614 if (QWidget *w = qobject_cast<QWidget *>(d->receiver))
QWidget *w = q...>(d->receiver)Description
TRUEnever evaluated
FALSEnever evaluated
0
615 point = w->mapFromGlobal(point.toPoint());
never executed: point = w->mapFromGlobal(point.toPoint());
0
616#ifndef QT_NO_GRAPHICSVIEW-
617 else if (QGraphicsObject *go = qobject_cast<QGraphicsObject *>(d->receiver))
QGraphicsObjec...>(d->receiver)Description
TRUEnever evaluated
FALSEnever evaluated
0
618 point = go->mapFromScene(point);
never executed: point = go->mapFromScene(point);
0
619#endif-
620-
621 // inform the scroller about the new event-
622 scroller->handleInput(inputType, point, monotonicTimer.elapsed());-
623 }
never executed: end of block
0
624-
625 // depending on the scroller state return the gesture state-
626 Result result(0);-
627 bool scrollerIsActive = (scroller->state() == QScroller::Dragging ||
scroller->stat...ller::DraggingDescription
TRUEnever evaluated
FALSEnever evaluated
0
628 scroller->state() == QScroller::Scrolling);
scroller->stat...ler::ScrollingDescription
TRUEnever evaluated
FALSEnever evaluated
0
629-
630 // Consume all mouse events while dragging or scrolling to avoid nasty-
631 // side effects with Qt's standard widgets.-
632 if ((me
meDescription
TRUEnever evaluated
FALSEnever evaluated
0
633#ifndef QT_NO_GRAPHICSVIEW-
634 || gsme
gsmeDescription
TRUEnever evaluated
FALSEnever evaluated
0
635#endif-
636 ) && scrollerIsActive)
scrollerIsActiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
637 result |= ConsumeEventHint;
never executed: result |= ConsumeEventHint;
0
638-
639 // The only problem with this approach is that we consume the-
640 // MouseRelease when we start the scrolling with a flick gesture, so we-
641 // have to fake a MouseRelease "somewhere" to not mess with the internal-
642 // states of Qt's widgets (a QPushButton would stay in 'pressed' state-
643 // forever, if it doesn't receive a MouseRelease).-
644 if (me
meDescription
TRUEnever evaluated
FALSEnever evaluated
0
645#ifndef QT_NO_GRAPHICSVIEW-
646 || gsme
gsmeDescription
TRUEnever evaluated
FALSEnever evaluated
0
647#endif-
648 ) {-
649 if (!scrollerWasDragging && !scrollerWasScrolling && scrollerIsActive)
!scrollerWasDraggingDescription
TRUEnever evaluated
FALSEnever evaluated
!scrollerWasScrollingDescription
TRUEnever evaluated
FALSEnever evaluated
scrollerIsActiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
650 PressDelayHandler::instance()->scrollerBecameActive();
never executed: PressDelayHandler::instance()->scrollerBecameActive();
0
651 else if (scrollerWasScrolling && (scroller->state() == QScroller::Dragging || scroller->state() == QScroller::Inactive))
scrollerWasScrollingDescription
TRUEnever evaluated
FALSEnever evaluated
scroller->stat...ller::DraggingDescription
TRUEnever evaluated
FALSEnever evaluated
scroller->stat...ller::InactiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
652 PressDelayHandler::instance()->scrollerWasIntercepted();
never executed: PressDelayHandler::instance()->scrollerWasIntercepted();
0
653 }
never executed: end of block
0
654-
655 if (!inputType) {
!inputTypeDescription
TRUEnever evaluated
FALSEnever evaluated
0
656 result |= Ignore;-
657 } else {
never executed: end of block
0
658 switch (event->type()) {-
659 case QEvent::MouseButtonPress:
never executed: case QEvent::MouseButtonPress:
0
660#ifndef QT_NO_GRAPHICSVIEW-
661 case QEvent::GraphicsSceneMousePress:
never executed: case QEvent::GraphicsSceneMousePress:
0
662#endif-
663 if (scroller->state() == QScroller::Pressed) {
scroller->stat...oller::PressedDescription
TRUEnever evaluated
FALSEnever evaluated
0
664 int pressDelay = int(1000 * scroller->scrollerProperties().scrollMetric(QScrollerProperties::MousePressEventDelay).toReal());-
665 if (pressDelay > 0) {
pressDelay > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
666 result |= ConsumeEventHint;-
667-
668 PressDelayHandler::instance()->pressed(event, pressDelay);-
669 event->accept();-
670 }
never executed: end of block
0
671 }
never executed: end of block
0
672 // fall through-
673 case QEvent::TouchBegin:
code before this statement never executed: case QEvent::TouchBegin:
never executed: case QEvent::TouchBegin:
0
674 q->setHotSpot(globalPos);-
675 result |= scrollerIsActive ? TriggerGesture : MayBeGesture;
scrollerIsActiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
676 break;
never executed: break;
0
677-
678 case QEvent::MouseMove:
never executed: case QEvent::MouseMove:
0
679#ifndef QT_NO_GRAPHICSVIEW-
680 case QEvent::GraphicsSceneMouseMove:
never executed: case QEvent::GraphicsSceneMouseMove:
0
681#endif-
682 if (PressDelayHandler::instance()->isDelaying())
PressDelayHand...->isDelaying()Description
TRUEnever evaluated
FALSEnever evaluated
0
683 result |= ConsumeEventHint;
never executed: result |= ConsumeEventHint;
0
684 // fall through-
685 case QEvent::TouchUpdate:
code before this statement never executed: case QEvent::TouchUpdate:
never executed: case QEvent::TouchUpdate:
0
686 result |= scrollerIsActive ? TriggerGesture : Ignore;
scrollerIsActiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
687 break;
never executed: break;
0
688-
689#ifndef QT_NO_GRAPHICSVIEW-
690 case QEvent::GraphicsSceneMouseRelease:
never executed: case QEvent::GraphicsSceneMouseRelease:
0
691#endif-
692 case QEvent::MouseButtonRelease:
never executed: case QEvent::MouseButtonRelease:
0
693 if (PressDelayHandler::instance()->released(event, scrollerWasDragging || scrollerWasScrolling, scrollerIsActive))
PressDelayHand...ollerIsActive)Description
TRUEnever evaluated
FALSEnever evaluated
0
694 result |= ConsumeEventHint;
never executed: result |= ConsumeEventHint;
0
695 // fall through-
696 case QEvent::TouchEnd:
code before this statement never executed: case QEvent::TouchEnd:
never executed: case QEvent::TouchEnd:
0
697 result |= scrollerIsActive ? FinishGesture : CancelGesture;
scrollerIsActiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
698 break;
never executed: break;
0
699-
700 default:
never executed: default:
0
701 result |= Ignore;-
702 break;
never executed: break;
0
703 }-
704 }-
705 return result;
never executed: return result;
0
706}-
707-
708-
709/*! \reimp-
710 */-
711void QFlickGestureRecognizer::reset(QGesture *state)-
712{-
713 QGestureRecognizer::reset(state);-
714}
never executed: end of block
0
715-
716QT_END_NAMESPACE-
717-
718#include "moc_qflickgesture_p.cpp"-
719-
720#endif // QT_NO_GESTURES-
Source codeSwitch to Preprocessed file

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