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 void flickX(qreal velocity);
149 void flickY(qreal velocity);
150 virtual void flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
151 QQuickTimeLineCallback::Callback fixupCallback, qreal velocity);
155 virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent);
157 void updateBeginningEnd();
159 bool isOutermostPressDelay() const;
160 void captureDelayedPress(QMouseEvent *event);
161 void clearDelayedPress();
163 void setViewportX(qreal x);
164 void setViewportY(qreal y);
166 qreal overShootDistance(qreal size);
168 void itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &);
170 void draggingStarting();
171 void draggingEnding();
174 QQuickItem *contentItem;
179 QQuickTimeLine timeline;
184 bool interactive : 1;
185 bool calcVelocity : 1;
186 bool pixelAligned : 1;
189 qint64 lastPressTime;
194 QElapsedTimer velocityTime;
195 QPointF lastFlickablePosition;
196 qreal reportedVelocitySmoothing;
197 QMouseEvent *delayedPressEvent;
198 QQuickItem *delayedPressTarget;
199 QBasicTimer delayedPressTimer;
204 enum FixupMode { Normal, Immediate, ExtentChanged };
207 static void fixupY_callback(void *);
208 static void fixupX_callback(void *);
210 void updateVelocity();
212 QQuickTimeLine velocityTimeline;
213 QQuickFlickableVisibleArea *visibleArea;
214 QQuickFlickable::FlickableDirection flickableDirection;
215 QQuickFlickable::BoundsBehavior boundsBehavior;
217 void handleMousePressEvent(QMouseEvent *);
218 void handleMouseMoveEvent(QMouseEvent *);
219 void handleMouseReleaseEvent(QMouseEvent *);
221 qint64 computeCurrentTime(QInputEvent *event);
223 // flickableData property
224 static void data_append(QQmlListProperty<QObject> *, QObject *);
225 static int data_count(QQmlListProperty<QObject> *);
226 static QObject *data_at(QQmlListProperty<QObject> *, int);
227 static void data_clear(QQmlListProperty<QObject> *);
230 class QQuickFlickableVisibleArea : public QObject
234 Q_PROPERTY(qreal xPosition READ xPosition NOTIFY xPositionChanged)
235 Q_PROPERTY(qreal yPosition READ yPosition NOTIFY yPositionChanged)
236 Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY widthRatioChanged)
237 Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY heightRatioChanged)
240 QQuickFlickableVisibleArea(QQuickFlickable *parent=0);
242 qreal xPosition() const;
243 qreal widthRatio() const;
244 qreal yPosition() const;
245 qreal heightRatio() const;
247 void updateVisible();
250 void xPositionChanged(qreal xPosition);
251 void yPositionChanged(qreal yPosition);
252 void widthRatioChanged(qreal widthRatio);
253 void heightRatioChanged(qreal heightRatio);
256 QQuickFlickable *flickable;
265 QML_DECLARE_TYPE(QQuickFlickableVisibleArea)
267 #endif // QQUICKFLICKABLE_P_P_H