source: trunk/src/declarative/graphicsitems/qdeclarativeflickable_p_p.h

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 7.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation (qt-info@nokia.com)
6**
7** This file is part of the QtDeclarative module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
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.
23**
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.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at qt-info@nokia.com.
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QDECLARATIVEFLICKABLE_P_H
43#define QDECLARATIVEFLICKABLE_P_H
44
45//
46// W A R N I N G
47// -------------
48//
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.
52//
53// We mean it.
54//
55
56#include "private/qdeclarativeflickable_p.h"
57
58#include "private/qdeclarativeitem_p.h"
59#include "private/qdeclarativeitemchangelistener_p.h"
60
61#include <qdeclarative.h>
62#include <qdeclarativetimeline_p_p.h>
63#include <qdeclarativeanimation_p_p.h>
64
65#include <qdatetime.h>
66
67QT_BEGIN_NAMESPACE
68
69// Really slow flicks can be annoying.
70const qreal MinimumFlickVelocity = 75.0;
71
72class QDeclarativeFlickableVisibleArea;
73class QDeclarativeFlickablePrivate : public QDeclarativeItemPrivate, public QDeclarativeItemChangeListener
74{
75 Q_DECLARE_PUBLIC(QDeclarativeFlickable)
76
77public:
78 QDeclarativeFlickablePrivate();
79 void init();
80
81 struct Velocity : public QDeclarativeTimeLineValue
82 {
83 Velocity(QDeclarativeFlickablePrivate *p)
84 : parent(p) {}
85 virtual void setValue(qreal v) {
86 if (v != value()) {
87 QDeclarativeTimeLineValue::setValue(v);
88 parent->updateVelocity();
89 }
90 }
91 QDeclarativeFlickablePrivate *parent;
92 };
93
94 struct AxisData {
95 AxisData(QDeclarativeFlickablePrivate *fp, void (QDeclarativeFlickablePrivate::*func)(qreal))
96 : move(fp, func), viewSize(-1), smoothVelocity(fp), atEnd(false), atBeginning(true)
97 {}
98
99 QDeclarativeTimeLineValueProxy<QDeclarativeFlickablePrivate> move;
100 qreal viewSize;
101 qreal pressPos;
102 qreal dragStartOffset;
103 qreal velocity;
104 qreal flickTarget;
105 QDeclarativeFlickablePrivate::Velocity smoothVelocity;
106 bool atEnd : 1;
107 bool atBeginning : 1;
108 };
109
110 void flickX(qreal velocity);
111 void flickY(qreal velocity);
112 virtual void flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
113 QDeclarativeTimeLineCallback::Callback fixupCallback, qreal velocity);
114
115 void fixupX();
116 void fixupY();
117 virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent);
118
119 void updateBeginningEnd();
120
121 void captureDelayedPress(QGraphicsSceneMouseEvent *event);
122 void clearDelayedPress();
123
124 void setRoundedViewportX(qreal x);
125 void setRoundedViewportY(qreal y);
126
127 qreal overShootDistance(qreal velocity, qreal size);
128
129 void itemGeometryChanged(QDeclarativeItem *, const QRectF &, const QRectF &);
130
131public:
132 QDeclarativeItem *contentItem;
133
134 AxisData hData;
135 AxisData vData;
136
137 QDeclarativeTimeLine timeline;
138 bool flickingHorizontally : 1;
139 bool flickingVertically : 1;
140 bool hMoved : 1;
141 bool vMoved : 1;
142 bool movingHorizontally : 1;
143 bool movingVertically : 1;
144 bool stealMouse : 1;
145 bool pressed : 1;
146 bool interactive : 1;
147 bool calcVelocity : 1;
148 QElapsedTimer lastPosTime;
149 QPointF lastPos;
150 QPointF pressPos;
151 QElapsedTimer pressTime;
152 qreal deceleration;
153 qreal maxVelocity;
154 QElapsedTimer velocityTime;
155 QPointF lastFlickablePosition;
156 qreal reportedVelocitySmoothing;
157 QGraphicsSceneMouseEvent *delayedPressEvent;
158 QGraphicsItem *delayedPressTarget;
159 QBasicTimer delayedPressTimer;
160 int pressDelay;
161 int fixupDuration;
162
163 static void fixupY_callback(void *);
164 static void fixupX_callback(void *);
165
166 void updateVelocity();
167 int vTime;
168 QDeclarativeTimeLine velocityTimeline;
169 QDeclarativeFlickableVisibleArea *visibleArea;
170 QDeclarativeFlickable::FlickableDirection flickableDirection;
171 QDeclarativeFlickable::BoundsBehavior boundsBehavior;
172
173 void handleMousePressEvent(QGraphicsSceneMouseEvent *);
174 void handleMouseMoveEvent(QGraphicsSceneMouseEvent *);
175 void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *);
176
177 // flickableData property
178 static void data_append(QDeclarativeListProperty<QObject> *, QObject *);
179 static int data_count(QDeclarativeListProperty<QObject> *);
180 static QObject *data_at(QDeclarativeListProperty<QObject> *, int);
181 static void data_clear(QDeclarativeListProperty<QObject> *);
182};
183
184class QDeclarativeFlickableVisibleArea : public QObject
185{
186 Q_OBJECT
187
188 Q_PROPERTY(qreal xPosition READ xPosition NOTIFY xPositionChanged)
189 Q_PROPERTY(qreal yPosition READ yPosition NOTIFY yPositionChanged)
190 Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY widthRatioChanged)
191 Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY heightRatioChanged)
192
193public:
194 QDeclarativeFlickableVisibleArea(QDeclarativeFlickable *parent=0);
195
196 qreal xPosition() const;
197 qreal widthRatio() const;
198 qreal yPosition() const;
199 qreal heightRatio() const;
200
201 void updateVisible();
202
203signals:
204 void xPositionChanged(qreal xPosition);
205 void yPositionChanged(qreal yPosition);
206 void widthRatioChanged(qreal widthRatio);
207 void heightRatioChanged(qreal heightRatio);
208
209private:
210 QDeclarativeFlickable *flickable;
211 qreal m_xPosition;
212 qreal m_widthRatio;
213 qreal m_yPosition;
214 qreal m_heightRatio;
215};
216
217QT_END_NAMESPACE
218
219QML_DECLARE_TYPE(QDeclarativeFlickableVisibleArea)
220
221#endif
Note: See TracBrowser for help on using the repository browser.