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
118public:
119 QQuickFlickable(QQuickItem *parent=nullptr);
120 ~QQuickFlickable() override;
121
122 QQmlListProperty<QObject> flickableData();
123 QQmlListProperty<QQuickItem> flickableChildren();
124
125 enum BoundsBehaviorFlag {
126 StopAtBounds = 0x0,
127 DragOverBounds = 0x1,
128 OvershootBounds = 0x2,
129 DragAndOvershootBounds = DragOverBounds | OvershootBounds
130 };
131 Q_DECLARE_FLAGS(BoundsBehavior, BoundsBehaviorFlag)
132 Q_FLAG(BoundsBehavior)
133
134 BoundsBehavior boundsBehavior() const;
135 void setBoundsBehavior(BoundsBehavior);
136
137 enum BoundsMovement {
138 // StopAtBounds = 0x0,
139 FollowBoundsBehavior = 0x1
140 };
141 Q_ENUM(BoundsMovement)
142
143 BoundsMovement boundsMovement() const;
144 void setBoundsMovement(BoundsMovement movement);
145
146 QQuickTransition *rebound() const;
147 void setRebound(QQuickTransition *transition);
148
149 qreal contentWidth() const;
150 void setContentWidth(qreal);
151
152 qreal contentHeight() const;
153 void setContentHeight(qreal);
154
155 qreal contentX() const;
156 virtual void setContentX(qreal pos);
157
158 qreal contentY() const;
159 virtual void setContentY(qreal pos);
160
161 qreal topMargin() const;
162 void setTopMargin(qreal m);
163
164 qreal bottomMargin() const;
165 void setBottomMargin(qreal m);
166
167 qreal leftMargin() const;
168 void setLeftMargin(qreal m);
169
170 qreal rightMargin() const;
171 void setRightMargin(qreal m);
172
173 virtual qreal originY() const;
174 virtual qreal originX() const;
175
176 bool isMoving() const;
177 bool isMovingHorizontally() const;
178 bool isMovingVertically() const;
179 bool isFlicking() const;
180 bool isFlickingHorizontally() const;
181 bool isFlickingVertically() const;
182 bool isDragging() const;
183 bool isDraggingHorizontally() const;
184 bool isDraggingVertically() const;
185
186 int pressDelay() const;
187 void setPressDelay(int delay);
188
189 qreal maximumFlickVelocity() const;
190 void setMaximumFlickVelocity(qreal);
191
192 qreal flickDeceleration() const;
193 void setFlickDeceleration(qreal);
194
195 bool isInteractive() const;
196 void setInteractive(bool);
197
198 qreal horizontalVelocity() const;
199 qreal verticalVelocity() const;
200
201 bool isAtXEnd() const;
202 bool isAtXBeginning() const;
203 bool isAtYEnd() const;
204 bool isAtYBeginning() const;
205
206 QQuickItem *contentItem() const;
207
208 enum FlickableDirection { AutoFlickDirection=0x0, HorizontalFlick=0x1, VerticalFlick=0x2, HorizontalAndVerticalFlick=0x3,
209 AutoFlickIfNeeded=0xc };
210 Q_ENUM(FlickableDirection)
211 FlickableDirection flickableDirection() const;
212 void setFlickableDirection(FlickableDirection);
213
214 bool pixelAligned() const;
215 void setPixelAligned(bool align);
216
217 bool synchronousDrag() const;
218 void setSynchronousDrag(bool v);
219
220 qreal horizontalOvershoot() const;
221 qreal verticalOvershoot() const;
222
223 Q_INVOKABLE void resizeContent(qreal w, qreal h, QPointF center);
224 Q_INVOKABLE void returnToBounds();
225 Q_INVOKABLE void flick(qreal xVelocity, qreal yVelocity);
226 Q_INVOKABLE void cancelFlick();
227
228Q_SIGNALS:
229 void contentWidthChanged();
230 void contentHeightChanged();
231 void contentXChanged();
232 void contentYChanged();
233 void topMarginChanged();
234 void bottomMarginChanged();
235 void leftMarginChanged();
236 void rightMarginChanged();
237 void originYChanged();
238 void originXChanged();
239 void movingChanged();
240 void movingHorizontallyChanged();
241 void movingVerticallyChanged();
242 void flickingChanged();
243 void flickingHorizontallyChanged();
244 void flickingVerticallyChanged();
245 void draggingChanged();
246 void draggingHorizontallyChanged();
247 void draggingVerticallyChanged();
248 void horizontalVelocityChanged();
249 void verticalVelocityChanged();
250 void isAtBoundaryChanged();
251 void flickableDirectionChanged();
252 void interactiveChanged();
253 void boundsBehaviorChanged();
254 Q_REVISION(10) void boundsMovementChanged();
255 void reboundChanged();
256 void maximumFlickVelocityChanged();
257 void flickDecelerationChanged();
258 void pressDelayChanged();
259 void movementStarted();
260 void movementEnded();
261 void flickStarted();
262 void flickEnded();
263 void dragStarted();
264 void dragEnded();
265 void pixelAlignedChanged();
266 Q_REVISION(12) void synchronousDragChanged();
267 Q_REVISION(9) void horizontalOvershootChanged();
268 Q_REVISION(9) void verticalOvershootChanged();
269
270 // The next four signals should be marked as Q_REVISION(12). See QTBUG-71243
271 void atXEndChanged();
272 void atYEndChanged();
273 void atXBeginningChanged();
274 void atYBeginningChanged();
275
276protected:
277 bool childMouseEventFilter(QQuickItem *, QEvent *) override;
278 void mousePressEvent(QMouseEvent *event) override;
279 void mouseMoveEvent(QMouseEvent *event) override;
280 void mouseReleaseEvent(QMouseEvent *event) override;
281#if QT_CONFIG(wheelevent)
282 void wheelEvent(QWheelEvent *event) override;
283#endif
284 void timerEvent(QTimerEvent *event) override;
285
286 QQuickFlickableVisibleArea *visibleArea();
287
288protected Q_SLOTS:
289 void movementStarting();
290 void movementEnding();
291 void movementEnding(bool hMovementEnding, bool vMovementEnding);
292 void velocityTimelineCompleted();
293 void timelineCompleted();
294
295protected:
296 virtual qreal minXExtent() const;
297 virtual qreal minYExtent() const;
298 virtual qreal maxXExtent() const;
299 virtual qreal maxYExtent() const;
300 qreal vWidth() const;
301 qreal vHeight() const;
302 void componentComplete() override;
303 virtual void viewportMoved(Qt::Orientations orient);
304 void geometryChanged(const QRectF &newGeometry,
305 const QRectF &oldGeometry) override;
306 void mouseUngrabEvent() override;
307 bool filterMouseEvent(QQuickItem *receiver, QMouseEvent *event);
308
309 bool xflick() const;
310 bool yflick() const;
311
312protected:
313 QQuickFlickable(QQuickFlickablePrivate &dd, QQuickItem *parent);
314
315private:
316 Q_DISABLE_COPY(QQuickFlickable)
317 Q_DECLARE_PRIVATE(QQuickFlickable)
318 friend class QQuickFlickableContentItem;
319 friend class QQuickFlickableVisibleArea;
320 friend class QQuickFlickableReboundTransition;
321};
322
323QT_END_NAMESPACE
324
325QML_DECLARE_TYPE(QQuickFlickable)
326
327#endif // QQUICKFLICKABLE_P_H
328