From ed24f677a411c449a2a3f862906aff2a313b4425 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Fri, 6 Mar 2009 18:49:56 +0100 Subject: Added animation to zooming gesture in collidingmice example. --- .../collidingmice/gesturerecognizerlinjazax.cpp | 7 ++--- examples/gestures/collidingmice/main.cpp | 35 ++++++++++++++++++++++ 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 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 +#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" -- cgit v0.12