Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qgesturemanager.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 "private/qgesturemanager_p.h" | - | ||||||||||||
35 | #include "private/qstandardgestures_p.h" | - | ||||||||||||
36 | #include "private/qwidget_p.h" | - | ||||||||||||
37 | #include "private/qgesture_p.h" | - | ||||||||||||
38 | #include "private/qgraphicsitem_p.h" | - | ||||||||||||
39 | #include "private/qevent_p.h" | - | ||||||||||||
40 | #include "private/qapplication_p.h" | - | ||||||||||||
41 | #include "private/qwidgetwindow_p.h" | - | ||||||||||||
42 | #include "qgesture.h" | - | ||||||||||||
43 | #include "qevent.h" | - | ||||||||||||
44 | #include "qgraphicsitem.h" | - | ||||||||||||
45 | - | |||||||||||||
46 | #ifdef Q_OS_OSX | - | ||||||||||||
47 | #include "qmacgesturerecognizer_p.h" | - | ||||||||||||
48 | #endif | - | ||||||||||||
49 | #if defined(Q_DEAD_CODE_FROM_QT4_WIN) && !defined(QT_NO_NATIVE_GESTURES) | - | ||||||||||||
50 | #include "qwinnativepangesturerecognizer_win_p.h" | - | ||||||||||||
51 | #endif | - | ||||||||||||
52 | - | |||||||||||||
53 | #include "qdebug.h" | - | ||||||||||||
54 | #include <QtCore/QLoggingCategory> | - | ||||||||||||
55 | - | |||||||||||||
56 | #ifndef QT_NO_GESTURES | - | ||||||||||||
57 | - | |||||||||||||
58 | QT_BEGIN_NAMESPACE | - | ||||||||||||
59 | - | |||||||||||||
60 | Q_LOGGING_CATEGORY(lcGestureManager, "qt.widgets.gestures") never executed: return category; | 0 | ||||||||||||
61 | - | |||||||||||||
62 | #if !defined(Q_OS_OSX) | - | ||||||||||||
63 | static inline int panTouchPoints() | - | ||||||||||||
64 | { | - | ||||||||||||
65 | // Override by environment variable for testing. | - | ||||||||||||
66 | static const char panTouchPointVariable[] = "QT_PAN_TOUCHPOINTS"; | - | ||||||||||||
67 | if (qEnvironmentVariableIsSet(panTouchPointVariable)) {
| 0 | ||||||||||||
68 | bool ok; | - | ||||||||||||
69 | const int result = qEnvironmentVariableIntValue(panTouchPointVariable, &ok); | - | ||||||||||||
70 | if (ok && result >= 1)
| 0 | ||||||||||||
71 | return result; never executed: return result; | 0 | ||||||||||||
72 | qWarning() << "Ignoring invalid value of " << panTouchPointVariable; | - | ||||||||||||
73 | } never executed: end of block | 0 | ||||||||||||
74 | // Pan should use 1 finger on a touch screen and 2 fingers on touch pads etc. | - | ||||||||||||
75 | // where 1 finger movements are used for mouse event synthetization. For now, | - | ||||||||||||
76 | // default to 2 until all classes inheriting QScrollArea are fixed to handle it | - | ||||||||||||
77 | // correctly. | - | ||||||||||||
78 | return 2; never executed: return 2; | 0 | ||||||||||||
79 | } | - | ||||||||||||
80 | #endif | - | ||||||||||||
81 | - | |||||||||||||
82 | QGestureManager::QGestureManager(QObject *parent) | - | ||||||||||||
83 | : QObject(parent), state(NotGesture), m_lastCustomGestureId(Qt::CustomGesture) | - | ||||||||||||
84 | { | - | ||||||||||||
85 | qRegisterMetaType<Qt::GestureState>(); | - | ||||||||||||
86 | - | |||||||||||||
87 | #if defined(Q_OS_OSX) | - | ||||||||||||
88 | registerGestureRecognizer(new QMacSwipeGestureRecognizer); | - | ||||||||||||
89 | registerGestureRecognizer(new QMacPinchGestureRecognizer); | - | ||||||||||||
90 | registerGestureRecognizer(new QMacPanGestureRecognizer); | - | ||||||||||||
91 | #else | - | ||||||||||||
92 | registerGestureRecognizer(new QPanGestureRecognizer(panTouchPoints())); | - | ||||||||||||
93 | registerGestureRecognizer(new QPinchGestureRecognizer); | - | ||||||||||||
94 | registerGestureRecognizer(new QSwipeGestureRecognizer); | - | ||||||||||||
95 | registerGestureRecognizer(new QTapGestureRecognizer); | - | ||||||||||||
96 | #endif | - | ||||||||||||
97 | #if defined(Q_DEAD_CODE_FROM_QT4_WIN) | - | ||||||||||||
98 | #if !defined(QT_NO_NATIVE_GESTURES) | - | ||||||||||||
99 | if (QApplicationPrivate::HasTouchSupport) | - | ||||||||||||
100 | registerGestureRecognizer(new QWinNativePanGestureRecognizer); | - | ||||||||||||
101 | #endif | - | ||||||||||||
102 | #else | - | ||||||||||||
103 | registerGestureRecognizer(new QTapAndHoldGestureRecognizer); | - | ||||||||||||
104 | #endif | - | ||||||||||||
105 | } never executed: end of block | 0 | ||||||||||||
106 | - | |||||||||||||
107 | QGestureManager::~QGestureManager() | - | ||||||||||||
108 | { | - | ||||||||||||
109 | qDeleteAll(m_recognizers.values()); | - | ||||||||||||
110 | foreach (QGestureRecognizer *recognizer, m_obsoleteGestures.keys()) { | - | ||||||||||||
111 | qDeleteAll(m_obsoleteGestures.value(recognizer)); | - | ||||||||||||
112 | delete recognizer; | - | ||||||||||||
113 | } never executed: end of block | 0 | ||||||||||||
114 | m_obsoleteGestures.clear(); | - | ||||||||||||
115 | } never executed: end of block | 0 | ||||||||||||
116 | - | |||||||||||||
117 | Qt::GestureType QGestureManager::registerGestureRecognizer(QGestureRecognizer *recognizer) | - | ||||||||||||
118 | { | - | ||||||||||||
119 | QGesture *dummy = recognizer->create(0); | - | ||||||||||||
120 | if (!dummy) {
| 0 | ||||||||||||
121 | qWarning("QGestureManager::registerGestureRecognizer: " | - | ||||||||||||
122 | "the recognizer fails to create a gesture object, skipping registration."); | - | ||||||||||||
123 | return Qt::GestureType(0); never executed: return Qt::GestureType(0); | 0 | ||||||||||||
124 | } | - | ||||||||||||
125 | Qt::GestureType type = dummy->gestureType(); | - | ||||||||||||
126 | if (type == Qt::CustomGesture) {
| 0 | ||||||||||||
127 | // generate a new custom gesture id | - | ||||||||||||
128 | ++m_lastCustomGestureId; | - | ||||||||||||
129 | type = Qt::GestureType(m_lastCustomGestureId); | - | ||||||||||||
130 | } never executed: end of block | 0 | ||||||||||||
131 | m_recognizers.insertMulti(type, recognizer); | - | ||||||||||||
132 | delete dummy; | - | ||||||||||||
133 | return type; never executed: return type; | 0 | ||||||||||||
134 | } | - | ||||||||||||
135 | - | |||||||||||||
136 | void QGestureManager::unregisterGestureRecognizer(Qt::GestureType type) | - | ||||||||||||
137 | { | - | ||||||||||||
138 | QList<QGestureRecognizer *> list = m_recognizers.values(type); | - | ||||||||||||
139 | while (QGestureRecognizer *recognizer = m_recognizers.take(type)) {
| 0 | ||||||||||||
140 | if (!m_obsoleteGestures.contains(recognizer)) {
| 0 | ||||||||||||
141 | // inserting even an empty QSet will cause the recognizer to be deleted on destruction of the manager | - | ||||||||||||
142 | m_obsoleteGestures.insert(recognizer, QSet<QGesture *>()); | - | ||||||||||||
143 | } never executed: end of block | 0 | ||||||||||||
144 | } never executed: end of block | 0 | ||||||||||||
145 | foreach (QGesture *g, m_gestureToRecognizer.keys()) { | - | ||||||||||||
146 | QGestureRecognizer *recognizer = m_gestureToRecognizer.value(g); | - | ||||||||||||
147 | if (list.contains(recognizer)) {
| 0 | ||||||||||||
148 | m_deletedRecognizers.insert(g, recognizer); | - | ||||||||||||
149 | } never executed: end of block | 0 | ||||||||||||
150 | } never executed: end of block | 0 | ||||||||||||
151 | - | |||||||||||||
152 | QMap<ObjectGesture, QList<QGesture *> >::const_iterator iter = m_objectGestures.constBegin(); | - | ||||||||||||
153 | while (iter != m_objectGestures.constEnd()) {
| 0 | ||||||||||||
154 | ObjectGesture objectGesture = iter.key(); | - | ||||||||||||
155 | if (objectGesture.gesture == type) {
| 0 | ||||||||||||
156 | foreach (QGesture *g, iter.value()) { | - | ||||||||||||
157 | if (QGestureRecognizer *recognizer = m_gestureToRecognizer.value(g)) {
| 0 | ||||||||||||
158 | m_gestureToRecognizer.remove(g); | - | ||||||||||||
159 | m_obsoleteGestures[recognizer].insert(g); | - | ||||||||||||
160 | } never executed: end of block | 0 | ||||||||||||
161 | } never executed: end of block | 0 | ||||||||||||
162 | } never executed: end of block | 0 | ||||||||||||
163 | ++iter; | - | ||||||||||||
164 | } never executed: end of block | 0 | ||||||||||||
165 | } never executed: end of block | 0 | ||||||||||||
166 | - | |||||||||||||
167 | void QGestureManager::cleanupCachedGestures(QObject *target, Qt::GestureType type) | - | ||||||||||||
168 | { | - | ||||||||||||
169 | QMap<ObjectGesture, QList<QGesture *> >::Iterator iter = m_objectGestures.begin(); | - | ||||||||||||
170 | while (iter != m_objectGestures.end()) {
| 0 | ||||||||||||
171 | ObjectGesture objectGesture = iter.key(); | - | ||||||||||||
172 | if (objectGesture.gesture == type && target == objectGesture.object) {
| 0 | ||||||||||||
173 | QSet<QGesture *> gestures = iter.value().toSet(); | - | ||||||||||||
174 | for (QHash<QGestureRecognizer *, QSet<QGesture *> >::iterator | - | ||||||||||||
175 | it = m_obsoleteGestures.begin(), e = m_obsoleteGestures.end(); it != e; ++it) {
| 0 | ||||||||||||
176 | it.value() -= gestures; | - | ||||||||||||
177 | } never executed: end of block | 0 | ||||||||||||
178 | foreach (QGesture *g, gestures) { | - | ||||||||||||
179 | m_deletedRecognizers.remove(g); | - | ||||||||||||
180 | m_gestureToRecognizer.remove(g); | - | ||||||||||||
181 | m_maybeGestures.remove(g); | - | ||||||||||||
182 | m_activeGestures.remove(g); | - | ||||||||||||
183 | m_gestureOwners.remove(g); | - | ||||||||||||
184 | m_gestureTargets.remove(g); | - | ||||||||||||
185 | m_gesturesToDelete.insert(g); | - | ||||||||||||
186 | } never executed: end of block | 0 | ||||||||||||
187 | - | |||||||||||||
188 | iter = m_objectGestures.erase(iter); | - | ||||||||||||
189 | } else { never executed: end of block | 0 | ||||||||||||
190 | ++iter; | - | ||||||||||||
191 | } never executed: end of block | 0 | ||||||||||||
192 | } | - | ||||||||||||
193 | } never executed: end of block | 0 | ||||||||||||
194 | - | |||||||||||||
195 | // get or create a QGesture object that will represent the state for a given object, used by the recognizer | - | ||||||||||||
196 | QGesture *QGestureManager::getState(QObject *object, QGestureRecognizer *recognizer, Qt::GestureType type) | - | ||||||||||||
197 | { | - | ||||||||||||
198 | // if the widget is being deleted we should be careful not to | - | ||||||||||||
199 | // create a new state, as it will create QWeakPointer which doesn't work | - | ||||||||||||
200 | // from the destructor. | - | ||||||||||||
201 | if (object->isWidgetType()) {
| 0 | ||||||||||||
202 | if (static_cast<QWidget *>(object)->d_func()->data.in_destructor)
| 0 | ||||||||||||
203 | return 0; never executed: return 0; | 0 | ||||||||||||
204 | } else if (QGesture *g = qobject_cast<QGesture *>(object)) { never executed: end of block
| 0 | ||||||||||||
205 | return g; never executed: return g; | 0 | ||||||||||||
206 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||
207 | } else { | - | ||||||||||||
208 | Q_ASSERT(qobject_cast<QGraphicsObject *>(object)); | - | ||||||||||||
209 | QGraphicsObject *graphicsObject = static_cast<QGraphicsObject *>(object); | - | ||||||||||||
210 | if (graphicsObject->QGraphicsItem::d_func()->inDestructor)
| 0 | ||||||||||||
211 | return 0; never executed: return 0; | 0 | ||||||||||||
212 | #endif | - | ||||||||||||
213 | } never executed: end of block | 0 | ||||||||||||
214 | - | |||||||||||||
215 | // check if the QGesture for this recognizer has already been created | - | ||||||||||||
216 | foreach (QGesture *state, m_objectGestures.value(QGestureManager::ObjectGesture(object, type))) { | - | ||||||||||||
217 | if (m_gestureToRecognizer.value(state) == recognizer)
| 0 | ||||||||||||
218 | return state; never executed: return state; | 0 | ||||||||||||
219 | } never executed: end of block | 0 | ||||||||||||
220 | - | |||||||||||||
221 | Q_ASSERT(recognizer); | - | ||||||||||||
222 | QGesture *state = recognizer->create(object); | - | ||||||||||||
223 | if (!state)
| 0 | ||||||||||||
224 | return 0; never executed: return 0; | 0 | ||||||||||||
225 | state->setParent(this); | - | ||||||||||||
226 | if (state->gestureType() == Qt::CustomGesture) {
| 0 | ||||||||||||
227 | // if the recognizer didn't fill in the gesture type, then this | - | ||||||||||||
228 | // is a custom gesture with autogenerated id and we fill it. | - | ||||||||||||
229 | state->d_func()->gestureType = type; | - | ||||||||||||
230 | if (lcGestureManager().isDebugEnabled())
| 0 | ||||||||||||
231 | state->setObjectName(QString::number((int)type)); never executed: state->setObjectName(QString::number((int)type)); | 0 | ||||||||||||
232 | } never executed: end of block | 0 | ||||||||||||
233 | m_objectGestures[QGestureManager::ObjectGesture(object, type)].append(state); | - | ||||||||||||
234 | m_gestureToRecognizer[state] = recognizer; | - | ||||||||||||
235 | m_gestureOwners[state] = object; | - | ||||||||||||
236 | - | |||||||||||||
237 | return state; never executed: return state; | 0 | ||||||||||||
238 | } | - | ||||||||||||
239 | - | |||||||||||||
240 | bool QGestureManager::filterEventThroughContexts(const QMultiMap<QObject *, | - | ||||||||||||
241 | Qt::GestureType> &contexts, | - | ||||||||||||
242 | QEvent *event) | - | ||||||||||||
243 | { | - | ||||||||||||
244 | QSet<QGesture *> triggeredGestures; | - | ||||||||||||
245 | QSet<QGesture *> finishedGestures; | - | ||||||||||||
246 | QSet<QGesture *> newMaybeGestures; | - | ||||||||||||
247 | QSet<QGesture *> notGestures; | - | ||||||||||||
248 | - | |||||||||||||
249 | // TODO: sort contexts by the gesture type and check if one of the contexts | - | ||||||||||||
250 | // is already active. | - | ||||||||||||
251 | - | |||||||||||||
252 | bool consumeEventHint = false; | - | ||||||||||||
253 | - | |||||||||||||
254 | // filter the event through recognizers | - | ||||||||||||
255 | typedef QMultiMap<QObject *, Qt::GestureType>::const_iterator ContextIterator; | - | ||||||||||||
256 | ContextIterator contextEnd = contexts.end(); | - | ||||||||||||
257 | for (ContextIterator context = contexts.begin(); context != contextEnd; ++context) {
| 0 | ||||||||||||
258 | Qt::GestureType gestureType = context.value(); | - | ||||||||||||
259 | const QMap<Qt::GestureType, QGestureRecognizer *> &const_recognizers = m_recognizers; | - | ||||||||||||
260 | QMap<Qt::GestureType, QGestureRecognizer *>::const_iterator | - | ||||||||||||
261 | typeToRecognizerIterator = const_recognizers.lowerBound(gestureType), | - | ||||||||||||
262 | typeToRecognizerEnd = const_recognizers.upperBound(gestureType); | - | ||||||||||||
263 | for (; typeToRecognizerIterator != typeToRecognizerEnd; ++typeToRecognizerIterator) {
| 0 | ||||||||||||
264 | QGestureRecognizer *recognizer = typeToRecognizerIterator.value(); | - | ||||||||||||
265 | QObject *target = context.key(); | - | ||||||||||||
266 | QGesture *state = getState(target, recognizer, gestureType); | - | ||||||||||||
267 | if (!state)
| 0 | ||||||||||||
268 | continue; never executed: continue; | 0 | ||||||||||||
269 | QGestureRecognizer::Result recognizerResult = recognizer->recognize(state, target, event); | - | ||||||||||||
270 | QGestureRecognizer::Result recognizerState = recognizerResult & QGestureRecognizer::ResultState_Mask; | - | ||||||||||||
271 | QGestureRecognizer::Result resultHint = recognizerResult & QGestureRecognizer::ResultHint_Mask; | - | ||||||||||||
272 | if (recognizerState == QGestureRecognizer::TriggerGesture) {
| 0 | ||||||||||||
273 | qCDebug(lcGestureManager) << "QGestureManager:Recognizer: gesture triggered: " << state << event; never executed: QMessageLogger(__FILE__, 273, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager:Recognizer: gesture triggered: " << state << event;
| 0 | ||||||||||||
274 | triggeredGestures << state; | - | ||||||||||||
275 | } else if (recognizerState == QGestureRecognizer::FinishGesture) { never executed: end of block
| 0 | ||||||||||||
276 | qCDebug(lcGestureManager) << "QGestureManager:Recognizer: gesture finished: " << state << event; never executed: QMessageLogger(__FILE__, 276, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager:Recognizer: gesture finished: " << state << event;
| 0 | ||||||||||||
277 | finishedGestures << state; | - | ||||||||||||
278 | } else if (recognizerState == QGestureRecognizer::MayBeGesture) { never executed: end of block
| 0 | ||||||||||||
279 | qCDebug(lcGestureManager) << "QGestureManager:Recognizer: maybe gesture: " << state << event; never executed: QMessageLogger(__FILE__, 279, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager:Recognizer: maybe gesture: " << state << event;
| 0 | ||||||||||||
280 | newMaybeGestures << state; | - | ||||||||||||
281 | } else if (recognizerState == QGestureRecognizer::CancelGesture) { never executed: end of block
| 0 | ||||||||||||
282 | qCDebug(lcGestureManager) << "QGestureManager:Recognizer: not gesture: " << state << event; never executed: QMessageLogger(__FILE__, 282, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager:Recognizer: not gesture: " << state << event;
| 0 | ||||||||||||
283 | notGestures << state; | - | ||||||||||||
284 | } else if (recognizerState == QGestureRecognizer::Ignore) { never executed: end of block
| 0 | ||||||||||||
285 | qCDebug(lcGestureManager) << "QGestureManager:Recognizer: ignored the event: " << state << event; never executed: QMessageLogger(__FILE__, 285, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager:Recognizer: ignored the event: " << state << event;
| 0 | ||||||||||||
286 | } else { never executed: end of block | 0 | ||||||||||||
287 | qCDebug(lcGestureManager) << "QGestureManager:Recognizer: hm, lets assume the recognizer" never executed: QMessageLogger(__FILE__, 287, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager:Recognizer: hm, lets assume the recognizer" << "ignored the event: " << state << event;
| 0 | ||||||||||||
288 | << "ignored the event: " << state << event; never executed: QMessageLogger(__FILE__, 287, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager:Recognizer: hm, lets assume the recognizer" << "ignored the event: " << state << event; | 0 | ||||||||||||
289 | } never executed: end of block | 0 | ||||||||||||
290 | if (resultHint & QGestureRecognizer::ConsumeEventHint) {
| 0 | ||||||||||||
291 | qCDebug(lcGestureManager) << "QGestureManager: we were asked to consume the event: " never executed: QMessageLogger(__FILE__, 291, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager: we were asked to consume the event: " << state << event;
| 0 | ||||||||||||
292 | << state << event; never executed: QMessageLogger(__FILE__, 291, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager: we were asked to consume the event: " << state << event; | 0 | ||||||||||||
293 | consumeEventHint = true; | - | ||||||||||||
294 | } never executed: end of block | 0 | ||||||||||||
295 | } never executed: end of block | 0 | ||||||||||||
296 | } never executed: end of block | 0 | ||||||||||||
297 | if (!triggeredGestures.isEmpty() || !finishedGestures.isEmpty()
| 0 | ||||||||||||
298 | || !newMaybeGestures.isEmpty() || !notGestures.isEmpty()) {
| 0 | ||||||||||||
299 | QSet<QGesture *> startedGestures = triggeredGestures - m_activeGestures; | - | ||||||||||||
300 | triggeredGestures &= m_activeGestures; | - | ||||||||||||
301 | - | |||||||||||||
302 | // check if a running gesture switched back to maybe state | - | ||||||||||||
303 | QSet<QGesture *> activeToMaybeGestures = m_activeGestures & newMaybeGestures; | - | ||||||||||||
304 | - | |||||||||||||
305 | // check if a maybe gesture switched to canceled - reset it but don't send an event | - | ||||||||||||
306 | QSet<QGesture *> maybeToCanceledGestures = m_maybeGestures & notGestures; | - | ||||||||||||
307 | - | |||||||||||||
308 | // check if a running gesture switched back to not gesture state, | - | ||||||||||||
309 | // i.e. were canceled | - | ||||||||||||
310 | QSet<QGesture *> canceledGestures = m_activeGestures & notGestures; | - | ||||||||||||
311 | - | |||||||||||||
312 | // new gestures in maybe state | - | ||||||||||||
313 | m_maybeGestures += newMaybeGestures; | - | ||||||||||||
314 | - | |||||||||||||
315 | // gestures that were in maybe state | - | ||||||||||||
316 | QSet<QGesture *> notMaybeGestures = (startedGestures | triggeredGestures | - | ||||||||||||
317 | | finishedGestures | canceledGestures | - | ||||||||||||
318 | | notGestures); | - | ||||||||||||
319 | m_maybeGestures -= notMaybeGestures; | - | ||||||||||||
320 | - | |||||||||||||
321 | Q_ASSERT((startedGestures & finishedGestures).isEmpty()); | - | ||||||||||||
322 | Q_ASSERT((startedGestures & newMaybeGestures).isEmpty()); | - | ||||||||||||
323 | Q_ASSERT((startedGestures & canceledGestures).isEmpty()); | - | ||||||||||||
324 | Q_ASSERT((finishedGestures & newMaybeGestures).isEmpty()); | - | ||||||||||||
325 | Q_ASSERT((finishedGestures & canceledGestures).isEmpty()); | - | ||||||||||||
326 | Q_ASSERT((canceledGestures & newMaybeGestures).isEmpty()); | - | ||||||||||||
327 | - | |||||||||||||
328 | QSet<QGesture *> notStarted = finishedGestures - m_activeGestures; | - | ||||||||||||
329 | if (!notStarted.isEmpty()) {
| 0 | ||||||||||||
330 | // there are some gestures that claim to be finished, but never started. | - | ||||||||||||
331 | // probably those are "singleshot" gestures so we'll fake the started state. | - | ||||||||||||
332 | foreach (QGesture *gesture, notStarted) | - | ||||||||||||
333 | gesture->d_func()->state = Qt::GestureStarted; never executed: gesture->d_func()->state = Qt::GestureStarted; | 0 | ||||||||||||
334 | QSet<QGesture *> undeliveredGestures; | - | ||||||||||||
335 | deliverEvents(notStarted, &undeliveredGestures); | - | ||||||||||||
336 | finishedGestures -= undeliveredGestures; | - | ||||||||||||
337 | } never executed: end of block | 0 | ||||||||||||
338 | - | |||||||||||||
339 | m_activeGestures += startedGestures; | - | ||||||||||||
340 | // sanity check: all triggered gestures should already be in active gestures list | - | ||||||||||||
341 | Q_ASSERT((m_activeGestures & triggeredGestures).size() == triggeredGestures.size()); | - | ||||||||||||
342 | m_activeGestures -= finishedGestures; | - | ||||||||||||
343 | m_activeGestures -= activeToMaybeGestures; | - | ||||||||||||
344 | m_activeGestures -= canceledGestures; | - | ||||||||||||
345 | - | |||||||||||||
346 | // set the proper gesture state on each gesture | - | ||||||||||||
347 | foreach (QGesture *gesture, startedGestures) | - | ||||||||||||
348 | gesture->d_func()->state = Qt::GestureStarted; never executed: gesture->d_func()->state = Qt::GestureStarted; | 0 | ||||||||||||
349 | foreach (QGesture *gesture, triggeredGestures) | - | ||||||||||||
350 | gesture->d_func()->state = Qt::GestureUpdated; never executed: gesture->d_func()->state = Qt::GestureUpdated; | 0 | ||||||||||||
351 | foreach (QGesture *gesture, finishedGestures) | - | ||||||||||||
352 | gesture->d_func()->state = Qt::GestureFinished; never executed: gesture->d_func()->state = Qt::GestureFinished; | 0 | ||||||||||||
353 | foreach (QGesture *gesture, canceledGestures) | - | ||||||||||||
354 | gesture->d_func()->state = Qt::GestureCanceled; never executed: gesture->d_func()->state = Qt::GestureCanceled; | 0 | ||||||||||||
355 | foreach (QGesture *gesture, activeToMaybeGestures) | - | ||||||||||||
356 | gesture->d_func()->state = Qt::GestureFinished; never executed: gesture->d_func()->state = Qt::GestureFinished; | 0 | ||||||||||||
357 | - | |||||||||||||
358 | if (!m_activeGestures.isEmpty() || !m_maybeGestures.isEmpty() ||
| 0 | ||||||||||||
359 | !startedGestures.isEmpty() || !triggeredGestures.isEmpty() ||
| 0 | ||||||||||||
360 | !finishedGestures.isEmpty() || !canceledGestures.isEmpty()) {
| 0 | ||||||||||||
361 | qCDebug(lcGestureManager) << "QGestureManager::filterEventThroughContexts:" never executed: QMessageLogger(__FILE__, 361, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::filterEventThroughContexts:" << "\n\tactiveGestures:" << m_activeGestures << "\n\tmaybeGestures:" << m_maybeGestures << "\n\tstarted:" << startedGestures << "\n\ttriggered:" << triggeredGestures << "\n\tfinished:" << finishedGestures << "\n\tcanceled:" << canceledGestures << "\n\tmaybe-canceled:" << maybeToCanceledGestures;
| 0 | ||||||||||||
362 | << "\n\tactiveGestures:" << m_activeGestures never executed: QMessageLogger(__FILE__, 361, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::filterEventThroughContexts:" << "\n\tactiveGestures:" << m_activeGestures << "\n\tmaybeGestures:" << m_maybeGestures << "\n\tstarted:" << startedGestures << "\n\ttriggered:" << triggeredGestures << "\n\tfinished:" << finishedGestures << "\n\tcanceled:" << canceledGestures << "\n\tmaybe-canceled:" << maybeToCanceledGestures; | 0 | ||||||||||||
363 | << "\n\tmaybeGestures:" << m_maybeGestures never executed: QMessageLogger(__FILE__, 361, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::filterEventThroughContexts:" << "\n\tactiveGestures:" << m_activeGestures << "\n\tmaybeGestures:" << m_maybeGestures << "\n\tstarted:" << startedGestures << "\n\ttriggered:" << triggeredGestures << "\n\tfinished:" << finishedGestures << "\n\tcanceled:" << canceledGestures << "\n\tmaybe-canceled:" << maybeToCanceledGestures; | 0 | ||||||||||||
364 | << "\n\tstarted:" << startedGestures never executed: QMessageLogger(__FILE__, 361, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::filterEventThroughContexts:" << "\n\tactiveGestures:" << m_activeGestures << "\n\tmaybeGestures:" << m_maybeGestures << "\n\tstarted:" << startedGestures << "\n\ttriggered:" << triggeredGestures << "\n\tfinished:" << finishedGestures << "\n\tcanceled:" << canceledGestures << "\n\tmaybe-canceled:" << maybeToCanceledGestures; | 0 | ||||||||||||
365 | << "\n\ttriggered:" << triggeredGestures never executed: QMessageLogger(__FILE__, 361, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::filterEventThroughContexts:" << "\n\tactiveGestures:" << m_activeGestures << "\n\tmaybeGestures:" << m_maybeGestures << "\n\tstarted:" << startedGestures << "\n\ttriggered:" << triggeredGestures << "\n\tfinished:" << finishedGestures << "\n\tcanceled:" << canceledGestures << "\n\tmaybe-canceled:" << maybeToCanceledGestures; | 0 | ||||||||||||
366 | << "\n\tfinished:" << finishedGestures never executed: QMessageLogger(__FILE__, 361, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::filterEventThroughContexts:" << "\n\tactiveGestures:" << m_activeGestures << "\n\tmaybeGestures:" << m_maybeGestures << "\n\tstarted:" << startedGestures << "\n\ttriggered:" << triggeredGestures << "\n\tfinished:" << finishedGestures << "\n\tcanceled:" << canceledGestures << "\n\tmaybe-canceled:" << maybeToCanceledGestures; | 0 | ||||||||||||
367 | << "\n\tcanceled:" << canceledGestures never executed: QMessageLogger(__FILE__, 361, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::filterEventThroughContexts:" << "\n\tactiveGestures:" << m_activeGestures << "\n\tmaybeGestures:" << m_maybeGestures << "\n\tstarted:" << startedGestures << "\n\ttriggered:" << triggeredGestures << "\n\tfinished:" << finishedGestures << "\n\tcanceled:" << canceledGestures << "\n\tmaybe-canceled:" << maybeToCanceledGestures; | 0 | ||||||||||||
368 | << "\n\tmaybe-canceled:" << maybeToCanceledGestures; never executed: QMessageLogger(__FILE__, 361, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::filterEventThroughContexts:" << "\n\tactiveGestures:" << m_activeGestures << "\n\tmaybeGestures:" << m_maybeGestures << "\n\tstarted:" << startedGestures << "\n\ttriggered:" << triggeredGestures << "\n\tfinished:" << finishedGestures << "\n\tcanceled:" << canceledGestures << "\n\tmaybe-canceled:" << maybeToCanceledGestures; | 0 | ||||||||||||
369 | } never executed: end of block | 0 | ||||||||||||
370 | - | |||||||||||||
371 | QSet<QGesture *> undeliveredGestures; | - | ||||||||||||
372 | deliverEvents(startedGestures+triggeredGestures+finishedGestures+canceledGestures, | - | ||||||||||||
373 | &undeliveredGestures); | - | ||||||||||||
374 | - | |||||||||||||
375 | foreach (QGesture *g, startedGestures) { | - | ||||||||||||
376 | if (undeliveredGestures.contains(g))
| 0 | ||||||||||||
377 | continue; never executed: continue; | 0 | ||||||||||||
378 | if (g->gestureCancelPolicy() == QGesture::CancelAllInContext) {
| 0 | ||||||||||||
379 | qCDebug(lcGestureManager) << "lets try to cancel some"; never executed: QMessageLogger(__FILE__, 379, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "lets try to cancel some";
| 0 | ||||||||||||
380 | // find gestures in context in Qt::GestureStarted or Qt::GestureUpdated state and cancel them | - | ||||||||||||
381 | cancelGesturesForChildren(g); | - | ||||||||||||
382 | } never executed: end of block | 0 | ||||||||||||
383 | } never executed: end of block | 0 | ||||||||||||
384 | - | |||||||||||||
385 | m_activeGestures -= undeliveredGestures; | - | ||||||||||||
386 | - | |||||||||||||
387 | // reset gestures that ended | - | ||||||||||||
388 | QSet<QGesture *> endedGestures = | - | ||||||||||||
389 | finishedGestures + canceledGestures + undeliveredGestures + maybeToCanceledGestures; | - | ||||||||||||
390 | foreach (QGesture *gesture, endedGestures) { | - | ||||||||||||
391 | recycle(gesture); | - | ||||||||||||
392 | m_gestureTargets.remove(gesture); | - | ||||||||||||
393 | } never executed: end of block | 0 | ||||||||||||
394 | } never executed: end of block | 0 | ||||||||||||
395 | //Clean up the Gestures | - | ||||||||||||
396 | qDeleteAll(m_gesturesToDelete); | - | ||||||||||||
397 | m_gesturesToDelete.clear(); | - | ||||||||||||
398 | - | |||||||||||||
399 | return consumeEventHint; never executed: return consumeEventHint; | 0 | ||||||||||||
400 | } | - | ||||||||||||
401 | - | |||||||||||||
402 | // Cancel all gestures of children of the widget that original is associated with | - | ||||||||||||
403 | void QGestureManager::cancelGesturesForChildren(QGesture *original) | - | ||||||||||||
404 | { | - | ||||||||||||
405 | Q_ASSERT(original); | - | ||||||||||||
406 | QWidget *originatingWidget = m_gestureTargets.value(original); | - | ||||||||||||
407 | Q_ASSERT(originatingWidget); | - | ||||||||||||
408 | if (!originatingWidget)
| 0 | ||||||||||||
409 | return; never executed: return; | 0 | ||||||||||||
410 | - | |||||||||||||
411 | // iterate over all active gestures and all maybe gestures | - | ||||||||||||
412 | // for each find the owner | - | ||||||||||||
413 | // if the owner is part of our sub-hierarchy, cancel it. | - | ||||||||||||
414 | - | |||||||||||||
415 | QSet<QGesture*> cancelledGestures; | - | ||||||||||||
416 | QSet<QGesture*>::Iterator iter = m_activeGestures.begin(); | - | ||||||||||||
417 | while (iter != m_activeGestures.end()) {
| 0 | ||||||||||||
418 | QWidget *widget = m_gestureTargets.value(*iter); | - | ||||||||||||
419 | // note that we don't touch the gestures for our originatingWidget | - | ||||||||||||
420 | if (widget != originatingWidget && originatingWidget->isAncestorOf(widget)) {
| 0 | ||||||||||||
421 | qCDebug(lcGestureManager) << " found a gesture to cancel" << (*iter); never executed: QMessageLogger(__FILE__, 421, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << " found a gesture to cancel" << (*iter);
| 0 | ||||||||||||
422 | (*iter)->d_func()->state = Qt::GestureCanceled; | - | ||||||||||||
423 | cancelledGestures << *iter; | - | ||||||||||||
424 | iter = m_activeGestures.erase(iter); | - | ||||||||||||
425 | } else { never executed: end of block | 0 | ||||||||||||
426 | ++iter; | - | ||||||||||||
427 | } never executed: end of block | 0 | ||||||||||||
428 | } | - | ||||||||||||
429 | - | |||||||||||||
430 | // TODO handle 'maybe' gestures too | - | ||||||||||||
431 | - | |||||||||||||
432 | // sort them per target widget by cherry picking from almostCanceledGestures and delivering | - | ||||||||||||
433 | QSet<QGesture *> almostCanceledGestures = cancelledGestures; | - | ||||||||||||
434 | while (!almostCanceledGestures.isEmpty()) {
| 0 | ||||||||||||
435 | QWidget *target = 0; | - | ||||||||||||
436 | QSet<QGesture*> gestures; | - | ||||||||||||
437 | iter = almostCanceledGestures.begin(); | - | ||||||||||||
438 | // sort per target widget | - | ||||||||||||
439 | while (iter != almostCanceledGestures.end()) {
| 0 | ||||||||||||
440 | QWidget *widget = m_gestureTargets.value(*iter); | - | ||||||||||||
441 | if (target == 0)
| 0 | ||||||||||||
442 | target = widget; never executed: target = widget; | 0 | ||||||||||||
443 | if (target == widget) {
| 0 | ||||||||||||
444 | gestures << *iter; | - | ||||||||||||
445 | iter = almostCanceledGestures.erase(iter); | - | ||||||||||||
446 | } else { never executed: end of block | 0 | ||||||||||||
447 | ++iter; | - | ||||||||||||
448 | } never executed: end of block | 0 | ||||||||||||
449 | } | - | ||||||||||||
450 | Q_ASSERT(target); | - | ||||||||||||
451 | - | |||||||||||||
452 | QSet<QGesture*> undeliveredGestures; | - | ||||||||||||
453 | deliverEvents(gestures, &undeliveredGestures); | - | ||||||||||||
454 | } never executed: end of block | 0 | ||||||||||||
455 | - | |||||||||||||
456 | for (iter = cancelledGestures.begin(); iter != cancelledGestures.end(); ++iter)
| 0 | ||||||||||||
457 | recycle(*iter); never executed: recycle(*iter); | 0 | ||||||||||||
458 | } never executed: end of block | 0 | ||||||||||||
459 | - | |||||||||||||
460 | void QGestureManager::cleanupGesturesForRemovedRecognizer(QGesture *gesture) | - | ||||||||||||
461 | { | - | ||||||||||||
462 | QGestureRecognizer *recognizer = m_deletedRecognizers.value(gesture); | - | ||||||||||||
463 | if(!recognizer) //The Gesture is removed while in the even loop, so the recognizers for this gestures was removed
| 0 | ||||||||||||
464 | return; never executed: return; | 0 | ||||||||||||
465 | m_deletedRecognizers.remove(gesture); | - | ||||||||||||
466 | if (m_deletedRecognizers.keys(recognizer).isEmpty()) {
| 0 | ||||||||||||
467 | // no more active gestures, cleanup! | - | ||||||||||||
468 | qDeleteAll(m_obsoleteGestures.value(recognizer)); | - | ||||||||||||
469 | m_obsoleteGestures.remove(recognizer); | - | ||||||||||||
470 | delete recognizer; | - | ||||||||||||
471 | } never executed: end of block | 0 | ||||||||||||
472 | } never executed: end of block | 0 | ||||||||||||
473 | - | |||||||||||||
474 | // return true if accepted (consumed) | - | ||||||||||||
475 | bool QGestureManager::filterEvent(QWidget *receiver, QEvent *event) | - | ||||||||||||
476 | { | - | ||||||||||||
477 | QMap<Qt::GestureType, int> types; | - | ||||||||||||
478 | QMultiMap<QObject *, Qt::GestureType> contexts; | - | ||||||||||||
479 | QWidget *w = receiver; | - | ||||||||||||
480 | typedef QMap<Qt::GestureType, Qt::GestureFlags>::const_iterator ContextIterator; | - | ||||||||||||
481 | if (!w->d_func()->gestureContext.isEmpty()) {
| 0 | ||||||||||||
482 | for(ContextIterator it = w->d_func()->gestureContext.constBegin(), | - | ||||||||||||
483 | e = w->d_func()->gestureContext.constEnd(); it != e; ++it) {
| 0 | ||||||||||||
484 | types.insert(it.key(), 0); | - | ||||||||||||
485 | contexts.insertMulti(w, it.key()); | - | ||||||||||||
486 | } never executed: end of block | 0 | ||||||||||||
487 | } never executed: end of block | 0 | ||||||||||||
488 | // find all gesture contexts for the widget tree | - | ||||||||||||
489 | w = w->isWindow() ? 0 : w->parentWidget();
| 0 | ||||||||||||
490 | while (w)
| 0 | ||||||||||||
491 | { | - | ||||||||||||
492 | for (ContextIterator it = w->d_func()->gestureContext.constBegin(), | - | ||||||||||||
493 | e = w->d_func()->gestureContext.constEnd(); it != e; ++it) {
| 0 | ||||||||||||
494 | if (!(it.value() & Qt::DontStartGestureOnChildren)) {
| 0 | ||||||||||||
495 | if (!types.contains(it.key())) {
| 0 | ||||||||||||
496 | types.insert(it.key(), 0); | - | ||||||||||||
497 | contexts.insertMulti(w, it.key()); | - | ||||||||||||
498 | } never executed: end of block | 0 | ||||||||||||
499 | } never executed: end of block | 0 | ||||||||||||
500 | } never executed: end of block | 0 | ||||||||||||
501 | if (w->isWindow())
| 0 | ||||||||||||
502 | break; never executed: break; | 0 | ||||||||||||
503 | w = w->parentWidget(); | - | ||||||||||||
504 | } never executed: end of block | 0 | ||||||||||||
505 | return contexts.isEmpty() ? false : filterEventThroughContexts(contexts, event); never executed: return contexts.isEmpty() ? false : filterEventThroughContexts(contexts, event);
| 0 | ||||||||||||
506 | } | - | ||||||||||||
507 | - | |||||||||||||
508 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||
509 | bool QGestureManager::filterEvent(QGraphicsObject *receiver, QEvent *event) | - | ||||||||||||
510 | { | - | ||||||||||||
511 | QMap<Qt::GestureType, int> types; | - | ||||||||||||
512 | QMultiMap<QObject *, Qt::GestureType> contexts; | - | ||||||||||||
513 | QGraphicsObject *item = receiver; | - | ||||||||||||
514 | if (!item->QGraphicsItem::d_func()->gestureContext.isEmpty()) {
| 0 | ||||||||||||
515 | typedef QMap<Qt::GestureType, Qt::GestureFlags>::const_iterator ContextIterator; | - | ||||||||||||
516 | for(ContextIterator it = item->QGraphicsItem::d_func()->gestureContext.constBegin(), | - | ||||||||||||
517 | e = item->QGraphicsItem::d_func()->gestureContext.constEnd(); it != e; ++it) {
| 0 | ||||||||||||
518 | types.insert(it.key(), 0); | - | ||||||||||||
519 | contexts.insertMulti(item, it.key()); | - | ||||||||||||
520 | } never executed: end of block | 0 | ||||||||||||
521 | } never executed: end of block | 0 | ||||||||||||
522 | // find all gesture contexts for the graphics object tree | - | ||||||||||||
523 | item = item->parentObject(); | - | ||||||||||||
524 | while (item)
| 0 | ||||||||||||
525 | { | - | ||||||||||||
526 | typedef QMap<Qt::GestureType, Qt::GestureFlags>::const_iterator ContextIterator; | - | ||||||||||||
527 | for (ContextIterator it = item->QGraphicsItem::d_func()->gestureContext.constBegin(), | - | ||||||||||||
528 | e = item->QGraphicsItem::d_func()->gestureContext.constEnd(); it != e; ++it) {
| 0 | ||||||||||||
529 | if (!(it.value() & Qt::DontStartGestureOnChildren)) {
| 0 | ||||||||||||
530 | if (!types.contains(it.key())) {
| 0 | ||||||||||||
531 | types.insert(it.key(), 0); | - | ||||||||||||
532 | contexts.insertMulti(item, it.key()); | - | ||||||||||||
533 | } never executed: end of block | 0 | ||||||||||||
534 | } never executed: end of block | 0 | ||||||||||||
535 | } never executed: end of block | 0 | ||||||||||||
536 | item = item->parentObject(); | - | ||||||||||||
537 | } never executed: end of block | 0 | ||||||||||||
538 | return contexts.isEmpty() ? false : filterEventThroughContexts(contexts, event); never executed: return contexts.isEmpty() ? false : filterEventThroughContexts(contexts, event);
| 0 | ||||||||||||
539 | } | - | ||||||||||||
540 | #endif | - | ||||||||||||
541 | - | |||||||||||||
542 | bool QGestureManager::filterEvent(QObject *receiver, QEvent *event) | - | ||||||||||||
543 | { | - | ||||||||||||
544 | // if the receiver is actually a widget, we need to call the correct event | - | ||||||||||||
545 | // filter method. | - | ||||||||||||
546 | QWidgetWindow *widgetWindow = qobject_cast<QWidgetWindow *>(receiver); | - | ||||||||||||
547 | - | |||||||||||||
548 | if (widgetWindow && widgetWindow->widget())
| 0 | ||||||||||||
549 | return filterEvent(widgetWindow->widget(), event); never executed: return filterEvent(widgetWindow->widget(), event); | 0 | ||||||||||||
550 | - | |||||||||||||
551 | QGesture *state = qobject_cast<QGesture *>(receiver); | - | ||||||||||||
552 | if (!state || !m_gestureToRecognizer.contains(state))
| 0 | ||||||||||||
553 | return false; never executed: return false; | 0 | ||||||||||||
554 | QMultiMap<QObject *, Qt::GestureType> contexts; | - | ||||||||||||
555 | contexts.insert(state, state->gestureType()); | - | ||||||||||||
556 | return filterEventThroughContexts(contexts, event); never executed: return filterEventThroughContexts(contexts, event); | 0 | ||||||||||||
557 | } | - | ||||||||||||
558 | - | |||||||||||||
559 | void QGestureManager::getGestureTargets(const QSet<QGesture*> &gestures, | - | ||||||||||||
560 | QHash<QWidget *, QList<QGesture *> > *conflicts, | - | ||||||||||||
561 | QHash<QWidget *, QList<QGesture *> > *normal) | - | ||||||||||||
562 | { | - | ||||||||||||
563 | typedef QHash<Qt::GestureType, QHash<QWidget *, QGesture *> > GestureByTypes; | - | ||||||||||||
564 | GestureByTypes gestureByTypes; | - | ||||||||||||
565 | - | |||||||||||||
566 | // sort gestures by types | - | ||||||||||||
567 | foreach (QGesture *gesture, gestures) { | - | ||||||||||||
568 | QWidget *receiver = m_gestureTargets.value(gesture, 0); | - | ||||||||||||
569 | Q_ASSERT(receiver); | - | ||||||||||||
570 | if (receiver)
| 0 | ||||||||||||
571 | gestureByTypes[gesture->gestureType()].insert(receiver, gesture); never executed: gestureByTypes[gesture->gestureType()].insert(receiver, gesture); | 0 | ||||||||||||
572 | } never executed: end of block | 0 | ||||||||||||
573 | - | |||||||||||||
574 | // for each gesture type | - | ||||||||||||
575 | for (GestureByTypes::const_iterator git = gestureByTypes.cbegin(), gend = gestureByTypes.cend(); git != gend; ++git) {
| 0 | ||||||||||||
576 | const QHash<QWidget *, QGesture *> &gestures = git.value(); | - | ||||||||||||
577 | for (QHash<QWidget *, QGesture *>::const_iterator wit = gestures.cbegin(), wend = gestures.cend(); wit != wend; ++wit) {
| 0 | ||||||||||||
578 | QWidget *widget = wit.key(); | - | ||||||||||||
579 | QWidget *w = widget->parentWidget(); | - | ||||||||||||
580 | while (w) {
| 0 | ||||||||||||
581 | QMap<Qt::GestureType, Qt::GestureFlags>::const_iterator it | - | ||||||||||||
582 | = w->d_func()->gestureContext.constFind(git.key()); | - | ||||||||||||
583 | if (it != w->d_func()->gestureContext.constEnd()) {
| 0 | ||||||||||||
584 | // i.e. 'w' listens to gesture 'type' | - | ||||||||||||
585 | if (!(it.value() & Qt::DontStartGestureOnChildren) && w != widget) {
| 0 | ||||||||||||
586 | // conflicting gesture! | - | ||||||||||||
587 | (*conflicts)[widget].append(wit.value()); | - | ||||||||||||
588 | break; never executed: break; | 0 | ||||||||||||
589 | } | - | ||||||||||||
590 | } never executed: end of block | 0 | ||||||||||||
591 | if (w->isWindow()) {
| 0 | ||||||||||||
592 | w = 0; | - | ||||||||||||
593 | break; never executed: break; | 0 | ||||||||||||
594 | } | - | ||||||||||||
595 | w = w->parentWidget(); | - | ||||||||||||
596 | } never executed: end of block | 0 | ||||||||||||
597 | if (!w)
| 0 | ||||||||||||
598 | (*normal)[widget].append(wit.value()); never executed: (*normal)[widget].append(wit.value()); | 0 | ||||||||||||
599 | } never executed: end of block | 0 | ||||||||||||
600 | } never executed: end of block | 0 | ||||||||||||
601 | } never executed: end of block | 0 | ||||||||||||
602 | - | |||||||||||||
603 | void QGestureManager::deliverEvents(const QSet<QGesture *> &gestures, | - | ||||||||||||
604 | QSet<QGesture *> *undeliveredGestures) | - | ||||||||||||
605 | { | - | ||||||||||||
606 | if (gestures.isEmpty())
| 0 | ||||||||||||
607 | return; never executed: return; | 0 | ||||||||||||
608 | - | |||||||||||||
609 | typedef QHash<QWidget *, QList<QGesture *> > GesturesPerWidget; | - | ||||||||||||
610 | GesturesPerWidget conflictedGestures; | - | ||||||||||||
611 | GesturesPerWidget normalStartedGestures; | - | ||||||||||||
612 | - | |||||||||||||
613 | QSet<QGesture *> startedGestures; | - | ||||||||||||
614 | // first figure out the initial receivers of gestures | - | ||||||||||||
615 | for (QSet<QGesture *>::const_iterator it = gestures.begin(), | - | ||||||||||||
616 | e = gestures.end(); it != e; ++it) {
| 0 | ||||||||||||
617 | QGesture *gesture = *it; | - | ||||||||||||
618 | QWidget *target = m_gestureTargets.value(gesture, 0); | - | ||||||||||||
619 | if (!target) {
| 0 | ||||||||||||
620 | // the gesture has just started and doesn't have a target yet. | - | ||||||||||||
621 | Q_ASSERT(gesture->state() == Qt::GestureStarted); | - | ||||||||||||
622 | if (gesture->hasHotSpot()) {
| 0 | ||||||||||||
623 | // guess the target widget using the hotspot of the gesture | - | ||||||||||||
624 | QPoint pt = gesture->hotSpot().toPoint(); | - | ||||||||||||
625 | if (QWidget *topLevel = QApplication::topLevelAt(pt)) {
| 0 | ||||||||||||
626 | QWidget *child = topLevel->childAt(topLevel->mapFromGlobal(pt)); | - | ||||||||||||
627 | target = child ? child : topLevel;
| 0 | ||||||||||||
628 | } never executed: end of block | 0 | ||||||||||||
629 | } else { never executed: end of block | 0 | ||||||||||||
630 | // or use the context of the gesture | - | ||||||||||||
631 | QObject *context = m_gestureOwners.value(gesture, 0); | - | ||||||||||||
632 | if (context->isWidgetType())
| 0 | ||||||||||||
633 | target = static_cast<QWidget *>(context); never executed: target = static_cast<QWidget *>(context); | 0 | ||||||||||||
634 | } never executed: end of block | 0 | ||||||||||||
635 | if (target)
| 0 | ||||||||||||
636 | m_gestureTargets.insert(gesture, target); never executed: m_gestureTargets.insert(gesture, target); | 0 | ||||||||||||
637 | } never executed: end of block | 0 | ||||||||||||
638 | - | |||||||||||||
639 | Qt::GestureType gestureType = gesture->gestureType(); | - | ||||||||||||
640 | Q_ASSERT(gestureType != Qt::CustomGesture); | - | ||||||||||||
641 | Q_UNUSED(gestureType); | - | ||||||||||||
642 | - | |||||||||||||
643 | if (target) {
| 0 | ||||||||||||
644 | if (gesture->state() == Qt::GestureStarted) {
| 0 | ||||||||||||
645 | startedGestures.insert(gesture); | - | ||||||||||||
646 | } else { never executed: end of block | 0 | ||||||||||||
647 | normalStartedGestures[target].append(gesture); | - | ||||||||||||
648 | } never executed: end of block | 0 | ||||||||||||
649 | } else { | - | ||||||||||||
650 | qCDebug(lcGestureManager) << "QGestureManager::deliverEvent: could not find the target for gesture" never executed: QMessageLogger(__FILE__, 650, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::deliverEvent: could not find the target for gesture" << gesture->gestureType();
| 0 | ||||||||||||
651 | << gesture->gestureType(); never executed: QMessageLogger(__FILE__, 650, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::deliverEvent: could not find the target for gesture" << gesture->gestureType(); | 0 | ||||||||||||
652 | qWarning("QGestureManager::deliverEvent: could not find the target for gesture"); | - | ||||||||||||
653 | undeliveredGestures->insert(gesture); | - | ||||||||||||
654 | } never executed: end of block | 0 | ||||||||||||
655 | } | - | ||||||||||||
656 | - | |||||||||||||
657 | getGestureTargets(startedGestures, &conflictedGestures, &normalStartedGestures); | - | ||||||||||||
658 | qCDebug(lcGestureManager) << "QGestureManager::deliverEvents:" never executed: QMessageLogger(__FILE__, 658, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::deliverEvents:" << "\nstarted: " << startedGestures << "\nconflicted: " << conflictedGestures << "\nnormal: " << normalStartedGestures << "\n";
| 0 | ||||||||||||
659 | << "\nstarted: " << startedGestures never executed: QMessageLogger(__FILE__, 658, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::deliverEvents:" << "\nstarted: " << startedGestures << "\nconflicted: " << conflictedGestures << "\nnormal: " << normalStartedGestures << "\n"; | 0 | ||||||||||||
660 | << "\nconflicted: " << conflictedGestures never executed: QMessageLogger(__FILE__, 658, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::deliverEvents:" << "\nstarted: " << startedGestures << "\nconflicted: " << conflictedGestures << "\nnormal: " << normalStartedGestures << "\n"; | 0 | ||||||||||||
661 | << "\nnormal: " << normalStartedGestures never executed: QMessageLogger(__FILE__, 658, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::deliverEvents:" << "\nstarted: " << startedGestures << "\nconflicted: " << conflictedGestures << "\nnormal: " << normalStartedGestures << "\n"; | 0 | ||||||||||||
662 | << "\n"; never executed: QMessageLogger(__FILE__, 658, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::deliverEvents:" << "\nstarted: " << startedGestures << "\nconflicted: " << conflictedGestures << "\nnormal: " << normalStartedGestures << "\n"; | 0 | ||||||||||||
663 | - | |||||||||||||
664 | // if there are conflicting gestures, send the GestureOverride event | - | ||||||||||||
665 | for (GesturesPerWidget::const_iterator it = conflictedGestures.constBegin(), | - | ||||||||||||
666 | e = conflictedGestures.constEnd(); it != e; ++it) {
| 0 | ||||||||||||
667 | QWidget *receiver = it.key(); | - | ||||||||||||
668 | QList<QGesture *> gestures = it.value(); | - | ||||||||||||
669 | qCDebug(lcGestureManager) << "QGestureManager::deliverEvents: sending GestureOverride to" never executed: QMessageLogger(__FILE__, 669, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::deliverEvents: sending GestureOverride to" << receiver << "gestures:" << gestures;
| 0 | ||||||||||||
670 | << receiver never executed: QMessageLogger(__FILE__, 669, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::deliverEvents: sending GestureOverride to" << receiver << "gestures:" << gestures; | 0 | ||||||||||||
671 | << "gestures:" << gestures; never executed: QMessageLogger(__FILE__, 669, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::deliverEvents: sending GestureOverride to" << receiver << "gestures:" << gestures; | 0 | ||||||||||||
672 | QGestureEvent event(gestures); | - | ||||||||||||
673 | event.t = QEvent::GestureOverride; | - | ||||||||||||
674 | // mark event and individual gestures as ignored | - | ||||||||||||
675 | event.ignore(); | - | ||||||||||||
676 | foreach(QGesture *g, gestures) | - | ||||||||||||
677 | event.setAccepted(g, false); never executed: event.setAccepted(g, false); | 0 | ||||||||||||
678 | - | |||||||||||||
679 | QApplication::sendEvent(receiver, &event); | - | ||||||||||||
680 | bool eventAccepted = event.isAccepted(); | - | ||||||||||||
681 | foreach(QGesture *gesture, event.gestures()) { | - | ||||||||||||
682 | if (eventAccepted || event.isAccepted(gesture)) {
| 0 | ||||||||||||
683 | QWidget *w = event.m_targetWidgets.value(gesture->gestureType(), 0); | - | ||||||||||||
684 | Q_ASSERT(w); | - | ||||||||||||
685 | qCDebug(lcGestureManager) << "override event: gesture was accepted:" << gesture << w; never executed: QMessageLogger(__FILE__, 685, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "override event: gesture was accepted:" << gesture << w;
| 0 | ||||||||||||
686 | QList<QGesture *> &gestures = normalStartedGestures[w]; | - | ||||||||||||
687 | gestures.append(gesture); | - | ||||||||||||
688 | // override the target | - | ||||||||||||
689 | m_gestureTargets[gesture] = w; | - | ||||||||||||
690 | } else { never executed: end of block | 0 | ||||||||||||
691 | qCDebug(lcGestureManager) << "override event: gesture wasn't accepted. putting back:" << gesture; never executed: QMessageLogger(__FILE__, 691, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "override event: gesture wasn't accepted. putting back:" << gesture;
| 0 | ||||||||||||
692 | QList<QGesture *> &gestures = normalStartedGestures[receiver]; | - | ||||||||||||
693 | gestures.append(gesture); | - | ||||||||||||
694 | } never executed: end of block | 0 | ||||||||||||
695 | } | - | ||||||||||||
696 | } never executed: end of block | 0 | ||||||||||||
697 | - | |||||||||||||
698 | // delivering gestures that are not in conflicted state | - | ||||||||||||
699 | for (GesturesPerWidget::const_iterator it = normalStartedGestures.constBegin(), | - | ||||||||||||
700 | e = normalStartedGestures.constEnd(); it != e; ++it) {
| 0 | ||||||||||||
701 | if (!it.value().isEmpty()) {
| 0 | ||||||||||||
702 | qCDebug(lcGestureManager) << "QGestureManager::deliverEvents: sending to" << it.key() never executed: QMessageLogger(__FILE__, 702, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::deliverEvents: sending to" << it.key() << "gestures:" << it.value();
| 0 | ||||||||||||
703 | << "gestures:" << it.value(); never executed: QMessageLogger(__FILE__, 702, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "QGestureManager::deliverEvents: sending to" << it.key() << "gestures:" << it.value(); | 0 | ||||||||||||
704 | QGestureEvent event(it.value()); | - | ||||||||||||
705 | QApplication::sendEvent(it.key(), &event); | - | ||||||||||||
706 | bool eventAccepted = event.isAccepted(); | - | ||||||||||||
707 | foreach (QGesture *gesture, event.gestures()) { | - | ||||||||||||
708 | if (gesture->state() == Qt::GestureStarted &&
| 0 | ||||||||||||
709 | (eventAccepted || event.isAccepted(gesture))) {
| 0 | ||||||||||||
710 | QWidget *w = event.m_targetWidgets.value(gesture->gestureType(), 0); | - | ||||||||||||
711 | Q_ASSERT(w); | - | ||||||||||||
712 | qCDebug(lcGestureManager) << "started gesture was delivered and accepted by" << w; never executed: QMessageLogger(__FILE__, 712, __PRETTY_FUNCTION__, lcGestureManager().categoryName()).debug() << "started gesture was delivered and accepted by" << w;
| 0 | ||||||||||||
713 | m_gestureTargets[gesture] = w; | - | ||||||||||||
714 | } never executed: end of block | 0 | ||||||||||||
715 | } never executed: end of block | 0 | ||||||||||||
716 | } never executed: end of block | 0 | ||||||||||||
717 | } never executed: end of block | 0 | ||||||||||||
718 | } never executed: end of block | 0 | ||||||||||||
719 | - | |||||||||||||
720 | void QGestureManager::recycle(QGesture *gesture) | - | ||||||||||||
721 | { | - | ||||||||||||
722 | QGestureRecognizer *recognizer = m_gestureToRecognizer.value(gesture, 0); | - | ||||||||||||
723 | if (recognizer) {
| 0 | ||||||||||||
724 | gesture->setGestureCancelPolicy(QGesture::CancelNone); | - | ||||||||||||
725 | recognizer->reset(gesture); | - | ||||||||||||
726 | m_activeGestures.remove(gesture); | - | ||||||||||||
727 | } else { never executed: end of block | 0 | ||||||||||||
728 | cleanupGesturesForRemovedRecognizer(gesture); | - | ||||||||||||
729 | } never executed: end of block | 0 | ||||||||||||
730 | } | - | ||||||||||||
731 | - | |||||||||||||
732 | bool QGestureManager::gesturePending(QObject *o) | - | ||||||||||||
733 | { | - | ||||||||||||
734 | const QGestureManager *gm = QGestureManager::instance(); | - | ||||||||||||
735 | return gm && gm->m_gestureOwners.key(o); never executed: return gm && gm->m_gestureOwners.key(o);
| 0 | ||||||||||||
736 | } | - | ||||||||||||
737 | - | |||||||||||||
738 | QT_END_NAMESPACE | - | ||||||||||||
739 | - | |||||||||||||
740 | #endif // QT_NO_GESTURES | - | ||||||||||||
741 | - | |||||||||||||
742 | #include "moc_qgesturemanager_p.cpp" | - | ||||||||||||
Source code | Switch to Preprocessed file |