|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbCore module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #ifndef HBSCROLLAREA_P_H |
|
27 #define HBSCROLLAREA_P_H |
|
28 |
|
29 // |
|
30 // W A R N I N G |
|
31 // ------------- |
|
32 // |
|
33 // This file is not part of the Qt API. It exists purely as an |
|
34 // implementation detail. This header file may change from version to |
|
35 // version without notice, or even be removed. |
|
36 // |
|
37 // We mean it. |
|
38 // |
|
39 |
|
40 #include "hbscrollarea.h" |
|
41 #include <hbwidget_p.h> |
|
42 |
|
43 #include <QTimer> |
|
44 #include <QTime> |
|
45 |
|
46 class HbGestureSceneFilter; |
|
47 class HbScrollBar; |
|
48 class QEasingCurve; |
|
49 |
|
50 class HB_CORE_PRIVATE_EXPORT HbScrollAreaPrivate: public HbWidgetPrivate |
|
51 { |
|
52 Q_DECLARE_PUBLIC( HbScrollArea ) |
|
53 |
|
54 public: |
|
55 HbScrollAreaPrivate(); |
|
56 virtual ~HbScrollAreaPrivate(); |
|
57 |
|
58 void init(); |
|
59 void doLazyInit(); |
|
60 |
|
61 bool mScrollFeedbackOngoing; |
|
62 bool mBoundaryReached; |
|
63 virtual void updateScrollBar(Qt::Orientation orientation); |
|
64 void displayScrollBar(Qt::Orientation orientation); |
|
65 |
|
66 void setScrollBarPolicy(Qt::Orientation orientation, HbScrollArea::ScrollBarPolicy policy); |
|
67 void replaceScrollBar(Qt::Orientation orientation, HbScrollBar *scrollBar); |
|
68 |
|
69 void changeLayoutDirection(Qt::LayoutDirection aNewDirection); |
|
70 |
|
71 void updateGestures(); |
|
72 |
|
73 // returns true if it was able to scroll in either direction |
|
74 bool scrollByAmount(const QPointF& delta); |
|
75 |
|
76 void startAnimating(); |
|
77 void stopAnimating(); |
|
78 virtual void stopScrolling(); |
|
79 |
|
80 void animateScroll(QPointF speed); // speed in pixels per millisecond |
|
81 |
|
82 qreal calculateVelocity ( qreal timeDifference, qreal curVelocity, qreal pos, qreal min, qreal max ); |
|
83 bool clampToBoundaries ( qreal& deltaRef, qreal pos, qreal min, qreal max ); |
|
84 |
|
85 void addPositionToQueue(const QPointF& position, qreal time, |
|
86 bool isRelative); |
|
87 virtual void setScrollBarMetrics(Qt::Orientation orientation); |
|
88 // private slot functions |
|
89 void _q_animateScrollTimeout(); |
|
90 void _q_hideScrollBars(); |
|
91 void _q_thumbPositionChanged(qreal value, Qt::Orientation orientation); |
|
92 void _q_groovePressed(qreal value, Qt::Orientation orientation); |
|
93 |
|
94 //void bounceBackValueChanged(qreal value); |
|
95 virtual void updateScrollMetrics(); |
|
96 void prepareScrollBars(); |
|
97 |
|
98 void setContentPosition( const QPointF &newPosition ); |
|
99 |
|
100 bool sceneEvent(QEvent *event); |
|
101 |
|
102 bool positionOutOfBounds (); |
|
103 |
|
104 void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
105 void mouseReleaseEvent(QGraphicsSceneMouseEvent * event); |
|
106 void adjustContent(); |
|
107 |
|
108 virtual void ensureVisible(QPointF position, qreal xMargin, qreal yMargin); |
|
109 |
|
110 void startTargetAnimation (QPointF delta, const int time); |
|
111 |
|
112 void createPrimitives(); |
|
113 void updatePrimitives(); |
|
114 void updateIndicators(QPointF newPosition); |
|
115 |
|
116 void hideChildComponents(); |
|
117 void orientationChanged(); |
|
118 |
|
119 virtual void setContentPosition( qreal value, Qt::Orientation orientation, bool animate ); |
|
120 |
|
121 virtual qreal topBoundary () |
|
122 { |
|
123 return mContents->boundingRect().top(); |
|
124 } |
|
125 virtual qreal bottomBoundary () |
|
126 { |
|
127 Q_Q ( HbScrollArea ); |
|
128 return mContents->boundingRect().bottom() - q->boundingRect().height(); |
|
129 } |
|
130 virtual qreal leftBoundary () |
|
131 { |
|
132 return mContents->boundingRect().left(); |
|
133 } |
|
134 virtual qreal rightBoundary () |
|
135 { |
|
136 Q_Q ( HbScrollArea ); |
|
137 return mContents->boundingRect().right() - q->boundingRect().width(); |
|
138 } |
|
139 |
|
140 // HbScrollAreaPrivate data |
|
141 QGraphicsWidget* mContents; |
|
142 // We need our own copy of this in order to pass it to the animation state machines |
|
143 // valid during animation |
|
144 QPointF mScrollPosition; |
|
145 |
|
146 Qt::Orientations mScrollDirections; |
|
147 |
|
148 HbGestureSceneFilter* mGestureFilter; |
|
149 |
|
150 HbScrollBar* mHorizontalScrollBar; |
|
151 HbScrollBar* mVerticalScrollBar; |
|
152 |
|
153 HbScrollArea::ScrollBarPolicy mVerticalScrollBarPolicy; |
|
154 HbScrollArea::ScrollBarPolicy mHorizontalScrollBarPolicy; |
|
155 |
|
156 bool mAbleToScrollX; |
|
157 bool mAbleToScrollY; |
|
158 |
|
159 bool mIsScrolling; |
|
160 bool mIsAnimating; |
|
161 |
|
162 QPointF mScrollSpeed; // in pixels per ms |
|
163 QTimer mScrollTimer; |
|
164 QTime mScrollElapsedTime; |
|
165 qreal mLastElapsedTime; |
|
166 |
|
167 bool mTargetAnimationInProgress; |
|
168 qreal mElapsedTimeInAnimation; |
|
169 qreal mOverallTimeToTarget; |
|
170 QPointF mTargetDelta; |
|
171 QPointF mAnimationInitialPosition; |
|
172 QEasingCurve* mAnimationShape; |
|
173 |
|
174 QTimer mScrollBarHideTimer; |
|
175 |
|
176 bool mFrictionEnabled; |
|
177 bool mScrollbarVisible; |
|
178 |
|
179 HbScrollArea::ClampingStyle mClampingStyle; |
|
180 HbScrollArea::ScrollingStyle mScrollingStyle; |
|
181 |
|
182 bool mHandleLongPress; |
|
183 |
|
184 bool mOrientationChanged; |
|
185 |
|
186 // TODO/Q: All circular array related members could go |
|
187 // to circular array class if so wanted. |
|
188 |
|
189 // circular array to keep track of last N event positions |
|
190 // this is used to compute the velocity at the end |
|
191 // of a panning action when the scrollingStyle is PanFollowOn |
|
192 QTime mDragElapsedTime; |
|
193 QPointF mEventPositionQueue[10]; |
|
194 qreal mEventTimeQueue[10]; |
|
195 uint mEventPositionQueueSize; |
|
196 uint mEventPositionQueueLastIndex; |
|
197 bool mEventPositionQueueIsFull; |
|
198 Qt::LayoutDirection mLayoutDirection; |
|
199 #if 0 |
|
200 QTime *mFlickTimer; |
|
201 Qt::DirectionType mPanDirection; |
|
202 #endif //HB_NEW_GESTURE_FW |
|
203 |
|
204 Qt::Alignment mAlignment; |
|
205 bool mContinuationIndicators; |
|
206 QGraphicsItem *continuationIndicatorTopItem; |
|
207 QGraphicsItem *continuationIndicatorBottomItem; |
|
208 QGraphicsItem *continuationIndicatorLeftItem; |
|
209 QGraphicsItem *continuationIndicatorRightItem; |
|
210 |
|
211 private: |
|
212 // Private access for the fute application to enable setting tweaking |
|
213 // should be removed at some point |
|
214 static HbScrollAreaPrivate *d_ptr(HbScrollArea *scrollArea) { |
|
215 Q_ASSERT(scrollArea); |
|
216 return scrollArea->d_func(); |
|
217 } |
|
218 friend class ParameterTweakerWidget; |
|
219 |
|
220 // Tweakable settings |
|
221 qreal mSpeedFactor; |
|
222 qreal mInertiaSpeedFactor; |
|
223 qreal mMaxScrollSpeed; |
|
224 qreal mSpringStrength; |
|
225 qreal mSpringDampingFactor; |
|
226 qreal mFrictionPerMilliSecond; |
|
227 bool mMultiFlickEnabled; |
|
228 |
|
229 }; |
|
230 |
|
231 #endif // HBSCROLLAREA_P_H |