1 // Commit: cb0a6844705802564c81b581f24a76c5d5adf6d1
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 ** No Commercial Usage
12 ** This file contains pre-release code and may not be distributed.
13 ** You may use this file in accordance with the terms and conditions
14 ** contained in the Technology Preview License Agreement accompanying
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
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)
102 QDeclarativeTimeLineValueProxy<QSGFlickablePrivate> move;
105 qreal dragStartOffset;
110 QSGFlickablePrivate::Velocity smoothVelocity;
112 bool atBeginning : 1;
116 void flickX(qreal velocity);
117 void flickY(qreal velocity);
118 virtual void flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
119 QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity);
123 virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent);
125 void updateBeginningEnd();
127 bool isOutermostPressDelay() const;
128 void captureDelayedPress(QGraphicsSceneMouseEvent *event);
129 void clearDelayedPress();
131 void setRoundedViewportX(qreal x);
132 void setRoundedViewportY(qreal y);
134 qreal overShootDistance(qreal velocity, qreal size);
136 void itemGeometryChanged(QSGItem *, const QRectF &, const QRectF &);
139 QSGItem *contentItem;
144 QDeclarativeTimeLine timeline;
145 bool flickingHorizontally : 1;
146 bool flickingVertically : 1;
149 bool movingHorizontally : 1;
150 bool movingVertically : 1;
153 bool interactive : 1;
154 bool calcVelocity : 1;
155 QElapsedTimer lastPosTime;
158 QElapsedTimer pressTime;
161 QElapsedTimer velocityTime;
162 QPointF lastFlickablePosition;
163 qreal reportedVelocitySmoothing;
164 QGraphicsSceneMouseEvent *delayedPressEvent;
165 QSGItem *delayedPressTarget;
166 QBasicTimer delayedPressTimer;
170 enum FixupMode { Normal, Immediate, ExtentChanged };
173 static void fixupY_callback(void *);
174 static void fixupX_callback(void *);
176 void updateVelocity();
178 QDeclarativeTimeLine velocityTimeline;
179 QSGFlickableVisibleArea *visibleArea;
180 QSGFlickable::FlickableDirection flickableDirection;
181 QSGFlickable::BoundsBehavior boundsBehavior;
183 void handleMousePressEvent(QGraphicsSceneMouseEvent *);
184 void handleMouseMoveEvent(QGraphicsSceneMouseEvent *);
185 void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *);
187 // flickableData property
188 static void data_append(QDeclarativeListProperty<QObject> *, QObject *);
189 static int data_count(QDeclarativeListProperty<QObject> *);
190 static QObject *data_at(QDeclarativeListProperty<QObject> *, int);
191 static void data_clear(QDeclarativeListProperty<QObject> *);
194 class QSGFlickableVisibleArea : public QObject
198 Q_PROPERTY(qreal xPosition READ xPosition NOTIFY xPositionChanged)
199 Q_PROPERTY(qreal yPosition READ yPosition NOTIFY yPositionChanged)
200 Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY widthRatioChanged)
201 Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY heightRatioChanged)
204 QSGFlickableVisibleArea(QSGFlickable *parent=0);
206 qreal xPosition() const;
207 qreal widthRatio() const;
208 qreal yPosition() const;
209 qreal heightRatio() const;
211 void updateVisible();
214 void xPositionChanged(qreal xPosition);
215 void yPositionChanged(qreal yPosition);
216 void widthRatioChanged(qreal widthRatio);
217 void heightRatioChanged(qreal heightRatio);
220 QSGFlickable *flickable;
229 QML_DECLARE_TYPE(QSGFlickableVisibleArea)
231 #endif // QSGFLICKABLE_P_P_H