1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
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 <QtDeclarative/qdeclarative.h>
62 #include <QtQuick1/private/qdeclarativetimeline_p_p.h>
63 #include <QtQuick1/private/qdeclarativeanimation_p_p.h>
65 #include <qdatetime.h>
69 // Really slow flicks can be annoying.
70 const qreal MinimumFlickVelocity = 75.0;
72 class QDeclarative1FlickableVisibleArea;
73 class QDeclarative1FlickablePrivate : public QDeclarativeItemPrivate, public QDeclarativeItemChangeListener
75 Q_DECLARE_PUBLIC(QDeclarative1Flickable)
78 QDeclarative1FlickablePrivate();
81 struct Velocity : public QDeclarative1TimeLineValue
83 Velocity(QDeclarative1FlickablePrivate *p)
85 virtual void setValue(qreal v) {
87 QDeclarative1TimeLineValue::setValue(v);
88 parent->updateVelocity();
91 QDeclarative1FlickablePrivate *parent;
95 AxisData(QDeclarative1FlickablePrivate *fp, void (QDeclarative1FlickablePrivate::*func)(qreal))
96 : move(fp, func), viewSize(-1), smoothVelocity(fp), atEnd(false), atBeginning(true)
97 , fixingUp(false), inOvershoot(false), moving(false), flicking(false)
101 velocityBuffer.clear();
107 void addVelocitySample(qreal v, qreal maxVelocity);
108 void updateVelocity();
110 QDeclarative1TimeLineValueProxy<QDeclarative1FlickablePrivate> move;
113 qreal dragStartOffset;
118 QDeclarative1FlickablePrivate::Velocity smoothVelocity;
119 QPODVector<qreal,10> velocityBuffer;
121 bool atBeginning : 1;
123 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 QDeclarative1TimeLineCallback::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 setRoundedViewportX(qreal x);
144 void setRoundedViewportY(qreal y);
146 qreal overShootDistance(qreal size);
148 void itemGeometryChanged(QDeclarativeItem *, const QRectF &, const QRectF &);
151 QDeclarativeItem *contentItem;
156 QDeclarative1TimeLine timeline;
161 bool interactive : 1;
162 bool calcVelocity : 1;
163 QElapsedTimer lastPosTime;
166 QElapsedTimer pressTime;
169 QElapsedTimer velocityTime;
170 QPointF lastFlickablePosition;
171 qreal reportedVelocitySmoothing;
172 QGraphicsSceneMouseEvent *delayedPressEvent;
173 QGraphicsItem *delayedPressTarget;
174 QBasicTimer delayedPressTimer;
178 enum FixupMode { Normal, Immediate, ExtentChanged };
181 static void fixupY_callback(void *);
182 static void fixupX_callback(void *);
184 void updateVelocity();
186 QDeclarative1TimeLine velocityTimeline;
187 QDeclarative1FlickableVisibleArea *visibleArea;
188 QDeclarative1Flickable::FlickableDirection flickableDirection;
189 QDeclarative1Flickable::BoundsBehavior boundsBehavior;
191 void handleMousePressEvent(QGraphicsSceneMouseEvent *);
192 void handleMouseMoveEvent(QGraphicsSceneMouseEvent *);
193 void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *);
195 // flickableData property
196 static void data_append(QDeclarativeListProperty<QObject> *, QObject *);
197 static int data_count(QDeclarativeListProperty<QObject> *);
198 static QObject *data_at(QDeclarativeListProperty<QObject> *, int);
199 static void data_clear(QDeclarativeListProperty<QObject> *);
202 class QDeclarative1FlickableVisibleArea : public QObject
206 Q_PROPERTY(qreal xPosition READ xPosition NOTIFY xPositionChanged)
207 Q_PROPERTY(qreal yPosition READ yPosition NOTIFY yPositionChanged)
208 Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY widthRatioChanged)
209 Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY heightRatioChanged)
212 QDeclarative1FlickableVisibleArea(QDeclarative1Flickable *parent=0);
214 qreal xPosition() const;
215 qreal widthRatio() const;
216 qreal yPosition() const;
217 qreal heightRatio() const;
219 void updateVisible();
222 void xPositionChanged(qreal xPosition);
223 void yPositionChanged(qreal yPosition);
224 void widthRatioChanged(qreal widthRatio);
225 void heightRatioChanged(qreal heightRatio);
228 QDeclarative1Flickable *flickable;
237 QML_DECLARE_TYPE(QDeclarative1FlickableVisibleArea)