130 m_recognizers.remove(type); |
130 m_recognizers.remove(type); |
131 foreach (QGesture *g, m_gestureToRecognizer.keys()) { |
131 foreach (QGesture *g, m_gestureToRecognizer.keys()) { |
132 QGestureRecognizer *recognizer = m_gestureToRecognizer.value(g); |
132 QGestureRecognizer *recognizer = m_gestureToRecognizer.value(g); |
133 if (list.contains(recognizer)) { |
133 if (list.contains(recognizer)) { |
134 m_deletedRecognizers.insert(g, recognizer); |
134 m_deletedRecognizers.insert(g, recognizer); |
135 m_gestureToRecognizer.remove(g); |
135 } |
136 } |
136 } |
137 } |
137 |
138 |
138 QMap<ObjectGesture, QList<QGesture *> >::const_iterator iter = m_objectGestures.begin(); |
139 foreach (QGestureRecognizer *recognizer, list) { |
139 while (iter != m_objectGestures.end()) { |
140 QList<QGesture *> obsoleteGestures; |
140 ObjectGesture objectGesture = iter.key(); |
141 QMap<ObjectGesture, QList<QGesture *> >::Iterator iter = m_objectGestures.begin(); |
141 if (objectGesture.gesture == type) { |
142 while (iter != m_objectGestures.end()) { |
142 foreach (QGesture *g, iter.value()) { |
143 ObjectGesture objectGesture = iter.key(); |
143 if (QGestureRecognizer *recognizer = m_gestureToRecognizer.value(g)) { |
144 if (objectGesture.gesture == type) |
144 m_gestureToRecognizer.remove(g); |
145 obsoleteGestures << iter.value(); |
145 m_obsoleteGestures[recognizer].insert(g); |
146 ++iter; |
146 } |
147 } |
147 } |
148 m_obsoleteGestures.insert(recognizer, obsoleteGestures); |
148 } |
|
149 ++iter; |
149 } |
150 } |
150 } |
151 } |
151 |
152 |
152 void QGestureManager::cleanupCachedGestures(QObject *target, Qt::GestureType type) |
153 void QGestureManager::cleanupCachedGestures(QObject *target, Qt::GestureType type) |
153 { |
154 { |
154 QMap<ObjectGesture, QList<QGesture *> >::Iterator iter = m_objectGestures.begin(); |
155 QMap<ObjectGesture, QList<QGesture *> >::Iterator iter = m_objectGestures.begin(); |
155 while (iter != m_objectGestures.end()) { |
156 while (iter != m_objectGestures.end()) { |
156 ObjectGesture objectGesture = iter.key(); |
157 ObjectGesture objectGesture = iter.key(); |
157 if (objectGesture.gesture == type && target == objectGesture.object.data()) { |
158 if (objectGesture.gesture == type && target == objectGesture.object.data()) { |
158 qDeleteAll(iter.value()); |
159 QSet<QGesture *> gestures = iter.value().toSet(); |
|
160 for (QHash<QGestureRecognizer *, QSet<QGesture *> >::iterator |
|
161 it = m_obsoleteGestures.begin(), e = m_obsoleteGestures.end(); it != e; ++it) { |
|
162 it.value() -= gestures; |
|
163 } |
|
164 foreach (QGesture *g, gestures) { |
|
165 m_deletedRecognizers.remove(g); |
|
166 m_gestureToRecognizer.remove(g); |
|
167 } |
|
168 qDeleteAll(gestures); |
159 iter = m_objectGestures.erase(iter); |
169 iter = m_objectGestures.erase(iter); |
160 } else { |
170 } else { |
161 ++iter; |
171 ++iter; |
162 } |
172 } |
163 } |
173 } |
175 } else if (QGesture *g = qobject_cast<QGesture *>(object)) { |
185 } else if (QGesture *g = qobject_cast<QGesture *>(object)) { |
176 return g; |
186 return g; |
177 #ifndef QT_NO_GRAPHICSVIEW |
187 #ifndef QT_NO_GRAPHICSVIEW |
178 } else { |
188 } else { |
179 Q_ASSERT(qobject_cast<QGraphicsObject *>(object)); |
189 Q_ASSERT(qobject_cast<QGraphicsObject *>(object)); |
|
190 QGraphicsObject *graphicsObject = static_cast<QGraphicsObject *>(object); |
|
191 if (graphicsObject->QGraphicsItem::d_func()->inDestructor) |
|
192 return 0; |
180 #endif |
193 #endif |
181 } |
194 } |
182 |
195 |
183 // check if the QGesture for this recognizer has already been created |
196 // check if the QGesture for this recognizer has already been created |
184 foreach (QGesture *state, m_objectGestures.value(QGestureManager::ObjectGesture(object, type))) { |
197 foreach (QGesture *state, m_objectGestures.value(QGestureManager::ObjectGesture(object, type))) { |
273 |
286 |
274 // check if a running gesture switched back to not gesture state, |
287 // check if a running gesture switched back to not gesture state, |
275 // i.e. were canceled |
288 // i.e. were canceled |
276 QSet<QGesture *> canceledGestures = m_activeGestures & notGestures; |
289 QSet<QGesture *> canceledGestures = m_activeGestures & notGestures; |
277 |
290 |
278 // start timers for new gestures in maybe state |
291 // new gestures in maybe state |
279 foreach (QGesture *state, newMaybeGestures) { |
292 m_maybeGestures += newMaybeGestures; |
280 QBasicTimer &timer = m_maybeGestures[state]; |
293 |
281 if (!timer.isActive()) |
294 // gestures that were in maybe state |
282 timer.start(3000, this); |
|
283 } |
|
284 // kill timers for gestures that were in maybe state |
|
285 QSet<QGesture *> notMaybeGestures = (startedGestures | triggeredGestures |
295 QSet<QGesture *> notMaybeGestures = (startedGestures | triggeredGestures |
286 | finishedGestures | canceledGestures |
296 | finishedGestures | canceledGestures |
287 | notGestures); |
297 | notGestures); |
288 foreach(QGesture *gesture, notMaybeGestures) { |
298 m_maybeGestures -= notMaybeGestures; |
289 QHash<QGesture *, QBasicTimer>::iterator it = |
|
290 m_maybeGestures.find(gesture); |
|
291 if (it != m_maybeGestures.end()) { |
|
292 it.value().stop(); |
|
293 m_maybeGestures.erase(it); |
|
294 } |
|
295 } |
|
296 |
299 |
297 Q_ASSERT((startedGestures & finishedGestures).isEmpty()); |
300 Q_ASSERT((startedGestures & finishedGestures).isEmpty()); |
298 Q_ASSERT((startedGestures & newMaybeGestures).isEmpty()); |
301 Q_ASSERT((startedGestures & newMaybeGestures).isEmpty()); |
299 Q_ASSERT((startedGestures & canceledGestures).isEmpty()); |
302 Q_ASSERT((startedGestures & canceledGestures).isEmpty()); |
300 Q_ASSERT((finishedGestures & newMaybeGestures).isEmpty()); |
303 Q_ASSERT((finishedGestures & newMaybeGestures).isEmpty()); |
334 if (!m_activeGestures.isEmpty() || !m_maybeGestures.isEmpty() || |
337 if (!m_activeGestures.isEmpty() || !m_maybeGestures.isEmpty() || |
335 !startedGestures.isEmpty() || !triggeredGestures.isEmpty() || |
338 !startedGestures.isEmpty() || !triggeredGestures.isEmpty() || |
336 !finishedGestures.isEmpty() || !canceledGestures.isEmpty()) { |
339 !finishedGestures.isEmpty() || !canceledGestures.isEmpty()) { |
337 DEBUG() << "QGestureManager::filterEventThroughContexts:" |
340 DEBUG() << "QGestureManager::filterEventThroughContexts:" |
338 << "\n\tactiveGestures:" << m_activeGestures |
341 << "\n\tactiveGestures:" << m_activeGestures |
339 << "\n\tmaybeGestures:" << m_maybeGestures.keys() |
342 << "\n\tmaybeGestures:" << m_maybeGestures |
340 << "\n\tstarted:" << startedGestures |
343 << "\n\tstarted:" << startedGestures |
341 << "\n\ttriggered:" << triggeredGestures |
344 << "\n\ttriggered:" << triggeredGestures |
342 << "\n\tfinished:" << finishedGestures |
345 << "\n\tfinished:" << finishedGestures |
343 << "\n\tcanceled:" << canceledGestures; |
346 << "\n\tcanceled:" << canceledGestures; |
344 } |
347 } |
673 } |
676 } |
674 } |
677 } |
675 } |
678 } |
676 } |
679 } |
677 |
680 |
678 void QGestureManager::timerEvent(QTimerEvent *event) |
|
679 { |
|
680 QHash<QGesture *, QBasicTimer>::iterator it = m_maybeGestures.begin(), |
|
681 e = m_maybeGestures.end(); |
|
682 for (; it != e; ) { |
|
683 QBasicTimer &timer = it.value(); |
|
684 Q_ASSERT(timer.isActive()); |
|
685 if (timer.timerId() == event->timerId()) { |
|
686 timer.stop(); |
|
687 QGesture *gesture = it.key(); |
|
688 it = m_maybeGestures.erase(it); |
|
689 DEBUG() << "QGestureManager::timerEvent: gesture stopped due to timeout:" |
|
690 << gesture; |
|
691 recycle(gesture); |
|
692 } else { |
|
693 ++it; |
|
694 } |
|
695 } |
|
696 } |
|
697 |
|
698 void QGestureManager::recycle(QGesture *gesture) |
681 void QGestureManager::recycle(QGesture *gesture) |
699 { |
682 { |
700 QGestureRecognizer *recognizer = m_gestureToRecognizer.value(gesture, 0); |
683 QGestureRecognizer *recognizer = m_gestureToRecognizer.value(gesture, 0); |
701 if (recognizer) { |
684 if (recognizer) { |
702 gesture->setGestureCancelPolicy(QGesture::CancelNone); |
685 gesture->setGestureCancelPolicy(QGesture::CancelNone); |