From 7e8734879ea7619a632553b59b2a8bd491033cce Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Thu, 18 Jun 2009 12:58:29 +0200 Subject: update examples now that we get both touch and mouse events at the same time added a new example to show how to enable touch for an existing widget (QDial in this case), and that the mouse event emulation of QWidget does the Right Thing (tm) --- examples/multitouch/dials/dials.pro | 2 + examples/multitouch/dials/dials.ui | 77 ++++++++++++++++++++++++++ examples/multitouch/dials/main.cpp | 18 ++++++ examples/multitouch/multitouch.pro | 2 +- examples/multitouch/pinchzoom/graphicsview.cpp | 8 +-- 5 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 examples/multitouch/dials/dials.pro create mode 100644 examples/multitouch/dials/dials.ui create mode 100644 examples/multitouch/dials/main.cpp diff --git a/examples/multitouch/dials/dials.pro b/examples/multitouch/dials/dials.pro new file mode 100644 index 0000000..e592232 --- /dev/null +++ b/examples/multitouch/dials/dials.pro @@ -0,0 +1,2 @@ +SOURCES += main.cpp +FORMS += dials.ui diff --git a/examples/multitouch/dials/dials.ui b/examples/multitouch/dials/dials.ui new file mode 100644 index 0000000..8ca7ae9 --- /dev/null +++ b/examples/multitouch/dials/dials.ui @@ -0,0 +1,77 @@ + + + Dials + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + true + + + + + + + true + + + + + + + true + + + + + + + true + + + + + + + true + + + + + + + true + + + + + + + true + + + + + + + true + + + + + + + + diff --git a/examples/multitouch/dials/main.cpp b/examples/multitouch/dials/main.cpp new file mode 100644 index 0000000..f4d3e83 --- /dev/null +++ b/examples/multitouch/dials/main.cpp @@ -0,0 +1,18 @@ +#include +#include +#include + +#include "ui_dials.h" + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + QWidget window; + Ui::Dials dialsUi; + dialsUi.setupUi(&window); + QList sliders = window.findChildren(); + foreach (QAbstractSlider *slider, sliders) + slider->setAttribute(Qt::WA_AcceptTouchEvents); + window.showMaximized(); + return app.exec(); +} diff --git a/examples/multitouch/multitouch.pro b/examples/multitouch/multitouch.pro index b3d1d55..d5983eb 100644 --- a/examples/multitouch/multitouch.pro +++ b/examples/multitouch/multitouch.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS = pinchzoom fingerpaint knobs +SUBDIRS = pinchzoom fingerpaint knobs dials diff --git a/examples/multitouch/pinchzoom/graphicsview.cpp b/examples/multitouch/pinchzoom/graphicsview.cpp index b72da77..9d29a28 100644 --- a/examples/multitouch/pinchzoom/graphicsview.cpp +++ b/examples/multitouch/pinchzoom/graphicsview.cpp @@ -48,6 +48,7 @@ GraphicsView::GraphicsView(QGraphicsScene *scene, QWidget *parent) : QGraphicsView(scene, parent) { setAttribute(Qt::WA_AcceptTouchEvents); + setDragMode(ScrollHandDrag); } bool GraphicsView::event(QEvent *event) @@ -58,12 +59,7 @@ bool GraphicsView::event(QEvent *event) case QEvent::TouchEnd: { 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) { + if (touchPoints.count() == 2) { // determine scale factor const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first(); const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last(); -- cgit v0.12