1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QQUICKFLICKABLE_P_P_H
43 #define QQUICKFLICKABLE_P_P_H
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.
56 #include "qquickflickable_p.h"
57 #include "qquickitem_p.h"
58 #include "qquickitemchangelistener_p.h"
60 #include <QtQml/qqml.h>
61 #include <QtCore/qdatetime.h>
62 #include "qplatformdefs.h"
64 #include <private/qquicktimeline_p_p.h>
65 #include <private/qquickanimation_p_p.h>
69 // Really slow flicks can be annoying.
70 const qreal MinimumFlickVelocity = 75.0;
72 class QQuickFlickableVisibleArea;
73 class Q_AUTOTEST_EXPORT QQuickFlickablePrivate : public QQuickItemPrivate, public QQuickItemChangeListener
75 Q_DECLARE_PUBLIC(QQuickFlickable)
78 static inline QQuickFlickablePrivate *get(QQuickFlickable *o) { return o->d_func(); }
80 QQuickFlickablePrivate();
83 struct Velocity : public QQuickTimeLineValue
85 Velocity(QQuickFlickablePrivate *p)
87 virtual void setValue(qreal v) {
89 QQuickTimeLineValue::setValue(v);
90 parent->updateVelocity();
93 QQuickFlickablePrivate *parent;
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)
107 velocityBuffer.clear();
113 void markExtentsDirty() {
114 minExtentDirty = true;
115 maxExtentDirty = true;
116 extentsChanged = true;
119 void addVelocitySample(qreal v, qreal maxVelocity);
120 void updateVelocity();
122 QQuickTimeLineValueProxy<QQuickFlickablePrivate> move;
125 qreal dragStartOffset;
132 qreal continuousFlickVelocity;
133 QQuickFlickablePrivate::Velocity smoothVelocity;
134 QPODVector<qreal,10> velocityBuffer;
136 bool atBeginning : 1;
138 bool inOvershoot : 1;
142 bool extentsChanged : 1;
143 bool explicitValue : 1;
144 mutable bool minExtentDirty : 1;
145 mutable bool maxExtentDirty : 1;
148 bool flickX(qreal velocity);
149 bool flickY(qreal velocity);
150 virtual bool flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
151 QQuickTimeLineCallback::Callback fixupCallback, qreal velocity);
152 void flickingStarted(bool flickingH, bool flickingV);
156 virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent);
158 void updateBeginningEnd();
160 bool isOutermostPressDelay() const;
161 void captureDelayedPress(QMouseEvent *event);
162 void clearDelayedPress();
164 void setViewportX(qreal x);
165 void setViewportY(qreal y);
167 qreal overShootDistance(qreal size);
169 void itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &);
171 void draggingStarting();
172 void draggingEnding();
175 QQuickItem *contentItem;
180 QQuickTimeLine timeline;
185 bool interactive : 1;
186 bool calcVelocity : 1;
187 bool pixelAligned : 1;
190 qint64 lastPressTime;
195 QElapsedTimer velocityTime;
196 QPointF lastFlickablePosition;
197 qreal reportedVelocitySmoothing;
198 QMouseEvent *delayedPressEvent;
199 QQuickItem *delayedPressTarget;
200 QBasicTimer delayedPressTimer;
205 enum FixupMode { Normal, Immediate, ExtentChanged };
208 static void fixupY_callback(void *);
209 static void fixupX_callback(void *);
211 void updateVelocity();
213 QQuickTimeLine velocityTimeline;
214 QQuickFlickableVisibleArea *visibleArea;
215 QQuickFlickable::FlickableDirection flickableDirection;
216 QQuickFlickable::BoundsBehavior boundsBehavior;
218 void handleMousePressEvent(QMouseEvent *);
219 void handleMouseMoveEvent(QMouseEvent *);
220 void handleMouseReleaseEvent(QMouseEvent *);
222 qint64 computeCurrentTime(QInputEvent *event);
224 // flickableData property
225 static void data_append(QQmlListProperty<QObject> *, QObject *);
226 static int data_count(QQmlListProperty<QObject> *);
227 static QObject *data_at(QQmlListProperty<QObject> *, int);
228 static void data_clear(QQmlListProperty<QObject> *);
231 class QQuickFlickableVisibleArea : public QObject
235 Q_PROPERTY(qreal xPosition READ xPosition NOTIFY xPositionChanged)
236 Q_PROPERTY(qreal yPosition READ yPosition NOTIFY yPositionChanged)
237 Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY widthRatioChanged)
238 Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY heightRatioChanged)
241 QQuickFlickableVisibleArea(QQuickFlickable *parent=0);
243 qreal xPosition() const;
244 qreal widthRatio() const;
245 qreal yPosition() const;
246 qreal heightRatio() const;
248 void updateVisible();
251 void xPositionChanged(qreal xPosition);
252 void yPositionChanged(qreal yPosition);
253 void widthRatioChanged(qreal widthRatio);
254 void heightRatioChanged(qreal heightRatio);
257 QQuickFlickable *flickable;
266 QML_DECLARE_TYPE(QQuickFlickableVisibleArea)
268 #endif // QQUICKFLICKABLE_P_P_H