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 | |
4 | #ifndef QQUICKFLICKABLE_P_H |
5 | #define QQUICKFLICKABLE_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include "qquickitem.h" |
19 | #include <private/qtquickglobal_p.h> |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | class QQuickFlickablePrivate; |
24 | class QQuickFlickableVisibleArea; |
25 | class Q_QUICK_PRIVATE_EXPORT QQuickFlickable : public QQuickItem |
26 | { |
27 | Q_OBJECT |
28 | |
29 | Q_PROPERTY(qreal contentWidth READ contentWidth WRITE setContentWidth NOTIFY contentWidthChanged) |
30 | Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight NOTIFY contentHeightChanged) |
31 | Q_PROPERTY(qreal contentX READ contentX WRITE setContentX NOTIFY contentXChanged FINAL) |
32 | Q_PROPERTY(qreal contentY READ contentY WRITE setContentY NOTIFY contentYChanged FINAL) |
33 | Q_PROPERTY(QQuickItem *contentItem READ contentItem CONSTANT FINAL) |
34 | |
35 | Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin NOTIFY topMarginChanged FINAL) |
36 | Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin NOTIFY bottomMarginChanged FINAL) |
37 | Q_PROPERTY(qreal originY READ originY NOTIFY originYChanged FINAL) |
38 | |
39 | Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin NOTIFY leftMarginChanged FINAL) |
40 | Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin NOTIFY rightMarginChanged FINAL) |
41 | Q_PROPERTY(qreal originX READ originX NOTIFY originXChanged FINAL) |
42 | |
43 | Q_PROPERTY(qreal horizontalVelocity READ horizontalVelocity NOTIFY horizontalVelocityChanged FINAL) |
44 | Q_PROPERTY(qreal verticalVelocity READ verticalVelocity NOTIFY verticalVelocityChanged FINAL) |
45 | |
46 | Q_PROPERTY(BoundsBehavior boundsBehavior READ boundsBehavior WRITE setBoundsBehavior NOTIFY boundsBehaviorChanged FINAL) |
47 | Q_PROPERTY(BoundsMovement boundsMovement READ boundsMovement WRITE setBoundsMovement NOTIFY boundsMovementChanged REVISION(2, 10) FINAL) |
48 | Q_PROPERTY(QQuickTransition *rebound READ rebound WRITE setRebound NOTIFY reboundChanged FINAL) |
49 | Q_PROPERTY(qreal maximumFlickVelocity READ maximumFlickVelocity WRITE setMaximumFlickVelocity NOTIFY maximumFlickVelocityChanged FINAL) |
50 | Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration NOTIFY flickDecelerationChanged FINAL) |
51 | Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged FINAL) |
52 | Q_PROPERTY(bool movingHorizontally READ isMovingHorizontally NOTIFY movingHorizontallyChanged FINAL) |
53 | Q_PROPERTY(bool movingVertically READ isMovingVertically NOTIFY movingVerticallyChanged FINAL) |
54 | Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged FINAL) |
55 | Q_PROPERTY(bool flickingHorizontally READ isFlickingHorizontally NOTIFY flickingHorizontallyChanged FINAL) |
56 | Q_PROPERTY(bool flickingVertically READ isFlickingVertically NOTIFY flickingVerticallyChanged FINAL) |
57 | Q_PROPERTY(bool dragging READ isDragging NOTIFY draggingChanged FINAL) |
58 | Q_PROPERTY(bool draggingHorizontally READ isDraggingHorizontally NOTIFY draggingHorizontallyChanged FINAL) |
59 | Q_PROPERTY(bool draggingVertically READ isDraggingVertically NOTIFY draggingVerticallyChanged FINAL) |
60 | Q_PROPERTY(FlickableDirection flickableDirection READ flickableDirection WRITE setFlickableDirection NOTIFY flickableDirectionChanged FINAL) |
61 | |
62 | Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged FINAL) |
63 | Q_PROPERTY(int pressDelay READ pressDelay WRITE setPressDelay NOTIFY pressDelayChanged FINAL) |
64 | |
65 | Q_PROPERTY(bool atXEnd READ isAtXEnd NOTIFY atXEndChanged FINAL) |
66 | Q_PROPERTY(bool atYEnd READ isAtYEnd NOTIFY atYEndChanged FINAL) |
67 | Q_PROPERTY(bool atXBeginning READ isAtXBeginning NOTIFY atXBeginningChanged FINAL) |
68 | Q_PROPERTY(bool atYBeginning READ isAtYBeginning NOTIFY atYBeginningChanged FINAL) |
69 | |
70 | Q_PROPERTY(QQuickFlickableVisibleArea *visibleArea READ visibleArea CONSTANT FINAL) |
71 | |
72 | Q_PROPERTY(bool pixelAligned READ pixelAligned WRITE setPixelAligned NOTIFY pixelAlignedChanged FINAL) |
73 | Q_PROPERTY(bool synchronousDrag READ synchronousDrag WRITE setSynchronousDrag NOTIFY synchronousDragChanged REVISION(2, 12) FINAL) |
74 | |
75 | Q_PROPERTY(qreal horizontalOvershoot READ horizontalOvershoot NOTIFY horizontalOvershootChanged REVISION(2, 9) FINAL) |
76 | Q_PROPERTY(qreal verticalOvershoot READ verticalOvershoot NOTIFY verticalOvershootChanged REVISION(2, 9) FINAL) |
77 | |
78 | Q_PROPERTY(QQmlListProperty<QObject> flickableData READ flickableData FINAL) |
79 | Q_PROPERTY(QQmlListProperty<QQuickItem> flickableChildren READ flickableChildren FINAL) |
80 | Q_CLASSINFO("DefaultProperty" , "flickableData" ) |
81 | QML_NAMED_ELEMENT(Flickable) |
82 | QML_ADDED_IN_VERSION(2, 0) |
83 | |
84 | public: |
85 | QQuickFlickable(QQuickItem *parent=nullptr); |
86 | ~QQuickFlickable() override; |
87 | |
88 | QQmlListProperty<QObject> flickableData(); |
89 | QQmlListProperty<QQuickItem> flickableChildren(); |
90 | |
91 | enum BoundsBehaviorFlag { |
92 | StopAtBounds = 0x0, |
93 | DragOverBounds = 0x1, |
94 | OvershootBounds = 0x2, |
95 | DragAndOvershootBounds = DragOverBounds | OvershootBounds |
96 | }; |
97 | Q_DECLARE_FLAGS(BoundsBehavior, BoundsBehaviorFlag) |
98 | Q_FLAG(BoundsBehavior) |
99 | |
100 | BoundsBehavior boundsBehavior() const; |
101 | void setBoundsBehavior(BoundsBehavior); |
102 | |
103 | enum BoundsMovement { |
104 | // StopAtBounds = 0x0, |
105 | FollowBoundsBehavior = 0x1 |
106 | }; |
107 | Q_ENUM(BoundsMovement) |
108 | |
109 | BoundsMovement boundsMovement() const; |
110 | void setBoundsMovement(BoundsMovement movement); |
111 | |
112 | QQuickTransition *rebound() const; |
113 | void setRebound(QQuickTransition *transition); |
114 | |
115 | qreal contentWidth() const; |
116 | void setContentWidth(qreal); |
117 | |
118 | qreal contentHeight() const; |
119 | void setContentHeight(qreal); |
120 | |
121 | qreal contentX() const; |
122 | virtual void setContentX(qreal pos); |
123 | |
124 | qreal contentY() const; |
125 | virtual void setContentY(qreal pos); |
126 | |
127 | qreal topMargin() const; |
128 | void setTopMargin(qreal m); |
129 | |
130 | qreal bottomMargin() const; |
131 | void setBottomMargin(qreal m); |
132 | |
133 | qreal leftMargin() const; |
134 | void setLeftMargin(qreal m); |
135 | |
136 | qreal rightMargin() const; |
137 | void setRightMargin(qreal m); |
138 | |
139 | virtual qreal originY() const; |
140 | virtual qreal originX() const; |
141 | |
142 | bool isMoving() const; |
143 | bool isMovingHorizontally() const; |
144 | bool isMovingVertically() const; |
145 | bool isFlicking() const; |
146 | bool isFlickingHorizontally() const; |
147 | bool isFlickingVertically() const; |
148 | bool isDragging() const; |
149 | bool isDraggingHorizontally() const; |
150 | bool isDraggingVertically() const; |
151 | |
152 | int pressDelay() const; |
153 | void setPressDelay(int delay); |
154 | |
155 | qreal maximumFlickVelocity() const; |
156 | void setMaximumFlickVelocity(qreal); |
157 | |
158 | qreal flickDeceleration() const; |
159 | void setFlickDeceleration(qreal); |
160 | |
161 | bool isInteractive() const; |
162 | void setInteractive(bool); |
163 | |
164 | qreal horizontalVelocity() const; |
165 | qreal verticalVelocity() const; |
166 | |
167 | bool isAtXEnd() const; |
168 | bool isAtXBeginning() const; |
169 | bool isAtYEnd() const; |
170 | bool isAtYBeginning() const; |
171 | |
172 | QQuickItem *contentItem() const; |
173 | |
174 | enum FlickableDirection { AutoFlickDirection=0x0, HorizontalFlick=0x1, VerticalFlick=0x2, HorizontalAndVerticalFlick=0x3, |
175 | AutoFlickIfNeeded=0xc }; |
176 | Q_ENUM(FlickableDirection) |
177 | FlickableDirection flickableDirection() const; |
178 | void setFlickableDirection(FlickableDirection); |
179 | |
180 | bool pixelAligned() const; |
181 | void setPixelAligned(bool align); |
182 | |
183 | bool synchronousDrag() const; |
184 | void setSynchronousDrag(bool v); |
185 | |
186 | qreal horizontalOvershoot() const; |
187 | qreal verticalOvershoot() const; |
188 | |
189 | Q_INVOKABLE void resizeContent(qreal w, qreal h, QPointF center); |
190 | Q_INVOKABLE void returnToBounds(); |
191 | Q_INVOKABLE void flick(qreal xVelocity, qreal yVelocity); |
192 | Q_INVOKABLE void cancelFlick(); |
193 | |
194 | Q_SIGNALS: |
195 | void contentWidthChanged(); |
196 | void contentHeightChanged(); |
197 | void contentXChanged(); |
198 | void contentYChanged(); |
199 | void topMarginChanged(); |
200 | void bottomMarginChanged(); |
201 | void leftMarginChanged(); |
202 | void rightMarginChanged(); |
203 | void originYChanged(); |
204 | void originXChanged(); |
205 | void movingChanged(); |
206 | void movingHorizontallyChanged(); |
207 | void movingVerticallyChanged(); |
208 | void flickingChanged(); |
209 | void flickingHorizontallyChanged(); |
210 | void flickingVerticallyChanged(); |
211 | void draggingChanged(); |
212 | void draggingHorizontallyChanged(); |
213 | void draggingVerticallyChanged(); |
214 | void horizontalVelocityChanged(); |
215 | void verticalVelocityChanged(); |
216 | void isAtBoundaryChanged(); |
217 | void flickableDirectionChanged(); |
218 | void interactiveChanged(); |
219 | void boundsBehaviorChanged(); |
220 | Q_REVISION(2, 10) void boundsMovementChanged(); |
221 | void reboundChanged(); |
222 | void maximumFlickVelocityChanged(); |
223 | void flickDecelerationChanged(); |
224 | void pressDelayChanged(); |
225 | void movementStarted(); |
226 | void movementEnded(); |
227 | void flickStarted(); |
228 | void flickEnded(); |
229 | void dragStarted(); |
230 | void dragEnded(); |
231 | void pixelAlignedChanged(); |
232 | Q_REVISION(2, 12) void synchronousDragChanged(); |
233 | Q_REVISION(2, 9) void horizontalOvershootChanged(); |
234 | Q_REVISION(2, 9) void verticalOvershootChanged(); |
235 | |
236 | // The next four signals should be marked as Q_REVISION(2, 12). See QTBUG-71243 |
237 | void atXEndChanged(); |
238 | void atYEndChanged(); |
239 | void atXBeginningChanged(); |
240 | void atYBeginningChanged(); |
241 | |
242 | protected: |
243 | bool childMouseEventFilter(QQuickItem *, QEvent *) override; |
244 | void mousePressEvent(QMouseEvent *event) override; |
245 | void mouseMoveEvent(QMouseEvent *event) override; |
246 | void mouseReleaseEvent(QMouseEvent *event) override; |
247 | void touchEvent(QTouchEvent *event) override; |
248 | #if QT_CONFIG(wheelevent) |
249 | void wheelEvent(QWheelEvent *event) override; |
250 | #endif |
251 | void timerEvent(QTimerEvent *event) override; |
252 | |
253 | QQuickFlickableVisibleArea *visibleArea(); |
254 | |
255 | protected Q_SLOTS: |
256 | void movementStarting(); |
257 | void movementEnding(); |
258 | void movementEnding(bool hMovementEnding, bool vMovementEnding); |
259 | void velocityTimelineCompleted(); |
260 | void timelineCompleted(); |
261 | |
262 | protected: |
263 | virtual qreal minXExtent() const; |
264 | virtual qreal minYExtent() const; |
265 | virtual qreal maxXExtent() const; |
266 | virtual qreal maxYExtent() const; |
267 | qreal vWidth() const; |
268 | qreal vHeight() const; |
269 | void componentComplete() override; |
270 | virtual void viewportMoved(Qt::Orientations orient); |
271 | void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; |
272 | void mouseUngrabEvent() override; |
273 | bool filterPointerEvent(QQuickItem *receiver, QPointerEvent *event); |
274 | |
275 | bool xflick() const; |
276 | bool yflick() const; |
277 | |
278 | protected: |
279 | QQuickFlickable(QQuickFlickablePrivate &dd, QQuickItem *parent); |
280 | |
281 | private: |
282 | Q_DISABLE_COPY(QQuickFlickable) |
283 | Q_DECLARE_PRIVATE(QQuickFlickable) |
284 | friend class QQuickFlickableVisibleArea; |
285 | friend class QQuickFlickableReboundTransition; |
286 | }; |
287 | |
288 | QT_END_NAMESPACE |
289 | |
290 | QML_DECLARE_TYPE(QQuickFlickable) |
291 | |
292 | #endif // QQUICKFLICKABLE_P_H |
293 | |