|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
|
19 * |
|
20 */ |
|
21 |
|
22 #ifndef KineticScroller_h |
|
23 #define KineticScroller_h |
|
24 |
|
25 #include "KineticScrollable.h" |
|
26 |
|
27 #include <QObject> |
|
28 |
|
29 namespace GVA { |
|
30 |
|
31 class KineticScroller : public QObject { |
|
32 Q_OBJECT |
|
33 |
|
34 public : |
|
35 enum OvershootPolicy { |
|
36 OvershootWhenScrollable, |
|
37 OvershootAlwaysOff, |
|
38 OvershootAlwaysOn, |
|
39 }; |
|
40 |
|
41 enum Mode { |
|
42 AutoMode, |
|
43 PushMode |
|
44 }; |
|
45 |
|
46 enum { |
|
47 MotionEventsPerSecond = 25 |
|
48 }; |
|
49 |
|
50 KineticScroller(KineticScrollable* scrollableView); |
|
51 ~KineticScroller(); |
|
52 |
|
53 OvershootPolicy overshootPolicy() const; |
|
54 void setOvershootPolicy(OvershootPolicy policy); |
|
55 |
|
56 qreal decelerationFactor() const; |
|
57 void setDecelerationFactor(qreal f); |
|
58 |
|
59 int scrollsPerSecond() const; |
|
60 void setScrollsPerSecond(int sps); |
|
61 |
|
62 void reset(); |
|
63 void doPan(QPoint delta); |
|
64 void doFlick(QPointF velocity); |
|
65 void stop(); |
|
66 |
|
67 protected: |
|
68 void changeState(KineticScrollable::State newState); |
|
69 void setScrollPositionHelper(const QPoint& point); |
|
70 |
|
71 void handleScrollTimer(); |
|
72 void handleIdleTimer(); |
|
73 void timerEvent(QTimerEvent* ev); |
|
74 |
|
75 private: |
|
76 KineticScrollable* m_scrollableView; |
|
77 |
|
78 Mode m_mode; |
|
79 KineticScrollable::State m_state; |
|
80 |
|
81 QPoint m_motion; |
|
82 bool m_move; |
|
83 |
|
84 // overshoot |
|
85 OvershootPolicy m_overshootPolicy; |
|
86 int m_bounceSteps; |
|
87 QPoint m_maxOvershoot; |
|
88 int m_vmaxOvershoot; |
|
89 QPoint m_overshootDist; |
|
90 int m_overshooting; // the overshooting time in idleTimer steps |
|
91 |
|
92 // velocity |
|
93 QPointF m_velocity; |
|
94 qreal m_minVelocity; |
|
95 qreal m_maxVelocity; |
|
96 qreal m_deceleration; |
|
97 int m_scrollsPerSecond; |
|
98 |
|
99 // timer |
|
100 int m_idleTimerId; |
|
101 int m_scrollTimerId; |
|
102 int m_inactivityTimerId; |
|
103 };//KineticScroller |
|
104 |
|
105 }//namespace GVA |
|
106 |
|
107 #endif //KineticScroller_h |