Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickflickable_p_p.h
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QQUICKFLICKABLE_P_P_H
6#define QQUICKFLICKABLE_P_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
20#include "qquickitem_p.h"
23
24#include <QtQml/qqml.h>
25#include <QtCore/qdatetime.h>
26#include "qplatformdefs.h"
27
28#include <private/qquicktimeline_p_p.h>
29#include <private/qquickanimation_p_p.h>
30#include <private/qquicktransitionmanager_p_p.h>
31
32#if QT_CONFIG(accessibility)
33# include <QElapsedTimer>
34#endif
35
36#include <array>
37
38QT_BEGIN_NAMESPACE
39
40class QQuickFlickableVisibleArea;
41class QQuickTransition;
43
44class Q_QUICK_EXPORT QQuickFlickablePrivate : public QQuickItemPrivate,
45 public QSafeQuickItemChangeListener<QQuickFlickablePrivate>
46{
47 Q_DECLARE_PUBLIC(QQuickFlickable)
48
49public:
50 static inline QQuickFlickablePrivate *get(QQuickFlickable *o) { return o->d_func(); }
51
52 QQuickFlickablePrivate();
53 void init();
54
55 struct Velocity : public QQuickTimeLineValue
56 {
57 Velocity(QQuickFlickablePrivate *p)
58 : parent(p) {}
59 void setValue(qreal v) override {
60 if (v != value()) {
61 QQuickTimeLineValue::setValue(v);
62 parent->updateVelocity();
63 }
64 }
65 QQuickFlickablePrivate *parent;
66 };
67
68 enum MovementReason { Other, SetIndex, Mouse };
69
70 struct AxisData {
71 AxisData(QQuickFlickablePrivate *fp, void (QQuickFlickablePrivate::*func)(qreal))
72 : move(fp, func)
73 , smoothVelocity(fp), atEnd(false), atBeginning(true)
74 , transitionToSet(false)
75 , fixingUp(false), inOvershoot(false), inRebound(false), moving(false), flicking(false)
76 , flickingWhenDragBegan(false), dragging(false), extentsChanged(false)
77 , explicitValue(false), contentPositionChangedExternallyDuringDrag(false)
78 , minExtentDirty(true), maxExtentDirty(true)
79 {}
80
81 ~AxisData();
82
83 void reset() {
84 velocitySamples = 0;
85 velocityWritePos = 0;
86 dragStartOffset = 0;
87 fixingUp = false;
88 inOvershoot = false;
89 contentPositionChangedExternallyDuringDrag = false;
90 }
91
92 void markExtentsDirty() {
93 minExtentDirty = true;
94 maxExtentDirty = true;
95 extentsChanged = true;
96 }
97
98 void resetTransitionTo() {
99 transitionTo = 0;
100 transitionToSet = false;
101 }
102
103 void addVelocitySample(qreal v, qreal maxVelocity);
104 void updateVelocity();
105
106 QQuickTimeLineValueProxy<QQuickFlickablePrivate> move;
107 QQuickFlickableReboundTransition *transitionToBounds = nullptr;
108 qreal viewSize = -1;
109 qreal pressPos = 0;
110 qreal lastPos = 0;
111 qreal dragStartOffset = 0;
112 qreal dragMinBound = 0;
113 qreal dragMaxBound = 0;
114 qreal previousDragDelta = 0;
115 qreal velocity = 0;
116 qreal flickTarget = 0;
117 qreal startMargin = 0;
118 qreal endMargin = 0;
119 qreal origin = 0;
120 qreal overshoot = 0;
121 qreal transitionTo = 0;
122 qreal continuousFlickVelocity = 0;
123 QElapsedTimer velocityTime;
124 int vTime = 0;
125 QQuickFlickablePrivate::Velocity smoothVelocity;
126 std::array<qreal, QML_FLICK_SAMPLEBUFFER> velocityBuffer;
127 int velocitySamples = 0;
128 int velocityWritePos = 0;
129 // bitfield
130 uint atEnd : 1;
131 uint atBeginning : 1;
132 uint transitionToSet : 1;
133 uint fixingUp : 1;
134 uint inOvershoot : 1;
135 uint inRebound : 1;
136 uint moving : 1;
137 uint flicking : 1;
138 uint flickingWhenDragBegan : 1;
139 uint dragging : 1;
140 uint extentsChanged : 1;
141 uint explicitValue : 1;
142 uint contentPositionChangedExternallyDuringDrag : 1;
143 // mutable portion of bitfield
144 mutable uint minExtentDirty : 1;
145 mutable uint maxExtentDirty : 1;
146 // end bitfield
147 };
148
149 bool flickX(QEvent::Type eventType, qreal velocity);
150 bool flickY(QEvent::Type eventType, qreal velocity);
151 virtual bool flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
152 QQuickTimeLineCallback::Callback fixupCallback,
153 QEvent::Type eventType, qreal velocity);
154 void flickingStarted(bool flickingH, bool flickingV);
155
156 void fixupX();
157 void fixupY();
158 virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent);
159 void adjustContentPos(AxisData &data, qreal toPos);
160 void resetTimeline(AxisData &data);
161 void clearTimeline();
162
163 void updateBeginningEnd();
164
165 bool isInnermostPressDelay(QQuickItem *item) const;
166 void captureDelayedPress(QQuickItem *item, QPointerEvent *event);
167 void clearDelayedPress();
168 void replayDelayedPress();
169
170 void setViewportX(qreal x);
171 void setViewportY(qreal y);
172
173 qreal overShootDistance(qreal velocity) const;
174
175 void itemGeometryChanged(QQuickItem *, QQuickGeometryChange, const QRectF &) override;
176
177 void draggingStarting();
178 void draggingEnding();
179
180 bool isViewMoving() const;
181
182 void cancelInteraction();
183
184 void addPointerHandler(QQuickPointerHandler *h) override;
185
186 virtual bool wantsPointerEvent(const QPointerEvent *) { return true; }
187
188public:
189 QQuickItem *contentItem;
190
191 AxisData hData;
192 AxisData vData;
193
194 MovementReason moveReason = Other;
195
196 QQuickTimeLine timeline;
197 bool hMoved : 1;
198 bool vMoved : 1;
199 bool stealGrab : 1;
200 bool pressed : 1;
201 bool scrollingPhase : 1;
202 bool interactive : 1;
203 bool calcVelocity : 1;
204 bool pixelAligned : 1;
205 bool syncDrag : 1;
206 Qt::MouseButtons acceptedButtons = Qt::LeftButton;
207 QElapsedTimer timer;
208 qint64 lastPosTime;
209 qint64 lastPressTime;
210 QPointF lastPos;
211 QPointF pressPos;
212 QVector2D accumulatedWheelPixelDelta;
213 qreal deceleration;
214 qreal wheelDeceleration;
215 qreal maxVelocity;
216 QPointerEvent *delayedPressEvent;
217 QBasicTimer delayedPressTimer;
218 int pressDelay;
219 int fixupDuration;
220 qreal flickBoost;
221 qreal initialWheelFlickDistance;
222
223 enum FixupMode { Normal, Immediate, ExtentChanged };
224 FixupMode fixupMode;
225
226 static void fixupY_callback(void *);
227 static void fixupX_callback(void *);
228
229 void updateVelocity();
230 int vTime;
231 QQuickTimeLine velocityTimeline;
232 QQuickFlickableVisibleArea *visibleArea;
233 QQuickFlickable::FlickableDirection flickableDirection;
234 QQuickFlickable::BoundsBehavior boundsBehavior;
235 QQuickFlickable::BoundsMovement boundsMovement;
236 QQuickTransition *rebound;
237
238 void viewportAxisMoved(AxisData &data, qreal minExtent, qreal maxExtent,
239 QQuickTimeLineCallback::Callback fixupCallback);
240
241 void handlePressEvent(QPointerEvent *);
242 void handleMoveEvent(QPointerEvent *);
243 void handleReleaseEvent(QPointerEvent *);
244 bool buttonsAccepted(const QSinglePointEvent *event);
245
246 void maybeBeginDrag(qint64 currentTimestamp, const QPointF &pressPosn,
247 Qt::MouseButtons buttons = Qt::NoButton);
248 void drag(qint64 currentTimestamp, QEvent::Type eventType, const QPointF &localPos,
249 const QVector2D &deltas, bool overThreshold, bool momentum,
250 bool velocitySensitiveOverBounds, const QVector2D &velocity);
251
252 QVector2D firstPointLocalVelocity(QPointerEvent *event);
253 qint64 computeCurrentTime(QInputEvent *event) const;
254
255 // flickableData property
256 static void data_append(QQmlListProperty<QObject> *, QObject *);
257 static qsizetype data_count(QQmlListProperty<QObject> *);
258 static QObject *data_at(QQmlListProperty<QObject> *, qsizetype);
259 static void data_clear(QQmlListProperty<QObject> *);
260
261#if QT_CONFIG(accessibility)
262private:
263 QElapsedTimer m_scrollEventTimer;
264#endif
265};
266
267class Q_QUICK_EXPORT QQuickFlickableVisibleArea : public QObject
268{
269 Q_OBJECT
270
271 Q_PROPERTY(qreal xPosition READ xPosition NOTIFY xPositionChanged FINAL)
272 Q_PROPERTY(qreal yPosition READ yPosition NOTIFY yPositionChanged FINAL)
273 Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY widthRatioChanged FINAL)
274 Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY heightRatioChanged FINAL)
275 QML_ANONYMOUS
276 QML_ADDED_IN_VERSION(2, 0)
277
278public:
279 QQuickFlickableVisibleArea(QQuickFlickable *parent=nullptr);
280
281 qreal xPosition() const;
282 qreal widthRatio() const;
283 qreal yPosition() const;
284 qreal heightRatio() const;
285
286 void updateVisible();
287
288Q_SIGNALS:
289 void xPositionChanged(qreal xPosition);
290 void yPositionChanged(qreal yPosition);
291 void widthRatioChanged(qreal widthRatio);
292 void heightRatioChanged(qreal heightRatio);
293
294private:
295 QQuickFlickable *flickable;
296 qreal m_xPosition;
297 qreal m_widthRatio;
298 qreal m_yPosition;
299 qreal m_heightRatio;
300};
301
302QT_END_NAMESPACE
303
304#endif // QQUICKFLICKABLE_P_P_H
bool contains(const QPointF &point) const override
QQuickFlickableContentItem(QQuickItem *parent=nullptr)
bool startTransition(QQuickFlickablePrivate::AxisData *data, qreal toPos)
QQuickFlickableReboundTransition(QQuickFlickable *f, const QString &name)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
Combined button and popup list for selecting options.
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
static bool fuzzyLessThanOrEqualTo(qreal a, qreal b)
static qreal EaseOvershoot(qreal t)
#define QML_FLICK_SAMPLEBUFFER
#define QML_FLICK_OVERSHOOT
#define QML_FLICK_MULTIFLICK_MAXBOOST
#define QML_FLICK_MULTIFLICK_THRESHOLD
#define QML_FLICK_OVERSHOOTFRICTION
#define QML_FLICK_DISCARDSAMPLES
#define QML_FLICK_MULTIFLICK_RATIO
QDebug Q_QUICK_EXPORT operator<<(QDebug debug, const QQuickWindow *item)