| 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 QQUICKLOADER_P_H |
| 5 | #define QQUICKLOADER_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 "qquickimplicitsizeitem_p.h" |
| 19 | |
| 20 | QT_BEGIN_NAMESPACE |
| 21 | |
| 22 | class QQuickLoaderPrivate; |
| 23 | class QQmlComponent; |
| 24 | |
| 25 | class Q_QUICK_EXPORT QQuickLoader : public QQuickImplicitSizeItem |
| 26 | { |
| 27 | Q_OBJECT |
| 28 | |
| 29 | Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged) |
| 30 | Q_PROPERTY(QUrl source READ source WRITE setSourceWithoutResolve NOTIFY sourceChanged) |
| 31 | Q_PROPERTY(QQmlComponent *sourceComponent READ sourceComponent WRITE setSourceComponent RESET resetSourceComponent NOTIFY sourceComponentChanged) |
| 32 | Q_PROPERTY(QObject *item READ item NOTIFY itemChanged) |
| 33 | Q_PROPERTY(Status status READ status NOTIFY statusChanged) |
| 34 | Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) |
| 35 | Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged) |
| 36 | QML_NAMED_ELEMENT(Loader) |
| 37 | QML_ADDED_IN_VERSION(2, 0) |
| 38 | |
| 39 | public: |
| 40 | QQuickLoader(QQuickItem *parent = nullptr); |
| 41 | virtual ~QQuickLoader(); |
| 42 | |
| 43 | bool active() const; |
| 44 | void setActive(bool newVal); |
| 45 | |
| 46 | Q_INVOKABLE void setSource(const QUrl &source, QJSValue initialProperties); |
| 47 | Q_INVOKABLE void setSource(const QUrl &source); |
| 48 | |
| 49 | QUrl source() const; |
| 50 | void setSourceWithoutResolve(const QUrl &source); |
| 51 | |
| 52 | QQmlComponent *sourceComponent() const; |
| 53 | void setSourceComponent(QQmlComponent *); |
| 54 | void resetSourceComponent(); |
| 55 | |
| 56 | enum Status { Null, Ready, Loading, Error }; |
| 57 | Q_ENUM(Status) |
| 58 | Status status() const; |
| 59 | qreal progress() const; |
| 60 | |
| 61 | bool asynchronous() const; |
| 62 | void setAsynchronous(bool a); |
| 63 | |
| 64 | QObject *item() const; |
| 65 | |
| 66 | Q_SIGNALS: |
| 67 | void itemChanged(); |
| 68 | void activeChanged(); |
| 69 | void sourceChanged(); |
| 70 | void sourceComponentChanged(); |
| 71 | void statusChanged(); |
| 72 | void progressChanged(); |
| 73 | void loaded(); |
| 74 | void asynchronousChanged(); |
| 75 | |
| 76 | protected: |
| 77 | void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; |
| 78 | void componentComplete() override; |
| 79 | void itemChange(ItemChange change, const ItemChangeData &value) override; |
| 80 | |
| 81 | private: |
| 82 | QUrl setSourceUrlHelper(const QUrl &unresolvedUrl); |
| 83 | void setSource(const QUrl &sourceUrl, bool needsClear); |
| 84 | void loadFromSource(); |
| 85 | void loadFromSourceComponent(); |
| 86 | Q_DISABLE_COPY(QQuickLoader) |
| 87 | Q_DECLARE_PRIVATE(QQuickLoader) |
| 88 | Q_PRIVATE_SLOT(d_func(), void _q_sourceLoaded()) |
| 89 | Q_PRIVATE_SLOT(d_func(), void _q_updateSize()) |
| 90 | }; |
| 91 | |
| 92 | QT_END_NAMESPACE |
| 93 | |
| 94 | #endif // QQUICKLOADER_P_H |
| 95 | |