| 1 | // Copyright (C) 2024 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 QQUICKVECTORIMAGE_P_H |
| 5 | #define QQUICKVECTORIMAGE_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 <QQuickItem> |
| 19 | #include <QtQuick/private/qquickanimation_p.h> |
| 20 | #include <QtQuickVectorImage/qtquickvectorimageexports.h> |
| 21 | |
| 22 | QT_BEGIN_NAMESPACE |
| 23 | |
| 24 | class QQuickVectorImagePrivate; |
| 25 | class QQuickVectorImageAnimations; |
| 26 | |
| 27 | class Q_QUICKVECTORIMAGE_EXPORT QQuickVectorImage : public QQuickItem |
| 28 | { |
| 29 | Q_OBJECT |
| 30 | |
| 31 | Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) |
| 32 | Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged) |
| 33 | Q_PROPERTY(RendererType preferredRendererType READ preferredRendererType WRITE setPreferredRendererType NOTIFY preferredRendererTypeChanged) |
| 34 | Q_PROPERTY(QQuickVectorImageAnimations *animations READ animations CONSTANT REVISION(6, 10) FINAL) |
| 35 | Q_PROPERTY(bool assumeTrustedSource READ assumeTrustedSource WRITE setAssumeTrustedSource NOTIFY assumeTrustedSourceChanged FINAL) |
| 36 | QML_NAMED_ELEMENT(VectorImage) |
| 37 | |
| 38 | public: |
| 39 | enum FillMode { |
| 40 | NoResize, |
| 41 | PreserveAspectFit, |
| 42 | PreserveAspectCrop, |
| 43 | Stretch |
| 44 | }; |
| 45 | Q_ENUM(FillMode) |
| 46 | |
| 47 | enum RendererType { |
| 48 | GeometryRenderer, |
| 49 | CurveRenderer |
| 50 | }; |
| 51 | Q_ENUM(RendererType) |
| 52 | |
| 53 | QQuickVectorImage(QQuickItem *parent = nullptr); |
| 54 | |
| 55 | QUrl source() const; |
| 56 | void setSource(const QUrl &source); |
| 57 | |
| 58 | FillMode fillMode() const; |
| 59 | void setFillMode(FillMode newFillMode); |
| 60 | |
| 61 | RendererType preferredRendererType() const; |
| 62 | void setPreferredRendererType(RendererType newPreferredRendererType); |
| 63 | |
| 64 | QQuickVectorImageAnimations *animations(); |
| 65 | |
| 66 | bool assumeTrustedSource() const; |
| 67 | void setAssumeTrustedSource(bool assumeTrustedSource); |
| 68 | |
| 69 | void componentComplete() override; |
| 70 | |
| 71 | signals: |
| 72 | void sourceChanged(); |
| 73 | void fillModeChanged(); |
| 74 | |
| 75 | void preferredRendererTypeChanged(); |
| 76 | void assumeTrustedSourceChanged(); |
| 77 | |
| 78 | private slots: |
| 79 | void updateRootItemScale(); |
| 80 | void updateAnimationProperties(); |
| 81 | |
| 82 | private: |
| 83 | Q_DISABLE_COPY(QQuickVectorImage) |
| 84 | Q_DECLARE_PRIVATE(QQuickVectorImage) |
| 85 | }; |
| 86 | |
| 87 | class Q_QUICKVECTORIMAGE_EXPORT QQuickVectorImageAnimations : public QObject |
| 88 | { |
| 89 | Q_OBJECT |
| 90 | |
| 91 | Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopsChanged FINAL) |
| 92 | Q_PROPERTY(bool paused READ paused WRITE setPaused NOTIFY pausedChanged FINAL) |
| 93 | |
| 94 | QML_ANONYMOUS |
| 95 | QML_ADDED_IN_VERSION(6, 10) |
| 96 | public: |
| 97 | QQuickVectorImageAnimations(QObject *parent = nullptr) : QObject(parent) {} |
| 98 | |
| 99 | int loops() const; |
| 100 | |
| 101 | void setLoops(int loops); |
| 102 | |
| 103 | bool paused() const; |
| 104 | void setPaused(bool paused); |
| 105 | |
| 106 | Q_INVOKABLE void restart(); |
| 107 | |
| 108 | Q_SIGNALS: |
| 109 | void loopsChanged(); |
| 110 | void enabledChanged(); |
| 111 | void pausedChanged(); |
| 112 | |
| 113 | private: |
| 114 | int m_loops = 1; |
| 115 | bool m_paused = false; |
| 116 | }; |
| 117 | |
| 118 | QT_END_NAMESPACE |
| 119 | |
| 120 | #endif // QQUICKVECTORIMAGE_P_H |
| 121 | |
| 122 |
