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 ** 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)
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;
126 void flickX(qreal velocity);
127 void flickY(qreal velocity);
128 virtual void flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
129 QDeclarative1TimeLineCallback::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 QDeclarative1TimeLine 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 QDeclarative1TimeLine velocityTimeline;
189 QDeclarative1FlickableVisibleArea *visibleArea;
190 QDeclarative1Flickable::FlickableDirection flickableDirection;
191 QDeclarative1Flickable::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 QDeclarative1FlickableVisibleArea : 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 QDeclarative1FlickableVisibleArea(QDeclarative1Flickable *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 QDeclarative1Flickable *flickable;
239 QML_DECLARE_TYPE(QDeclarative1FlickableVisibleArea)