From 6c7d3f73e361c460ad5523f1d9c9d9d6ebc81299 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Wed, 21 Oct 2009 16:33:11 +0200 Subject: Fixed the gestures/graphicsview manualtest --- tests/manual/gestures/graphicsview/main.cpp | 2 ++ .../graphicsview/mousepangesturerecognizer.cpp | 25 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/tests/manual/gestures/graphicsview/main.cpp b/tests/manual/gestures/graphicsview/main.cpp index 263a963..b4d74e4 100644 --- a/tests/manual/gestures/graphicsview/main.cpp +++ b/tests/manual/gestures/graphicsview/main.cpp @@ -126,6 +126,8 @@ public: scene = new QGraphicsScene(this); scene->setSceneRect(-2000, -2000, 4000, 4000); view = new QGraphicsView(scene, 0); + view->viewport()->grabGesture(Qt::PanGesture); + view->viewport()->grabGesture(ThreeFingerSlideGesture::Type); QVBoxLayout *l = new QVBoxLayout(this); l->addWidget(view); } diff --git a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp index 0e7f538..acd525f 100644 --- a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp +++ b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp @@ -42,6 +42,8 @@ #include "mousepangesturerecognizer.h" #include +#include +#include #include #include @@ -57,16 +59,31 @@ QGesture* MousePanGestureRecognizer::createGesture(QObject *) QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event) { QPanGesture *g = static_cast(state); - QMouseEvent *me = static_cast(event); + QPoint globalPos; + switch (event->type()) { + case QEvent::GraphicsSceneMousePress: + case QEvent::GraphicsSceneMouseDoubleClick: + case QEvent::GraphicsSceneMouseMove: + case QEvent::GraphicsSceneMouseRelease: + globalPos = static_cast(event)->screenPos(); + break; + case QEvent::MouseButtonPress: + case QEvent::MouseMove: + case QEvent::MouseButtonRelease: + globalPos = static_cast(event)->globalPos(); + break; + default: + break; + } if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick || event->type() == QEvent::GraphicsSceneMousePress || event->type() == QEvent::GraphicsSceneMouseDoubleClick) { - g->setHotSpot(me->globalPos()); - g->setProperty("lastPos", me->globalPos()); + g->setHotSpot(globalPos); + g->setProperty("lastPos", globalPos); g->setProperty("pressed", QVariant::fromValue(true)); return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint; } else if (event->type() == QEvent::MouseMove || event->type() == QEvent::GraphicsSceneMouseMove) { if (g->property("pressed").toBool()) { - QPoint pos = me->globalPos(); + QPoint pos = globalPos; QPoint lastPos = g->property("lastPos").toPoint(); g->setLastOffset(g->offset()); lastPos = pos - lastPos; -- cgit v0.12