1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL3$
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 http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
28 ** Software Foundation and appearing in the file LICENSE.GPL included in
29 ** the packaging of this file. Please review the following information to
30 ** ensure the GNU General Public License version 2.0 requirements will be
31 ** met: http://www.gnu.org/licenses/gpl-2.0.html.
32 **
33 ** $QT_END_LICENSE$
34 **
35 ****************************************************************************/
36 
37 #ifndef QQUICKSCROLLBAR_P_H
38 #define QQUICKSCROLLBAR_P_H
39 
40 //
41 //  W A R N I N G
42 //  -------------
43 //
44 // This file is not part of the Qt API.  It exists purely as an
45 // implementation detail.  This header file may change from version to
46 // version without notice, or even be removed.
47 //
48 // We mean it.
49 //
50 
51 #include <QtQuickTemplates2/private/qquickcontrol_p.h>
52 
53 QT_BEGIN_NAMESPACE
54 
55 class QQuickScrollBarAttached;
56 class QQuickScrollBarPrivate;
57 
58 class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickScrollBar : public QQuickControl
59 {
60     Q_OBJECT
61     Q_PROPERTY(qreal size READ size WRITE setSize NOTIFY sizeChanged FINAL)
62     Q_PROPERTY(qreal position READ position WRITE setPosition NOTIFY positionChanged FINAL)
63     Q_PROPERTY(qreal stepSize READ stepSize WRITE setStepSize NOTIFY stepSizeChanged FINAL)
64     Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged FINAL)
65     Q_PROPERTY(bool pressed READ isPressed WRITE setPressed NOTIFY pressedChanged FINAL)
66     Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged FINAL)
67     // 2.2 (Qt 5.9)
68     Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged FINAL REVISION 2)
69     Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive RESET resetInteractive NOTIFY interactiveChanged FINAL REVISION 2)
70     Q_PROPERTY(Policy policy READ policy WRITE setPolicy NOTIFY policyChanged FINAL REVISION 2)
71     // 2.3 (Qt 5.10)
72     Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL REVISION 3)
73     Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL REVISION 3)
74     // 2.4 (Qt 5.11)
75     Q_PROPERTY(qreal minimumSize READ minimumSize WRITE setMinimumSize NOTIFY minimumSizeChanged FINAL REVISION 4)
76     Q_PROPERTY(qreal visualSize READ visualSize NOTIFY visualSizeChanged FINAL REVISION 4)
77     Q_PROPERTY(qreal visualPosition READ visualPosition NOTIFY visualPositionChanged FINAL REVISION 4)
78 
79 public:
80     explicit QQuickScrollBar(QQuickItem *parent = nullptr);
81 
82     static QQuickScrollBarAttached *qmlAttachedProperties(QObject *object);
83 
84     qreal size() const;
85     qreal position() const;
86 
87     qreal stepSize() const;
88     void setStepSize(qreal step);
89 
90     bool isActive() const;
91     void setActive(bool active);
92 
93     bool isPressed() const;
94     void setPressed(bool pressed);
95 
96     Qt::Orientation orientation() const;
97     void setOrientation(Qt::Orientation orientation);
98 
99     // 2.2 (Qt 5.9)
100     enum SnapMode {
101         NoSnap,
102         SnapAlways,
103         SnapOnRelease
104     };
105     Q_ENUM(SnapMode)
106 
107     SnapMode snapMode() const;
108     void setSnapMode(SnapMode mode);
109 
110     bool isInteractive() const;
111     void setInteractive(bool interactive);
112     void resetInteractive();
113 
114     enum Policy {
115         AsNeeded = Qt::ScrollBarAsNeeded,
116         AlwaysOff = Qt::ScrollBarAlwaysOff,
117         AlwaysOn = Qt::ScrollBarAlwaysOn
118     };
119     Q_ENUM(Policy)
120 
121     Policy policy() const;
122     void setPolicy(Policy policy);
123 
124     // 2.3 (Qt 5.10)
125     bool isHorizontal() const;
126     bool isVertical() const;
127 
128     // 2.4 (Qt 5.11)
129     qreal minimumSize() const;
130     void setMinimumSize(qreal minimumSize);
131 
132     qreal visualSize() const;
133     qreal visualPosition() const;
134 
135 public Q_SLOTS:
136     void increase();
137     void decrease();
138     void setSize(qreal size);
139     void setPosition(qreal position);
140 
141 Q_SIGNALS:
142     void sizeChanged();
143     void positionChanged();
144     void stepSizeChanged();
145     void activeChanged();
146     void pressedChanged();
147     void orientationChanged();
148     // 2.2 (Qt 5.9)
149     Q_REVISION(2) void snapModeChanged();
150     Q_REVISION(2) void interactiveChanged();
151     Q_REVISION(2) void policyChanged();
152     // 2.4 (Qt 5.11)
153     Q_REVISION(4) void minimumSizeChanged();
154     Q_REVISION(4) void visualSizeChanged();
155     Q_REVISION(4) void visualPositionChanged();
156 
157 protected:
158     void mousePressEvent(QMouseEvent *event) override;
159 
160 #if QT_CONFIG(quicktemplates2_hover)
161     void hoverChange() override;
162 #endif
163 
164 #if QT_CONFIG(accessibility)
165     void accessibilityActiveChanged(bool active) override;
166     QAccessible::Role accessibleRole() const override;
167 #endif
168 
169 private:
170     Q_DISABLE_COPY(QQuickScrollBar)
171     Q_DECLARE_PRIVATE(QQuickScrollBar)
172 };
173 
174 class QQuickScrollBarAttachedPrivate;
175 
176 class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickScrollBarAttached : public QObject
177 {
178     Q_OBJECT
179     Q_PROPERTY(QQuickScrollBar *horizontal READ horizontal WRITE setHorizontal NOTIFY horizontalChanged FINAL)
180     Q_PROPERTY(QQuickScrollBar *vertical READ vertical WRITE setVertical NOTIFY verticalChanged FINAL)
181 
182 public:
183     explicit QQuickScrollBarAttached(QObject *parent = nullptr);
184     ~QQuickScrollBarAttached();
185 
186     QQuickScrollBar *horizontal() const;
187     void setHorizontal(QQuickScrollBar *horizontal);
188 
189     QQuickScrollBar *vertical() const;
190     void setVertical(QQuickScrollBar *vertical);
191 
192 Q_SIGNALS:
193     void horizontalChanged();
194     void verticalChanged();
195 
196 private:
197     Q_DISABLE_COPY(QQuickScrollBarAttached)
198     Q_DECLARE_PRIVATE(QQuickScrollBarAttached)
199 };
200 
201 QT_END_NAMESPACE
202 
203 QML_DECLARE_TYPE(QQuickScrollBar)
204 QML_DECLARE_TYPEINFO(QQuickScrollBar, QML_HAS_ATTACHED_PROPERTIES)
205 
206 #endif // QQUICKSCROLLBAR_P_H
207