1 | // Copyright (C) 2016 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 QSCROLLER_H |
5 | #define QSCROLLER_H |
6 | |
7 | #include <QtWidgets/qtwidgetsglobal.h> |
8 | #include <QtCore/QObject> |
9 | #include <QtCore/QPointF> |
10 | #include <QtWidgets/QScrollerProperties> |
11 | |
12 | QT_REQUIRE_CONFIG(scroller); |
13 | |
14 | QT_BEGIN_NAMESPACE |
15 | |
16 | |
17 | class QWidget; |
18 | class QScrollerPrivate; |
19 | class QScrollerProperties; |
20 | #ifndef QT_NO_GESTURES |
21 | class QFlickGestureRecognizer; |
22 | class QMouseFlickGestureRecognizer; |
23 | #endif |
24 | |
25 | class Q_WIDGETS_EXPORT QScroller : public QObject |
26 | { |
27 | Q_OBJECT |
28 | Q_PROPERTY(State state READ state NOTIFY stateChanged) |
29 | Q_PROPERTY(QScrollerProperties scrollerProperties READ scrollerProperties |
30 | WRITE setScrollerProperties NOTIFY scrollerPropertiesChanged) |
31 | |
32 | public: |
33 | enum State |
34 | { |
35 | Inactive, |
36 | Pressed, |
37 | Dragging, |
38 | Scrolling |
39 | }; |
40 | Q_ENUM(State) |
41 | |
42 | enum ScrollerGestureType |
43 | { |
44 | TouchGesture, |
45 | LeftMouseButtonGesture, |
46 | RightMouseButtonGesture, |
47 | MiddleMouseButtonGesture |
48 | }; |
49 | |
50 | enum Input |
51 | { |
52 | InputPress = 1, |
53 | InputMove, |
54 | InputRelease |
55 | }; |
56 | |
57 | static bool hasScroller(QObject *target); |
58 | |
59 | static QScroller *scroller(QObject *target); |
60 | static const QScroller *scroller(const QObject *target); |
61 | |
62 | #ifndef QT_NO_GESTURES |
63 | static Qt::GestureType grabGesture(QObject *target, ScrollerGestureType gestureType = TouchGesture); |
64 | static Qt::GestureType grabbedGesture(QObject *target); |
65 | static void ungrabGesture(QObject *target); |
66 | #endif |
67 | |
68 | static QList<QScroller *> activeScrollers(); |
69 | |
70 | QObject *target() const; |
71 | |
72 | State state() const; |
73 | |
74 | bool handleInput(Input input, const QPointF &position, qint64 timestamp = 0); |
75 | |
76 | void stop(); |
77 | QPointF velocity() const; |
78 | QPointF finalPosition() const; |
79 | QPointF pixelPerMeter() const; |
80 | |
81 | QScrollerProperties scrollerProperties() const; |
82 | |
83 | void setSnapPositionsX( const QList<qreal> &positions ); |
84 | void setSnapPositionsX( qreal first, qreal interval ); |
85 | void setSnapPositionsY( const QList<qreal> &positions ); |
86 | void setSnapPositionsY( qreal first, qreal interval ); |
87 | |
88 | public Q_SLOTS: |
89 | void setScrollerProperties(const QScrollerProperties &prop); |
90 | void scrollTo(const QPointF &pos); |
91 | void scrollTo(const QPointF &pos, int scrollTime); |
92 | void ensureVisible(const QRectF &rect, qreal xmargin, qreal ymargin); |
93 | void ensureVisible(const QRectF &rect, qreal xmargin, qreal ymargin, int scrollTime); |
94 | void resendPrepareEvent(); |
95 | |
96 | Q_SIGNALS: |
97 | void stateChanged(QScroller::State newstate); |
98 | void scrollerPropertiesChanged(const QScrollerProperties &); |
99 | |
100 | private: |
101 | QScrollerPrivate *d_ptr; |
102 | |
103 | QScroller(QObject *target); |
104 | virtual ~QScroller(); |
105 | |
106 | Q_DISABLE_COPY(QScroller) |
107 | Q_DECLARE_PRIVATE(QScroller) |
108 | |
109 | #ifndef QT_NO_GESTURES |
110 | friend class QFlickGestureRecognizer; |
111 | #endif |
112 | }; |
113 | |
114 | QT_END_NAMESPACE |
115 | |
116 | #endif // QSCROLLER_H |
117 | |