| 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 QQUICKQMLGENERATOR_P_H |
| 5 | #define QQUICKQMLGENERATOR_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 "qquickgenerator_p.h" |
| 19 | #include "qquicknodeinfo_p.h" |
| 20 | #include "qquickanimatedproperty_p.h" |
| 21 | |
| 22 | #include <QtCore/qtextstream.h> |
| 23 | #include <QtCore/qbuffer.h> |
| 24 | #include <QtCore/qmap.h> |
| 25 | |
| 26 | QT_BEGIN_NAMESPACE |
| 27 | |
| 28 | class Q_QUICKVECTORIMAGEGENERATOR_EXPORT QQuickQmlGenerator : public QQuickGenerator |
| 29 | { |
| 30 | public: |
| 31 | QQuickQmlGenerator(const QString fileName, QQuickVectorImageGenerator::GeneratorFlags flags, const QString &outFileName); |
| 32 | ~QQuickQmlGenerator(); |
| 33 | |
| 34 | bool save(); |
| 35 | |
| 36 | void setShapeTypeName(const QString &name); |
| 37 | QString shapeTypeName() const; |
| 38 | |
| 39 | void (const QString ); |
| 40 | QString () const; |
| 41 | |
| 42 | void setRetainFilePaths(bool retainFilePaths) |
| 43 | { |
| 44 | m_retainFilePaths = retainFilePaths; |
| 45 | } |
| 46 | |
| 47 | bool retainFilePaths() const |
| 48 | { |
| 49 | return m_retainFilePaths; |
| 50 | } |
| 51 | |
| 52 | void setAssetFileDirectory(const QString &assetFileDirectory) |
| 53 | { |
| 54 | m_assetFileDirectory = assetFileDirectory; |
| 55 | } |
| 56 | |
| 57 | QString assetFileDirectory() const |
| 58 | { |
| 59 | return m_assetFileDirectory; |
| 60 | } |
| 61 | |
| 62 | void setAssetFilePrefix(const QString &assetFilePrefix) |
| 63 | { |
| 64 | m_assetFilePrefix = assetFilePrefix; |
| 65 | } |
| 66 | |
| 67 | QString assetFilePrefix() const |
| 68 | { |
| 69 | return m_assetFilePrefix; |
| 70 | } |
| 71 | |
| 72 | void setUrlPrefix(const QString &prefix) |
| 73 | { |
| 74 | m_urlPrefix = prefix; |
| 75 | } |
| 76 | |
| 77 | QString urlPrefix() const |
| 78 | { |
| 79 | return m_urlPrefix; |
| 80 | } |
| 81 | |
| 82 | void (const QString &import) |
| 83 | { |
| 84 | m_extraImports.append(t: import); |
| 85 | } |
| 86 | |
| 87 | QStringList () const |
| 88 | { |
| 89 | return m_extraImports; |
| 90 | } |
| 91 | |
| 92 | bool isRuntimeGenerator() const |
| 93 | { |
| 94 | return !m_urlPrefix.isEmpty(); |
| 95 | } |
| 96 | |
| 97 | protected: |
| 98 | QString generateNodeBase(const NodeInfo &info) override; |
| 99 | bool generateDefsNode(const NodeInfo &info) override; |
| 100 | void generateImageNode(const ImageNodeInfo &info) override; |
| 101 | void generatePath(const PathNodeInfo &info, const QRectF &overrideBoundingRect) override; |
| 102 | void generateNode(const NodeInfo &info) override; |
| 103 | void generateTextNode(const TextNodeInfo &info) override; |
| 104 | void generateUseNode(const UseNodeInfo &info) override; |
| 105 | bool generateStructureNode(const StructureNodeInfo &info) override; |
| 106 | bool generateRootNode(const StructureNodeInfo &info) override; |
| 107 | void outputShapePath(const PathNodeInfo &info, const QPainterPath *path, const QQuadPath *quadPath, QQuickVectorImageGenerator::PathSelector pathSelector, const QRectF &boundingRect) override; |
| 108 | |
| 109 | private: |
| 110 | enum class AnimationType { |
| 111 | Auto = 0, |
| 112 | ColorOpacity = 1 |
| 113 | }; |
| 114 | |
| 115 | void generateGradient(const QGradient *grad); |
| 116 | void generateTransform(const QTransform &xf); |
| 117 | void generatePathContainer(const StructureNodeInfo &info); |
| 118 | void generateAnimateTransform(const QString &targetName, const NodeInfo &info); |
| 119 | void generateAnimationBindings(); |
| 120 | void generateEasing(const QQuickAnimatedProperty::PropertyAnimation &animation, int time); |
| 121 | void generateAnimatedPropertySetter(const QString &targetName, |
| 122 | const QString &propertyName, |
| 123 | const QVariant &value, |
| 124 | const QQuickAnimatedProperty::PropertyAnimation &animation, |
| 125 | int time, |
| 126 | int frameTime, |
| 127 | AnimationType animationType = AnimationType::Auto); |
| 128 | void generatePropertyAnimation(const QQuickAnimatedProperty &property, |
| 129 | const QString &targetName, |
| 130 | const QString &propertyName, |
| 131 | AnimationType animationType = AnimationType::Auto); |
| 132 | |
| 133 | QStringView indent(); |
| 134 | enum StreamFlags { NoFlags = 0x0, SameLine = 0x1 }; |
| 135 | QTextStream &stream(int flags = NoFlags); |
| 136 | const char *shapeName() const; |
| 137 | |
| 138 | protected: |
| 139 | QBuffer m_result; |
| 140 | |
| 141 | private: |
| 142 | int m_indentLevel = 0; |
| 143 | QTextStream m_stream; |
| 144 | QString outputFileName; |
| 145 | int m_inShapeItemLevel = 0; |
| 146 | QByteArray m_shapeTypeName; |
| 147 | QString ; |
| 148 | bool m_retainFilePaths = false; |
| 149 | QString m_assetFileDirectory; |
| 150 | QString m_assetFilePrefix; |
| 151 | QString m_urlPrefix; |
| 152 | QString m_topLevelIdString; |
| 153 | QStringList ; |
| 154 | QMap<std::array<qreal, 4>, QString> m_easings; |
| 155 | }; |
| 156 | |
| 157 | QT_END_NAMESPACE |
| 158 | |
| 159 | #endif // QQUICKQMLGENERATOR_P_H |
| 160 | |