Remove commit headers
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickflickable_p_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General 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 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQUICKFLICKABLE_P_P_H
43 #define QQUICKFLICKABLE_P_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55
56 #include "qquickflickable_p.h"
57 #include "qquickitem_p.h"
58 #include "qquickitemchangelistener_p.h"
59
60 #include <QtDeclarative/qdeclarative.h>
61 #include <QtCore/qdatetime.h>
62 #include "qplatformdefs.h"
63
64 #include <private/qdeclarativetimeline_p_p.h>
65 #include <private/qdeclarativeanimation_p_p.h>
66
67 QT_BEGIN_NAMESPACE
68
69 // Really slow flicks can be annoying.
70 const qreal MinimumFlickVelocity = 75.0;
71
72 class QQuickFlickableVisibleArea;
73 class Q_AUTOTEST_EXPORT QQuickFlickablePrivate : public QQuickItemPrivate, public QQuickItemChangeListener
74 {
75     Q_DECLARE_PUBLIC(QQuickFlickable)
76
77 public:
78     static inline QQuickFlickablePrivate *get(QQuickFlickable *o) { return o->d_func(); }
79
80     QQuickFlickablePrivate();
81     void init();
82
83     struct Velocity : public QDeclarativeTimeLineValue
84     {
85         Velocity(QQuickFlickablePrivate *p)
86             : parent(p) {}
87         virtual void setValue(qreal v) {
88             if (v != value()) {
89                 QDeclarativeTimeLineValue::setValue(v);
90                 parent->updateVelocity();
91             }
92         }
93         QQuickFlickablePrivate *parent;
94     };
95
96     struct AxisData {
97         AxisData(QQuickFlickablePrivate *fp, void (QQuickFlickablePrivate::*func)(qreal))
98             : move(fp, func), viewSize(-1), startMargin(0), endMargin(0)
99             , continuousFlickVelocity(0)
100             , smoothVelocity(fp), atEnd(false), atBeginning(true)
101             , fixingUp(false), inOvershoot(false), moving(false), flicking(false)
102             , dragging(false), extentsChanged(false)
103             , explicitValue(false), minExtentDirty(true), maxExtentDirty(true)
104         {}
105
106         void reset() {
107             velocityBuffer.clear();
108             dragStartOffset = 0;
109             fixingUp = false;
110             inOvershoot = false;
111         }
112
113         void markExtentsDirty() {
114             minExtentDirty = true;
115             maxExtentDirty = true;
116             extentsChanged = true;
117         }
118
119         void addVelocitySample(qreal v, qreal maxVelocity);
120         void updateVelocity();
121
122         QDeclarativeTimeLineValueProxy<QQuickFlickablePrivate> move;
123         qreal viewSize;
124         qreal pressPos;
125         qreal dragStartOffset;
126         qreal dragMinBound;
127         qreal dragMaxBound;
128         qreal velocity;
129         qreal flickTarget;
130         qreal startMargin;
131         qreal endMargin;
132         qreal continuousFlickVelocity;
133         QQuickFlickablePrivate::Velocity smoothVelocity;
134         QPODVector<qreal,10> velocityBuffer;
135         bool atEnd : 1;
136         bool atBeginning : 1;
137         bool fixingUp : 1;
138         bool inOvershoot : 1;
139         bool moving : 1;
140         bool flicking : 1;
141         bool dragging : 1;
142         bool extentsChanged : 1;
143         bool explicitValue : 1;
144         mutable bool minExtentDirty : 1;
145         mutable bool maxExtentDirty : 1;
146     };
147
148     void flickX(qreal velocity);
149     void flickY(qreal velocity);
150     virtual void flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
151                         QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity);
152
153     void fixupX();
154     void fixupY();
155     virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent);
156
157     void updateBeginningEnd();
158
159     bool isOutermostPressDelay() const;
160     void captureDelayedPress(QMouseEvent *event);
161     void clearDelayedPress();
162
163     void setViewportX(qreal x);
164     void setViewportY(qreal y);
165
166     qreal overShootDistance(qreal size);
167
168     void itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &);
169
170     void draggingStarting();
171     void draggingEnding();
172
173 public:
174     QQuickItem *contentItem;
175
176     AxisData hData;
177     AxisData vData;
178
179     QDeclarativeTimeLine timeline;
180     bool hMoved : 1;
181     bool vMoved : 1;
182     bool stealMouse : 1;
183     bool pressed : 1;
184     bool interactive : 1;
185     bool calcVelocity : 1;
186     bool pixelAligned : 1;
187     QElapsedTimer timer;
188     qint64 lastPosTime;
189     qint64 lastPressTime;
190     QPointF lastPos;
191     QPointF pressPos;
192     qreal deceleration;
193     qreal maxVelocity;
194     QElapsedTimer velocityTime;
195     QPointF lastFlickablePosition;
196     qreal reportedVelocitySmoothing;
197     QMouseEvent *delayedPressEvent;
198     QQuickItem *delayedPressTarget;
199     QBasicTimer delayedPressTimer;
200     int pressDelay;
201     int fixupDuration;
202     qreal flickBoost;
203
204     enum FixupMode { Normal, Immediate, ExtentChanged };
205     FixupMode fixupMode;
206
207     static void fixupY_callback(void *);
208     static void fixupX_callback(void *);
209
210     void updateVelocity();
211     int vTime;
212     QDeclarativeTimeLine velocityTimeline;
213     QQuickFlickableVisibleArea *visibleArea;
214     QQuickFlickable::FlickableDirection flickableDirection;
215     QQuickFlickable::BoundsBehavior boundsBehavior;
216
217     void handleMousePressEvent(QMouseEvent *);
218     void handleMouseMoveEvent(QMouseEvent *);
219     void handleMouseReleaseEvent(QMouseEvent *);
220
221     qint64 computeCurrentTime(QInputEvent *event);
222
223     // flickableData property
224     static void data_append(QDeclarativeListProperty<QObject> *, QObject *);
225     static int data_count(QDeclarativeListProperty<QObject> *);
226     static QObject *data_at(QDeclarativeListProperty<QObject> *, int);
227     static void data_clear(QDeclarativeListProperty<QObject> *);
228 };
229
230 class QQuickFlickableVisibleArea : public QObject
231 {
232     Q_OBJECT
233
234     Q_PROPERTY(qreal xPosition READ xPosition NOTIFY xPositionChanged)
235     Q_PROPERTY(qreal yPosition READ yPosition NOTIFY yPositionChanged)
236     Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY widthRatioChanged)
237     Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY heightRatioChanged)
238
239 public:
240     QQuickFlickableVisibleArea(QQuickFlickable *parent=0);
241
242     qreal xPosition() const;
243     qreal widthRatio() const;
244     qreal yPosition() const;
245     qreal heightRatio() const;
246
247     void updateVisible();
248
249 signals:
250     void xPositionChanged(qreal xPosition);
251     void yPositionChanged(qreal yPosition);
252     void widthRatioChanged(qreal widthRatio);
253     void heightRatioChanged(qreal heightRatio);
254
255 private:
256     QQuickFlickable *flickable;
257     qreal m_xPosition;
258     qreal m_widthRatio;
259     qreal m_yPosition;
260     qreal m_heightRatio;
261 };
262
263 QT_END_NAMESPACE
264
265 QML_DECLARE_TYPE(QQuickFlickableVisibleArea)
266
267 #endif // QQUICKFLICKABLE_P_P_H