From b35d2d4717f71b4e519d33160dfce8b23607f9c8 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Thu, 18 Feb 2010 11:21:48 +0100 Subject: Cache scene coordinates of a hotspot in a QGesture. Reviewed-by: trustme --- src/gui/graphicsview/qgraphicsscene.cpp | 27 ++++++++++++++++++--------- src/gui/graphicsview/qgraphicsscene_p.h | 4 ++-- src/gui/kernel/qgesture_p.h | 2 +- src/gui/kernel/qgesturerecognizer.cpp | 1 + 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index aaae88e..34543e3 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -5901,7 +5901,6 @@ void QGraphicsScenePrivate::leaveModal(QGraphicsItem *panel) } void QGraphicsScenePrivate::getGestureTargets(const QSet &gestures, - QWidget *viewport, QMap *conflictedGestures, QList > *conflictedItems, QHash *normalGestures) @@ -5909,8 +5908,7 @@ void QGraphicsScenePrivate::getGestureTargets(const QSet &gestures, foreach (QGesture *gesture, gestures) { Qt::GestureType gestureType = gesture->gestureType(); if (gesture->hasHotSpot()) { - QPoint screenPos = gesture->hotSpot().toPoint(); - QList items = itemsAtPosition(screenPos, QPointF(), viewport); + QList items = itemsAtPosition(QPoint(), gesture->d_func()->sceneHotSpot, 0); QList result; for (int j = 0; j < items.size(); ++j) { QGraphicsItem *item = items.at(j); @@ -5946,6 +5944,10 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) QWidget *viewport = event->widget(); if (!viewport) return; + QGraphicsView *graphicsView = qobject_cast(viewport->parent()); + if (!graphicsView) + return; + QList allGestures = event->gestures(); DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" << "Delivering gestures:" << allGestures; @@ -5958,6 +5960,14 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) QSet startedGestures; foreach (QGesture *gesture, allGestures) { + // cache scene coordinates of the hot spot + if (gesture->hasHotSpot()) { + gesture->d_func()->sceneHotSpot = graphicsView->mapToScene( + graphicsView->mapFromGlobal(gesture->hotSpot().toPoint())); + } else { + gesture->d_func()->sceneHotSpot = QPointF(); + } + QGraphicsObject *target = gestureTargets.value(gesture, 0); if (!target) { // when we are not in started mode but don't have a target @@ -5976,7 +5986,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) QMap conflictedGestures; QList > conflictedItems; QHash normalGestures; - getGestureTargets(startedGestures, viewport, &conflictedGestures, &conflictedItems, + getGestureTargets(startedGestures, &conflictedGestures, &conflictedItems, &normalGestures); DEBUG() << "QGraphicsScenePrivate::gestureEventHandler:" << "Conflicting gestures:" << conflictedGestures.values() << conflictedItems; @@ -6186,7 +6196,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) QMap conflictedGestures; QList > itemsForConflictedGestures; QHash normalGestures; - getGestureTargets(ignoredGestures, viewport, + getGestureTargets(ignoredGestures, &conflictedGestures, &itemsForConflictedGestures, &normalGestures); for (int k = 0; k < itemsForConflictedGestures.size(); ++k) @@ -6205,7 +6215,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) if (g->gestureCancelPolicy() == QGesture::CancelAllInContext) { DEBUG() << "lets try to cancel some"; // find gestures in context in Qt::GestureStarted or Qt::GestureUpdated state and cancel them - cancelGesturesForChildren(g, event->widget()); + cancelGesturesForChildren(g); } } @@ -6222,7 +6232,7 @@ void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) } } -void QGraphicsScenePrivate::cancelGesturesForChildren(QGesture *original, QWidget *viewport) +void QGraphicsScenePrivate::cancelGesturesForChildren(QGesture *original) { Q_ASSERT(original); QGraphicsItem *originalItem = gestureTargets.value(original); @@ -6278,8 +6288,7 @@ void QGraphicsScenePrivate::cancelGesturesForChildren(QGesture *original, QWidge if (!g->hasHotSpot()) continue; - QPoint screenPos = g->hotSpot().toPoint(); - QList items = itemsAtPosition(screenPos, QPointF(), viewport); + QList items = itemsAtPosition(QPoint(), g->d_func()->sceneHotSpot, 0); for (int j = 0; j < items.size(); ++j) { QGraphicsObject *item = items.at(j)->toGraphicsObject(); if (!item) diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h index 04ffe0f..2e19a89 100644 --- a/src/gui/graphicsview/qgraphicsscene_p.h +++ b/src/gui/graphicsview/qgraphicsscene_p.h @@ -296,11 +296,11 @@ public: QHash gestureTargets; void gestureEventHandler(QGestureEvent *event); - void getGestureTargets(const QSet &gestures, QWidget *viewport, + void getGestureTargets(const QSet &gestures, QMap *conflictedGestures, QList > *conflictedItems, QHash *normalGestures); - void cancelGesturesForChildren(QGesture *original, QWidget *viewport); + void cancelGesturesForChildren(QGesture *original); void updateInputMethodSensitivityInViews(); diff --git a/src/gui/kernel/qgesture_p.h b/src/gui/kernel/qgesture_p.h index dee5592..649a310 100644 --- a/src/gui/kernel/qgesture_p.h +++ b/src/gui/kernel/qgesture_p.h @@ -69,13 +69,13 @@ public: QGesturePrivate() : gestureType(Qt::CustomGesture), state(Qt::NoGesture), isHotSpotSet(false), gestureCancelPolicy(0) - { } Qt::GestureType gestureType; Qt::GestureState state; QPointF hotSpot; + QPointF sceneHotSpot; uint isHotSpotSet : 1; uint gestureCancelPolicy : 2; }; diff --git a/src/gui/kernel/qgesturerecognizer.cpp b/src/gui/kernel/qgesturerecognizer.cpp index 8735d27..c88a9a7 100644 --- a/src/gui/kernel/qgesturerecognizer.cpp +++ b/src/gui/kernel/qgesturerecognizer.cpp @@ -181,6 +181,7 @@ void QGestureRecognizer::reset(QGesture *gesture) QGesturePrivate *d = gesture->d_func(); d->state = Qt::NoGesture; d->hotSpot = QPointF(); + d->sceneHotSpot = QPointF(); d->isHotSpotSet = false; } } -- cgit v0.12