summaryrefslogtreecommitdiffstats
path: root/examples/gestures/collidingmice
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-03-06 17:49:56 (GMT)
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-05-11 13:42:40 (GMT)
commited24f677a411c449a2a3f862906aff2a313b4425 (patch)
treefd63f0fe7c1c4d12331a9e154c1d6058ed020d85 /examples/gestures/collidingmice
parent90ead023ec593bd3dba0ef8eb4e38f2299cfb783 (diff)
downloadQt-ed24f677a411c449a2a3f862906aff2a313b4425.zip
Qt-ed24f677a411c449a2a3f862906aff2a313b4425.tar.gz
Qt-ed24f677a411c449a2a3f862906aff2a313b4425.tar.bz2
Added animation to zooming gesture in collidingmice example.
Diffstat (limited to 'examples/gestures/collidingmice')
-rw-r--r--examples/gestures/collidingmice/gesturerecognizerlinjazax.cpp7
-rw-r--r--examples/gestures/collidingmice/main.cpp35
2 files changed, 38 insertions, 4 deletions
diff --git a/examples/gestures/collidingmice/gesturerecognizerlinjazax.cpp b/examples/gestures/collidingmice/gesturerecognizerlinjazax.cpp
index 4c57209..3f90588 100644
--- a/examples/gestures/collidingmice/gesturerecognizerlinjazax.cpp
+++ b/examples/gestures/collidingmice/gesturerecognizerlinjazax.cpp
@@ -125,14 +125,13 @@ QGestureRecognizer::Result GestureRecognizerLinjaZax::recognize(const QList<QEve
result = QGestureRecognizer::GestureStarted;
}
if (!direction.isEmpty()) {
- if (currentDirection != direction)
- lastDirections.append(direction);
+ lastDirections.append(direction);
currentDirection = direction;
if (lastDirections.length() > 5)
lastDirections.remove(0, 1);
- if (lastDirections.contains("248"))
+ if (lastDirections.contains("248") || lastDirections.contains("2448"))
zoomState = LinjaZaxGesture::ZoomingIn;
- else if (lastDirections.contains("268"))
+ else if (lastDirections.contains("268") || lastDirections.contains("2668"))
zoomState = LinjaZaxGesture::ZoomingOut;
}
}
diff --git a/examples/gestures/collidingmice/main.cpp b/examples/gestures/collidingmice/main.cpp
index 9f50379..d6dbdb0 100644
--- a/examples/gestures/collidingmice/main.cpp
+++ b/examples/gestures/collidingmice/main.cpp
@@ -48,15 +48,26 @@
#include <math.h>
+#define ZOOMING_ANIMATION
+#ifdef ZOOMING_ANIMATION
+static const int AnimationSteps = 10;
+#endif
+
static const int MouseCount = 7;
class PannableGraphicsView : public QGraphicsView
{
+ Q_OBJECT
public:
PannableGraphicsView(QGraphicsScene *scene, QWidget *parent = 0)
: QGraphicsView(scene, parent)
{
grabGesture("LinjaZax");
+#ifdef ZOOMING_ANIMATION
+ timeline = new QTimeLine(700, this);
+ timeline->setFrameRange(0, AnimationSteps);
+ connect(timeline, SIGNAL(frameChanged(int)), this, SLOT(animationStep(int)));
+#endif
}
protected:
bool event(QEvent *event)
@@ -67,10 +78,22 @@ protected:
if (g) {
switch (g->zoomState()) {
case LinjaZaxGesture::ZoomingIn:
+#ifdef ZOOMING_ANIMATION
+ scaleStep = 1. + 0.5/AnimationSteps;
+ timeline->stop();
+ timeline->start();
+#else
scale(1.5, 1.5);
+#endif
break;
case LinjaZaxGesture::ZoomingOut:
+#ifdef ZOOMING_ANIMATION
+ scaleStep = 1. - 0.5/AnimationSteps;
+ timeline->stop();
+ timeline->start();
+#else
scale(0.6, 0.6);
+#endif
break;
default:
break;
@@ -84,6 +107,16 @@ protected:
}
return QGraphicsView::event(event);
}
+private slots:
+#ifdef ZOOMING_ANIMATION
+ void animationStep(int step)
+ {
+ scale(scaleStep, scaleStep);
+ }
+private:
+ qreal scaleStep;
+ QTimeLine *timeline;
+#endif
};
//! [0]
@@ -127,3 +160,5 @@ int main(int argc, char **argv)
return app.exec();
}
//! [6]
+
+#include "main.moc"