Update licenseheader text in source files for qtdeclarative Qt module
[profile/ivi/qtdeclarative.git] / src / declarative / items / qsgflickable_p_p.h
1 // Commit: 160f1867868cdea916923652b00484ed11f90aaa
2 /****************************************************************************
3 **
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 **
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 **
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this
15 ** file. Please review the following information to ensure the GNU Lesser
16 ** General Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** GNU General Public License Usage
24 ** Alternatively, this file may be used under the terms of the GNU General
25 ** Public License version 3.0 as published by the Free Software Foundation
26 ** and appearing in the file LICENSE.GPL included in the packaging of this
27 ** file. Please review the following information to ensure the GNU General
28 ** Public License version 3.0 requirements will be met:
29 ** http://www.gnu.org/copyleft/gpl.html.
30 **
31 ** Other Usage
32 ** Alternatively, this file may be used in accordance with the terms and
33 ** conditions contained in a signed written agreement between you and Nokia.
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QSGFLICKABLE_P_P_H
44 #define QSGFLICKABLE_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 "qsgflickable_p.h"
58 #include "qsgitem_p.h"
59 #include "qsgitemchangelistener_p.h"
60
61 #include <QtDeclarative/qdeclarative.h>
62 #include <QtCore/qdatetime.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 QSGFlickableVisibleArea;
73 class QSGFlickablePrivate : public QSGItemPrivate, public QSGItemChangeListener
74 {
75     Q_DECLARE_PUBLIC(QSGFlickable)
76
77 public:
78     static inline QSGFlickablePrivate *get(QSGFlickable *o) { return o->d_func(); }
79
80     QSGFlickablePrivate();
81     void init();
82
83     struct Velocity : public QDeclarativeTimeLineValue
84     {
85         Velocity(QSGFlickablePrivate *p)
86             : parent(p) {}
87         virtual void setValue(qreal v) {
88             if (v != value()) {
89                 QDeclarativeTimeLineValue::setValue(v);
90                 parent->updateVelocity();
91             }
92         }
93         QSGFlickablePrivate *parent;
94     };
95
96     struct AxisData {
97         AxisData(QSGFlickablePrivate *fp, void (QSGFlickablePrivate::*func)(qreal))
98             : move(fp, func), viewSize(-1), smoothVelocity(fp), atEnd(false), atBeginning(true)
99             , fixingUp(false), inOvershoot(false)
100         {}
101
102         void reset() {
103             velocityBuffer.clear();
104             dragStartOffset = 0;
105             fixingUp = false;
106             inOvershoot = false;
107         }
108
109         void addVelocitySample(qreal v, qreal maxVelocity);
110         void updateVelocity();
111
112         QDeclarativeTimeLineValueProxy<QSGFlickablePrivate> move;
113         qreal viewSize;
114         qreal pressPos;
115         qreal dragStartOffset;
116         qreal dragMinBound;
117         qreal dragMaxBound;
118         qreal velocity;
119         qreal flickTarget;
120         QSGFlickablePrivate::Velocity smoothVelocity;
121         QPODVector<qreal,10> velocityBuffer;
122         bool atEnd : 1;
123         bool atBeginning : 1;
124         bool fixingUp : 1;
125         bool inOvershoot : 1;
126     };
127
128     void flickX(qreal velocity);
129     void flickY(qreal velocity);
130     virtual void flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
131                         QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity);
132
133     void fixupX();
134     void fixupY();
135     virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent);
136
137     void updateBeginningEnd();
138
139     bool isOutermostPressDelay() const;
140     void captureDelayedPress(QGraphicsSceneMouseEvent *event);
141     void clearDelayedPress();
142
143     void setViewportX(qreal x);
144     void setViewportY(qreal y);
145
146     qreal overShootDistance(qreal size);
147
148     void itemGeometryChanged(QSGItem *, const QRectF &, const QRectF &);
149
150 public:
151     QSGItem *contentItem;
152
153     AxisData hData;
154     AxisData vData;
155
156     QDeclarativeTimeLine timeline;
157     bool flickingHorizontally : 1;
158     bool flickingVertically : 1;
159     bool hMoved : 1;
160     bool vMoved : 1;
161     bool movingHorizontally : 1;
162     bool movingVertically : 1;
163     bool stealMouse : 1;
164     bool pressed : 1;
165     bool interactive : 1;
166     bool calcVelocity : 1;
167     QElapsedTimer lastPosTime;
168     QPointF lastPos;
169     QPointF pressPos;
170     QElapsedTimer pressTime;
171     qreal deceleration;
172     qreal maxVelocity;
173     QElapsedTimer velocityTime;
174     QPointF lastFlickablePosition;
175     qreal reportedVelocitySmoothing;
176     QGraphicsSceneMouseEvent *delayedPressEvent;
177     QSGItem *delayedPressTarget;
178     QBasicTimer delayedPressTimer;
179     int pressDelay;
180     int fixupDuration;
181
182     enum FixupMode { Normal, Immediate, ExtentChanged };
183     FixupMode fixupMode;
184
185     static void fixupY_callback(void *);
186     static void fixupX_callback(void *);
187
188     void updateVelocity();
189     int vTime;
190     QDeclarativeTimeLine velocityTimeline;
191     QSGFlickableVisibleArea *visibleArea;
192     QSGFlickable::FlickableDirection flickableDirection;
193     QSGFlickable::BoundsBehavior boundsBehavior;
194
195     void handleMousePressEvent(QGraphicsSceneMouseEvent *);
196     void handleMouseMoveEvent(QGraphicsSceneMouseEvent *);
197     void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *);
198
199     // flickableData property
200     static void data_append(QDeclarativeListProperty<QObject> *, QObject *);
201     static int data_count(QDeclarativeListProperty<QObject> *);
202     static QObject *data_at(QDeclarativeListProperty<QObject> *, int);
203     static void data_clear(QDeclarativeListProperty<QObject> *);
204 };
205
206 class QSGFlickableVisibleArea : public QObject
207 {
208     Q_OBJECT
209
210     Q_PROPERTY(qreal xPosition READ xPosition NOTIFY xPositionChanged)
211     Q_PROPERTY(qreal yPosition READ yPosition NOTIFY yPositionChanged)
212     Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY widthRatioChanged)
213     Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY heightRatioChanged)
214
215 public:
216     QSGFlickableVisibleArea(QSGFlickable *parent=0);
217
218     qreal xPosition() const;
219     qreal widthRatio() const;
220     qreal yPosition() const;
221     qreal heightRatio() const;
222
223     void updateVisible();
224
225 signals:
226     void xPositionChanged(qreal xPosition);
227     void yPositionChanged(qreal yPosition);
228     void widthRatioChanged(qreal widthRatio);
229     void heightRatioChanged(qreal heightRatio);
230
231 private:
232     QSGFlickable *flickable;
233     qreal m_xPosition;
234     qreal m_widthRatio;
235     qreal m_yPosition;
236     qreal m_heightRatio;
237 };
238
239 QT_END_NAMESPACE
240
241 QML_DECLARE_TYPE(QSGFlickableVisibleArea)
242
243 #endif // QSGFLICKABLE_P_P_H