Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / qtquick1 / graphicsitems / qdeclarativeflickable_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 QDECLARATIVEFLICKABLE_P_H
43 #define QDECLARATIVEFLICKABLE_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 "private/qdeclarativeflickable_p.h"
57
58 #include "private/qdeclarativeitem_p.h"
59 #include "private/qdeclarativeitemchangelistener_p.h"
60
61 #include <QtDeclarative/qdeclarative.h>
62 #include <QtQuick1/private/qdeclarativetimeline_p_p.h>
63 #include <QtQuick1/private/qdeclarativeanimation_p_p.h>
64
65 #include <qdatetime.h>
66
67 QT_BEGIN_NAMESPACE
68
69 // Really slow flicks can be annoying.
70 const qreal MinimumFlickVelocity = 75.0;
71
72 class QDeclarative1FlickableVisibleArea;
73 class QDeclarative1FlickablePrivate : public QDeclarativeItemPrivate, public QDeclarativeItemChangeListener
74 {
75     Q_DECLARE_PUBLIC(QDeclarative1Flickable)
76
77 public:
78     QDeclarative1FlickablePrivate();
79     void init();
80
81     struct Velocity : public QDeclarative1TimeLineValue
82     {
83         Velocity(QDeclarative1FlickablePrivate *p)
84             : parent(p) {}
85         virtual void setValue(qreal v) {
86             if (v != value()) {
87                 QDeclarative1TimeLineValue::setValue(v);
88                 parent->updateVelocity();
89             }
90         }
91         QDeclarative1FlickablePrivate *parent;
92     };
93
94     struct AxisData {
95         AxisData(QDeclarative1FlickablePrivate *fp, void (QDeclarative1FlickablePrivate::*func)(qreal))
96             : move(fp, func), viewSize(-1), smoothVelocity(fp), atEnd(false), atBeginning(true)
97             , fixingUp(false), inOvershoot(false), moving(false), flicking(false)
98         {}
99
100         void reset() {
101             velocityBuffer.clear();
102             dragStartOffset = 0;
103             fixingUp = false;
104             inOvershoot = false;
105         }
106
107         void addVelocitySample(qreal v, qreal maxVelocity);
108         void updateVelocity();
109
110         QDeclarative1TimeLineValueProxy<QDeclarative1FlickablePrivate> move;
111         qreal viewSize;
112         qreal pressPos;
113         qreal dragStartOffset;
114         qreal dragMinBound;
115         qreal dragMaxBound;
116         qreal velocity;
117         qreal flickTarget;
118         QDeclarative1FlickablePrivate::Velocity smoothVelocity;
119         QPODVector<qreal,10> velocityBuffer;
120         bool atEnd : 1;
121         bool atBeginning : 1;
122         bool fixingUp : 1;
123         bool inOvershoot : 1;
124         bool moving : 1;
125         bool flicking : 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                         QDeclarative1TimeLineCallback::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 setRoundedViewportX(qreal x);
144     void setRoundedViewportY(qreal y);
145
146     qreal overShootDistance(qreal size);
147
148     void itemGeometryChanged(QDeclarativeItem *, const QRectF &, const QRectF &);
149
150 public:
151     QDeclarativeItem *contentItem;
152
153     AxisData hData;
154     AxisData vData;
155
156     QDeclarative1TimeLine timeline;
157     bool hMoved : 1;
158     bool vMoved : 1;
159     bool stealMouse : 1;
160     bool pressed : 1;
161     bool interactive : 1;
162     bool calcVelocity : 1;
163     QElapsedTimer lastPosTime;
164     QPointF lastPos;
165     QPointF pressPos;
166     QElapsedTimer pressTime;
167     qreal deceleration;
168     qreal maxVelocity;
169     QElapsedTimer velocityTime;
170     QPointF lastFlickablePosition;
171     qreal reportedVelocitySmoothing;
172     QGraphicsSceneMouseEvent *delayedPressEvent;
173     QGraphicsItem *delayedPressTarget;
174     QBasicTimer delayedPressTimer;
175     int pressDelay;
176     int fixupDuration;
177
178     enum FixupMode { Normal, Immediate, ExtentChanged };
179     FixupMode fixupMode;
180
181     static void fixupY_callback(void *);
182     static void fixupX_callback(void *);
183
184     void updateVelocity();
185     int vTime;
186     QDeclarative1TimeLine velocityTimeline;
187     QDeclarative1FlickableVisibleArea *visibleArea;
188     QDeclarative1Flickable::FlickableDirection flickableDirection;
189     QDeclarative1Flickable::BoundsBehavior boundsBehavior;
190
191     void handleMousePressEvent(QGraphicsSceneMouseEvent *);
192     void handleMouseMoveEvent(QGraphicsSceneMouseEvent *);
193     void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *);
194
195     // flickableData property
196     static void data_append(QDeclarativeListProperty<QObject> *, QObject *);
197     static int data_count(QDeclarativeListProperty<QObject> *);
198     static QObject *data_at(QDeclarativeListProperty<QObject> *, int);
199     static void data_clear(QDeclarativeListProperty<QObject> *);
200 };
201
202 class QDeclarative1FlickableVisibleArea : public QObject
203 {
204     Q_OBJECT
205
206     Q_PROPERTY(qreal xPosition READ xPosition NOTIFY xPositionChanged)
207     Q_PROPERTY(qreal yPosition READ yPosition NOTIFY yPositionChanged)
208     Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY widthRatioChanged)
209     Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY heightRatioChanged)
210
211 public:
212     QDeclarative1FlickableVisibleArea(QDeclarative1Flickable *parent=0);
213
214     qreal xPosition() const;
215     qreal widthRatio() const;
216     qreal yPosition() const;
217     qreal heightRatio() const;
218
219     void updateVisible();
220
221 signals:
222     void xPositionChanged(qreal xPosition);
223     void yPositionChanged(qreal yPosition);
224     void widthRatioChanged(qreal widthRatio);
225     void heightRatioChanged(qreal heightRatio);
226
227 private:
228     QDeclarative1Flickable *flickable;
229     qreal m_xPosition;
230     qreal m_widthRatio;
231     qreal m_yPosition;
232     qreal m_heightRatio;
233 };
234
235 QT_END_NAMESPACE
236
237 QML_DECLARE_TYPE(QDeclarative1FlickableVisibleArea)
238
239 #endif