diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2024-04-22 11:35:29 +0200 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2024-05-06 13:15:47 +0200 |
commit | 3fa280b76bb9f3fc600c10683ad2186d9cdcf9cf (patch) | |
tree | c1d8d4bd5a24305a14807dfa1021fee83f52ae96 /tools | |
parent | 4ddedea6e1e992e215019af1b725d14725a99ffe (diff) |
More options for embedded images in QML generator
This adds a few options to the svgtoqml generator, to enable
more control over how embedded images are stored.
It adds the "keep-asset-paths" option. When this is set,
the generator will check if an image reference was originally
to a file on disk. Instead of duplicating this, the output
will contain a relative reference to the original file instead.
It adds the "asset-output-prefix" which overrides the default
prefix of output files.
And it adds the "asset-output-directory" which overrides the
default target directory. The default target directory has
also been changed to match the directory of the output QML
instead of always saving to the currently active directory.
In addition, this change makes the tool always output PNG
files, since JPEG is a lossy format and should never be preferred.
Previously, PNG was only preferred when the image had an alpha
channel.
Change-Id: I9a9b03eaea3ac511419789cfc5651d398ce42a5b
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/svgtoqml/main.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tools/svgtoqml/main.cpp b/tools/svgtoqml/main.cpp index 8ae290db84..59f0e99ca0 100644 --- a/tools/svgtoqml/main.cpp +++ b/tools/svgtoqml/main.cpp @@ -50,6 +50,28 @@ int main(int argc, char *argv[]) "the original path. Also sets optimize-paths.")); parser.addOption(outlineModeOption); + QCommandLineOption keepPathsOption("keep-external-paths", + QCoreApplication::translate("main", "Any paths to external files will be retained in the QML output. " + "The paths will be reformatted as relative to the output file. If " + "this is not enabled, copies of the file will be saved to the asset output " + "directory. Embedded data will still be saved to files, even if " + "this option is set.")); + parser.addOption(keepPathsOption); + + QCommandLineOption assetOutputDirectoryOption("asset-output-directory", + QCoreApplication::translate("main", "If the SVG refers to external or embedded files, such as images, these " + "will be copied into the same directory as the output QML file by default. " + "Set the asset output directory to override the location."), + QCoreApplication::translate("main", "directory")); + parser.addOption(assetOutputDirectoryOption); + + QCommandLineOption assetOutputPrefixOption("asset-output-prefix", + QCoreApplication::translate("main", "If the SVG refers to external or embedded files, such as images, these " + "will be copied to files with unique identifiers. By default, the files will be prefixed " + "with \"svg_asset_\". Set the asset output prefix to override the prefix."), + QCoreApplication::translate("main", "prefix")); + parser.addOption(assetOutputPrefixOption); + #ifdef ENABLE_GUI QCommandLineOption guiOption(QStringList() << "v" << "view", QCoreApplication::translate("main", "Display the SVG in a window.")); @@ -67,6 +89,9 @@ int main(int argc, char *argv[]) const auto outFileName = args.size() > 1 ? args.at(1) : QString{}; const auto typeName = parser.value(typeNameOption); + const auto assetOutputDirectory = parser.value(assetOutputDirectoryOption); + const auto assetOutputPrefix = parser.value(assetOutputPrefixOption); + const bool keepPaths = parser.isSet(keepPathsOption); auto copyrightString = parser.value(copyrightOption); if (!copyrightString.isEmpty()) { @@ -86,6 +111,9 @@ int main(int argc, char *argv[]) QQuickQmlGenerator generator(inFileName, flags, outFileName); generator.setShapeTypeName(typeName); generator.setCommentString(commentString); + generator.setAssetFileDirectory(assetOutputDirectory); + generator.setAssetFilePrefix(assetOutputPrefix); + generator.setRetainFilePaths(keepPaths); generator.generate(); #ifdef ENABLE_GUI |