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)
106 , continuousFlickVelocity(0), vTime(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;
142 qreal dragStartOffset;
150 qreal continuousFlickVelocity;
151 QElapsedTimer velocityTime;
153 QQuickFlickablePrivate::Velocity smoothVelocity;
154 QPODVector<qreal,10> velocityBuffer;
156 bool atBeginning : 1;
157 bool transitionToSet : 1;
159 bool inOvershoot : 1;
163 bool extentsChanged : 1;
164 bool explicitValue : 1;
165 mutable bool minExtentDirty : 1;
166 mutable bool maxExtentDirty : 1;
169 bool flickX(qreal velocity);
170 bool flickY(qreal velocity);
171 virtual bool flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
172 QQuickTimeLineCallback::Callback fixupCallback, qreal velocity);
173 void flickingStarted(bool flickingH, bool flickingV);
177 virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent);
178 void adjustContentPos(AxisData &data, qreal toPos);
179 void resetTimeline(AxisData &data);
180 void clearTimeline();
182 void updateBeginningEnd();
184 bool isOutermostPressDelay() const;
185 void captureDelayedPress(QMouseEvent *event);
186 void clearDelayedPress();
188 void setViewportX(qreal x);
189 void setViewportY(qreal y);
191 qreal overShootDistance(qreal size);
193 void itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &);
195 void draggingStarting();
196 void draggingEnding();
198 bool isViewMoving() const;
201 QQuickItem *contentItem;
206 QQuickTimeLine timeline;
211 bool interactive : 1;
212 bool calcVelocity : 1;
213 bool pixelAligned : 1;
216 qint64 lastPressTime;
221 qreal reportedVelocitySmoothing;
222 QMouseEvent *delayedPressEvent;
223 QQuickItem *delayedPressTarget;
224 QBasicTimer delayedPressTimer;
229 enum FixupMode { Normal, Immediate, ExtentChanged };
232 static void fixupY_callback(void *);
233 static void fixupX_callback(void *);
235 void updateVelocity();
237 QQuickTimeLine velocityTimeline;
238 QQuickFlickableVisibleArea *visibleArea;
239 QQuickFlickable::FlickableDirection flickableDirection;
240 QQuickFlickable::BoundsBehavior boundsBehavior;
241 QQuickTransition *rebound;
243 void viewportAxisMoved(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
244 QQuickTimeLineCallback::Callback fixupCallback);
246 void handleMousePressEvent(QMouseEvent *);
247 void handleMouseMoveEvent(QMouseEvent *);
248 void handleMouseReleaseEvent(QMouseEvent *);
250 qint64 computeCurrentTime(QInputEvent *event);
252 // flickableData property
253 static void data_append(QQmlListProperty<QObject> *, QObject *);
254 static int data_count(QQmlListProperty<QObject> *);
255 static QObject *data_at(QQmlListProperty<QObject> *, int);
256 static void data_clear(QQmlListProperty<QObject> *);
259 class QQuickFlickableVisibleArea : public QObject
263 Q_PROPERTY(qreal xPosition READ xPosition NOTIFY xPositionChanged)
264 Q_PROPERTY(qreal yPosition READ yPosition NOTIFY yPositionChanged)
265 Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY widthRatioChanged)
266 Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY heightRatioChanged)
269 QQuickFlickableVisibleArea(QQuickFlickable *parent=0);
271 qreal xPosition() const;
272 qreal widthRatio() const;
273 qreal yPosition() const;
274 qreal heightRatio() const;
276 void updateVisible();
279 void xPositionChanged(qreal xPosition);
280 void yPositionChanged(qreal yPosition);
281 void widthRatioChanged(qreal widthRatio);
282 void heightRatioChanged(qreal heightRatio);
285 QQuickFlickable *flickable;
294 QML_DECLARE_TYPE(QQuickFlickableVisibleArea)
296 #endif // QQUICKFLICKABLE_P_P_H