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"
22
23#include <QtQml/qqml.h>
24#include <QtCore/qdatetime.h>
25#include "qplatformdefs.h"
26
27#include <private/qquicktimeline_p_p.h>
28#include <private/qquickanimation_p_p.h>
29#include <private/qquicktransitionmanager_p_p.h>
30#include <private/qpodvector_p.h>
31
33
34class QQuickFlickableVisibleArea;
35class QQuickTransition;
37
38class Q_QUICK_EXPORT QQuickFlickablePrivate : public QQuickItemPrivate,
39 public QSafeQuickItemChangeListener<QQuickFlickablePrivate>
40{
41 Q_DECLARE_PUBLIC(QQuickFlickable)
42
43public:
44 static inline QQuickFlickablePrivate *get(QQuickFlickable *o) { return o->d_func(); }
45
46 QQuickFlickablePrivate();
47 void init();
48
49 struct Velocity : public QQuickTimeLineValue
50 {
51 Velocity(QQuickFlickablePrivate *p)
52 : parent(p) {}
53 void setValue(qreal v) override {
54 if (v != value()) {
55 QQuickTimeLineValue::setValue(v);
56 parent->updateVelocity();
57 }
58 }
59 QQuickFlickablePrivate *parent;
60 };
61
62 enum MovementReason { Other, SetIndex, Mouse };
63
64 struct AxisData {
65 AxisData(QQuickFlickablePrivate *fp, void (QQuickFlickablePrivate::*func)(qreal))
66 : move(fp, func)
67 , smoothVelocity(fp), atEnd(false), atBeginning(true)
68 , transitionToSet(false)
69 , fixingUp(false), inOvershoot(false), inRebound(false), moving(false), flicking(false)
70 , flickingWhenDragBegan(false), dragging(false), extentsChanged(false)
71 , explicitValue(false), contentPositionChangedExternallyDuringDrag(false)
72 , minExtentDirty(true), maxExtentDirty(true)
73 {}
74
75 ~AxisData();
76
77 void reset() {
78 velocityBuffer.clear();
79 dragStartOffset = 0;
80 fixingUp = false;
81 inOvershoot = false;
82 contentPositionChangedExternallyDuringDrag = false;
83 }
84
85 void markExtentsDirty() {
86 minExtentDirty = true;
87 maxExtentDirty = true;
88 extentsChanged = true;
89 }
90
91 void resetTransitionTo() {
92 transitionTo = 0;
93 transitionToSet = false;
94 }
95
96 void addVelocitySample(qreal v, qreal maxVelocity);
97 void updateVelocity();
98
99 QQuickTimeLineValueProxy<QQuickFlickablePrivate> move;
100 QQuickFlickableReboundTransition *transitionToBounds = nullptr;
101 qreal viewSize = -1;
102 qreal pressPos = 0;
103 qreal lastPos = 0;
104 qreal dragStartOffset = 0;
105 qreal dragMinBound = 0;
106 qreal dragMaxBound = 0;
107 qreal previousDragDelta = 0;
108 qreal velocity = 0;
109 qreal flickTarget = 0;
110 qreal startMargin = 0;
111 qreal endMargin = 0;
112 qreal origin = 0;
113 qreal overshoot = 0;
114 qreal transitionTo = 0;
115 qreal continuousFlickVelocity = 0;
116 QElapsedTimer velocityTime;
117 int vTime = 0;
118 QQuickFlickablePrivate::Velocity smoothVelocity;
119 QPODVector<qreal,10> velocityBuffer;
120 // bitfield
121 uint atEnd : 1;
122 uint atBeginning : 1;
123 uint transitionToSet : 1;
124 uint fixingUp : 1;
125 uint inOvershoot : 1;
126 uint inRebound : 1;
127 uint moving : 1;
128 uint flicking : 1;
129 uint flickingWhenDragBegan : 1;
130 uint dragging : 1;
131 uint extentsChanged : 1;
132 uint explicitValue : 1;
133 uint contentPositionChangedExternallyDuringDrag : 1;
134 // mutable portion of bitfield
135 mutable uint minExtentDirty : 1;
136 mutable uint maxExtentDirty : 1;
137 // end bitfield
138 };
139
140 bool flickX(QEvent::Type eventType, qreal velocity);
141 bool flickY(QEvent::Type eventType, qreal velocity);
142 virtual bool flick(AxisData &data, qreal minExtent, qreal maxExtent, qreal vSize,
143 QQuickTimeLineCallback::Callback fixupCallback,
144 QEvent::Type eventType, qreal velocity);
145 void flickingStarted(bool flickingH, bool flickingV);
146
147 void fixupX();
148 void fixupY();
149 virtual void fixup(AxisData &data, qreal minExtent, qreal maxExtent);
150 void adjustContentPos(AxisData &data, qreal toPos);
151 void resetTimeline(AxisData &data);
152 void clearTimeline();
153
154 void updateBeginningEnd();
155
156 bool isInnermostPressDelay(QQuickItem *item) const;
157 void captureDelayedPress(QQuickItem *item, QPointerEvent *event);
158 void clearDelayedPress();
159 void replayDelayedPress();
160
161 void setViewportX(qreal x);
162 void setViewportY(qreal y);
163
164 qreal overShootDistance(qreal velocity) const;
165
166 void itemGeometryChanged(QQuickItem *, QQuickGeometryChange, const QRectF &) override;
167
168 void draggingStarting();
169 void draggingEnding();
170
171 bool isViewMoving() const;
172
173 void cancelInteraction();
174
175 void addPointerHandler(QQuickPointerHandler *h) override;
176
177 virtual bool wantsPointerEvent(const QPointerEvent *) { return true; }
178
179public:
180 QQuickItem *contentItem;
181
182 AxisData hData;
183 AxisData vData;
184
185 MovementReason moveReason = Other;
186
187 QQuickTimeLine timeline;
188 bool hMoved : 1;
189 bool vMoved : 1;
190 bool stealMouse : 1;
191 bool pressed : 1;
192 bool scrollingPhase : 1;
193 bool interactive : 1;
194 bool calcVelocity : 1;
195 bool pixelAligned : 1;
196 bool syncDrag : 1;
197 Qt::MouseButtons acceptedButtons = Qt::LeftButton;
198 QElapsedTimer timer;
199 qint64 lastPosTime;
200 qint64 lastPressTime;
201 QPointF lastPos;
202 QPointF pressPos;
203 QVector2D accumulatedWheelPixelDelta;
204 qreal deceleration;
205 qreal wheelDeceleration;
206 qreal maxVelocity;
207 QPointerEvent *delayedPressEvent;
208 QBasicTimer delayedPressTimer;
209 int pressDelay;
210 int fixupDuration;
211 qreal flickBoost;
212 qreal initialWheelFlickDistance;
213
214 enum FixupMode { Normal, Immediate, ExtentChanged };
215 FixupMode fixupMode;
216
217 static void fixupY_callback(void *);
218 static void fixupX_callback(void *);
219
220 void updateVelocity();
221 int vTime;
222 QQuickTimeLine velocityTimeline;
223 QQuickFlickableVisibleArea *visibleArea;
224 QQuickFlickable::FlickableDirection flickableDirection;
225 QQuickFlickable::BoundsBehavior boundsBehavior;
226 QQuickFlickable::BoundsMovement boundsMovement;
227 QQuickTransition *rebound;
228
229 void viewportAxisMoved(AxisData &data, qreal minExtent, qreal maxExtent,
230 QQuickTimeLineCallback::Callback fixupCallback);
231
232 void handlePressEvent(QPointerEvent *);
233 void handleMoveEvent(QPointerEvent *);
234 void handleReleaseEvent(QPointerEvent *);
235 bool buttonsAccepted(const QSinglePointEvent *event);
236
237 void maybeBeginDrag(qint64 currentTimestamp, const QPointF &pressPosn,
238 Qt::MouseButtons buttons = Qt::NoButton);
239 void drag(qint64 currentTimestamp, QEvent::Type eventType, const QPointF &localPos,
240 const QVector2D &deltas, bool overThreshold, bool momentum,
241 bool velocitySensitiveOverBounds, const QVector2D &velocity);
242
243 QVector2D firstPointLocalVelocity(QPointerEvent *event);
244 qint64 computeCurrentTime(QInputEvent *event) const;
245
246 // flickableData property
247 static void data_append(QQmlListProperty<QObject> *, QObject *);
248 static qsizetype data_count(QQmlListProperty<QObject> *);
249 static QObject *data_at(QQmlListProperty<QObject> *, qsizetype);
250 static void data_clear(QQmlListProperty<QObject> *);
251};
252
253class Q_QUICK_EXPORT QQuickFlickableVisibleArea : public QObject
254{
255 Q_OBJECT
256
257 Q_PROPERTY(qreal xPosition READ xPosition NOTIFY xPositionChanged FINAL)
258 Q_PROPERTY(qreal yPosition READ yPosition NOTIFY yPositionChanged FINAL)
259 Q_PROPERTY(qreal widthRatio READ widthRatio NOTIFY widthRatioChanged FINAL)
260 Q_PROPERTY(qreal heightRatio READ heightRatio NOTIFY heightRatioChanged FINAL)
261 QML_ANONYMOUS
262 QML_ADDED_IN_VERSION(2, 0)
263
264public:
265 QQuickFlickableVisibleArea(QQuickFlickable *parent=nullptr);
266
267 qreal xPosition() const;
268 qreal widthRatio() const;
269 qreal yPosition() const;
270 qreal heightRatio() const;
271
272 void updateVisible();
273
274Q_SIGNALS:
275 void xPositionChanged(qreal xPosition);
276 void yPositionChanged(qreal yPosition);
277 void widthRatioChanged(qreal widthRatio);
278 void heightRatioChanged(qreal heightRatio);
279
280private:
281 QQuickFlickable *flickable;
282 qreal m_xPosition;
283 qreal m_widthRatio;
284 qreal m_yPosition;
285 qreal m_heightRatio;
286};
287
288QT_END_NAMESPACE
289
290#endif // QQUICKFLICKABLE_P_P_H
bool contains(const QPointF &point) const override
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
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")
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)