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