| 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 | |
| 20 | #include <QtCore/qtextstream.h> | 
| 21 | #include <QtCore/qbuffer.h> | 
| 22 | |
| 23 | QT_BEGIN_NAMESPACE | 
| 24 | |
| 25 | class Q_QUICKVECTORIMAGEGENERATOR_EXPORT QQuickQmlGenerator : public QQuickGenerator | 
| 26 | { | 
| 27 | public: | 
| 28 | QQuickQmlGenerator(const QString fileName, QQuickVectorImageGenerator::GeneratorFlags flags, const QString &outFileName); | 
| 29 | ~QQuickQmlGenerator(); | 
| 30 | |
| 31 | void setShapeTypeName(const QString &name); | 
| 32 | QString shapeTypeName() const; | 
| 33 | |
| 34 | void setCommentString(const QString commentString); | 
| 35 | QString commentString() const; | 
| 36 | |
| 37 | void setRetainFilePaths(bool retainFilePaths) | 
| 38 | { | 
| 39 | m_retainFilePaths = retainFilePaths; | 
| 40 | } | 
| 41 | |
| 42 | bool retainFilePaths() const | 
| 43 | { | 
| 44 | return m_retainFilePaths; | 
| 45 | } | 
| 46 | |
| 47 | void setAssetFileDirectory(const QString &assetFileDirectory) | 
| 48 | { | 
| 49 | m_assetFileDirectory = assetFileDirectory; | 
| 50 | } | 
| 51 | |
| 52 | QString assetFileDirectory() const | 
| 53 | { | 
| 54 | return m_assetFileDirectory; | 
| 55 | } | 
| 56 | |
| 57 | void setAssetFilePrefix(const QString &assetFilePrefix) | 
| 58 | { | 
| 59 | m_assetFilePrefix = assetFilePrefix; | 
| 60 | } | 
| 61 | |
| 62 | QString assetFilePrefix() const | 
| 63 | { | 
| 64 | return m_assetFilePrefix; | 
| 65 | } | 
| 66 | |
| 67 | protected: | 
| 68 | void generateNodeBase(const NodeInfo &info) override; | 
| 69 | bool generateDefsNode(const NodeInfo &info) override; | 
| 70 | void generateImageNode(const ImageNodeInfo &info) override; | 
| 71 | void generatePath(const PathNodeInfo &info, const QRectF &overrideBoundingRect) override; | 
| 72 | void generateNode(const NodeInfo &info) override; | 
| 73 | void generateTextNode(const TextNodeInfo &info) override; | 
| 74 | void generateUseNode(const UseNodeInfo &info) override; | 
| 75 | bool generateStructureNode(const StructureNodeInfo &info) override; | 
| 76 | bool generateRootNode(const StructureNodeInfo &info) override; | 
| 77 | void outputShapePath(const PathNodeInfo &info, const QPainterPath *path, const QQuadPath *quadPath, QQuickVectorImageGenerator::PathSelector pathSelector, const QRectF &boundingRect) override; | 
| 78 | |
| 79 | private: | 
| 80 | void generateGradient(const QGradient *grad); | 
| 81 | void generateTransform(const QTransform &xf); | 
| 82 | void generatePathContainer(const StructureNodeInfo &info); | 
| 83 | |
| 84 | QStringView indent(); | 
| 85 | enum StreamFlags { NoFlags = 0x0, SameLine = 0x1 }; | 
| 86 | QTextStream &stream(int flags = NoFlags); | 
| 87 | const char *shapeName() const; | 
| 88 | |
| 89 | private: | 
| 90 | int m_indentLevel = 0; | 
| 91 | QBuffer m_result; | 
| 92 | QTextStream m_stream; | 
| 93 | QString outputFileName; | 
| 94 | bool m_inShapeItem = false; | 
| 95 | QByteArray m_shapeTypeName; | 
| 96 | QString m_commentString; | 
| 97 | bool m_retainFilePaths = false; | 
| 98 | QString m_assetFileDirectory; | 
| 99 | QString m_assetFilePrefix; | 
| 100 | }; | 
| 101 | |
| 102 | QT_END_NAMESPACE | 
| 103 | |
| 104 | #endif // QQUICKQMLGENERATOR_P_H | 
| 105 | 
