| 1 | // Copyright (C) 2022 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include <QGuiApplication> |
| 5 | #include <QQmlApplicationEngine> |
| 6 | #include <QQmlContext> |
| 7 | #include <QtCore/QCommandLineParser> |
| 8 | #include <QDir> |
| 9 | #include <QIcon> |
| 10 | #include "effectmanager.h" |
| 11 | #include "nodeview.h" |
| 12 | #include "propertyhandler.h" |
| 13 | #include "fpshelper.h" |
| 14 | #include "syntaxhighlighter.h" |
| 15 | #include "qsbinspectorhelper.h" |
| 16 | |
| 17 | #ifdef _WIN32 |
| 18 | #include <Windows.h> |
| 19 | #endif |
| 20 | |
| 21 | // QQEM version number which is shown in About dialog and saved into files. |
| 22 | // Note: Use string which can be converted to decimal number. |
| 23 | // So e.g. "0.41" and no "0.41.2", "0.41beta" etc. |
| 24 | #define APP_VERSION_STR "0.44" |
| 25 | |
| 26 | int main(int argc, char *argv[]) |
| 27 | { |
| 28 | #ifdef _WIN32 |
| 29 | if (AttachConsole(ATTACH_PARENT_PROCESS)) { |
| 30 | FILE *out, *err; |
| 31 | freopen_s(&out, "CONOUT$" , "w" , stdout); |
| 32 | freopen_s(&err, "CONOUT$" , "w" , stderr); |
| 33 | } |
| 34 | #endif |
| 35 | bool isQDSMode = false; |
| 36 | QGuiApplication app(argc, argv); |
| 37 | app.setOrganizationName("The Qt Company" ); |
| 38 | app.setOrganizationDomain("qt.io" ); |
| 39 | app.setApplicationName("Qt Quick Effect Maker" ); |
| 40 | app.setApplicationVersion(QLatin1String(APP_VERSION_STR)); |
| 41 | app.setWindowIcon(QIcon(":/qqem.ico" )); |
| 42 | |
| 43 | // Setup command line arguments |
| 44 | QCommandLineParser cmdLineParser; |
| 45 | cmdLineParser.setApplicationDescription("Qt Quick Effect Maker - Tool to create custom Qt Quick shader effects." ); |
| 46 | cmdLineParser.addHelpOption(); |
| 47 | cmdLineParser.addVersionOption(); |
| 48 | |
| 49 | // Add the cmd options |
| 50 | cmdLineParser.addPositionalArgument(name: "project" , QStringLiteral("Effects project file (*.qep) to open" )); |
| 51 | QCommandLineOption exportPathOption("exportpath" , |
| 52 | "Path used for exporting the effect" , |
| 53 | "exportpath" ); |
| 54 | QCommandLineOption createOption("create" , |
| 55 | "Create a new project with the given project file" ); |
| 56 | cmdLineParser.addOptions(options: {exportPathOption, createOption}); |
| 57 | |
| 58 | cmdLineParser.process(arguments: app.arguments()); |
| 59 | const QStringList args = cmdLineParser.positionalArguments(); |
| 60 | // Parsing args |
| 61 | if (args.count() > 0) { |
| 62 | QString projectPath = QDir::fromNativeSeparators(pathName: args.at(i: 0)); |
| 63 | g_argData.insert(key: "effects_project_path" , value: projectPath); |
| 64 | } |
| 65 | if (cmdLineParser.isSet(option: exportPathOption)) { |
| 66 | // Switch to QDS mode when the exportPath is given. |
| 67 | isQDSMode = true; |
| 68 | auto val = cmdLineParser.value(option: exportPathOption); |
| 69 | QString exportPath = QDir::fromNativeSeparators(pathName: val); |
| 70 | g_argData.insert(key: "export_path" , value: exportPath); |
| 71 | } |
| 72 | bool createProject = cmdLineParser.isSet(option: createOption); |
| 73 | if (createProject) { |
| 74 | if (args.isEmpty()) { |
| 75 | qWarning(msg: "Error: Creating a new project requires also the project parameter." ); |
| 76 | exit(status: 1); |
| 77 | } |
| 78 | g_argData.insert(key: "create_project" , value: createProject); |
| 79 | } |
| 80 | |
| 81 | qmlRegisterType<EffectManager>(uri: "QQEMLib" , versionMajor: 1, versionMinor: 0, qmlName: "EffectManager" ); |
| 82 | qmlRegisterType<NodeView>(uri: "QQEMLib" , versionMajor: 1, versionMinor: 0, qmlName: "NodeViewItem" ); |
| 83 | qmlRegisterType<FpsHelper>(uri: "QQEMLib" , versionMajor: 1, versionMinor: 0, qmlName: "FpsHelper" ); |
| 84 | qmlRegisterType<SyntaxHighlighter>(uri: "QQEMLib" , versionMajor: 1, versionMinor: 0, qmlName: "SyntaxHighlighter" ); |
| 85 | qmlRegisterType<QsbInspectorHelper>(uri: "QQEMLib" , versionMajor: 1, versionMinor: 0, qmlName: "QsbInspectorHelper" ); |
| 86 | |
| 87 | QQmlApplicationEngine engine; |
| 88 | QQmlContext *context = engine.rootContext(); |
| 89 | if (context) { |
| 90 | context->setContextProperty("g_argData" , &g_argData); |
| 91 | context->setContextProperty("g_propertyData" , &g_propertyData); |
| 92 | context->setContextProperty("buildQtVersion" , QLatin1String(QT_VERSION_STR)); |
| 93 | context->setContextProperty("qdsMode" , isQDSMode); |
| 94 | } else { |
| 95 | qWarning(msg: "Unable to get access into root QQmlContext!" ); |
| 96 | } |
| 97 | |
| 98 | const QUrl url(QStringLiteral("qrc:/qml/main.qml" )); |
| 99 | QObject::connect(sender: &engine, signal: &QQmlApplicationEngine::objectCreated, |
| 100 | context: &app, slot: [url](QObject *obj, const QUrl &objUrl) { |
| 101 | if (!obj && url == objUrl) |
| 102 | QCoreApplication::exit(retcode: -1); |
| 103 | }, type: Qt::QueuedConnection); |
| 104 | engine.load(url); |
| 105 | |
| 106 | return app.exec(); |
| 107 | } |
| 108 | |