1 // Commit: 160f1867868cdea916923652b00484ed11f90aaa
2 /****************************************************************************
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: http://www.qt-project.org/
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this
15 ** file. Please review the following information to ensure the GNU Lesser
16 ** General Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
23 ** GNU General Public License Usage
24 ** Alternatively, this file may be used under the terms of the GNU General
25 ** Public License version 3.0 as published by the Free Software Foundation
26 ** and appearing in the file LICENSE.GPL included in the packaging of this
27 ** file. Please review the following information to ensure the GNU General
28 ** Public License version 3.0 requirements will be met:
29 ** http://www.gnu.org/copyleft/gpl.html.
32 ** Alternatively, this file may be used in accordance with the terms and
33 ** conditions contained in a signed written agreement between you and Nokia.
41 ****************************************************************************/
43 #ifndef QQUICKFLICKABLE_P_P_H
44 #define QQUICKFLICKABLE_P_P_H
50 // This file is not part of the Qt API. It exists purely as an
51 // implementation detail. This header file may change from version to
52 // version without notice, or even be removed.
57 #include "qquickflickable_p.h"
58 #include "qquickitem_p.h"
59 #include "qquickitemchangelistener_p.h"
61 #include <QtDeclarative/qdeclarative.h>
62 #include <QtCore/qdatetime.h>
63 #include "qplatformdefs.h"
65 #include <private/qdeclarativetimeline_p_p.h>
66 #include <private/qdeclarativeanimation_p_p.h>
70 // Really slow flicks can be annoying.
71 const qreal MinimumFlickVelocity = 75.0;
73 class QQuickFlickableVisibleArea;
74 class QQuickFlickablePrivate : public QQuickItemPrivate, public QQuickItemChangeListener
76 Q_DECLARE_PUBLIC(QQuickFlickable)
79 static inline QQuickFlickablePrivate *get(QQuickFlickable *o) { return o->d_func(); }
81 QQuickFlickablePrivate();
84 struct Velocity : public QDeclarativeTimeLineValue
86 Velocity(QQuickFlickablePrivate *p)
88 virtual void setValue(qreal v) {
90 QDeclarativeTimeLineValue::setValue(v);
91 parent->updateVelocity();
94 QQuickFlickablePrivate *parent;
98 AxisData(QQuickFlickablePrivate *fp, void (QQuickFlickablePrivate::*func)(qreal))
99 : move(fp, func), viewSize(-1), startMargin(0), endMargin(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 QDeclarativeTimeLineValueProxy<QQuickFlickablePrivate> move;
125 qreal dragStartOffset;
132 QQuickFlickablePrivate::Velocity smoothVelocity;
133 QPODVector<qreal,10> velocityBuffer;
135 bool atBeginning : 1;
137 bool inOvershoot : 1;
141 bool extentsChanged : 1;
142 bool explicitValue : 1;
143 mutable bool minExtentDirty : 1;
144 mutable bool maxExtentDirty : 1;
147 void flickX(qreal velocity);
148 void flickY(qreal velocity);
149 virtual void flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
150 QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity);
154 virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent);
156 void updateBeginningEnd();
158 bool isOutermostPressDelay() const;
159 void captureDelayedPress(QMouseEvent *event);
160 void clearDelayedPress();
162 void setViewportX(qreal x);
163 void setViewportY(qreal y);
165 qreal overShootDistance(qreal size);
167 void itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &);
169 void draggingStarting();
170 void draggingEnding();
173 QQuickItem *contentItem;
178 QDeclarativeTimeLine timeline;
183 bool interactive : 1;
184 bool calcVelocity : 1;
185 bool pixelAligned : 1;
188 qint64 lastPressTime;
193 QElapsedTimer velocityTime;
194 QPointF lastFlickablePosition;
195 qreal reportedVelocitySmoothing;
196 QMouseEvent *delayedPressEvent;
197 QQuickItem *delayedPressTarget;
198 QBasicTimer delayedPressTimer;
202 enum FixupMode { Normal, Immediate, ExtentChanged };
205 static void fixupY_callback(void *);
206 static void fixupX_callback(void *);
208 void updateVelocity();
210 QDeclarativeTimeLine velocityTimeline;
211 QQuickFlickableVisibleArea *visibleArea;
212 QQuickFlickable::FlickableDirection flickableDirection;
213 QQuickFlickable::BoundsBehavior boundsBehavior;
215 void handleMousePressEvent(QMouseEvent *);
216 void handleMouseMoveEvent(QMouseEvent *);
217 void handleMouseReleaseEvent(QMouseEvent *);
219 qint64 computeCurrentTime(QInputEvent *event);
221 // flickableData property
222 static void data_append(QDeclarativeListProperty<QObject> *, QObject *);
223 static int data_count(QDeclarativeListProperty<QObject> *);
224 static QObject *data_at(QDeclarativeListProperty<QObject> *, int);
225 static void data_clear(QDeclarativeListProperty<QObject> *);
228 class QQuickFlickableVisibleArea : public QObject
232 Q_PROPERTY(qreal xPosition READ xPosition NOTIFY xPositionChanged)
233 Q_PROPERTY(qreal yPosition READ yPosition NOTIFY yPositionChanged)
234 Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY widthRatioChanged)
235 Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY heightRatioChanged)
238 QQuickFlickableVisibleArea(QQuickFlickable *parent=0);
240 qreal xPosition() const;
241 qreal widthRatio() const;
242 qreal yPosition() const;
243 qreal heightRatio() const;
245 void updateVisible();
248 void xPositionChanged(qreal xPosition);
249 void yPositionChanged(qreal yPosition);
250 void widthRatioChanged(qreal widthRatio);
251 void heightRatioChanged(qreal heightRatio);
254 QQuickFlickable *flickable;
263 QML_DECLARE_TYPE(QQuickFlickableVisibleArea)
265 #endif // QQUICKFLICKABLE_P_P_H