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

source code of qtbase/src/widgets/util/qscroller.h