From e1400d3bd15a1d86c51b05a88a79188fc1c785d4 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Wed, 21 Jul 2010 19:16:47 +0200 Subject: add animal pieces example for gestures --- animals/Animal.qml | 183 +++++++++++++++++++++ animals/animals.pro | 29 ++++ animals/animals.qml | 47 ++++++ animals/images/Andy_ant.png | Bin 0 -> 11944 bytes animals/images/ArtFavor_Cartoon_Sheep.png | Bin 0 -> 18879 bytes animals/images/ArtFavor_Sheep_(Ewe).png | Bin 0 -> 30354 bytes animals/images/PeterM_Angry_black_panther.png | Bin 0 -> 17613 bytes animals/images/PeterM_Bee.png | Bin 0 -> 25503 bytes animals/images/PeterM_Housefly.png | Bin 0 -> 31738 bytes animals/images/PeterM_Penguin_with_a_shirt.png | Bin 0 -> 12432 bytes animals/images/PeterM_Sad_cat.png | Bin 0 -> 19364 bytes animals/images/TheresaKnott_frog.png | Bin 0 -> 16981 bytes animals/images/johnny_automatic_chicken.png | Bin 0 -> 14869 bytes animals/images/johnny_automatic_cow.png | Bin 0 -> 12037 bytes animals/images/johnny_automatic_cow_1.png | Bin 0 -> 17520 bytes animals/images/johnny_automatic_hare_and_tabor.png | Bin 0 -> 23699 bytes .../images/johnny_automatic_horse_silhouette.png | Bin 0 -> 9580 bytes animals/images/johnny_automatic_startled_bears.png | Bin 0 -> 64255 bytes animals/images/johnny_automatic_turkey.png | Bin 0 -> 39701 bytes .../images/lakeside_witch_over_harvest_moon.png | Bin 0 -> 13113 bytes animals/images/lemmling_Cartoon_cow.png | Bin 0 -> 24077 bytes animals/images/liftarn_Ddraig.png | Bin 0 -> 8181 bytes animals/images/liftarn_Owl_on_book.png | Bin 0 -> 11975 bytes animals/images/liftarn_Taun_taun.png | Bin 0 -> 16688 bytes animals/images/obi_Dragon_s_head.png | Bin 0 -> 10346 bytes animals/images/qt-logo.png | Bin 0 -> 28187 bytes animals/images/rejon_Ant_Icon.png | Bin 0 -> 8718 bytes animals/main.cpp | 51 ++++++ animals/mainwindow.cpp | 31 ++++ animals/mainwindow.h | 19 +++ animals/pangesturerecognizer.cpp | 100 +++++++++++ animals/pangesturerecognizer.h | 58 +++++++ animals/pinchgesturerecognizer.cpp | 109 ++++++++++++ animals/pinchgesturerecognizer.h | 58 +++++++ animals/swipegesturerecognizer.cpp | 97 +++++++++++ animals/swipegesturerecognizer.h | 58 +++++++ animals/tapandholdgesturerecognizer.cpp | 159 ++++++++++++++++++ animals/tapandholdgesturerecognizer.h | 87 ++++++++++ animals/tapgesturerecognizer.cpp | 106 ++++++++++++ animals/tapgesturerecognizer.h | 58 +++++++ 40 files changed, 1250 insertions(+) create mode 100755 animals/Animal.qml create mode 100644 animals/animals.pro create mode 100644 animals/animals.qml create mode 100644 animals/images/Andy_ant.png create mode 100644 animals/images/ArtFavor_Cartoon_Sheep.png create mode 100644 animals/images/ArtFavor_Sheep_(Ewe).png create mode 100644 animals/images/PeterM_Angry_black_panther.png create mode 100644 animals/images/PeterM_Bee.png create mode 100644 animals/images/PeterM_Housefly.png create mode 100644 animals/images/PeterM_Penguin_with_a_shirt.png create mode 100644 animals/images/PeterM_Sad_cat.png create mode 100644 animals/images/TheresaKnott_frog.png create mode 100644 animals/images/johnny_automatic_chicken.png create mode 100644 animals/images/johnny_automatic_cow.png create mode 100644 animals/images/johnny_automatic_cow_1.png create mode 100644 animals/images/johnny_automatic_hare_and_tabor.png create mode 100644 animals/images/johnny_automatic_horse_silhouette.png create mode 100644 animals/images/johnny_automatic_startled_bears.png create mode 100644 animals/images/johnny_automatic_turkey.png create mode 100644 animals/images/lakeside_witch_over_harvest_moon.png create mode 100644 animals/images/lemmling_Cartoon_cow.png create mode 100644 animals/images/liftarn_Ddraig.png create mode 100644 animals/images/liftarn_Owl_on_book.png create mode 100644 animals/images/liftarn_Taun_taun.png create mode 100644 animals/images/obi_Dragon_s_head.png create mode 100644 animals/images/qt-logo.png create mode 100644 animals/images/rejon_Ant_Icon.png create mode 100755 animals/main.cpp create mode 100755 animals/mainwindow.cpp create mode 100755 animals/mainwindow.h create mode 100644 animals/pangesturerecognizer.cpp create mode 100644 animals/pangesturerecognizer.h create mode 100644 animals/pinchgesturerecognizer.cpp create mode 100644 animals/pinchgesturerecognizer.h create mode 100644 animals/swipegesturerecognizer.cpp create mode 100644 animals/swipegesturerecognizer.h create mode 100644 animals/tapandholdgesturerecognizer.cpp create mode 100644 animals/tapandholdgesturerecognizer.h create mode 100644 animals/tapgesturerecognizer.cpp create mode 100644 animals/tapgesturerecognizer.h 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 Binary files /dev/null and b/animals/images/Andy_ant.png differ diff --git a/animals/images/ArtFavor_Cartoon_Sheep.png b/animals/images/ArtFavor_Cartoon_Sheep.png new file mode 100644 index 0000000..e081e23 Binary files /dev/null and b/animals/images/ArtFavor_Cartoon_Sheep.png differ diff --git a/animals/images/ArtFavor_Sheep_(Ewe).png b/animals/images/ArtFavor_Sheep_(Ewe).png new file mode 100644 index 0000000..141838c Binary files /dev/null and b/animals/images/ArtFavor_Sheep_(Ewe).png 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 Binary files /dev/null and b/animals/images/PeterM_Angry_black_panther.png differ diff --git a/animals/images/PeterM_Bee.png b/animals/images/PeterM_Bee.png new file mode 100644 index 0000000..f7fe23d Binary files /dev/null and b/animals/images/PeterM_Bee.png differ diff --git a/animals/images/PeterM_Housefly.png b/animals/images/PeterM_Housefly.png new file mode 100644 index 0000000..b2bf56f Binary files /dev/null and b/animals/images/PeterM_Housefly.png 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 Binary files /dev/null and b/animals/images/PeterM_Penguin_with_a_shirt.png differ diff --git a/animals/images/PeterM_Sad_cat.png b/animals/images/PeterM_Sad_cat.png new file mode 100644 index 0000000..323d6a6 Binary files /dev/null and b/animals/images/PeterM_Sad_cat.png differ diff --git a/animals/images/TheresaKnott_frog.png b/animals/images/TheresaKnott_frog.png new file mode 100644 index 0000000..5dea82a Binary files /dev/null and b/animals/images/TheresaKnott_frog.png differ diff --git a/animals/images/johnny_automatic_chicken.png b/animals/images/johnny_automatic_chicken.png new file mode 100644 index 0000000..f9efebc Binary files /dev/null and b/animals/images/johnny_automatic_chicken.png differ diff --git a/animals/images/johnny_automatic_cow.png b/animals/images/johnny_automatic_cow.png new file mode 100644 index 0000000..31db8ec Binary files /dev/null and b/animals/images/johnny_automatic_cow.png 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 Binary files /dev/null and b/animals/images/johnny_automatic_cow_1.png 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 Binary files /dev/null and b/animals/images/johnny_automatic_hare_and_tabor.png 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 Binary files /dev/null and b/animals/images/johnny_automatic_horse_silhouette.png 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 Binary files /dev/null and b/animals/images/johnny_automatic_startled_bears.png differ diff --git a/animals/images/johnny_automatic_turkey.png b/animals/images/johnny_automatic_turkey.png new file mode 100644 index 0000000..2a2e94e Binary files /dev/null and b/animals/images/johnny_automatic_turkey.png 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 Binary files /dev/null and b/animals/images/lakeside_witch_over_harvest_moon.png differ diff --git a/animals/images/lemmling_Cartoon_cow.png b/animals/images/lemmling_Cartoon_cow.png new file mode 100644 index 0000000..476bd38 Binary files /dev/null and b/animals/images/lemmling_Cartoon_cow.png differ diff --git a/animals/images/liftarn_Ddraig.png b/animals/images/liftarn_Ddraig.png new file mode 100644 index 0000000..9c233a6 Binary files /dev/null and b/animals/images/liftarn_Ddraig.png 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 Binary files /dev/null and b/animals/images/liftarn_Owl_on_book.png differ diff --git a/animals/images/liftarn_Taun_taun.png b/animals/images/liftarn_Taun_taun.png new file mode 100644 index 0000000..458dfc6 Binary files /dev/null and b/animals/images/liftarn_Taun_taun.png 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 Binary files /dev/null and b/animals/images/obi_Dragon_s_head.png differ diff --git a/animals/images/qt-logo.png b/animals/images/qt-logo.png new file mode 100644 index 0000000..b9eed00 Binary files /dev/null and b/animals/images/qt-logo.png differ diff --git a/animals/images/rejon_Ant_Icon.png b/animals/images/rejon_Ant_Icon.png new file mode 100644 index 0000000..938ba32 Binary files /dev/null and b/animals/images/rejon_Ant_Icon.png 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 +#include "mainwindow.h" + + +#include +#include + +#include +#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("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 +#include + +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 + +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(state); + QGraphicsSceneMouseEvent *ev = static_cast(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(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 + +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(state); + QGraphicsSceneMouseEvent *ev = static_cast(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(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 + +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(state); + QGraphicsSceneMouseEvent *ev = static_cast(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(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 + +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(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 + +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(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(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 + +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 -- cgit v1.2.3