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 QQUICKPATHVIEW_P_H |
5 | #define QQUICKPATHVIEW_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 <private/qtquickglobal_p.h> |
19 | |
20 | QT_REQUIRE_CONFIG(quick_pathview); |
21 | |
22 | #include "qquickitem.h" |
23 | |
24 | #include <private/qtquickglobal_p.h> |
25 | #include <private/qquickpath_p.h> |
26 | |
27 | QT_BEGIN_NAMESPACE |
28 | |
29 | class QQmlChangeSet; |
30 | |
31 | class QQuickPathViewPrivate; |
32 | class QQuickPathViewAttached; |
33 | class Q_QUICK_PRIVATE_EXPORT QQuickPathView : public QQuickItem |
34 | { |
35 | Q_OBJECT |
36 | |
37 | Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged FINAL) |
38 | Q_PROPERTY(QQuickPath *path READ path WRITE setPath NOTIFY pathChanged FINAL) |
39 | Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged FINAL) |
40 | Q_PROPERTY(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged FINAL) |
41 | Q_PROPERTY(qreal offset READ offset WRITE setOffset NOTIFY offsetChanged FINAL) |
42 | |
43 | Q_PROPERTY(QQmlComponent *highlight READ highlight WRITE setHighlight NOTIFY highlightChanged FINAL) |
44 | Q_PROPERTY(QQuickItem *highlightItem READ highlightItem NOTIFY highlightItemChanged FINAL) |
45 | |
46 | Q_PROPERTY(qreal preferredHighlightBegin READ preferredHighlightBegin WRITE setPreferredHighlightBegin NOTIFY preferredHighlightBeginChanged FINAL) |
47 | Q_PROPERTY(qreal preferredHighlightEnd READ preferredHighlightEnd WRITE setPreferredHighlightEnd NOTIFY preferredHighlightEndChanged FINAL) |
48 | Q_PROPERTY(HighlightRangeMode highlightRangeMode READ highlightRangeMode WRITE setHighlightRangeMode NOTIFY highlightRangeModeChanged FINAL) |
49 | Q_PROPERTY(int highlightMoveDuration READ highlightMoveDuration WRITE setHighlightMoveDuration NOTIFY highlightMoveDurationChanged FINAL) |
50 | |
51 | Q_PROPERTY(qreal dragMargin READ dragMargin WRITE setDragMargin NOTIFY dragMarginChanged FINAL) |
52 | Q_PROPERTY(qreal maximumFlickVelocity READ maximumFlickVelocity WRITE setMaximumFlickVelocity NOTIFY maximumFlickVelocityChanged FINAL) |
53 | Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration NOTIFY flickDecelerationChanged FINAL) |
54 | Q_PROPERTY(bool interactive READ isInteractive WRITE setInteractive NOTIFY interactiveChanged FINAL) |
55 | |
56 | Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged FINAL) |
57 | Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged FINAL) |
58 | Q_PROPERTY(bool dragging READ isDragging NOTIFY draggingChanged FINAL) |
59 | |
60 | Q_PROPERTY(int count READ count NOTIFY countChanged FINAL) |
61 | Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged FINAL) |
62 | Q_PROPERTY(int pathItemCount READ pathItemCount WRITE setPathItemCount RESET resetPathItemCount NOTIFY pathItemCountChanged FINAL) |
63 | Q_PROPERTY(SnapMode snapMode READ snapMode WRITE setSnapMode NOTIFY snapModeChanged FINAL) |
64 | Q_PROPERTY(MovementDirection movementDirection READ movementDirection WRITE setMovementDirection NOTIFY movementDirectionChanged REVISION(2, 7) FINAL) |
65 | |
66 | Q_PROPERTY(int cacheItemCount READ cacheItemCount WRITE setCacheItemCount NOTIFY cacheItemCountChanged FINAL) |
67 | QML_NAMED_ELEMENT(PathView) |
68 | QML_ADDED_IN_VERSION(2, 0) |
69 | QML_ATTACHED(QQuickPathViewAttached) |
70 | |
71 | public: |
72 | QQuickPathView(QQuickItem *parent = nullptr); |
73 | virtual ~QQuickPathView(); |
74 | |
75 | QVariant model() const; |
76 | void setModel(const QVariant &); |
77 | |
78 | QQuickPath *path() const; |
79 | void setPath(QQuickPath *); |
80 | |
81 | int currentIndex() const; |
82 | void setCurrentIndex(int idx); |
83 | |
84 | QQuickItem *currentItem() const; |
85 | |
86 | qreal offset() const; |
87 | void setOffset(qreal offset); |
88 | |
89 | QQmlComponent *highlight() const; |
90 | void setHighlight(QQmlComponent *highlight); |
91 | QQuickItem *highlightItem() const; |
92 | |
93 | enum HighlightRangeMode { NoHighlightRange, ApplyRange, StrictlyEnforceRange }; |
94 | Q_ENUM(HighlightRangeMode) |
95 | HighlightRangeMode highlightRangeMode() const; |
96 | void setHighlightRangeMode(HighlightRangeMode mode); |
97 | |
98 | qreal preferredHighlightBegin() const; |
99 | void setPreferredHighlightBegin(qreal); |
100 | |
101 | qreal preferredHighlightEnd() const; |
102 | void setPreferredHighlightEnd(qreal); |
103 | |
104 | int highlightMoveDuration() const; |
105 | void setHighlightMoveDuration(int); |
106 | |
107 | qreal dragMargin() const; |
108 | void setDragMargin(qreal margin); |
109 | |
110 | qreal flickDeceleration() const; |
111 | void setFlickDeceleration(qreal dec); |
112 | |
113 | qreal maximumFlickVelocity() const; |
114 | void setMaximumFlickVelocity(qreal); |
115 | |
116 | bool isInteractive() const; |
117 | void setInteractive(bool); |
118 | |
119 | bool isMoving() const; |
120 | bool isFlicking() const; |
121 | bool isDragging() const; |
122 | |
123 | int count() const; |
124 | |
125 | QQmlComponent *delegate() const; |
126 | void setDelegate(QQmlComponent *); |
127 | |
128 | int pathItemCount() const; |
129 | void setPathItemCount(int); |
130 | void resetPathItemCount(); |
131 | |
132 | int cacheItemCount() const; |
133 | void setCacheItemCount(int); |
134 | |
135 | enum SnapMode { NoSnap, SnapToItem, SnapOneItem }; |
136 | Q_ENUM(SnapMode) |
137 | SnapMode snapMode() const; |
138 | void setSnapMode(SnapMode mode); |
139 | |
140 | enum MovementDirection { Shortest, Negative, Positive }; |
141 | Q_ENUM(MovementDirection) |
142 | MovementDirection movementDirection() const; |
143 | void setMovementDirection(MovementDirection dir); |
144 | |
145 | enum PositionMode { Beginning, Center, End, Contain=4, SnapPosition }; // 3 == Visible in other views |
146 | Q_ENUM(PositionMode) |
147 | Q_INVOKABLE void positionViewAtIndex(int index, int mode); |
148 | Q_INVOKABLE int indexAt(qreal x, qreal y) const; |
149 | Q_INVOKABLE QQuickItem *itemAt(qreal x, qreal y) const; |
150 | Q_REVISION(2, 13) Q_INVOKABLE QQuickItem *itemAtIndex(int index) const; |
151 | |
152 | static QQuickPathViewAttached *qmlAttachedProperties(QObject *); |
153 | |
154 | public Q_SLOTS: |
155 | void incrementCurrentIndex(); |
156 | void decrementCurrentIndex(); |
157 | |
158 | Q_SIGNALS: |
159 | void currentIndexChanged(); |
160 | void currentItemChanged(); |
161 | void offsetChanged(); |
162 | void modelChanged(); |
163 | void countChanged(); |
164 | void pathChanged(); |
165 | void preferredHighlightBeginChanged(); |
166 | void preferredHighlightEndChanged(); |
167 | void highlightRangeModeChanged(); |
168 | void dragMarginChanged(); |
169 | void snapPositionChanged(); |
170 | void delegateChanged(); |
171 | void pathItemCountChanged(); |
172 | void maximumFlickVelocityChanged(); |
173 | void flickDecelerationChanged(); |
174 | void interactiveChanged(); |
175 | void movingChanged(); |
176 | void flickingChanged(); |
177 | void draggingChanged(); |
178 | void highlightChanged(); |
179 | void highlightItemChanged(); |
180 | void highlightMoveDurationChanged(); |
181 | void movementStarted(); |
182 | void movementEnded(); |
183 | Q_REVISION(2, 7) void movementDirectionChanged(); |
184 | void flickStarted(); |
185 | void flickEnded(); |
186 | void dragStarted(); |
187 | void dragEnded(); |
188 | void snapModeChanged(); |
189 | void cacheItemCountChanged(); |
190 | |
191 | protected: |
192 | void updatePolish() override; |
193 | void mousePressEvent(QMouseEvent *event) override; |
194 | void mouseMoveEvent(QMouseEvent *event) override; |
195 | void mouseReleaseEvent(QMouseEvent *) override; |
196 | bool childMouseEventFilter(QQuickItem *, QEvent *) override; |
197 | void mouseUngrabEvent() override; |
198 | void componentComplete() override; |
199 | |
200 | private Q_SLOTS: |
201 | void refill(); |
202 | void ticked(); |
203 | void movementEnding(); |
204 | void modelUpdated(const QQmlChangeSet &changeSet, bool reset); |
205 | void createdItem(int index, QObject *item); |
206 | void initItem(int index, QObject *item); |
207 | void destroyingItem(QObject *item); |
208 | void pathUpdated(); |
209 | |
210 | private: |
211 | friend class QQuickPathViewAttached; |
212 | Q_DISABLE_COPY(QQuickPathView) |
213 | Q_DECLARE_PRIVATE(QQuickPathView) |
214 | }; |
215 | |
216 | class QQmlOpenMetaObject; |
217 | class QQuickPathViewAttached : public QObject |
218 | { |
219 | Q_OBJECT |
220 | |
221 | Q_PROPERTY(QQuickPathView *view READ view CONSTANT FINAL) |
222 | Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY currentItemChanged FINAL) |
223 | Q_PROPERTY(bool onPath READ isOnPath NOTIFY pathChanged FINAL) |
224 | |
225 | public: |
226 | QQuickPathViewAttached(QObject *parent); |
227 | ~QQuickPathViewAttached(); |
228 | |
229 | QQuickPathView *view() const { return m_view; } |
230 | |
231 | bool isCurrentItem() const { return m_isCurrent; } |
232 | void setIsCurrentItem(bool c) { |
233 | if (m_isCurrent != c) { |
234 | m_isCurrent = c; |
235 | Q_EMIT currentItemChanged(); |
236 | } |
237 | } |
238 | |
239 | QVariant value(const QByteArray &name) const; |
240 | void setValue(const QByteArray &name, const QVariant &val); |
241 | |
242 | bool isOnPath() const { return m_onPath; } |
243 | void setOnPath(bool on) { |
244 | if (on != m_onPath) { |
245 | m_onPath = on; |
246 | Q_EMIT pathChanged(); |
247 | } |
248 | } |
249 | qreal m_percent; |
250 | |
251 | Q_SIGNALS: |
252 | void currentItemChanged(); |
253 | void pathChanged(); |
254 | |
255 | private: |
256 | friend class QQuickPathViewPrivate; |
257 | friend class QQuickPathView; |
258 | QQuickPathView *m_view; |
259 | QQmlOpenMetaObject *m_metaobject; |
260 | bool m_onPath : 1; |
261 | bool m_isCurrent : 1; |
262 | }; |
263 | |
264 | |
265 | QT_END_NAMESPACE |
266 | |
267 | QML_DECLARE_TYPE(QQuickPathView) |
268 | |
269 | #endif // QQUICKPATHVIEW_P_H |
270 | |