~saviq/ubuntu/saucy/qtdeclarative-opensource-src/add-qtquick-delegate-range

« back to all changes in this revision

Viewing changes to src/quick/items/qquickflickable_p_p.h

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 14:17:19 UTC
  • Revision ID: package-import@ubuntu.com-20130205141719-qqeyml8wslpyez52
Tags: upstream-5.0.1
ImportĀ upstreamĀ versionĀ 5.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the QtQml module of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
9
** Commercial License Usage
 
10
** Licensees holding valid commercial Qt licenses may use this file in
 
11
** accordance with the commercial license agreement provided with the
 
12
** Software or, alternatively, in accordance with the terms contained in
 
13
** a written agreement between you and Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/contact-us.
 
16
**
 
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.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#ifndef QQUICKFLICKABLE_P_P_H
 
43
#define QQUICKFLICKABLE_P_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 "qquickflickable_p.h"
 
57
#include "qquickitem_p.h"
 
58
#include "qquickitemchangelistener_p.h"
 
59
 
 
60
#include <QtQml/qqml.h>
 
61
#include <QtCore/qdatetime.h>
 
62
#include "qplatformdefs.h"
 
63
 
 
64
#include <private/qquicktimeline_p_p.h>
 
65
#include <private/qquickanimation_p_p.h>
 
66
#include <private/qquicktransitionmanager_p_p.h>
 
67
 
 
68
QT_BEGIN_NAMESPACE
 
69
 
 
70
// Really slow flicks can be annoying.
 
71
const qreal MinimumFlickVelocity = 75.0;
 
72
 
 
73
class QQuickFlickableVisibleArea;
 
74
class QQuickTransition;
 
75
class QQuickFlickableReboundTransition;
 
76
 
 
77
class Q_AUTOTEST_EXPORT QQuickFlickablePrivate : public QQuickItemPrivate, public QQuickItemChangeListener
 
78
{
 
79
    Q_DECLARE_PUBLIC(QQuickFlickable)
 
80
 
 
81
public:
 
82
    static inline QQuickFlickablePrivate *get(QQuickFlickable *o) { return o->d_func(); }
 
83
 
 
84
    QQuickFlickablePrivate();
 
85
    void init();
 
86
 
 
87
    struct Velocity : public QQuickTimeLineValue
 
88
    {
 
89
        Velocity(QQuickFlickablePrivate *p)
 
90
            : parent(p) {}
 
91
        virtual void setValue(qreal v) {
 
92
            if (v != value()) {
 
93
                QQuickTimeLineValue::setValue(v);
 
94
                parent->updateVelocity();
 
95
            }
 
96
        }
 
97
        QQuickFlickablePrivate *parent;
 
98
    };
 
99
 
 
100
    struct AxisData {
 
101
        AxisData(QQuickFlickablePrivate *fp, void (QQuickFlickablePrivate::*func)(qreal))
 
102
            : move(fp, func)
 
103
            , transitionToBounds(0)
 
104
            , viewSize(-1), startMargin(0), endMargin(0)
 
105
            , origin(0)
 
106
            , transitionTo(0)
 
107
            , continuousFlickVelocity(0), velocityTime(), vTime(0)
 
108
            , smoothVelocity(fp), atEnd(false), atBeginning(true)
 
109
            , transitionToSet(false)
 
110
            , fixingUp(false), inOvershoot(false), moving(false), flicking(false)
 
111
            , dragging(false), extentsChanged(false)
 
112
            , explicitValue(false), minExtentDirty(true), maxExtentDirty(true)
 
113
        {}
 
114
 
 
115
        ~AxisData();
 
116
 
 
117
        void reset() {
 
118
            velocityBuffer.clear();
 
119
            dragStartOffset = 0;
 
120
            fixingUp = false;
 
121
            inOvershoot = false;
 
122
        }
 
123
 
 
124
        void markExtentsDirty() {
 
125
            minExtentDirty = true;
 
126
            maxExtentDirty = true;
 
127
            extentsChanged = true;
 
128
        }
 
129
 
 
130
        void resetTransitionTo() {
 
131
            transitionTo = 0;
 
132
            transitionToSet = false;
 
133
        }
 
134
 
 
135
        void addVelocitySample(qreal v, qreal maxVelocity);
 
136
        void updateVelocity();
 
137
 
 
138
        QQuickTimeLineValueProxy<QQuickFlickablePrivate> move;
 
139
        QQuickFlickableReboundTransition *transitionToBounds;
 
140
        qreal viewSize;
 
141
        qreal pressPos;
 
142
        qreal lastPos;
 
143
        qreal dragStartOffset;
 
144
        qreal dragMinBound;
 
145
        qreal dragMaxBound;
 
146
        qreal velocity;
 
147
        qreal flickTarget;
 
148
        qreal startMargin;
 
149
        qreal endMargin;
 
150
        qreal origin;
 
151
        qreal transitionTo;
 
152
        qreal continuousFlickVelocity;
 
153
        QElapsedTimer velocityTime;
 
154
        int vTime;
 
155
        QQuickFlickablePrivate::Velocity smoothVelocity;
 
156
        QPODVector<qreal,10> velocityBuffer;
 
157
        bool atEnd : 1;
 
158
        bool atBeginning : 1;
 
159
        bool transitionToSet : 1;
 
160
        bool fixingUp : 1;
 
161
        bool inOvershoot : 1;
 
162
        bool moving : 1;
 
163
        bool flicking : 1;
 
164
        bool dragging : 1;
 
165
        bool extentsChanged : 1;
 
166
        bool explicitValue : 1;
 
167
        mutable bool minExtentDirty : 1;
 
168
        mutable bool maxExtentDirty : 1;
 
169
    };
 
170
 
 
171
    bool flickX(qreal velocity);
 
172
    bool flickY(qreal velocity);
 
173
    virtual bool flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
 
174
                        QQuickTimeLineCallback::Callback fixupCallback, qreal velocity);
 
