summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview/qgraphicsscene.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2010-02-18 15:48:32 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2010-02-18 15:48:32 (GMT)
commit4baa9dfb5273d7b501dcb3f456983262c53cc8d1 (patch)
treeaf04bea96067fcb8c282067aea00703a25b52069 /src/gui/graphicsview/qgraphicsscene.cpp
parent9eacc56619ce471a9777f88c89f64ca95cd6ae63 (diff)
parentc18beac8163634b48bbf1e7280923e96f5ef0a51 (diff)
downloadQt-4baa9dfb5273d7b501dcb3f456983262c53cc8d1.zip
Qt-4baa9dfb5273d7b501dcb3f456983262c53cc8d1.tar.gz
Qt-4baa9dfb5273d7b501dcb3f456983262c53cc8d1.tar.bz2
Merge remote branch 'origin/master' into qt-master-from-4.6
Conflicts: src/corelib/codecs/qtextcodec.h tests/auto/gestures/tst_gestures.cpp
Diffstat (limited to 'src/gui/graphicsview/qgraphicsscene.cpp')
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp78
1 files changed, 72 insertions, 6 deletions
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index d1ec7a5..aaae88e 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -5953,6 +5953,9 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
typedef QHash<QGraphicsObject *, QList<QGesture *> > GesturesPerItem;
GesturesPerItem gesturesPerItem;
+ // gestures that are only supposed to propagate to parent items.
+ QSet<QGesture *> parentPropagatedGestures;
+
QSet<QGesture *> startedGestures;
foreach (QGesture *gesture, allGestures) {
QGraphicsObject *target = gestureTargets.value(gesture, 0);
@@ -5963,6 +5966,10 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
startedGestures.insert(gesture);
} else {
gesturesPerItem[target].append(gesture);
+ Qt::GestureFlags flags =
+ target->QGraphicsItem::d_func()->gestureContext.value(gesture->gestureType());
+ if (flags & Qt::IgnoredGesturesPropagateToParent)
+ parentPropagatedGestures.insert(gesture);
}
}
@@ -6052,6 +6059,10 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
Q_ASSERT(!gestureTargets.contains(g));
gestureTargets.insert(g, receiver);
gesturesPerItem[receiver].append(g);
+ Qt::GestureFlags flags =
+ receiver->QGraphicsItem::d_func()->gestureContext.value(g->gestureType());
+ if (flags & Qt::IgnoredGesturesPropagateToParent)
+ parentPropagatedGestures.insert(g);
}
it = ignoredConflictedGestures.begin();
e = ignoredConflictedGestures.end();
@@ -6061,13 +6072,17 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
Q_ASSERT(!gestureTargets.contains(g));
gestureTargets.insert(g, receiver);
gesturesPerItem[receiver].append(g);
+ Qt::GestureFlags flags =
+ receiver->QGraphicsItem::d_func()->gestureContext.value(g->gestureType());
+ if (flags & Qt::IgnoredGesturesPropagateToParent)
+ parentPropagatedGestures.insert(g);
}
DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
<< "Started gestures:" << normalGestures.keys()
<< "All gestures:" << gesturesPerItem.values();
- // deliver all events
+ // deliver all gesture events
QList<QGesture *> alreadyIgnoredGestures;
QHash<QGraphicsObject *, QSet<QGesture *> > itemIgnoredGestures;
QList<QGraphicsObject *> targetItems = gesturesPerItem.keys();
@@ -6087,9 +6102,26 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
foreach(QGesture *g, alreadyIgnoredGestures) {
QMap<Qt::GestureType, Qt::GestureFlags>::iterator contextit =
gid->gestureContext.find(g->gestureType());
- bool deliver = contextit != gid->gestureContext.end() &&
- (g->state() == Qt::GestureStarted ||
- (contextit.value() & Qt::ReceivePartialGestures));
+ bool deliver = false;
+ if (contextit != gid->gestureContext.end()) {
+ if (g->state() == Qt::GestureStarted) {
+ deliver = true;
+ } else {
+ const Qt::GestureFlags flags = contextit.value();
+ if (flags & Qt::ReceivePartialGestures) {
+ QGraphicsObject *originalTarget = gestureTargets.value(g);
+ Q_ASSERT(originalTarget);
+ QGraphicsItemPrivate *otd = originalTarget->QGraphicsItem::d_func();
+ const Qt::GestureFlags originalTargetFlags = otd->gestureContext.value(g->gestureType());
+ if (originalTargetFlags & Qt::IgnoredGesturesPropagateToParent) {
+ // only deliver to parents of the original target item
+ deliver = item->isAncestorOf(originalTarget);
+ } else {
+ deliver = true;
+ }
+ }
+ }
+ }
if (deliver)
gestures += g;
}
@@ -6117,18 +6149,52 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event)
<< "item has ignored the event, will propagate."
<< item << ignoredGestures;
itemIgnoredGestures[item] += ignoredGestures;
+ alreadyIgnoredGestures = ignoredGestures.toList();
+
+ // remove gestures that are supposed to be propagated to
+ // parent items only.
+ QSet<QGesture *> parentGestures;
+ for (QSet<QGesture *>::iterator it = ignoredGestures.begin();
+ it != ignoredGestures.end();) {
+ if (parentPropagatedGestures.contains(*it)) {
+ parentGestures.insert(*it);
+ it = ignoredGestures.erase(it);
+ } else {
+ ++it;
+ }
+ }
+
+ QSet<QGraphicsObject *> itemsSet = targetItems.toSet();
+
+ foreach(QGesture *g, parentGestures) {
+ // get the original target for the gesture
+ QGraphicsItem *item = gestureTargets.value(g, 0);
+ Q_ASSERT(item);
+ const Qt::GestureType gestureType = g->gestureType();
+ // iterate through parent items of the original gesture
+ // target item and collect potential receivers
+ do {
+ if (QGraphicsObject *obj = item->toGraphicsObject()) {
+ if (item->d_func()->gestureContext.contains(gestureType))
+ itemsSet.insert(obj);
+ }
+ if (item->isPanel())
+ break;
+ } while ((item = item->parentItem()));
+ }
+
QMap<Qt::GestureType, QGesture *> conflictedGestures;
QList<QList<QGraphicsObject *> > itemsForConflictedGestures;
QHash<QGesture *, QGraphicsObject *> normalGestures;
getGestureTargets(ignoredGestures, viewport,
&conflictedGestures, &itemsForConflictedGestures,
&normalGestures);
- QSet<QGraphicsObject *> itemsSet = targetItems.toSet();
for (int k = 0; k < itemsForConflictedGestures.size(); ++k)
itemsSet += itemsForConflictedGestures.at(k).toSet();
+
targetItems = itemsSet.toList();
+
qSort(targetItems.begin(), targetItems.end(), qt_closestItemFirst);
- alreadyIgnoredGestures = conflictedGestures.values();
DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:"
<< "new targets:" << targetItems;
i = -1; // start delivery again