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