From b3a2c210973a77d1517d017637a3d6ef849f4089 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Thu, 26 Mar 2009 08:54:36 +0100 Subject: implement panning using touch events since we don't get mouse events to send to QGraphicsView's ScrollHandDrag handlers, we need to do it ourselves --- examples/multitouch/pinchzoom/graphicsview.cpp | 13 ++++++++----- examples/multitouch/pinchzoom/main.cpp | 1 - 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/examples/multitouch/pinchzoom/graphicsview.cpp b/examples/multitouch/pinchzoom/graphicsview.cpp index b77c926..f763e6f 100644 --- a/examples/multitouch/pinchzoom/graphicsview.cpp +++ b/examples/multitouch/pinchzoom/graphicsview.cpp @@ -41,9 +41,9 @@ #include "graphicsview.h" +#include #include - GraphicsView::GraphicsView(QGraphicsScene *scene, QWidget *parent) : QGraphicsView(scene, parent) { @@ -57,10 +57,13 @@ bool GraphicsView::event(QEvent *event) case QEvent::TouchUpdate: case QEvent::TouchEnd: { - qDebug("touch events"); - - QList touchPoints = static_cast(event)->touchPoints(); - if (touchPoints.count() == 2) { + QList touchPoints = static_cast(event)->touchPoints(); + if (touchPoints.count() == 1) { + const QTouchEvent::TouchPoint *touchPoint = touchPoints.first(); + QPointF delta = touchPoint->pos() - touchPoint->lastPos(); + horizontalScrollBar()->setValue(horizontalScrollBar()->value() - delta.x()); + verticalScrollBar()->setValue(verticalScrollBar()->value() - delta.y()); + } else if (touchPoints.count() == 2) { // determine scale factor const QTouchEvent::TouchPoint *touchPoint0 = touchPoints.first(); const QTouchEvent::TouchPoint *touchPoint1 = touchPoints.last(); diff --git a/examples/multitouch/pinchzoom/main.cpp b/examples/multitouch/pinchzoom/main.cpp index 6b25060..bb86870 100644 --- a/examples/multitouch/pinchzoom/main.cpp +++ b/examples/multitouch/pinchzoom/main.cpp @@ -78,7 +78,6 @@ int main(int argc, char **argv) //! [4] //! [5] view.setCacheMode(QGraphicsView::CacheBackground); view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); - view.setDragMode(QGraphicsView::ScrollHandDrag); //! [5] //! [6] view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Colliding Mice")); view.showMaximized(); -- cgit v0.12