1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWidgets 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 QSCROLLER_H
41 #define QSCROLLER_H
42 
43 #include <QtWidgets/qtwidgetsglobal.h>
44 #include <QtCore/QObject>
45 #include <QtCore/QPointF>
46 #include <QtWidgets/QScrollerProperties>
47 
48 QT_REQUIRE_CONFIG(scroller);
49 
50 QT_BEGIN_NAMESPACE
51 
52 
53 class QWidget;
54 class QScrollerPrivate;
55 class QScrollerProperties;
56 #ifndef QT_NO_GESTURES
57 class QFlickGestureRecognizer;
58 class QMouseFlickGestureRecognizer;
59 #endif
60 
61 class Q_WIDGETS_EXPORT QScroller : public QObject
62 {
63     Q_OBJECT
64     Q_PROPERTY(State state READ state NOTIFY stateChanged)
65     Q_PROPERTY(QScrollerProperties scrollerProperties READ scrollerProperties WRITE setScrollerProperties NOTIFY scrollerPropertiesChanged)
66 
67 public:
68     enum State
69     {
70         Inactive,
71         Pressed,
72         Dragging,
73         Scrolling
74     };
75     Q_ENUM(State)
76 
77     enum ScrollerGestureType
78     {
79         TouchGesture,
80         LeftMouseButtonGesture,
81         RightMouseButtonGesture,
82         MiddleMouseButtonGesture
83     };
84 
85     enum Input
86     {
87         InputPress = 1,
88         InputMove,
89         InputRelease
90     };
91 
92     static bool hasScroller(QObject *target);
93 
94     static QScroller *scroller(QObject *target);
95     static const QScroller *scroller(const QObject *target);
96 
97 #ifndef QT_NO_GESTURES
98     static Qt::GestureType grabGesture(QObject *target, ScrollerGestureType gestureType = TouchGesture);
99     static Qt::GestureType grabbedGesture(QObject *target);
100     static void ungrabGesture(QObject *target);
101 #endif
102 
103     static QList<QScroller *> activeScrollers();
104 
105     QObject *target() const;
106 
107     State state() const;
108 
109     bool handleInput(Input input, const QPointF &position, qint64 timestamp = 0);
110 
111     void stop();
112     QPointF velocity() const;
113     QPointF finalPosition() const;
114     QPointF pixelPerMeter() const;
115 
116     QScrollerProperties scrollerProperties() const;
117 
118     void setSnapPositionsX( const QList<qreal> &positions );
119     void setSnapPositionsX( qreal first, qreal interval );
120     void setSnapPositionsY( const QList<qreal> &positions );
121     void setSnapPositionsY( qreal first, qreal interval );
122 
123 public Q_SLOTS:
124     void setScrollerProperties(const QScrollerProperties &prop);
125     void scrollTo(const QPointF &pos);
126     void scrollTo(const QPointF &pos, int scrollTime);
127     void ensureVisible(const QRectF &rect, qreal xmargin, qreal ymargin);
128     void ensureVisible(const QRectF &rect, qreal xmargin, qreal ymargin, int scrollTime);
129     void resendPrepareEvent();
130 
131 Q_SIGNALS:
132     void stateChanged(QScroller::State newstate);
133     void scrollerPropertiesChanged(const QScrollerProperties &);
134 
135 private:
136     QScrollerPrivate *d_ptr;
137 
138     QScroller(QObject *target);
139     virtual ~QScroller();
140 
141     Q_DISABLE_COPY(QScroller)
142     Q_DECLARE_PRIVATE(QScroller)
143 
144 #ifndef QT_NO_GESTURES
145     friend class QFlickGestureRecognizer;
146 #endif
147 };
148 
149 QT_END_NAMESPACE
150 
151 #endif // QSCROLLER_H
152