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