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>
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)
106 , continuousFlickVelocity(0)
107 , smoothVelocity(fp), atEnd(false), atBeginning(true)
108 , transitionToSet(false)
109 , fixingUp(false), inOvershoot(false), moving(false), flicking(false)
110 , dragging(false), extentsChanged(false)
111 , explicitValue(false), minExtentDirty(true), maxExtentDirty(true)
117 velocityBuffer.clear();
123 void markExtentsDirty() {
124 minExtentDirty = true;
125 maxExtentDirty = true;
126 extentsChanged = true;
129 void resetTransitionTo() {
131 transitionToSet = false;
134 void addVelocitySample(qreal v, qreal maxVelocity);
135 void updateVelocity();
137 QQuickTimeLineValueProxy<QQuickFlickablePrivate> move;
138 QQuickFlickableReboundTransition *transitionToBounds;
141 qreal dragStartOffset;
149 qreal continuousFlickVelocity;
150 QQuickFlickablePrivate::Velocity smoothVelocity;
151 QPODVector<qreal,10> velocityBuffer;
153 bool atBeginning : 1;
154 bool transitionToSet : 1;
156 bool inOvershoot : 1;
160 bool extentsChanged : 1;
161 bool explicitValue : 1;
162 mutable bool minExtentDirty : 1;
163 mutable bool maxExtentDirty : 1;
166 bool flickX(qreal velocity);
167 bool flickY(qreal velocity);
168 virtual bool flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
169 QQuickTimeLineCallback::Callback fixupCallback, qreal velocity);
170 void flickingStarted(bool flickingH, bool flickingV);
174 virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent);
175 void adjustContentPos(AxisData &data, qreal toPos);
176 void resetTimeline(AxisData &data);
177 void clearTimeline();
179 void updateBeginningEnd();
181 bool isOutermostPressDelay() const;
182 void captureDelayedPress(QMouseEvent *event);
183 void clearDelayedPress();
185 void setViewportX(qreal x);
186 void setViewportY(qreal y);
188 qreal overShootDistance(qreal size);
190 void itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &);
192 void draggingStarting();
193 void draggingEnding();
195 bool isViewMoving() const;
198 QQuickItem *contentItem;
203 QQuickTimeLine timeline;
208 bool interactive : 1;
209 bool calcVelocity : 1;
210 bool pixelAligned : 1;
213 qint64 lastPressTime;
218 QElapsedTimer velocityTime;
219 QPointF lastFlickablePosition;
220 qreal reportedVelocitySmoothing;
221 QMouseEvent *delayedPressEvent;
222 QQuickItem *delayedPressTarget;
223 QBasicTimer delayedPressTimer;
228 enum FixupMode { Normal, Immediate, ExtentChanged };
231 static void fixupY_callback(void *);
232 static void fixupX_callback(void *);
234 void updateVelocity();
236 QQuickTimeLine velocityTimeline;
237 QQuickFlickableVisibleArea *visibleArea;
238 QQuickFlickable::FlickableDirection flickableDirection;
239 QQuickFlickable::BoundsBehavior boundsBehavior;
240 QQuickTransition *rebound;
242 void handleMousePressEvent(QMouseEvent *);
243 void handleMouseMoveEvent(QMouseEvent *);
244 void handleMouseReleaseEvent(QMouseEvent *);
246 qint64 computeCurrentTime(QInputEvent *event);
248 // flickableData property
249 static void data_append(QQmlListProperty<QObject> *, QObject *);
250 static int data_count(QQmlListProperty<QObject> *);
251 static QObject *data_at(QQmlListProperty<QObject> *, int);
252 static void data_clear(QQmlListProperty<QObject> *);
255 class QQuickFlickableVisibleArea : public QObject
259 Q_PROPERTY(qreal xPosition READ xPosition NOTIFY xPositionChanged)
260 Q_PROPERTY(qreal yPosition READ yPosition NOTIFY yPositionChanged)
261 Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY widthRatioChanged)
262 Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY heightRatioChanged)
265 QQuickFlickableVisibleArea(QQuickFlickable *parent=0);
267 qreal xPosition() const;
268 qreal widthRatio() const;
269 qreal yPosition() const;
270 qreal heightRatio() const;
272 void updateVisible();
275 void xPositionChanged(qreal xPosition);
276 void yPositionChanged(qreal yPosition);
277 void widthRatioChanged(qreal widthRatio);
278 void heightRatioChanged(qreal heightRatio);
281 QQuickFlickable *flickable;
290 QML_DECLARE_TYPE(QQuickFlickableVisibleArea)
292 #endif // QQUICKFLICKABLE_P_P_H