diff options
Diffstat (limited to 'src/gui/graphicsview/qgraphicsscene.cpp')
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 9b7cf12..b7e2fda 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -710,6 +710,9 @@ void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item) cachedTargetItems.removeOne(dummy); cachedItemGestures.remove(dummy); cachedAlreadyDeliveredGestures.remove(dummy); + + foreach (Qt::GestureType gesture, item->d_ptr->gestureContext.keys()) + ungrabGesture(item, gesture); } /*! @@ -2595,6 +2598,9 @@ void QGraphicsScene::addItem(QGraphicsItem *item) d->enableTouchEventsOnViews(); } + foreach (Qt::GestureType gesture, item->d_ptr->gestureContext.keys()) + d->grabGesture(item, gesture); + // Update selection lists if (item->isSelected()) d->selectedItems << item; @@ -5609,6 +5615,8 @@ bool QGraphicsScene::sendEvent(QGraphicsItem *item, QEvent *event) void QGraphicsScenePrivate::addView(QGraphicsView *view) { views << view; + foreach (Qt::GestureType gesture, grabbedGestures.keys()) + view->viewport()->grabGesture(gesture); } void QGraphicsScenePrivate::removeView(QGraphicsView *view) @@ -6306,6 +6314,27 @@ void QGraphicsScenePrivate::cancelGesturesForChildren(QGesture *original) } } +void QGraphicsScenePrivate::grabGesture(QGraphicsItem *, Qt::GestureType gesture) +{ + (void)QGestureManager::instance(); // create a gesture manager + if (!grabbedGestures[gesture]++) { + foreach (QGraphicsView *view, views) + view->viewport()->grabGesture(gesture); + } +} + +void QGraphicsScenePrivate::ungrabGesture(QGraphicsItem *item, Qt::GestureType gesture) +{ + // we know this can only be an object + Q_ASSERT(item->d_ptr->isObject); + QGraphicsObject *obj = static_cast<QGraphicsObject *>(item); + QGestureManager::instance()->cleanupCachedGestures(obj, gesture); + if (!--grabbedGestures[gesture]) { + foreach (QGraphicsView *view, views) + view->viewport()->ungrabGesture(gesture); + } +} + QT_END_NAMESPACE #include "moc_qgraphicsscene.cpp" |