1 | // Copyright (C) 2016 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #include "qpixeltool.h" |
5 | |
6 | #include <qapplication.h> |
7 | #include <qcommandlineparser.h> |
8 | #include <qcommandlineoption.h> |
9 | #include <qfileinfo.h> |
10 | |
11 | QT_USE_NAMESPACE |
12 | |
13 | int main(int argc, char **argv) |
14 | { |
15 | QApplication app(argc, argv); |
16 | QCoreApplication::setApplicationName(QLatin1String("PixelTool")); |
17 | QCoreApplication::setApplicationVersion(QLatin1String(QT_VERSION_STR)); |
18 | QCoreApplication::setOrganizationName(QLatin1String("QtProject")); |
19 | |
20 | QCommandLineParser parser; |
21 | parser.addHelpOption(); |
22 | parser.addVersionOption(); |
23 | parser.addPositionalArgument(name: QLatin1String("preview"), |
24 | description: QLatin1String("The preview image to show.")); |
25 | |
26 | parser.process(app); |
27 | |
28 | QPixelTool pixelTool; |
29 | |
30 | if (!parser.positionalArguments().isEmpty()) { |
31 | const QString previewImageFileName = parser.positionalArguments().constFirst(); |
32 | if (QFileInfo(previewImageFileName).exists()) { |
33 | QImage previewImage(previewImageFileName); |
34 | if (!previewImage.size().isEmpty()) |
35 | pixelTool.setPreviewImage(previewImage); |
36 | } |
37 | } |
38 | |
39 | pixelTool.show(); |
40 | |
41 | QObject::connect(sender: &app, signal: &QApplication::lastWindowClosed, |
42 | context: &app, slot: &QCoreApplication::quit); |
43 | |
44 | return app.exec(); |
45 | } |
46 |