diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-10-13 08:11:54 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-10-22 14:59:18 (GMT) |
commit | d1a60dcbddbae46aaea655bb55c0c8fd46f38b2c (patch) | |
tree | 7da27d0d94a66a7806acffc57211c8d8556b5e5f /src/gui/graphicsview | |
parent | 1b154ddf00473700d697411304804ac065ef32ac (diff) | |
download | Qt-d1a60dcbddbae46aaea655bb55c0c8fd46f38b2c.zip Qt-d1a60dcbddbae46aaea655bb55c0c8fd46f38b2c.tar.gz Qt-d1a60dcbddbae46aaea655bb55c0c8fd46f38b2c.tar.bz2 |
Improved gesture event filtering inside QGraphicsView for QGraphicObjects
Reviewed-by: trustme
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.h | 2 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene.cpp | 40 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene_p.h | 2 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsview.cpp | 13 |
4 files changed, 55 insertions, 2 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h index 2665235..54a7a64 100644 --- a/src/gui/graphicsview/qgraphicsitem.h +++ b/src/gui/graphicsview/qgraphicsitem.h @@ -555,7 +555,7 @@ public: using QObject::children; #endif - void grabGesture(Qt::GestureType type, Qt::GestureContext context = Qt::WidgetWithChildrenGesture); + void grabGesture(Qt::GestureType type, Qt::GestureContext context = Qt::ItemWithChildrenGesture); Q_SIGNALS: void parentChanged(); diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index a624b10..373ee89 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -242,7 +242,6 @@ #include <QtGui/qstyleoption.h> #include <QtGui/qtooltip.h> #include <QtGui/qtransform.h> -#include <QtGui/qgesture.h> #include <QtGui/qinputcontext.h> #include <QtGui/qgraphicseffect.h> #include <private/qapplication_p.h> @@ -251,6 +250,7 @@ #include <private/qt_x11_p.h> #endif #include <private/qgraphicseffect_p.h> +#include <private/qgesturemanager_p.h> QT_BEGIN_NAMESPACE @@ -1052,6 +1052,14 @@ bool QGraphicsScenePrivate::filterEvent(QGraphicsItem *item, QEvent *event) */ bool QGraphicsScenePrivate::sendEvent(QGraphicsItem *item, QEvent *event) { + if (QGraphicsObject *object = item->toGraphicsObject()) { + QApplicationPrivate *qAppPriv = QApplicationPrivate::instance(); + if (qAppPriv->gestureManager) { + if (qAppPriv->gestureManager->filterEvent(object, event)) + return true; + } + } + if (filterEvent(item, event)) return false; if (filterDescendantEvent(item, event)) @@ -3365,6 +3373,10 @@ bool QGraphicsScene::event(QEvent *event) case QEvent::TouchEnd: d->touchEventHandler(static_cast<QTouchEvent *>(event)); break; + case QEvent::Gesture: + case QEvent::GestureOverride: + d->gestureEventHandler(static_cast<QGestureEvent *>(event)); + break; default: return QObject::event(event); } @@ -5699,6 +5711,32 @@ void QGraphicsScenePrivate::leaveModal(QGraphicsItem *panel) dispatchHoverEvent(&hoverEvent); } +void QGraphicsScenePrivate::gestureEventHandler(QGestureEvent *event) +{ + QWidget *viewport = event->widget(); + QList<QGesture *> gestures = event->allGestures(); + for (int i = 0; i < gestures.size(); ++i) { + QGesture *gesture = gestures.at(i); + Qt::GestureType gestureType = gesture->gestureType(); + QPoint screenPos = gesture->hotSpot().toPoint(); + QList<QGraphicsItem *> items = itemsAtPosition(screenPos, QPointF(), viewport); + for (int j = 0; j < items.size(); ++j) { + QGraphicsObject *item = items.at(j)->toGraphicsObject(); + if (!item) + continue; + QGraphicsItemPrivate *d = item->QGraphicsItem::d_func(); + if (d->gestureContext.contains(gestureType)) { + QGestureEvent ev(QList<QGesture *>() << gesture); + ev.t = event->t; + ev.spont = event->spont; + ev.setWidget(event->widget()); + sendEvent(item, &ev); + break; + } + } + } +} + QT_END_NAMESPACE #include "moc_qgraphicsscene.cpp" diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h index 8073695..4c82b49 100644 --- a/src/gui/graphicsview/qgraphicsscene_p.h +++ b/src/gui/graphicsview/qgraphicsscene_p.h @@ -282,6 +282,8 @@ public: bool allItemsIgnoreTouchEvents; void enableTouchEventsOnViews(); + void gestureEventHandler(QGestureEvent *event); + void updateInputMethodSensitivityInViews(); QList<QGraphicsItem *> modalPanels; diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index 32747cc..710c745 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -2701,6 +2701,19 @@ bool QGraphicsView::viewportEvent(QEvent *event) return true; } + case QEvent::Gesture: + case QEvent::GestureOverride: + { + if (!isEnabled()) + return false; + + if (d->scene && d->sceneInteractionAllowed) { + QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(event); + gestureEvent->setWidget(viewport()); + (void) QApplication::sendEvent(d->scene, gestureEvent); + } + return true; + } default: break; } |