summaryrefslogtreecommitdiffstats
path: root/examples/multitouch
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2009-03-26 07:54:36 (GMT)
committerBradley T. Hughes <bradley.hughes@nokia.com>2009-03-26 07:54:36 (GMT)
commitb3a2c210973a77d1517d017637a3d6ef849f4089 (patch)
treed01968c0b2a1e8189768d00f9a53c90dbc4eaef3 /examples/multitouch
parentb2824b384485ddba95091e49f81733485f1a73be (diff)
downloadQt-b3a2c210973a77d1517d017637a3d6ef849f4089.zip
Qt-b3a2c210973a77d1517d017637a3d6ef849f4089.tar.gz
Qt-b3a2c210973a77d1517d017637a3d6ef849f4089.tar.bz2
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
Diffstat (limited to 'examples/multitouch')
-rw-r--r--examples/multitouch/pinchzoom/graphicsview.cpp13
-rw-r--r--examples/multitouch/pinchzoom/main.cpp1
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 <QScrollBar>
#include <QTouchEvent>
-
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<QTouchEvent::TouchPoint *> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
- if (touchPoints.count() == 2) {
+ QList<QTouchEvent::TouchPoint *> touchPoints = static_cast<QTouchEvent *>(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();