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

source code of qtdeclarative/src/quick/items/qquickpathview_p.h