175
    void flickingStarted(bool flickingH, bool flickingV);
 
176
 
 
177
    void fixupX();
 
178
    void fixupY();
 
179
    virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent);
 
180
    void adjustContentPos(AxisData &data, qreal toPos);
 
181
    void resetTimeline(AxisData &data);
 
182
    void clearTimeline();
 
183
 
 
184
    void updateBeginningEnd();
 
185
 
 
186
    bool isInnermostPressDelay(QQuickItem *item) const;
 
187
    void captureDelayedPress(QQuickItem *item, QMouseEvent *event);
 
188
    void clearDelayedPress();
 
189
    void replayDelayedPress();
 
190
 
 
191
    void setViewportX(qreal x);
 
192
    void setViewportY(qreal y);
 
193
 
 
194
    qreal overShootDistance(qreal size);
 
195
 
 
196
    void itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &);
 
197
 
 
198
    void draggingStarting();
 
199
    void draggingEnding();
 
200
 
 
201
    bool isViewMoving() const;
 
202
 
 
203
public:
 
204
    QQuickItem *contentItem;
 
205
 
 
206
    AxisData hData;
 
207
    AxisData vData;
 
208
 
 
209
    QQuickTimeLine timeline;
 
210
    bool hMoved : 1;
 
211
    bool vMoved : 1;
 
212
    bool stealMouse : 1;
 
213
    bool pressed : 1;
 
214
    bool interactive : 1;
 
215
    bool calcVelocity : 1;
 
216
    bool pixelAligned : 1;
 
217
    bool replayingPressEvent : 1;
 
218
    QElapsedTimer timer;
 
219
    qint64 lastPosTime;
 
220
    qint64 lastPressTime;
 
221
    QPointF lastPos;
 
222
    QPointF pressPos;
 
223
    qreal deceleration;
 
224
    qreal maxVelocity;
 
225
    qreal reportedVelocitySmoothing;
 
226
    QMouseEvent *delayedPressEvent;
 
227
    QBasicTimer delayedPressTimer;
 
228
    int pressDelay;
 
229
    int fixupDuration;
 
230
    qreal flickBoost;
 
231
 
 
232
    enum FixupMode { Normal, Immediate, ExtentChanged };
 
233
    FixupMode fixupMode;
 
234
 
 
235
    static void fixupY_callback(void *);
 
236
    static void fixupX_callback(void *);
 
237
 
 
238
    void updateVelocity();
 
239
    int vTime;
 
240
    QQuickTimeLine velocityTimeline;
 
241
    QQuickFlickableVisibleArea *visibleArea;
 
242
    QQuickFlickable::FlickableDirection flickableDirection;
 
243
    QQuickFlickable::BoundsBehavior boundsBehavior;
 
244
    QQuickTransition *rebound;
 
245
 
 
246
    void viewportAxisMoved(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
 
247
                       QQuickTimeLineCallback::Callback fixupCallback);
 
248
 
 
249
    void handleMousePressEvent(QMouseEvent *);
 
250
    void handleMouseMoveEvent(QMouseEvent *);
 
251
    void handleMouseReleaseEvent(QMouseEvent *);
 
252
 
 
253
    qint64 computeCurrentTime(QInputEvent *event);
 
254
 
 
255
    // flickableData property
 
256
    static void data_append(QQmlListProperty<QObject> *, QObject *);
 
257
    static int data_count(QQmlListProperty<QObject> *);
 
258
    static QObject *data_at(QQmlListProperty<QObject> *, int);
 
259
    static void data_clear(QQmlListProperty<QObject> *);
 
260
};
 
261
 
 
262
class QQuickFlickableVisibleArea : public QObject
 
263
{
 
264
    Q_OBJECT
 
265
 
 
266
    Q_PROPERTY(qreal xPosition READ xPosition NOTIFY xPositionChanged)
 
267
    Q_PROPERTY(qreal yPosition READ yPosition NOTIFY yPositionChanged)
 
268
    Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY widthRatioChanged)
 
269
    Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY heightRatioChanged)
 
270
 
 
271
public:
 
272
    QQuickFlickableVisibleArea(QQuickFlickable *parent=0);
 
273
 
 
274
    qreal xPosition() const;
 
275
    qreal widthRatio() const;
 
276
    qreal yPosition() const;
 
277
    qreal heightRatio() const;
 
278
 
 
279
    void updateVisible();
 
280
 
 
281
signals:
 
282
    void xPositionChanged(qreal xPosition);
 
283
    void yPositionChanged(qreal yPosition);
 
284
    void widthRatioChanged(qreal widthRatio);
 
285
    void heightRatioChanged(qreal heightRatio);
 
286
 
 
287
private:
 
288
    QQuickFlickable *flickable;
 
289
    qreal m_xPosition;
 
290
    qreal m_widthRatio;
 
291
    qreal m_yPosition;
 
292
    qreal m_heightRatio;
 
293
};
 
294
 
 
295
QT_END_NAMESPACE
 
296
 
 
297
QML_DECLARE_TYPE(QQuickFlickableVisibleArea)
 
298
 
 
299
#endif // QQUICKFLICKABLE_P_P_H