summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qgesturemanager.cpp
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-10-28 12:06:03 (GMT)
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-10-28 12:49:30 (GMT)
commit3ce8fb5e754014ed29cabf9e33b71dabecb02e46 (patch)
tree321dddc236123d1b144517ff281284a1b91feabe /src/gui/kernel/qgesturemanager.cpp
parenta2b12363c96d4307444552eefc21eebf430dba5d (diff)
downloadQt-3ce8fb5e754014ed29cabf9e33b71dabecb02e46.zip
Qt-3ce8fb5e754014ed29cabf9e33b71dabecb02e46.tar.gz
Qt-3ce8fb5e754014ed29cabf9e33b71dabecb02e46.tar.bz2
Fixed the gesture event filtering through multiple gesture recognizers.
When there are several gesture recognizers registered for the same gesture type, we need to know which recognizer we need to get a state object for since those QGesture objects are tied to the recognizer that created them. Reviewed-by: Thomas Zander
Diffstat (limited to 'src/gui/kernel/qgesturemanager.cpp')
-rw-r--r--src/gui/kernel/qgesturemanager.cpp49
1 files changed, 26 insertions, 23 deletions
diff --git a/src/gui/kernel/qgesturemanager.cpp b/src/gui/kernel/qgesturemanager.cpp
index a90c299..04dcfe3 100644
--- a/src/gui/kernel/qgesturemanager.cpp
+++ b/src/gui/kernel/qgesturemanager.cpp
@@ -118,7 +118,7 @@ void QGestureManager::unregisterGestureRecognizer(Qt::GestureType type)
foreach (QGestureRecognizer *recognizer, list) {
QList<QGesture *> obsoleteGestures;
- QMap<ObjectGesture, QGesture *>::Iterator iter = m_objectGestures.begin();
+ QMap<ObjectGesture, QList<QGesture *> >::Iterator iter = m_objectGestures.begin();
while (iter != m_objectGestures.end()) {
ObjectGesture objectGesture = iter.key();
if (objectGesture.gesture == type)
@@ -131,11 +131,11 @@ void QGestureManager::unregisterGestureRecognizer(Qt::GestureType type)
void QGestureManager::cleanupCachedGestures(QObject *target, Qt::GestureType type)
{
- QMap<ObjectGesture, QGesture *>::Iterator iter = m_objectGestures.begin();
+ QMap<ObjectGesture, QList<QGesture *> >::Iterator iter = m_objectGestures.begin();
while (iter != m_objectGestures.end()) {
ObjectGesture objectGesture = iter.key();
if (objectGesture.gesture == type && target == objectGesture.object.data()) {
- delete iter.value();
+ qDeleteAll(iter.value());
iter = m_objectGestures.erase(iter);
} else {
++iter;
@@ -144,7 +144,7 @@ void QGestureManager::cleanupCachedGestures(QObject *target, Qt::GestureType typ
}
// get or create a QGesture object that will represent the state for a given object, used by the recognizer
-QGesture *QGestureManager::getState(QObject *object, Qt::GestureType type)
+QGesture *QGestureManager::getState(QObject *object, QGestureRecognizer *recognizer, Qt::GestureType type)
{
// if the widget is being deleted we should be carefull and not to
// create a new state, as it will create QWeakPointer which doesnt work
@@ -158,28 +158,31 @@ QGesture *QGestureManager::getState(QObject *object, Qt::GestureType type)
Q_ASSERT(qobject_cast<QGraphicsObject *>(object));
}
- QGesture *state =
+ QList<QGesture *> states =
m_objectGestures.value(QGestureManager::ObjectGesture(object, type));
- if (!state) {
- QGestureRecognizer *recognizer = m_recognizers.value(type);
- if (recognizer) {
- state = recognizer->createGesture(object);
- if (!state)
- return 0;
- state->setParent(this);
- if (state->gestureType() == Qt::CustomGesture) {
- // if the recognizer didn't fill in the gesture type, then this
- // is a custom gesture with autogenerated it and we fill it.
- state->d_func()->gestureType = type;
+ // check if the QGesture for this recognizer has already been created
+ foreach (QGesture *state, states) {
+ if (m_gestureToRecognizer.value(state) == recognizer)
+ return state;
+ }
+
+ Q_ASSERT(recognizer);
+ QGesture *state = recognizer->createGesture(object);
+ if (!state)
+ return 0;
+ state->setParent(this);
+ if (state->gestureType() == Qt::CustomGesture) {
+ // if the recognizer didn't fill in the gesture type, then this
+ // is a custom gesture with autogenerated id and we fill it.
+ state->d_func()->gestureType = type;
#if defined(GESTURE_DEBUG)
- state->setObjectName(QString::number((int)type));
+ state->setObjectName(QString::number((int)type));
#endif
- }
- m_objectGestures.insert(QGestureManager::ObjectGesture(object, type), state);
- m_gestureToRecognizer[state] = recognizer;
- m_gestureOwners[state] = object;
- }
}
+ m_objectGestures[QGestureManager::ObjectGesture(object, type)].append(state);
+ m_gestureToRecognizer[state] = recognizer;
+ m_gestureOwners[state] = object;
+
return state;
}
@@ -208,7 +211,7 @@ bool QGestureManager::filterEventThroughContexts(const QMap<QObject *,
for (; rit != re; ++rit) {
QGestureRecognizer *recognizer = rit.value();
QObject *target = cit.key();
- QGesture *state = getState(target, gestureType);
+ QGesture *state = getState(target, recognizer, gestureType);
if (!state)
continue;
QGestureRecognizer::Result result = recognizer->filterEvent(state, target, event);