1 // Commit: 160f1867868cdea916923652b00484ed11f90aaa
2 /****************************************************************************
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
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 QSGFLICKABLE_P_P_H
44 #define QSGFLICKABLE_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 "qsgflickable_p.h"
58 #include "qsgitem_p.h"
59 #include "qsgitemchangelistener_p.h"
61 #include <QtDeclarative/qdeclarative.h>
62 #include <QtCore/qdatetime.h>
64 #include <private/qdeclarativetimeline_p_p.h>
65 #include <private/qdeclarativeanimation_p_p.h>
69 // Really slow flicks can be annoying.
70 const qreal MinimumFlickVelocity = 75.0;
72 class QSGFlickableVisibleArea;
73 class QSGFlickablePrivate : public QSGItemPrivate, public QSGItemChangeListener
75 Q_DECLARE_PUBLIC(QSGFlickable)
78 static inline QSGFlickablePrivate *get(QSGFlickable *o) { return o->d_func(); }
80 QSGFlickablePrivate();
83 struct Velocity : public QDeclarativeTimeLineValue
85 Velocity(QSGFlickablePrivate *p)
87 virtual void setValue(qreal v) {
89 QDeclarativeTimeLineValue::setValue(v);
90 parent->updateVelocity();
93 QSGFlickablePrivate *parent;
97 AxisData(QSGFlickablePrivate *fp, void (QSGFlickablePrivate::*func)(qreal))
98 : move(fp, func), viewSize(-1), smoothVelocity(fp), atEnd(false), atBeginning(true)
99 , fixingUp(false), inOvershoot(false)
103 velocityBuffer.clear();
109 void addVelocitySample(qreal v, qreal maxVelocity);
110 void updateVelocity();
112 QDeclarativeTimeLineValueProxy<QSGFlickablePrivate> move;
115 qreal dragStartOffset;
120 QSGFlickablePrivate::Velocity smoothVelocity;
121 QPODVector<qreal,10> velocityBuffer;
123 bool atBeginning : 1;
125 bool inOvershoot : 1;
128 void flickX(qreal velocity);
129 void flickY(qreal velocity);
130 virtual void flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
131 QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity);
135 virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent);
137 void updateBeginningEnd();
139 bool isOutermostPressDelay() const;
140 void captureDelayedPress(QGraphicsSceneMouseEvent *event);
141 void clearDelayedPress();
143 void setViewportX(qreal x);
144 void setViewportY(qreal y);
146 qreal overShootDistance(qreal size);
148 void itemGeometryChanged(QSGItem *, const QRectF &, const QRectF &);
151 QSGItem *contentItem;
156 QDeclarativeTimeLine timeline;
157 bool flickingHorizontally : 1;
158 bool flickingVertically : 1;
161 bool movingHorizontally : 1;
162 bool movingVertically : 1;
165 bool interactive : 1;
166 bool calcVelocity : 1;
167 QElapsedTimer lastPosTime;
170 QElapsedTimer pressTime;
173 QElapsedTimer velocityTime;
174 QPointF lastFlickablePosition;
175 qreal reportedVelocitySmoothing;
176 QGraphicsSceneMouseEvent *delayedPressEvent;
177 QSGItem *delayedPressTarget;
178 QBasicTimer delayedPressTimer;
182 enum FixupMode { Normal, Immediate, ExtentChanged };
185 static void fixupY_callback(void *);
186 static void fixupX_callback(void *);
188 void updateVelocity();
190 QDeclarativeTimeLine velocityTimeline;
191 QSGFlickableVisibleArea *visibleArea;
192 QSGFlickable::FlickableDirection flickableDirection;
193 QSGFlickable::BoundsBehavior boundsBehavior;
195 void handleMousePressEvent(QGraphicsSceneMouseEvent *);
196 void handleMouseMoveEvent(QGraphicsSceneMouseEvent *);
197 void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *);
199 // flickableData property
200 static void data_append(QDeclarativeListProperty<QObject> *, QObject *);
201 static int data_count(QDeclarativeListProperty<QObject> *);
202 static QObject *data_at(QDeclarativeListProperty<QObject> *, int);
203 static void data_clear(QDeclarativeListProperty<QObject> *);
206 class QSGFlickableVisibleArea : public QObject
210 Q_PROPERTY(qreal xPosition READ xPosition NOTIFY xPositionChanged)
211 Q_PROPERTY(qreal yPosition READ yPosition NOTIFY yPositionChanged)
212 Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY widthRatioChanged)
213 Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY heightRatioChanged)
216 QSGFlickableVisibleArea(QSGFlickable *parent=0);
218 qreal xPosition() const;
219 qreal widthRatio() const;
220 qreal yPosition() const;
221 qreal heightRatio() const;
223 void updateVisible();
226 void xPositionChanged(qreal xPosition);
227 void yPositionChanged(qreal yPosition);
228 void widthRatioChanged(qreal widthRatio);
229 void heightRatioChanged(qreal heightRatio);
232 QSGFlickable *flickable;
241 QML_DECLARE_TYPE(QSGFlickableVisibleArea)
243 #endif // QSGFLICKABLE_P_P_H