1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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>
66 #include <private/qquicktransitionmanager_p_p.h>
70 // Really slow flicks can be annoying.
71 const qreal MinimumFlickVelocity = 75.0;
73 class QQuickFlickableVisibleArea;
74 class QQuickTransition;
75 class QQuickFlickableReboundTransition;
77 class Q_AUTOTEST_EXPORT QQuickFlickablePrivate : public QQuickItemPrivate, public QQuickItemChangeListener
79 Q_DECLARE_PUBLIC(QQuickFlickable)
82 static inline QQuickFlickablePrivate *get(QQuickFlickable *o) { return o->d_func(); }
84 QQuickFlickablePrivate();
87 struct Velocity : public QQuickTimeLineValue
89 Velocity(QQuickFlickablePrivate *p)
91 virtual void setValue(qreal v) {
93 QQuickTimeLineValue::setValue(v);
94 parent->updateVelocity();
97 QQuickFlickablePrivate *parent;
101 AxisData(QQuickFlickablePrivate *fp, void (QQuickFlickablePrivate::*func)(qreal))
103 , transitionToBounds(0)
104 , viewSize(-1), startMargin(0), endMargin(0)
107 , continuousFlickVelocity(0), velocityTime(), vTime(0)
108 , smoothVelocity(fp), atEnd(false), atBeginning(true)
109 , transitionToSet(false)
110 , fixingUp(false), inOvershoot(false), moving(false), flicking(false)
111 , dragging(false), extentsChanged(false)
112 , explicitValue(false), minExtentDirty(true), maxExtentDirty(true)
118 velocityBuffer.clear();
124 void markExtentsDirty() {
125 minExtentDirty = true;
126 maxExtentDirty = true;
127 extentsChanged = true;
130 void resetTransitionTo() {
132 transitionToSet = false;
135 void addVelocitySample(qreal v, qreal maxVelocity);
136 void updateVelocity();
138 QQuickTimeLineValueProxy<QQuickFlickablePrivate> move;
139 QQuickFlickableReboundTransition *transitionToBounds;
143 qreal dragStartOffset;
152 qreal continuousFlickVelocity;
153 QElapsedTimer velocityTime;
155 QQuickFlickablePrivate::Velocity smoothVelocity;
156 QPODVector<qreal,10> velocityBuffer;
158 bool atBeginning : 1;
159 bool transitionToSet : 1;
161 bool inOvershoot : 1;
165 bool extentsChanged : 1;
166 bool explicitValue : 1;
167 mutable bool minExtentDirty : 1;
168 mutable bool maxExtentDirty : 1;
171 bool flickX(qreal velocity);
172 bool flickY(qreal velocity);
173 virtual bool flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
174 QQuickTimeLineCallback::Callback fixupCallback, qreal velocity);
175 void flickingStarted(bool flickingH, bool flickingV);
179 virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent);
180 void adjustContentPos(AxisData &data, qreal toPos);
181 void resetTimeline(AxisData &data);
182 void clearTimeline();
184 void updateBeginningEnd();
186 bool isInnermostPressDelay(QQuickItem *item) const;
187 void captureDelayedPress(QQuickItem *item, QMouseEvent *event);
188 void clearDelayedPress();
189 void replayDelayedPress();
191 void setViewportX(qreal x);
192 void setViewportY(qreal y);
194 qreal overShootDistance(qreal size);
196 void itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &);
198 void draggingStarting();
199 void draggingEnding();
201 bool isViewMoving() const;
204 QQuickItem *contentItem;
209 QQuickTimeLine timeline;
214 bool interactive : 1;
215 bool calcVelocity : 1;
216 bool pixelAligned : 1;
217 bool replayingPressEvent : 1;
220 qint64 lastPressTime;
225 qreal reportedVelocitySmoothing;
226 QMouseEvent *delayedPressEvent;
227 QBasicTimer delayedPressTimer;
232 enum FixupMode { Normal, Immediate, ExtentChanged };
235 static void fixupY_callback(void *);
236 static void fixupX_callback(void *);
238 void updateVelocity();
240 QQuickTimeLine velocityTimeline;
241 QQuickFlickableVisibleArea *visibleArea;
242 QQuickFlickable::FlickableDirection flickableDirection;
243 QQuickFlickable::BoundsBehavior boundsBehavior;
244 QQuickTransition *rebound;
246 void viewportAxisMoved(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
247 QQuickTimeLineCallback::Callback fixupCallback);
249 void handleMousePressEvent(QMouseEvent *);
250 void handleMouseMoveEvent(QMouseEvent *);
251 void handleMouseReleaseEvent(QMouseEvent *);
253 qint64 computeCurrentTime(QInputEvent *event);
255 // flickableData property
256 static void data_append(QQmlListProperty<QObject> *, QObject *);
257 static int data_count(QQmlListProperty<QObject> *);
258 static QObject *data_at(QQmlListProperty<QObject> *, int);
259 static void data_clear(QQmlListProperty<QObject> *);
262 class QQuickFlickableVisibleArea : public QObject
266 Q_PROPERTY(qreal xPosition READ xPosition NOTIFY xPositionChanged)
267 Q_PROPERTY(qreal yPosition READ yPosition NOTIFY yPositionChanged)
268 Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY widthRatioChanged)
269 Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY heightRatioChanged)
272 QQuickFlickableVisibleArea(QQuickFlickable *parent=0);
274 qreal xPosition() const;
275 qreal widthRatio() const;
276 qreal yPosition() const;
277 qreal heightRatio() const;
279 void updateVisible();
282 void xPositionChanged(qreal xPosition);
283 void yPositionChanged(qreal yPosition);
284 void widthRatioChanged(qreal widthRatio);
285 void heightRatioChanged(qreal heightRatio);
288 QQuickFlickable *flickable;
297 QML_DECLARE_TYPE(QQuickFlickableVisibleArea)
299 #endif // QQUICKFLICKABLE_P_P_H