1// Copyright (C) 2017 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 QQUICKSTACKVIEW_P_H
5#define QQUICKSTACKVIEW_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 <QtCore/qdebug.h>
19#include <QtCore/qvariantmap.h>
20#include <QtQuickTemplates2/private/qquickcontrol_p.h>
21
22QT_BEGIN_NAMESPACE
23
24class QQuickTransition;
25class QQuickStackElement;
26class QQuickStackViewPrivate;
27class QQuickStackViewAttached;
28class QQuickStackViewAttachedPrivate;
29class QQmlComponent;
30
31/*!
32 \internal
33
34 Input from the user that is turned into QQuickStackElements.
35
36 This was added to support the QML-compiler-friendly pushElement[s]
37 functions.
38*/
39class QQuickStackViewArg
40{
41 Q_GADGET
42 QML_CONSTRUCTIBLE_VALUE
43 QML_ANONYMOUS
44
45public:
46 QQuickStackViewArg() = default;
47 Q_INVOKABLE QQuickStackViewArg(QQuickItem *item);
48 Q_INVOKABLE QQuickStackViewArg(const QUrl &url);
49 Q_INVOKABLE QQuickStackViewArg(QQmlComponent *component);
50 Q_INVOKABLE QQuickStackViewArg(const QVariantMap &properties);
51
52#ifndef QT_NO_DEBUG_STREAM
53 friend QDebug operator<<(QDebug debug, const QQuickStackViewArg &arg);
54#endif
55
56private:
57 friend class QQuickStackViewPrivate;
58 friend class QQuickStackElement;
59
60 QQuickItem *mItem = nullptr;
61 QQmlComponent *mComponent = nullptr;
62 QUrl mUrl;
63 QVariantMap mProperties;
64};
65
66class Q_QUICKTEMPLATES2_EXPORT QQuickStackView : public QQuickControl
67{
68 Q_OBJECT
69 Q_PROPERTY(bool busy READ isBusy NOTIFY busyChanged FINAL)
70 Q_PROPERTY(int depth READ depth NOTIFY depthChanged FINAL)
71 Q_PROPERTY(QQuickItem *currentItem READ currentItem NOTIFY currentItemChanged FINAL)
72 Q_PROPERTY(QJSValue initialItem READ initialItem WRITE setInitialItem FINAL)
73#if QT_CONFIG(quick_viewtransitions)
74 Q_PROPERTY(QQuickTransition *popEnter READ popEnter WRITE setPopEnter NOTIFY popEnterChanged FINAL)
75 Q_PROPERTY(QQuickTransition *popExit READ popExit WRITE setPopExit NOTIFY popExitChanged FINAL)
76 Q_PROPERTY(QQuickTransition *pushEnter READ pushEnter WRITE setPushEnter NOTIFY pushEnterChanged FINAL)
77 Q_PROPERTY(QQuickTransition *pushExit READ pushExit WRITE setPushExit NOTIFY pushExitChanged FINAL)
78 Q_PROPERTY(QQuickTransition *replaceEnter READ replaceEnter WRITE setReplaceEnter NOTIFY replaceEnterChanged FINAL)
79 Q_PROPERTY(QQuickTransition *replaceExit READ replaceExit WRITE setReplaceExit NOTIFY replaceExitChanged FINAL)
80#endif
81 // 2.3 (Qt 5.10)
82 Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged FINAL REVISION(2, 3))
83 QML_NAMED_ELEMENT(StackView)
84 QML_ATTACHED(QQuickStackViewAttached)
85 QML_ADDED_IN_VERSION(2, 0)
86
87public:
88 explicit QQuickStackView(QQuickItem *parent = nullptr);
89 ~QQuickStackView();
90
91 static QQuickStackViewAttached *qmlAttachedProperties(QObject *object);
92
93 bool isBusy() const;
94 int depth() const;
95 QQuickItem *currentItem() const;
96
97 enum Status {
98 Inactive = 0,
99 Deactivating = 1,
100 Activating = 2,
101 Active = 3
102 };
103 Q_ENUM(Status)
104
105 QJSValue initialItem() const;
106 void setInitialItem(const QJSValue &item);
107
108#if QT_CONFIG(quick_viewtransitions)
109 QQuickTransition *popEnter() const;
110 void setPopEnter(QQuickTransition *enter);
111
112 QQuickTransition *popExit() const;
113 void setPopExit(QQuickTransition *exit);
114
115 QQuickTransition *pushEnter() const;
116 void setPushEnter(QQuickTransition *enter);
117
118 QQuickTransition *pushExit() const;
119 void setPushExit(QQuickTransition *exit);
120
121 QQuickTransition *replaceEnter() const;
122 void setReplaceEnter(QQuickTransition *enter);
123
124 QQuickTransition *replaceExit() const;
125 void setReplaceExit(QQuickTransition *exit);
126#endif
127
128 enum LoadBehavior {
129 DontLoad,
130 ForceLoad
131 };
132 Q_ENUM(LoadBehavior)
133
134 Q_INVOKABLE QQuickItem *get(int index, QQuickStackView::LoadBehavior behavior = DontLoad);
135 Q_INVOKABLE QQuickItem *find(const QJSValue &callback, QQuickStackView::LoadBehavior behavior = DontLoad);
136
137 enum Operation {
138 Transition = -1, // ### Deprecated in Qt 6; remove in Qt 7.
139 Immediate = 0,
140 PushTransition = 1,
141 ReplaceTransition = 2,
142 PopTransition = 3,
143 };
144 Q_ENUM(Operation)
145
146 Q_INVOKABLE void push(QQmlV4FunctionPtr args);
147 Q_INVOKABLE void pop(QQmlV4FunctionPtr args);
148 Q_INVOKABLE void replace(QQmlV4FunctionPtr args);
149
150 Q_REVISION(6, 7) Q_INVOKABLE QQuickItem *pushItems(QList<QQuickStackViewArg> args,
151 Operation operation = PushTransition);
152 Q_REVISION(6, 7) Q_INVOKABLE QQuickItem *pushItem(QQuickItem *item, const QVariantMap &properties = {},
153 Operation operation = PushTransition);
154 Q_REVISION(6, 7) Q_INVOKABLE QQuickItem *pushItem(QQmlComponent *component, const QVariantMap &properties = {},
155 Operation operation = PushTransition);
156 Q_REVISION(6, 7) Q_INVOKABLE QQuickItem *pushItem(const QUrl &url, const QVariantMap &properties = {},
157 Operation operation = PushTransition);
158
159 Q_REVISION(6, 7) Q_INVOKABLE QQuickItem *popToItem(QQuickItem *item, Operation operation = PopTransition);
160 Q_REVISION(6, 7) Q_INVOKABLE QQuickItem *popToIndex(int index, Operation operation = PopTransition);
161 Q_REVISION(6, 7) Q_INVOKABLE QQuickItem *popCurrentItem(Operation operation = PopTransition);
162
163 Q_REVISION(6, 7) Q_INVOKABLE QQuickItem *replaceCurrentItem(const QList<QQuickStackViewArg> &args,
164 Operation operation = ReplaceTransition);
165 Q_REVISION(6, 7) Q_INVOKABLE QQuickItem *replaceCurrentItem(QQuickItem *item,
166 const QVariantMap &properties = {}, Operation operation = ReplaceTransition);
167 Q_REVISION(6, 7) Q_INVOKABLE QQuickItem *replaceCurrentItem(QQmlComponent *component,
168 const QVariantMap &properties = {}, Operation operation = ReplaceTransition);
169 Q_REVISION(6, 7) Q_INVOKABLE QQuickItem *replaceCurrentItem(const QUrl &url,
170 const QVariantMap &properties = {}, Operation operation = ReplaceTransition);
171
172 // 2.3 (Qt 5.10)
173 bool isEmpty() const;
174
175public Q_SLOTS:
176 void clear(Operation operation = Immediate);
177
178Q_SIGNALS:
179 void busyChanged();
180 void depthChanged();
181 void currentItemChanged();
182#if QT_CONFIG(quick_viewtransitions)
183 void popEnterChanged();
184 void popExitChanged();
185 void pushEnterChanged();
186 void pushExitChanged();
187 void replaceEnterChanged();
188 void replaceExitChanged();
189#endif
190 // 2.3 (Qt 5.10)
191 Q_REVISION(2, 3) void emptyChanged();
192
193protected:
194 void componentComplete() override;
195 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
196 bool childMouseEventFilter(QQuickItem *, QEvent *) override;
197
198#if QT_CONFIG(quicktemplates2_multitouch)
199 void touchEvent(QTouchEvent *event) override;
200#endif
201
202#if QT_CONFIG(accessibility)
203 QAccessible::Role accessibleRole() const override;
204#endif
205
206private:
207 Q_DISABLE_COPY(QQuickStackView)
208 Q_DECLARE_PRIVATE(QQuickStackView)
209};
210
211class Q_QUICKTEMPLATES2_EXPORT QQuickStackViewAttached : public QObject
212{
213 Q_OBJECT
214 Q_PROPERTY(int index READ index NOTIFY indexChanged FINAL)
215 Q_PROPERTY(QQuickStackView *view READ view NOTIFY viewChanged FINAL)
216 Q_PROPERTY(QQuickStackView::Status status READ status NOTIFY statusChanged FINAL)
217 // 2.2 (Qt 5.9)
218 Q_PROPERTY(bool visible READ isVisible WRITE setVisible RESET resetVisible NOTIFY visibleChanged FINAL) // REVISION(2, 2)
219
220public:
221 explicit QQuickStackViewAttached(QObject *parent = nullptr);
222 ~QQuickStackViewAttached();
223
224 int index() const;
225 QQuickStackView *view() const;
226 QQuickStackView::Status status() const;
227
228 // 2.2 (Qt 5.9)
229 bool isVisible() const;
230 void setVisible(bool visible);
231 void resetVisible();
232
233Q_SIGNALS:
234 void indexChanged();
235 void viewChanged();
236 void statusChanged();
237 // 2.1 (Qt 5.8)
238 /*Q_REVISION(2, 1)*/ void activated();
239 /*Q_REVISION(2, 1)*/ void activating();
240 /*Q_REVISION(2, 1)*/ void deactivated();
241 /*Q_REVISION(2, 1)*/ void deactivating();
242 /*Q_REVISION(2, 1)*/ void removed();
243 // 2.2 (Qt 5.9)
244 /*Q_REVISION(2, 2)*/ void visibleChanged();
245
246private:
247 Q_DISABLE_COPY(QQuickStackViewAttached)
248 Q_DECLARE_PRIVATE(QQuickStackViewAttached)
249};
250
251QT_END_NAMESPACE
252
253#endif // QQUICKSTACKVIEW_P_H
254

source code of qtdeclarative/src/quicktemplates/qquickstackview_p.h