summaryrefslogtreecommitdiffstats
path: root/animals
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@nokia.com>2010-07-21 19:16:47 +0200
committerFrederik Gladhorn <frederik.gladhorn@nokia.com>2010-07-21 19:16:47 +0200
commite1400d3bd15a1d86c51b05a88a79188fc1c785d4 (patch)
treeadf72ae6ee72f82d780065f008b8e7f93ee913a1 /animals
parentb10e7c8763987d9bb4f5f533a1cf8ca423f7528c (diff)
add animal pieces example for gestures
Diffstat (limited to 'animals')
-rwxr-xr-xanimals/Animal.qml183
-rw-r--r--animals/animals.pro29
-rw-r--r--animals/animals.qml47
-rw-r--r--animals/images/Andy_ant.pngbin0 -> 11944 bytes
-rw-r--r--animals/images/ArtFavor_Cartoon_Sheep.pngbin0 -> 18879 bytes
-rw-r--r--animals/images/ArtFavor_Sheep_(Ewe).pngbin0 -> 30354 bytes
-rw-r--r--animals/images/PeterM_Angry_black_panther.pngbin0 -> 17613 bytes
-rw-r--r--animals/images/PeterM_Bee.pngbin0 -> 25503 bytes
-rw-r--r--animals/images/PeterM_Housefly.pngbin0 -> 31738 bytes
-rw-r--r--animals/images/PeterM_Penguin_with_a_shirt.pngbin0 -> 12432 bytes
-rw-r--r--animals/images/PeterM_Sad_cat.pngbin0 -> 19364 bytes
-rw-r--r--animals/images/TheresaKnott_frog.pngbin0 -> 16981 bytes
-rw-r--r--animals/images/johnny_automatic_chicken.pngbin0 -> 14869 bytes
-rw-r--r--animals/images/johnny_automatic_cow.pngbin0 -> 12037 bytes
-rw-r--r--animals/images/johnny_automatic_cow_1.pngbin0 -> 17520 bytes
-rw-r--r--animals/images/johnny_automatic_hare_and_tabor.pngbin0 -> 23699 bytes
-rw-r--r--animals/images/johnny_automatic_horse_silhouette.pngbin0 -> 9580 bytes
-rw-r--r--animals/images/johnny_automatic_startled_bears.pngbin0 -> 64255 bytes
-rw-r--r--animals/images/johnny_automatic_turkey.pngbin0 -> 39701 bytes
-rw-r--r--animals/images/lakeside_witch_over_harvest_moon.pngbin0 -> 13113 bytes
-rw-r--r--animals/images/lemmling_Cartoon_cow.pngbin0 -> 24077 bytes
-rw-r--r--animals/images/liftarn_Ddraig.pngbin0 -> 8181 bytes
-rw-r--r--animals/images/liftarn_Owl_on_book.pngbin0 -> 11975 bytes
-rw-r--r--animals/images/liftarn_Taun_taun.pngbin0 -> 16688 bytes
-rw-r--r--animals/images/obi_Dragon_s_head.pngbin0 -> 10346 bytes
-rw-r--r--animals/images/qt-logo.pngbin0 -> 28187 bytes
-rw-r--r--animals/images/rejon_Ant_Icon.pngbin0 -> 8718 bytes
-rwxr-xr-xanimals/main.cpp51
-rwxr-xr-xanimals/mainwindow.cpp31
-rwxr-xr-xanimals/mainwindow.h19
-rw-r--r--animals/pangesturerecognizer.cpp100
-rw-r--r--animals/pangesturerecognizer.h58
-rw-r--r--animals/pinchgesturerecognizer.cpp109
-rw-r--r--animals/pinchgesturerecognizer.h58
-rw-r--r--animals/swipegesturerecognizer.cpp97
-rw-r--r--animals/swipegesturerecognizer.h58
-rw-r--r--animals/tapandholdgesturerecognizer.cpp159
-rw-r--r--animals/tapandholdgesturerecognizer.h87
-rw-r--r--animals/tapgesturerecognizer.cpp106
-rw-r--r--animals/tapgesturerecognizer.h58
40 files changed, 1250 insertions, 0 deletions
diff --git a/animals/Animal.qml b/animals/Animal.qml
new file mode 100755
index 0000000..5a8429a
--- /dev/null
+++ b/animals/Animal.qml
@@ -0,0 +1,183 @@
+import Qt 4.7
+
+import Qt.labs.gestures 1.0
+
+
+Rectangle {
+ id: animalRectangle;
+ property string image;
+ state: "back";
+
+ width: 100; height: 100; radius: 10;
+ color: 'white';
+
+ property int imageSize: width - 10
+
+ Image {
+ id: animalImage;
+ width: imageSize; height: imageSize; anchors.centerIn: parent;
+ fillMode: "PreserveAspectFit";
+ source: parent.image;
+ }
+ Image {
+ id: backImage;
+ width: imageSize; height: imageSize; anchors.centerIn: parent;
+ fillMode: "PreserveAspectFit";
+ source: "images/qt-logo.png";
+ }
+
+ function toggleSide() {
+ if (animalRectangle.state == "front")
+ animalRectangle.state = "back";
+ else
+ animalRectangle.state = "front";
+ }
+
+ states: [
+ State {
+ name: "back"
+ PropertyChanges { target: animalImage; opacity: 0.0 }
+ PropertyChanges { target: backImage; opacity: 1.0 }
+ },
+ State {
+ name: "front"
+ PropertyChanges { target: animalImage; opacity: 1.0 }
+ PropertyChanges { target: backImage; opacity: 0.0 }
+ }
+ ]
+
+
+ transitions: [
+ Transition {
+ from: "back"; to: "front"; reversible: true
+ ParallelAnimation {
+ NumberAnimation { properties: "opacity"; duration: 200; easing.type: Easing.InOutQuad }
+ }
+ }
+ ]
+
+ Behavior on scale {
+ NumberAnimation {
+ easing.type: Easing.OutBounce
+ easing.amplitude: 100
+ duration: 400
+ }
+ }
+ Behavior on opacity {
+ NumberAnimation {
+ easing.type: Easing.OutBounce
+ easing.amplitude: 100
+ duration: 400
+ }
+ }
+
+ GestureArea {
+ anchors.fill: parent
+
+ Tap {
+ when: gesture.state == Qt.GestureStarted
+ script: { console.log("tap started");
+ //animalRectangle.color = "red";
+ //animalRectangle.toggleSide();
+ animalRectangle.scale = 1.1;
+ }
+ }
+
+ Tap {
+ when: gesture.state == Qt.GestureCanceled
+ script: { console.log("tap canceled");
+ //animalRectangle.color = "white";
+ animalRectangle.scale = 1.0;
+ }
+ }
+ Tap {
+ when: gesture.state == Qt.GestureFinished
+ script: { console.log("tap finished");
+ //animalRectangle.color = "white";
+ animalRectangle.scale = 1.0;
+ }
+ }
+ TapAndHold {
+ when: gesture.state == Qt.GestureStarted
+ script: { console.log("tap-and-hold started"); }
+ }
+ TapAndHold {
+ when: gesture.state == Qt.GestureFinished
+ script: {
+ console.log("tap-and-hold finished");
+ animalRectangle.scale = 1.0;
+ animalRectangle.toggleSide();
+ }
+ }
+
+ Pan {
+ when: gesture.state == Qt.GestureStarted
+ script: { console.log("pan started");
+ }
+ }
+
+ Pan {
+ when: gesture.state == Qt.GestureUpdated
+ script: { //console.log("pan update");
+ animalRectangle.scale = 0.8;
+ //animalRectangle.x += gesture.offset.x;
+ animalRectangle.opacity = 0.7;
+ animalRectangle.x += gesture.delta.x;
+ animalRectangle.y += gesture.delta.y;
+ }
+ }
+
+ Pan {
+ when: gesture.state == Qt.GestureFinished
+ script: { console.log("pan finished" + gesture.delta.x + "," + gesture.delta.y
+ + " offset " + gesture.offset.x );
+
+ animalRectangle.scale = 1.0;
+ animalRectangle.opacity = 1.0;
+ //animalRectangle.x += gesture.offset.x;
+ //animalRectangle.y += gesture.offset.y;
+ }
+ }
+
+/*
+ Swipe {
+ when: gesture.state == Qt.GestureStarted
+ script: { console.log("swipe started");
+ }
+ }
+ Swipe {
+ when: gesture.state == Qt.GestureFinished
+ && gesture.horizontalDirection == QSwipeGesture.Left
+ script: { console.log("swipe left");
+ //animalRectangle.x -= (animalRectangle.width+5);
+ }
+ }
+ Swipe {
+ when: gesture.state == Qt.GestureFinished
+ && gesture.horizontalDirection == QSwipeGesture.Right
+ script: { console.log("swipe right");
+ //animalRectangle.x += (animalRectangle.width+5);
+ }
+ }
+*/
+
+ }
+
+
+ /*
+ MouseArea {
+ id: mouseArea
+ anchors.fill: parent
+ acceptedButtons: Qt.LeftButton
+ // yeah, we can drag around (but what for?)
+ drag.target: animalRectangle
+ drag.axis: Drag.XandYAxis
+ drag.minimumX: 0
+ drag.maximumX: parent.parent.width - parent.width
+ drag.minimumY: 0
+ drag.maximumY: parent.parent.height - parent.height
+ onClicked: toggleSide()
+ }*/
+
+
+}
diff --git a/animals/animals.pro b/animals/animals.pro
new file mode 100644
index 0000000..6346a72
--- /dev/null
+++ b/animals/animals.pro
@@ -0,0 +1,29 @@
+######################################################################
+# Automatically generated by qmake (2.01a) Tue Jul 20 15:52:04 2010
+######################################################################
+
+QT += core gui declarative
+
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+HEADERS += mainwindow.h \
+ pangesturerecognizer.h \
+ tapgesturerecognizer.h \
+ tapandholdgesturerecognizer.h \
+ swipegesturerecognizer.h \
+ pinchgesturerecognizer.h
+SOURCES += main.cpp mainwindow.cpp \
+ pangesturerecognizer.cpp \
+ pinchgesturerecognizer.cpp \
+ tapgesturerecognizer.cpp \
+ tapandholdgesturerecognizer.cpp \
+ swipegesturerecognizer.cpp
+
+OTHER_FILES += \
+ animals.qml \
+ Animal.qml \
+ AnimalLayout.qml
diff --git a/animals/animals.qml b/animals/animals.qml
new file mode 100644
index 0000000..58c68b6
--- /dev/null
+++ b/animals/animals.qml
@@ -0,0 +1,47 @@
+import Qt 4.7
+import Qt.labs.gestures 1.0
+
+Rectangle {
+ width: 520
+ height: 500
+
+ Flickable {
+ //Rectangle {
+ id: flickable
+ width: parent.width
+ height: parent.height
+ contentHeight: parent.height*3
+
+ Rectangle {
+ id: contentRect
+ anchors.fill: parent
+
+ gradient: Gradient {
+ GradientStop {
+ position: 0.00;
+ color: "#0FFF1B";
+ }
+ GradientStop {
+ position: 1.00;
+ color: "#0070ff";
+ }
+ }
+
+ Repeater {
+ model: [ "Andy_ant.png", "ArtFavor_Cartoon_Sheep.png", "johnny_automatic_chicken.png", "johnny_automatic_cow.png",
+ "liftarn_Ddraig.png", "liftarn_Owl_on_book.png", "johnny_automatic_turkey.png", "lemmling_Cartoon_cow.png",
+ "johnny_automatic_startled_bears.png", "PeterM_Angry_black_panther.png", "PeterM_Bee.png", "lakeside_witch_over_harvest_moon.png",
+ "PeterM_Sad_cat.png", "PeterM_Housefly.png", "ArtFavor_Sheep_(Ewe).png", "PeterM_Penguin_with_a_shirt.png",
+ "johnny_automatic_cow_1.png", "rejon_Ant_Icon.png", "liftarn_Taun_taun.png", "johnny_automatic_hare_and_tabor.png",
+ "TheresaKnott_frog.png", "johnny_automatic_horse_silhouette.png", "obi_Dragon_s_head.png"
+ ]
+
+ Animal {
+ image: "images/" + modelData
+ x: Math.floor(Math.random() * (contentRect.width/(width+5)) ) * (width+5)
+ y: Math.floor(Math.random() * (contentRect.height/(height+5) ) ) * (height+5)
+ }
+ }
+ }
+ }
+}
diff --git a/animals/images/Andy_ant.png b/animals/images/Andy_ant.png
new file mode 100644
index 0000000..54694cc
--- /dev/null
+++ b/animals/images/Andy_ant.png
Binary files differ
diff --git a/animals/images/ArtFavor_Cartoon_Sheep.png b/animals/images/ArtFavor_Cartoon_Sheep.png
new file mode 100644
index 0000000..e081e23
--- /dev/null
+++ b/animals/images/ArtFavor_Cartoon_Sheep.png
Binary files differ
diff --git a/animals/images/ArtFavor_Sheep_(Ewe).png b/animals/images/ArtFavor_Sheep_(Ewe).png
new file mode 100644
index 0000000..141838c
--- /dev/null
+++ b/animals/images/ArtFavor_Sheep_(Ewe).png
Binary files differ
diff --git a/animals/images/PeterM_Angry_black_panther.png b/animals/images/PeterM_Angry_black_panther.png
new file mode 100644
index 0000000..b8bc19c
--- /dev/null
+++ b/animals/images/PeterM_Angry_black_panther.png
Binary files differ
diff --git a/animals/images/PeterM_Bee.png b/animals/images/PeterM_Bee.png
new file mode 100644
index 0000000..f7fe23d
--- /dev/null
+++ b/animals/images/PeterM_Bee.png
Binary files differ
diff --git a/animals/images/PeterM_Housefly.png b/animals/images/PeterM_Housefly.png
new file mode 100644
index 0000000..b2bf56f
--- /dev/null
+++ b/animals/images/PeterM_Housefly.png
Binary files differ
diff --git a/animals/images/PeterM_Penguin_with_a_shirt.png b/animals/images/PeterM_Penguin_with_a_shirt.png
new file mode 100644
index 0000000..6524d25
--- /dev/null
+++ b/animals/images/PeterM_Penguin_with_a_shirt.png
Binary files differ
diff --git a/animals/images/PeterM_Sad_cat.png b/animals/images/PeterM_Sad_cat.png
new file mode 100644
index 0000000..323d6a6
--- /dev/null
+++ b/animals/images/PeterM_Sad_cat.png
Binary files differ
diff --git a/animals/images/TheresaKnott_frog.png b/animals/images/TheresaKnott_frog.png
new file mode 100644
index 0000000..5dea82a
--- /dev/null
+++ b/animals/images/TheresaKnott_frog.png
Binary files differ
diff --git a/animals/images/johnny_automatic_chicken.png b/animals/images/johnny_automatic_chicken.png
new file mode 100644
index 0000000..f9efebc
--- /dev/null
+++ b/animals/images/johnny_automatic_chicken.png
Binary files differ
diff --git a/animals/images/johnny_automatic_cow.png b/animals/images/johnny_automatic_cow.png
new file mode 100644
index 0000000..31db8ec
--- /dev/null
+++ b/animals/images/johnny_automatic_cow.png
Binary files differ
diff --git a/animals/images/johnny_automatic_cow_1.png b/animals/images/johnny_automatic_cow_1.png
new file mode 100644
index 0000000..a29b290
--- /dev/null
+++ b/animals/images/johnny_automatic_cow_1.png
Binary files differ
diff --git a/animals/images/johnny_automatic_hare_and_tabor.png b/animals/images/johnny_automatic_hare_and_tabor.png
new file mode 100644
index 0000000..376f2e9
--- /dev/null
+++ b/animals/images/johnny_automatic_hare_and_tabor.png
Binary files differ
diff --git a/animals/images/johnny_automatic_horse_silhouette.png b/animals/images/johnny_automatic_horse_silhouette.png
new file mode 100644
index 0000000..be71580
--- /dev/null
+++ b/animals/images/johnny_automatic_horse_silhouette.png
Binary files differ
diff --git a/animals/images/johnny_automatic_startled_bears.png b/animals/images/johnny_automatic_startled_bears.png
new file mode 100644
index 0000000..fe5396d
--- /dev/null
+++ b/animals/images/johnny_automatic_startled_bears.png
Binary files differ
diff --git a/animals/images/johnny_automatic_turkey.png b/animals/images/johnny_automatic_turkey.png
new file mode 100644
index 0000000..2a2e94e
--- /dev/null
+++ b/animals/images/johnny_automatic_turkey.png
Binary files differ
diff --git a/animals/images/lakeside_witch_over_harvest_moon.png b/animals/images/lakeside_witch_over_harvest_moon.png
new file mode 100644
index 0000000..235db84
--- /dev/null
+++ b/animals/images/lakeside_witch_over_harvest_moon.png
Binary files differ
diff --git a/animals/images/lemmling_Cartoon_cow.png b/animals/images/lemmling_Cartoon_cow.png
new file mode 100644
index 0000000..476bd38
--- /dev/null
+++ b/animals/images/lemmling_Cartoon_cow.png
Binary files differ
diff --git a/animals/images/liftarn_Ddraig.png b/animals/images/liftarn_Ddraig.png
new file mode 100644
index 0000000..9c233a6
--- /dev/null
+++ b/animals/images/liftarn_Ddraig.png
Binary files differ
diff --git a/animals/images/liftarn_Owl_on_book.png b/animals/images/liftarn_Owl_on_book.png
new file mode 100644
index 0000000..5b53a4e
--- /dev/null
+++ b/animals/images/liftarn_Owl_on_book.png
Binary files differ
diff --git a/animals/images/liftarn_Taun_taun.png b/animals/images/liftarn_Taun_taun.png
new file mode 100644
index 0000000..458dfc6
--- /dev/null
+++ b/animals/images/liftarn_Taun_taun.png
Binary files differ
diff --git a/animals/images/obi_Dragon_s_head.png b/animals/images/obi_Dragon_s_head.png
new file mode 100644
index 0000000..d965184
--- /dev/null
+++ b/animals/images/obi_Dragon_s_head.png
Binary files differ
diff --git a/animals/images/qt-logo.png b/animals/images/qt-logo.png
new file mode 100644
index 0000000..b9eed00
--- /dev/null
+++ b/animals/images/qt-logo.png
Binary files differ
diff --git a/animals/images/rejon_Ant_Icon.png b/animals/images/rejon_Ant_Icon.png
new file mode 100644
index 0000000..938ba32
--- /dev/null
+++ b/animals/images/rejon_Ant_Icon.png
Binary files differ
diff --git a/animals/main.cpp b/animals/main.cpp
new file mode 100755
index 0000000..6469fdb
--- /dev/null
+++ b/animals/main.cpp
@@ -0,0 +1,51 @@
+#include <QtGui/QApplication>
+#include "mainwindow.h"
+
+
+#include <QGesture>
+#include <QGestureRecognizer>
+
+#include <QDeclarativeEngine>
+#include "qdeclarative.h"
+
+#if defined(Q_OS_LINUX)
+#include "pangesturerecognizer.h"
+#include "pinchgesturerecognizer.h"
+#include "tapgesturerecognizer.h"
+#include "tapandholdgesturerecognizer.h"
+#include "swipegesturerecognizer.h"
+#endif
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow w;
+ w.show();
+
+
+#if defined(Q_OS_LINUX)
+ QGestureRecognizer::unregisterRecognizer(Qt::PanGesture);
+ PanGestureRecognizer::registerRecognizer();
+
+ QGestureRecognizer::unregisterRecognizer(Qt::TapGesture);
+ TapGestureRecognizer::registerRecognizer();
+ QGestureRecognizer::unregisterRecognizer(Qt::TapAndHoldGesture);
+ TapAndHoldGestureRecognizer::registerRecognizer();
+
+ QGestureRecognizer::unregisterRecognizer(Qt::PinchGesture);
+ PinchGestureRecognizer::registerRecognizer();
+ SwipeGestureRecognizer::registerRecognizer();
+#endif
+ app.setApplicationName("Animals");
+ app.setOrganizationName("Nokia");
+ app.setOrganizationDomain("nokia.com");
+
+ //QDeclarativeViewer::registerTypes();
+ //QDeclarativeTester::registerTypes();
+#ifndef QT_NO_GESTURES
+ qmlRegisterType<QGesture>("Qt.labs.gestures",1,0, "Gesture");
+#endif
+
+
+ return app.exec();
+}
diff --git a/animals/mainwindow.cpp b/animals/mainwindow.cpp
new file mode 100755
index 0000000..47ebc78
--- /dev/null
+++ b/animals/mainwindow.cpp
@@ -0,0 +1,31 @@
+#include "mainwindow.h"
+
+#include <QApplication>
+#include <QtDeclarative/QDeclarativeView>
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ view = new QDeclarativeView(this);
+ setCentralWidget(view);
+
+ view->setSource(QUrl::fromLocalFile("animals.qml"));
+ //view->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+
+
+ view->grabGesture(Qt::TapGesture,Qt::DontStartGestureOnChildren|Qt::ReceivePartialGestures|Qt::IgnoredGesturesPropagateToParent);
+ view->grabGesture(Qt::TapAndHoldGesture,Qt::DontStartGestureOnChildren|Qt::ReceivePartialGestures|Qt::IgnoredGesturesPropagateToParent);
+ view->grabGesture(Qt::PanGesture,Qt::DontStartGestureOnChildren|Qt::ReceivePartialGestures|Qt::IgnoredGesturesPropagateToParent);
+ view->grabGesture(Qt::PinchGesture,Qt::DontStartGestureOnChildren|Qt::ReceivePartialGestures|Qt::IgnoredGesturesPropagateToParent);
+ view->grabGesture(Qt::SwipeGesture,Qt::DontStartGestureOnChildren|Qt::ReceivePartialGestures|Qt::IgnoredGesturesPropagateToParent);
+ view->setAttribute(Qt::WA_AcceptTouchEvents);
+
+
+}
+
+MainWindow::~MainWindow()
+{
+ delete view;
+}
+
diff --git a/animals/mainwindow.h b/animals/mainwindow.h
new file mode 100755
index 0000000..d86cc19
--- /dev/null
+++ b/animals/mainwindow.h
@@ -0,0 +1,19 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QtGui/QMainWindow>
+
+class QDeclarativeView;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+
+ QDeclarativeView* view;
+};
+
+#endif // MAINWINDOW_H
diff --git a/animals/pangesturerecognizer.cpp b/animals/pangesturerecognizer.cpp
new file mode 100644
index 0000000..b2be0a3
--- /dev/null
+++ b/animals/pangesturerecognizer.cpp
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "pangesturerecognizer.h"
+
+void PanGestureRecognizer::registerRecognizer()
+{
+ QGestureRecognizer::registerRecognizer(new PanGestureRecognizer);
+}
+
+PanGestureRecognizer::PanGestureRecognizer()
+{
+}
+
+QGesture *PanGestureRecognizer::create(QObject *)
+{
+ return new QPanGesture;
+}
+
+QGestureRecognizer::Result PanGestureRecognizer::recognize(QGesture *state, QObject *,
+ QEvent *event)
+{
+ QPanGesture *q = static_cast<QPanGesture *>(state);
+ QGraphicsSceneMouseEvent *ev = static_cast<QGraphicsSceneMouseEvent *>(event);
+ switch(event->type()) {
+ case QEvent::GraphicsSceneMousePress:
+ if (ev->buttons() == Qt::LeftButton && !(ev->modifiers() & Qt::ControlModifier)) {
+ state->setProperty("startPos", ev->screenPos());
+ state->setHotSpot(ev->screenPos());
+ state->setHandled(false);
+ ev->accept();
+ return QGestureRecognizer::MayBeGesture | QGestureRecognizer::ConsumeEventHint;
+ } else if (state->state() == Qt::GestureUpdated) {
+ return QGestureRecognizer::CancelGesture;
+ } else
+ return QGestureRecognizer::Ignore;
+ case QEvent::GraphicsSceneMouseMove:
+ if (!state->property("startPos").toPoint().isNull()) {
+ QPoint delta = ev->screenPos() - state->property("startPos").toPoint();
+ q->setLastOffset(q->offset());
+ q->setOffset(delta);
+ return QGestureRecognizer::TriggerGesture;
+ }
+ return QGestureRecognizer::Ignore;
+ case QEvent::GraphicsSceneMouseRelease:
+ if (!state->property("startPos").toPoint().isNull()) {
+ state->setProperty("startPos", QPoint());
+ return QGestureRecognizer::FinishGesture;
+ }
+ return QGestureRecognizer::Ignore;
+ default:
+ break;
+ }
+ return QGestureRecognizer::Ignore;
+}
+
+void PanGestureRecognizer::reset(QGesture *state)
+{
+ QPanGesture *q = static_cast<QPanGesture *>(state);
+ q->setLastOffset(QPointF());
+ q->setOffset(QPointF());
+ q->setAcceleration(0);
+}
diff --git a/animals/pangesturerecognizer.h b/animals/pangesturerecognizer.h
new file mode 100644
index 0000000..6a593ca
--- /dev/null
+++ b/animals/pangesturerecognizer.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef PANGESTURERECOGNIZER_H
+#define PANGESTURERECOGNIZER_H
+
+#include <QtGui>
+
+class PanGestureRecognizer : public QGestureRecognizer
+{
+public:
+ static void registerRecognizer();
+
+private:
+ PanGestureRecognizer();
+ QGesture *create(QObject *);
+ QGestureRecognizer::Result recognize(QGesture *state, QObject *, QEvent *event);
+ void reset(QGesture *state);
+};
+
+#endif
diff --git a/animals/pinchgesturerecognizer.cpp b/animals/pinchgesturerecognizer.cpp
new file mode 100644
index 0000000..a3af555
--- /dev/null
+++ b/animals/pinchgesturerecognizer.cpp
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "pinchgesturerecognizer.h"
+
+void PinchGestureRecognizer::registerRecognizer()
+{
+ QGestureRecognizer::registerRecognizer(new PinchGestureRecognizer);
+}
+
+PinchGestureRecognizer::PinchGestureRecognizer()
+{
+}
+
+QGesture *PinchGestureRecognizer::create(QObject *)
+{
+ return new QPinchGesture;
+}
+
+QGestureRecognizer::Result PinchGestureRecognizer::recognize(QGesture *state, QObject *,
+ QEvent *event)
+{
+ QPinchGesture *q = static_cast<QPinchGesture *>(state);
+ QGraphicsSceneMouseEvent *ev = static_cast<QGraphicsSceneMouseEvent *>(event);
+ switch(event->type()) {
+ case QEvent::GraphicsSceneMousePress:
+ if (ev->buttons() == Qt::LeftButton && (ev->modifiers() & Qt::ControlModifier)) {
+ state->setProperty("startPos", ev->screenPos());
+ state->setHotSpot(ev->screenPos());
+ q->setCenterPoint(ev->screenPos());
+ state->setHandled(false);
+ ev->accept();
+ return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
+ } else if (state->state() == Qt::GestureUpdated) {
+ return QGestureRecognizer::CancelGesture;
+ } else
+ return QGestureRecognizer::Ignore;
+ case QEvent::GraphicsSceneMouseMove:
+ if (!state->property("startPos").toPoint().isNull()) {
+ QPoint delta = ev->screenPos() - state->property("startPos").toPoint();
+ int x = delta.x();
+ int y = -delta.y();
+ qreal dist = sqrt(pow(x,2)+pow(y,2))/100.0f;
+ if(!( (x>0 && abs(x) > abs(y)) || (y>0 && abs(y) > abs(x)))) {
+ dist = 1.0f-dist;
+ dist = dist > 0 ? dist : 0.01f;
+ }
+ else
+ dist+=1.0f;
+
+ q->setTotalScaleFactor(dist);
+ return QGestureRecognizer::TriggerGesture;
+ }
+ return QGestureRecognizer::Ignore;
+ case QEvent::GraphicsSceneMouseRelease:
+ if (!state->property("startPos").toPoint().isNull()) {
+ state->setProperty("startPos", QPoint());
+ return QGestureRecognizer::FinishGesture;
+ }
+ return QGestureRecognizer::Ignore;
+ default:
+ break;
+ }
+ return QGestureRecognizer::Ignore;
+}
+
+void PinchGestureRecognizer::reset(QGesture *state)
+{
+ QPinchGesture *q = static_cast<QPinchGesture *>(state);
+ //q->setLastOffset(QPointF());
+ q->setTotalScaleFactor(1);
+}
diff --git a/animals/pinchgesturerecognizer.h b/animals/pinchgesturerecognizer.h
new file mode 100644
index 0000000..a0a28d6
--- /dev/null
+++ b/animals/pinchgesturerecognizer.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef PINCHGESTURERECOGNIZER_H
+#define PINCHGESTURERECOGNIZER_H
+
+#include <QtGui>
+
+class PinchGestureRecognizer : public QGestureRecognizer
+{
+public:
+ static void registerRecognizer();
+
+private:
+ PinchGestureRecognizer();
+ QGesture *create(QObject *);
+ QGestureRecognizer::Result recognize(QGesture *state, QObject *, QEvent *event);
+ void reset(QGesture *state);
+};
+
+#endif
diff --git a/animals/swipegesturerecognizer.cpp b/animals/swipegesturerecognizer.cpp
new file mode 100644
index 0000000..300cd6f
--- /dev/null
+++ b/animals/swipegesturerecognizer.cpp
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "swipegesturerecognizer.h"
+
+void SwipeGestureRecognizer::registerRecognizer()
+{
+ QGestureRecognizer::registerRecognizer(new SwipeGestureRecognizer);
+}
+
+SwipeGestureRecognizer::SwipeGestureRecognizer()
+{
+}
+
+QGesture *SwipeGestureRecognizer::create(QObject *)
+{
+ return new QSwipeGesture;
+}
+
+QGestureRecognizer::Result SwipeGestureRecognizer::recognize(QGesture *state, QObject *,
+ QEvent *event)
+{
+ QSwipeGesture *q = static_cast<QSwipeGesture *>(state);
+ QGraphicsSceneMouseEvent *ev = static_cast<QGraphicsSceneMouseEvent *>(event);
+ switch(event->type()) {
+ case QEvent::GraphicsSceneMousePress:
+ if (ev->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier | Qt::ControlModifier))
+ return QGestureRecognizer::Ignore;
+ if (ev->buttons() == Qt::LeftButton) {
+ state->setProperty("startPos", ev->screenPos());
+ state->setHotSpot(ev->screenPos());
+ state->setHandled(false);
+ ev->accept();
+ return QGestureRecognizer::MayBeGesture;
+ }
+ return QGestureRecognizer::Ignore;
+ case QEvent::GraphicsSceneMouseMove:
+ if (!state->property("startPos").toPoint().isNull()) {
+ QPoint startPos = state->property("startPos").toPoint();
+ QPoint delta = ev->screenPos() - startPos;
+ if (delta.manhattanLength() > 100) {
+ q->setSwipeAngle(QLineF(startPos, ev->screenPos()).angle());
+ return QGestureRecognizer::FinishGesture;
+ }
+ }
+ return QGestureRecognizer::Ignore;
+ case QEvent::GraphicsSceneMouseRelease:
+ return QGestureRecognizer::Ignore;
+ default:
+ break;
+ }
+ return QGestureRecognizer::Ignore;
+}
+
+void SwipeGestureRecognizer::reset(QGesture *state)
+{
+ QSwipeGesture *q = static_cast<QSwipeGesture *>(state);
+ q->setSwipeAngle(0);
+ q->setProperty("startPos", QVariant());
+}
diff --git a/animals/swipegesturerecognizer.h b/animals/swipegesturerecognizer.h
new file mode 100644
index 0000000..4133a0d
--- /dev/null
+++ b/animals/swipegesturerecognizer.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef SWIPEGESTURERECOGNIZER_H
+#define SWIPEGESTURERECOGNIZER_H
+
+#include <QtGui>
+
+class SwipeGestureRecognizer : public QGestureRecognizer
+{
+public:
+ static void registerRecognizer();
+
+private:
+ SwipeGestureRecognizer();
+ QGesture *create(QObject *);
+ QGestureRecognizer::Result recognize(QGesture *state, QObject *, QEvent *event);
+ void reset(QGesture *state);
+};
+
+#endif
diff --git a/animals/tapandholdgesturerecognizer.cpp b/animals/tapandholdgesturerecognizer.cpp
new file mode 100644
index 0000000..2ff1ef9
--- /dev/null
+++ b/animals/tapandholdgesturerecognizer.cpp
@@ -0,0 +1,159 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "tapandholdgesturerecognizer.h"
+
+Qt::GestureType TapAndHoldFeedbackGesture::Type;
+
+TapAndHoldFeedbackGesture::TapAndHoldFeedbackGesture()
+ : m_completionStatus(0)
+{
+}
+
+int TapAndHoldFeedbackGesture::completionStatus() const
+{
+ return m_completionStatus;
+}
+
+void TapAndHoldFeedbackGesture::setCompletionStatus(int value)
+{
+ m_completionStatus = value;
+}
+
+QPointF TapAndHoldFeedbackGesture::position() const
+{
+ return m_position;
+}
+
+void TapAndHoldFeedbackGesture::setPosition(const QPointF &value)
+{
+ m_position = value;
+}
+
+void TapAndHoldGestureRecognizer::registerRecognizer()
+{
+ QGestureRecognizer::registerRecognizer(new TapAndHoldGestureRecognizer(false));
+ TapAndHoldFeedbackGesture::Type = QGestureRecognizer::registerRecognizer(new TapAndHoldGestureRecognizer(true));
+}
+
+TapAndHoldGestureRecognizer::TapAndHoldGestureRecognizer(bool feedback)
+ : m_feedback(feedback)
+{
+}
+
+QGesture *TapAndHoldGestureRecognizer::create(QObject *)
+{
+ if (m_feedback)
+ return new TapAndHoldFeedbackGesture;
+ return new QTapAndHoldGesture;
+}
+
+QGestureRecognizer::Result TapAndHoldGestureRecognizer::recognize(QGesture *state, QObject *watched,
+ QEvent *event)
+{
+ QGraphicsSceneMouseEvent *ev = static_cast<QGraphicsSceneMouseEvent *>(event);
+ switch(event->type()) {
+ case QEvent::GraphicsSceneMousePress:
+ if (m_feedback)
+ state->setProperty("completionStatus", 0);
+ state->setProperty("position", ev->screenPos());
+ Q_ASSERT(state->property("timerid").toInt() == 0);
+ state->setProperty("timerid", state->startTimer(100));
+ state->setHotSpot(ev->screenPos());
+ event->accept();
+ return m_feedback ?
+ QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint :
+ QGestureRecognizer::MayBeGesture | QGestureRecognizer::ConsumeEventHint;
+ case QEvent::GraphicsSceneMouseMove:
+ if (int timerid = state->property("timerid").toInt()) {
+ QPoint delta = ev->screenPos() - state->property("position").toPointF().toPoint();
+ enum { TapRadius = 40 };
+ if (delta.manhattanLength() > TapRadius) {
+ state->killTimer(timerid);
+#if 1
+ reset(state);
+#endif
+ return QGestureRecognizer::CancelGesture;
+ }
+ }
+ return m_feedback ?
+ QGestureRecognizer::Ignore :
+ QGestureRecognizer::MayBeGesture;
+ case QEvent::GraphicsSceneMouseRelease:
+ if (int timerid = state->property("timerid").toInt()) {
+ state->killTimer(timerid);
+#if 1
+ reset(state);
+#endif
+ return QGestureRecognizer::CancelGesture;
+ }
+ return QGestureRecognizer::Ignore;
+ case QEvent::Timer: {
+ Q_ASSERT(state == watched);
+ Q_ASSERT(state->property("timerid").toInt() != 0);
+ int iteration = state->property("iteration").toInt();
+ if (m_feedback)
+ state->setProperty("completionStatus", iteration+1);
+ if (iteration++ == 9) {
+ state->killTimer(state->property("timerid").toInt());
+ return QGestureRecognizer::FinishGesture;
+ }
+ state->setProperty("iteration", iteration);
+ return m_feedback ?
+ QGestureRecognizer::TriggerGesture|QGestureRecognizer::ConsumeEventHint :
+ QGestureRecognizer::Ignore|QGestureRecognizer::ConsumeEventHint;
+ }
+ default:
+ break;
+ }
+ return QGestureRecognizer::Ignore;
+}
+
+void TapAndHoldGestureRecognizer::reset(QGesture *q)
+{
+ q->setProperty("completionStatus", 0);
+ q->setProperty("position", QPointF());
+ if (int timerid = q->property("timerid").toInt())
+ q->killTimer(timerid);
+ q->setProperty("timerid", 0);
+ q->setProperty("iteration", 0);
+}
+
+
diff --git a/animals/tapandholdgesturerecognizer.h b/animals/tapandholdgesturerecognizer.h
new file mode 100644
index 0000000..f5e99f3
--- /dev/null
+++ b/animals/tapandholdgesturerecognizer.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef TAPANDHOLDGESTURE_H
+#define TAPANDHOLDGESTURE_H
+
+#include <QtGui>
+
+class TapAndHoldFeedbackGesture : public QGesture
+{
+ Q_OBJECT
+ Q_PROPERTY(int completionStatus READ completionStatus WRITE setCompletionStatus)
+ Q_PROPERTY(QPointF position READ position WRITE setPosition)
+
+public:
+ static Qt::GestureType Type;
+
+ TapAndHoldFeedbackGesture();
+
+ int completionStatus() const;
+ void setCompletionStatus(int value);
+
+ QPointF position() const;
+ void setPosition(const QPointF &value);
+
+private:
+ int m_completionStatus;
+ QPointF m_position;
+ friend class TapAndHoldGestureRecognizer;
+};
+
+class TapAndHoldGestureRecognizer : public QGestureRecognizer
+{
+public:
+ static void registerRecognizer();
+
+private:
+ TapAndHoldGestureRecognizer(bool feedback);
+
+ QGesture *create(QObject *);
+ QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event);
+ void reset(QGesture *q);
+
+ bool m_feedback;
+
+ const static int Timeout = 2000;
+};
+
+#endif
+
diff --git a/animals/tapgesturerecognizer.cpp b/animals/tapgesturerecognizer.cpp
new file mode 100644
index 0000000..9b22ee6
--- /dev/null
+++ b/animals/tapgesturerecognizer.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "tapgesturerecognizer.h"
+
+void TapGestureRecognizer::registerRecognizer()
+{
+ QGestureRecognizer::registerRecognizer(new TapGestureRecognizer);
+}
+
+TapGestureRecognizer::TapGestureRecognizer()
+{
+}
+
+QGesture *TapGestureRecognizer::create(QObject *)
+{
+ return new QTapGesture;
+}
+
+QGestureRecognizer::Result TapGestureRecognizer::recognize(QGesture *state, QObject *watched,
+ QEvent *event)
+{
+ QGraphicsSceneMouseEvent *ev = static_cast<QGraphicsSceneMouseEvent *>(event);
+ switch(event->type()) {
+ case QEvent::GraphicsSceneMousePress:
+ if (!(ev->modifiers() & Qt::ControlModifier)) {
+ state->setProperty("position", ev->screenPos());
+ state->setHotSpot(ev->screenPos());
+ state->setHandled(false);
+ event->accept();
+ return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
+ } else
+ return QGestureRecognizer::Ignore;
+
+ case QEvent::GraphicsSceneMouseMove:
+ return QGestureRecognizer::Ignore;
+
+ case QEvent::GraphicsSceneMouseRelease:
+ qDebug() << "Mouse release: " << state->state();
+ if (state->state() != Qt::GestureStarted) {
+ return QGestureRecognizer::CancelGesture;
+ } else if (state->state() != Qt::GestureCanceled) {
+ return QGestureRecognizer::FinishGesture;
+ }
+ return QGestureRecognizer::Ignore;
+ case QEvent::Gesture: {
+ QGestureEvent *ge = static_cast<QGestureEvent *>(event);
+ QGesture *tap = ge->gesture(Qt::TapGesture);
+ QGesture *pan = ge->gesture(Qt::PanGesture);
+ qDebug() << "got a gesture" << tap << (tap ? tap->state() : 0)
+ << ", " << pan << (pan ? pan->state() : 0);
+ if (ge->gesture(Qt::PanGesture)) {
+ return QGestureRecognizer::CancelGesture;
+ }
+ if (ge->gesture(Qt::TapAndHoldGesture))
+ return QGestureRecognizer::CancelGesture;
+ }
+
+ return QGestureRecognizer::Ignore;
+ default:
+ break;
+ }
+ return QGestureRecognizer::Ignore;
+}
+
+void TapGestureRecognizer::reset(QGesture *q)
+{
+ q->setProperty("position", QPointF());
+}
diff --git a/animals/tapgesturerecognizer.h b/animals/tapgesturerecognizer.h
new file mode 100644
index 0000000..165e236
--- /dev/null
+++ b/animals/tapgesturerecognizer.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef TAPGESTURERECOGNIZER_H
+#define TAPGESTURERECOGNIZER_H
+
+#include <QtGui>
+
+class TapGestureRecognizer : public QGestureRecognizer
+{
+public:
+ static void registerRecognizer();
+
+private:
+ TapGestureRecognizer();
+ QGesture *create(QObject *);
+ QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event);
+ void reset(QGesture *q);
+};
+
+#endif