From 8956b2ba6d5e3af1804ba03a1fd290bf3bf0c81c Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Fri, 6 Aug 2010 13:21:24 +0200 Subject: Add Flickable and changes in gesture recognizers. --- animals/Animal.qml | 50 ++++++++++++++++++++++++----------- animals/animals.qml | 57 +++++++++++++++++++++++++++++++++++++--- animals/main.cpp | 15 ++++++----- animals/pangesturerecognizer.cpp | 8 ++++++ animals/tapgesturerecognizer.cpp | 14 +++++++--- 5 files changed, 115 insertions(+), 29 deletions(-) (limited to 'animals') diff --git a/animals/Animal.qml b/animals/Animal.qml index 26139ff..784a1bd 100755 --- a/animals/Animal.qml +++ b/animals/Animal.qml @@ -73,6 +73,19 @@ Rectangle { } } +/* + z:20 + MouseArea { + anchors.fill: parent; + + onClicked: { + console.log("mouse clickety click"); + animalRectangle.toggleSide(); + } + z:20 + } +*/ + GestureArea { anchors.fill: parent @@ -84,7 +97,6 @@ Rectangle { animalRectangle.scale = 1.1; } } - Tap { when: gesture.state == Qt.GestureCanceled script: { console.log("tap canceled"); @@ -117,10 +129,11 @@ Rectangle { script: { console.log("pan started"); } } - Pan { when: gesture.state == Qt.GestureUpdated - script: { //console.log("pan update"); + script: { + //console.log("pan update dx:" + gesture.delta.x + " dy: " + gesture.delta.y + // + " ox: " + gesture.offset.x); animalRectangle.scale = 0.8; //animalRectangle.x += gesture.offset.x; animalRectangle.opacity = 0.7; @@ -128,20 +141,15 @@ Rectangle { 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 ); - + script: { console.log("pan finished"); 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"); @@ -149,18 +157,30 @@ Rectangle { } Swipe { when: gesture.state == Qt.GestureFinished - && gesture.horizontalDirection == QSwipeGesture.Left - script: { console.log("swipe left"); + //&& gesture.horizontalDirection == QSwipeGesture.Left + script: { console.log("swipe finished"); //animalRectangle.x -= (animalRectangle.width+5); } } + */ + /* + + PanSwipe { + when: gesture.state == Qt.GestureStarted + script: { console.log("I can haz custom gesture!"); } + } + PanSwipe { + when: gesture.state == Qt.GestureFinished + script: { console.log("I can haz custom gesture!"); } + } + */ + /* Swipe { when: gesture.state == Qt.GestureFinished - && gesture.horizontalDirection == QSwipeGesture.Right + //&& gesture.horizontalDirection == QSwipeGesture.Right script: { console.log("swipe right"); //animalRectangle.x += (animalRectangle.width+5); } - } -*/ + }*/ } } diff --git a/animals/animals.qml b/animals/animals.qml index 58c68b6..0477cf8 100644 --- a/animals/animals.qml +++ b/animals/animals.qml @@ -5,12 +5,63 @@ Rectangle { width: 520 height: 500 - Flickable { - //Rectangle { +/* + GestureArea { + anchors.fill: parent + + Tap { + when: gesture.state == Qt.GestureStarted + script: { console.log("tap wallpaper started"); + + } + } + + Pan { + when: gesture.state == Qt.GestureStarted + script: { console.log("pan wallpaper started"); + } + } + Pan { + when: gesture.state == Qt.GestureUpdated + script: { + //console.log("pan update dx:" + gesture.delta.x + " dy: " + gesture.delta.y + // + " ox: " + gesture.offset.x); + } + } + Pan { + when: gesture.state == Qt.GestureFinished + script: { console.log("pan finished"); + } + } + } +*/ + +Flickable { contentWidth: parent.width*3; contentHeight: parent.height*3; id: flickable width: parent.width height: parent.height - contentHeight: parent.height*3 + + Text { + id: bottomleft; + text: "(0," + parent.height + ")"; + anchors.bottom: parent.bottom; + anchors.left: parent.left; + z: 2; + } + Text { + id: bottomright; + text: "(" + parent.width + "," + parent.height + ")"; + anchors.bottom: parent.bottom; + anchors.right: parent.right; + z: 2; + } + Text { + id: topright; + text: "(" + parent.width + ",0)"; + anchors.top: parent.top; + anchors.right: parent.right; + z: 2; + } Rectangle { id: contentRect diff --git a/animals/main.cpp b/animals/main.cpp index 6469fdb..888cfd3 100755 --- a/animals/main.cpp +++ b/animals/main.cpp @@ -14,6 +14,7 @@ #include "tapgesturerecognizer.h" #include "tapandholdgesturerecognizer.h" #include "swipegesturerecognizer.h" + #endif int main(int argc, char *argv[]) @@ -24,28 +25,28 @@ int main(int argc, char *argv[]) #if defined(Q_OS_LINUX) - QGestureRecognizer::unregisterRecognizer(Qt::PanGesture); - PanGestureRecognizer::registerRecognizer(); + // Qt Gestures QGestureRecognizer::unregisterRecognizer(Qt::TapGesture); TapGestureRecognizer::registerRecognizer(); - QGestureRecognizer::unregisterRecognizer(Qt::TapAndHoldGesture); - TapAndHoldGestureRecognizer::registerRecognizer(); QGestureRecognizer::unregisterRecognizer(Qt::PinchGesture); PinchGestureRecognizer::registerRecognizer(); SwipeGestureRecognizer::registerRecognizer(); + + QGestureRecognizer::unregisterRecognizer(Qt::TapAndHoldGesture); + TapAndHoldGestureRecognizer::registerRecognizer(); + QGestureRecognizer::unregisterRecognizer(Qt::PanGesture); + PanGestureRecognizer::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/pangesturerecognizer.cpp b/animals/pangesturerecognizer.cpp index b2be0a3..2c936bf 100644 --- a/animals/pangesturerecognizer.cpp +++ b/animals/pangesturerecognizer.cpp @@ -47,6 +47,7 @@ void PanGestureRecognizer::registerRecognizer() PanGestureRecognizer::PanGestureRecognizer() { + qDebug() << "creating PanGestureRecognizer (Qt)"; } QGesture *PanGestureRecognizer::create(QObject *) @@ -76,6 +77,13 @@ QGestureRecognizer::Result PanGestureRecognizer::recognize(QGesture *state, QObj QPoint delta = ev->screenPos() - state->property("startPos").toPoint(); q->setLastOffset(q->offset()); q->setOffset(delta); + + if (delta.manhattanLength() < 50) { + return QGestureRecognizer::MayBeGesture; + } + + //qDebug() << "PanGestureRecognizer::recognize trigger"; + return QGestureRecognizer::TriggerGesture; } return QGestureRecognizer::Ignore; diff --git a/animals/tapgesturerecognizer.cpp b/animals/tapgesturerecognizer.cpp index 9b22ee6..f31115b 100644 --- a/animals/tapgesturerecognizer.cpp +++ b/animals/tapgesturerecognizer.cpp @@ -47,6 +47,7 @@ void TapGestureRecognizer::registerRecognizer() TapGestureRecognizer::TapGestureRecognizer() { + qDebug() << "creating TapGestureRecognizer (Qt)"; } QGesture *TapGestureRecognizer::create(QObject *) @@ -64,7 +65,10 @@ QGestureRecognizer::Result TapGestureRecognizer::recognize(QGesture *state, QObj state->setProperty("position", ev->screenPos()); state->setHotSpot(ev->screenPos()); state->setHandled(false); - event->accept(); + //event->accept(); + qDebug() << "TapGestureRecognizer::recognize: trigger gesture" << watched; + + return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint; } else return QGestureRecognizer::Ignore; @@ -80,14 +84,16 @@ QGestureRecognizer::Result TapGestureRecognizer::recognize(QGesture *state, QObj 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); + //qDebug() << "TapGestureRecognizer::recognize got a gesture" << tap << (tap ? tap->state() : 0) + // << ", " << pan << (pan ? pan->state() : 0); if (ge->gesture(Qt::PanGesture)) { - return QGestureRecognizer::CancelGesture; + //return QGestureRecognizer::CancelGesture; + return QGestureRecognizer::Ignore; } if (ge->gesture(Qt::TapAndHoldGesture)) return QGestureRecognizer::CancelGesture; -- cgit v1.2.3