1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #ifndef QDECLARATIVEFLICKABLE_P_H
43 #define QDECLARATIVEFLICKABLE_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 "private/qdeclarativeflickable_p.h"
58 #include "private/qdeclarativeitem_p.h"
59 #include "private/qdeclarativeitemchangelistener_p.h"
61 #include <qdeclarative.h>
62 #include <qdeclarativetimeline_p_p.h>
63 #include <qdeclarativeanimation_p_p.h>
65 #include <qdatetime.h>
69 // Really slow flicks can be annoying.
70 const qreal MinimumFlickVelocity = 75.0;
72 class QDeclarativeFlickableVisibleArea;
73 class QDeclarativeFlickablePrivate : public QDeclarativeItemPrivate, public QDeclarativeItemChangeListener
75 Q_DECLARE_PUBLIC(QDeclarativeFlickable)
78 QDeclarativeFlickablePrivate();
81 struct Velocity : public QDeclarativeTimeLineValue
83 Velocity(QDeclarativeFlickablePrivate *p)
85 virtual void setValue(qreal v) {
87 QDeclarativeTimeLineValue::setValue(v);
88 parent->updateVelocity();
91 QDeclarativeFlickablePrivate *parent;
95 AxisData(QDeclarativeFlickablePrivate *fp, void (QDeclarativeFlickablePrivate::*func)(qreal))
96 : move(fp, func), viewSize(-1), smoothVelocity(fp), atEnd(false), atBeginning(true)
97 , fixingUp(false), inOvershoot(false)
101 velocityBuffer.clear();
107 void addVelocitySample(qreal v, qreal maxVelocity);
108 void updateVelocity();
110 QDeclarativeTimeLineValueProxy<QDeclarativeFlickablePrivate> move;
113 qreal dragStartOffset;
118 QDeclarativeFlickablePrivate::Velocity smoothVelocity;
119 QPODVector<qreal,10> velocityBuffer;
121 bool atBeginning : 1;
123 bool inOvershoot : 1;
126 void flickX(qreal velocity);
127 void flickY(qreal velocity);
128 virtual void flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
129 QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity);
133 virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent);
135 void updateBeginningEnd();
137 bool isOutermostPressDelay() const;
138 void captureDelayedPress(QGraphicsSceneMouseEvent *event);
139 void clearDelayedPress();
141 void setRoundedViewportX(qreal x);
142 void setRoundedViewportY(qreal y);
144 qreal overShootDistance(qreal size);
146 void itemGeometryChanged(QDeclarativeItem *, const QRectF &, const QRectF &);
149 QDeclarativeItem *contentItem;
154 QDeclarativeTimeLine timeline;
155 bool flickingHorizontally : 1;
156 bool flickingVertically : 1;
159 bool movingHorizontally : 1;
160 bool movingVertically : 1;
163 bool interactive : 1;
164 bool calcVelocity : 1;
165 QElapsedTimer lastPosTime;
168 QElapsedTimer pressTime;
171 QElapsedTimer velocityTime;
172 QPointF lastFlickablePosition;
173 qreal reportedVelocitySmoothing;
174 QGraphicsSceneMouseEvent *delayedPressEvent;
175 QGraphicsItem *delayedPressTarget;
176 QBasicTimer delayedPressTimer;
180 enum FixupMode { Normal, Immediate, ExtentChanged };
183 static void fixupY_callback(void *);
184 static void fixupX_callback(void *);
186 void updateVelocity();
188 QDeclarativeTimeLine velocityTimeline;
189 QDeclarativeFlickableVisibleArea *visibleArea;
190 QDeclarativeFlickable::FlickableDirection flickableDirection;
191 QDeclarativeFlickable::BoundsBehavior boundsBehavior;
193 void handleMousePressEvent(QGraphicsSceneMouseEvent *);
194 void handleMouseMoveEvent(QGraphicsSceneMouseEvent *);
195 void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *);
197 // flickableData property
198 static void data_append(QDeclarativeListProperty<QObject> *, QObject *);
199 static int data_count(QDeclarativeListProperty<QObject> *);
200 static QObject *data_at(QDeclarativeListProperty<QObject> *, int);
201 static void data_clear(QDeclarativeListProperty<QObject> *);
204 class QDeclarativeFlickableVisibleArea : public QObject
208 Q_PROPERTY(qreal xPosition READ xPosition NOTIFY xPositionChanged)
209 Q_PROPERTY(qreal yPosition READ yPosition NOTIFY yPositionChanged)
210 Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY widthRatioChanged)
211 Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY heightRatioChanged)
214 QDeclarativeFlickableVisibleArea(QDeclarativeFlickable *parent=0);
216 qreal xPosition() const;
217 qreal widthRatio() const;
218 qreal yPosition() const;
219 qreal heightRatio() const;
221 void updateVisible();
224 void xPositionChanged(qreal xPosition);
225 void yPositionChanged(qreal yPosition);
226 void widthRatioChanged(qreal widthRatio);
227 void heightRatioChanged(qreal heightRatio);
230 QDeclarativeFlickable *flickable;
239 QML_DECLARE_TYPE(QDeclarativeFlickableVisibleArea)