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