LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
KineticScroller.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2010-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef KINETIC_SCROLLER_H_
23 #define KINETIC_SCROLLER_H_
24 
25 #include <QObject>
26 #include <QTimer>
27 #include <QTime>
28 #include <QEasingCurve>
29 #include <QPointer>
30 #include <QTextStream>
31 #include <QFile>
32 
33 #include <limits>
34 
35 QT_BEGIN_NAMESPACE
36 class QPropertyAnimation;
37 QT_END_NAMESPACE
38 
39 class KineticScroller : public QObject
40 {
41  Q_OBJECT
42  Q_PROPERTY(qreal scrollOffset READ scrollOffset WRITE setScrollOffset)
43 Q_SIGNALS:
44  void scrolled(qreal oldScroll);
45 
46 public:
47  KineticScroller(qreal minValue = -std::numeric_limits<qreal>::infinity(),
48  qreal maxValue = std::numeric_limits<qreal>::infinity());
50 
51  void setMaxOverscroll(qreal overscroll);
52  void setMinValue(qreal minValue);
53  void setMaxValue(qreal maxValue);
54 
55  qreal scrollOffset() const;
56  qreal getMinScrollValue() const;
57  void scrollBy(qreal offset);
58 
59  void setScrollOffset(qreal offset);
60 
61  void handleFlick(qreal velocity);
62  void handleMouseDown();
63  void handleMouseUp();
64  void stopImmediately();
65  void correctOverscroll();
66 
67  bool animatingFlick() const;
68 
69 private Q_SLOTS:
70  void flickAnimationTick();
71  void overscrollTrigger();
72  void flickTransitionToOverscroll();
73  void stopFlickAnimation();
74 
75 private:
76  enum FlickState {
77  FlickNormal,
78  FlickOverScroll,
79  FlickOverscrollCorrection,
80  };
81 
82  enum FlickDirection {
83  FlickUp = 1,
84  FlickDown = -1,
85  };
86 
87  static FlickDirection direction(qreal x)
88  {
89  return x >= 0 ? FlickUp : FlickDown;
90  }
91 
92  void zizz(qreal inV);
93  bool inOverscroll() const;
94  bool inOverscroll(qreal scrollOffset) const;
95  void checkUserActionOnOverscroll();
96 
97  qreal amountInOverscroll() const;
98  qreal instantaneousVelocity() const;
99  qreal easingCubicCoEfficient(qreal index) const;
100 
101  QTimer m_flickAnimationTimer;
102  QTimer m_flickFilter;
103  QTimer m_overscroll;
104  QTime m_clock;
105  QEasingCurve m_easing;
106  qreal m_minScroll;
107  qreal m_maxScroll;
108  qreal m_maxOverscroll;
109  qreal m_scrollOffset;
110  //static qreal m_scrollOffsetChecker;
111  qreal m_previousVelocity;
112  qreal m_accumulatedScroll;
113  QPointer<QPropertyAnimation> m_flickAnimation;
114  QPointer<QPropertyAnimation> m_flickOverscrollAnimation;
115  QPointer<QPropertyAnimation> m_overscrollAnimation;
116  FlickDirection m_flickEventDirection;
117  FlickState m_flickState;
118  qreal m_flickVelocity;
119  qreal m_friction;
120  qreal m_restoreForce;
121  qreal m_flickStopOffset;
122  qreal m_tRegularScrollingTime;
123  qreal m_s0;
124  qreal m_sp;
125  qreal m_s1;
126  qreal m_sReferenceTime;
127  qreal m_sReferenceTime1;
128  qreal m_v0;
129  qreal m_overScrollCorrectionStart;
130  bool m_BypassOverScrollInfo;
131  bool m_OverScrollCorrectionInterrupted;
132 #if TRACE_SCROLLER
133  QFile m_plotFile;
134  QFile m_plotFile2;
135  QTextStream *m_plot;
136  QTextStream *m_plotMouse;
137 #endif
138  bool m_flickAnimationTimerActive;
139 };
140 
141 #endif
142