diff options
-rw-r--r-- | src/gui/kernel/qapplication.cpp | 4 | ||||
-rw-r--r-- | src/gui/kernel/qgesturemanager.cpp | 42 | ||||
-rw-r--r-- | src/gui/kernel/qgesturemanager_p.h | 9 |
3 files changed, 49 insertions, 6 deletions
diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index 202d450..e64dfd2 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -5642,7 +5642,9 @@ Qt::GestureType QApplication::registerGestureRecognizer(QGestureRecognizer *reco */ void QApplication::unregisterGestureRecognizer(Qt::GestureType type) { - QGestureManager::instance()->unregisterGestureRecognizer(type); + QApplicationPrivate *d = qApp->d_func(); + if (d->gestureManager) + d->gestureManager->unregisterGestureRecognizer(type); } QT_END_NAMESPACE diff --git a/src/gui/kernel/qgesturemanager.cpp b/src/gui/kernel/qgesturemanager.cpp index 0601457..dc76c3f 100644 --- a/src/gui/kernel/qgesturemanager.cpp +++ b/src/gui/kernel/qgesturemanager.cpp @@ -104,9 +104,29 @@ Qt::GestureType QGestureManager::registerGestureRecognizer(QGestureRecognizer *r return type; } -void QGestureManager::unregisterGestureRecognizer(Qt::GestureType) +void QGestureManager::unregisterGestureRecognizer(Qt::GestureType type) { + QList<QGestureRecognizer *> list = recognizers.values(type); + recognizers.remove(type); + foreach (QGesture* g, gestureToRecognizer.keys()) { + QGestureRecognizer *recognizer = gestureToRecognizer.value(g); + if (list.contains(recognizer)) { + m_deletedRecognizers.insert(g, recognizer); + gestureToRecognizer.remove(g); + } + } + foreach (QGestureRecognizer *recognizer, list) { + QList<QGesture *> obsoleteGestures; + QMap<ObjectGesture, QGesture *>::Iterator iter = objectGestures.begin(); + while (iter != objectGestures.end()) { + ObjectGesture objectGesture = iter.key(); + if (objectGesture.gesture == type) + obsoleteGestures << iter.value(); + ++iter; + } + m_obsoleteGestures.insert(recognizer, obsoleteGestures); + } } QGesture *QGestureManager::getState(QObject *object, Qt::GestureType type) @@ -290,14 +310,28 @@ bool QGestureManager::filterEventThroughContexts(const QMap<QObject *, QSet<QGesture *> endedGestures = finishedGestures + canceledGestures + undeliveredGestures; foreach (QGesture *gesture, endedGestures) { - if (QGestureRecognizer *recognizer = gestureToRecognizer.value(gesture, 0)) { + if (QGestureRecognizer *recognizer = gestureToRecognizer.value(gesture, 0)) recognizer->reset(gesture); - } + else + cleanupGesturesForRemovedRecognizer(gesture); gestureTargets.remove(gesture); } return false; } +void QGestureManager::cleanupGesturesForRemovedRecognizer(QGesture *gesture) +{ + QGestureRecognizer *recognizer = m_deletedRecognizers.value(gesture); + Q_ASSERT(recognizer); + m_deletedRecognizers.remove(gesture); + if (m_deletedRecognizers.keys(recognizer).isEmpty()) { + // no more active gestures, cleanup! + qDeleteAll(m_obsoleteGestures.value(recognizer)); + m_obsoleteGestures.remove(recognizer); + delete recognizer; + } +} + bool QGestureManager::filterEvent(QWidget *receiver, QEvent *event) { QSet<Qt::GestureType> types; @@ -534,6 +568,8 @@ void QGestureManager::timerEvent(QTimerEvent *event) QGestureRecognizer *recognizer = gestureToRecognizer.value(gesture, 0); if (recognizer) recognizer->reset(gesture); + else + cleanupGesturesForRemovedRecognizer(gesture); } else { ++it; } diff --git a/src/gui/kernel/qgesturemanager_p.h b/src/gui/kernel/qgesturemanager_p.h index f0e7225..eef45d2 100644 --- a/src/gui/kernel/qgesturemanager_p.h +++ b/src/gui/kernel/qgesturemanager_p.h @@ -104,7 +104,7 @@ private: Qt::GestureType gesture; ObjectGesture(QObject *o, const Qt::GestureType &g) : object(o), gesture(g) { } - inline bool operator<(const ObjectGesture& rhs) const + inline bool operator<(const ObjectGesture &rhs) const { if (object.data() < rhs.object.data()) return true; @@ -114,7 +114,8 @@ private: } }; - QMap<ObjectGesture, QGesture *> objectGestures; + // TODO rename all member vars to be m_ + QMap<ObjectGesture, QGesture *> objectGestures; // TODO rename widgetGestures QMap<QGesture *, QGestureRecognizer *> gestureToRecognizer; QHash<QGesture *, QObject *> gestureOwners; @@ -122,6 +123,10 @@ private: int lastCustomGestureId; + QHash<QGestureRecognizer *, QList<QGesture *> > m_obsoleteGestures; + QMap<QGesture *, QGestureRecognizer *> m_deletedRecognizers; + void cleanupGesturesForRemovedRecognizer(QGesture *gesture); + QGesture *getState(QObject *widget, Qt::GestureType gesture); void deliverEvents(const QSet<QGesture *> &gestures, QSet<QGesture *> *undeliveredGestures); |