summaryrefslogtreecommitdiffstats
path: root/examples/multitouch
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2009-06-18 10:58:29 (GMT)
committerBradley T. Hughes <bradley.hughes@nokia.com>2009-06-18 10:58:29 (GMT)
commit7e8734879ea7619a632553b59b2a8bd491033cce (patch)
tree982f3a0ad66404afcffe0a06be31c1aa4caf3602 /examples/multitouch
parent3b04dba36b31360d94583f382b9054bcdea0e2a7 (diff)
downloadQt-7e8734879ea7619a632553b59b2a8bd491033cce.zip
Qt-7e8734879ea7619a632553b59b2a8bd491033cce.tar.gz
Qt-7e8734879ea7619a632553b59b2a8bd491033cce.tar.bz2
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)
Diffstat (limited to 'examples/multitouch')
-rw-r--r--examples/multitouch/dials/dials.pro2
-rw-r--r--examples/multitouch/dials/dials.ui77
-rw-r--r--examples/multitouch/dials/main.cpp18
-rw-r--r--examples/multitouch/multitouch.pro2
-rw-r--r--examples/multitouch/pinchzoom/graphicsview.cpp8
5 files changed, 100 insertions, 7 deletions
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Dials</class>
+ <widget class="QWidget" name="Dials">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QDial" name="dial_1">
+ <property name="notchesVisible">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QDial" name="dial_2">
+ <property name="notchesVisible">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QDial" name="dial_3">
+ <property name="notchesVisible">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="3">
+ <widget class="QDial" name="dial_4">
+ <property name="notchesVisible">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QDial" name="dial_5">
+ <property name="notchesVisible">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QDial" name="dial_6">
+ <property name="notchesVisible">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2">
+ <widget class="QDial" name="dial_7">
+ <property name="notchesVisible">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="3">
+ <widget class="QDial" name="dial_8">
+ <property name="notchesVisible">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
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 <QApplication>
+#include <QWidget>
+#include <QDial>
+
+#include "ui_dials.h"
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+ QWidget window;
+ Ui::Dials dialsUi;
+ dialsUi.setupUi(&window);
+ QList<QAbstractSlider *> sliders = window.findChildren<QAbstractSlider *>();
+ 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<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) {
+ if (touchPoints.count() == 2) {
// determine scale factor
const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();