Detecting when overshut animation should be done.
[kineticlist.git] / kineticscroll.cpp
blobed120f848aae8eca3389aed6f075eea7ecc90fe9
1 /////////////////////////////////////////////////////////////////////////
2 // kineticscroll.cpp //
3 // //
4 // Copyright(C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>//
5 // Copyright(C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>//
6 // //
7 // This library is free software; you can redistribute it and/or //
8 // modify it under the terms of the GNU Lesser General Public //
9 // License as published by the Free Software Foundation; either //
10 // version 2.1 of the License, or (at your option) any later version. //
11 // //
12 // This library is distributed in the hope that it will be useful, //
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
15 // Lesser General Public License for more details. //
16 // //
17 // You should have received a copy of the GNU Lesser General Public //
18 // License along with this library; if not, write to the Free Software //
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA //
20 // 02110-1301 USA //
21 /////////////////////////////////////////////////////////////////////////
22 #include "kineticscroll.h"
24 #include <QDebug>
26 void KineticScrollingPrivate::count()
28 t = QTime::currentTime();
29 t.start();
32 unsigned int KineticScrollingPrivate::elapsed()
34 return t.restart();
37 KineticScrolling::KineticScrolling(): d( 0 )
39 d = new KineticScrollingPrivate;
42 KineticScrolling::~KineticScrolling()
44 delete d;
47 int KineticScrolling::movement()
49 return d->movement;
52 int KineticScrolling::kin_movement()
54 return d->kin_movement;
57 qreal KineticScrolling::duration()
59 return d->timeDelta;
62 void KineticScrolling::mousePressEvent( QGraphicsSceneMouseEvent *event )
64 d->count();
65 d->scrollVelocity = 0;
66 d->movement = 0;
67 d->kin_movement = 0;
70 void KineticScrolling::mouseMoveEvent( QGraphicsSceneMouseEvent *event )
72 int temp = event->lastPos().y() - event->pos().y();
73 if ( temp ) {
74 d->movement = temp;
75 d->kin_movement += temp;
79 void KineticScrolling::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
81 d->timeDelta = d->elapsed();
82 int temp = event->lastPos().y() - event->pos().y();
83 if ( temp )
84 d->kin_movement += temp;
86 if ( d->timeDelta > 200) {
87 if ( d->kin_movement > 0 )
88 d->kin_movement = 3;
89 else
90 d->kin_movement = -3;