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

source code of qtdeclarative/src/quick/items/qquickflickable_p.h