| 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 | using namespace Qt::StringLiterals; |
| 14 | |
| 15 | int main(int argc, char **argv) |
| 16 | { |
| 17 | QApplication app(argc, argv); |
| 18 | QCoreApplication::setApplicationName("PixelTool"_L1); |
| 19 | QCoreApplication::setApplicationVersion(QLatin1StringView(qVersion())); |
| 20 | QCoreApplication::setOrganizationName("QtProject"_L1); |
| 21 | |
| 22 | QCommandLineParser parser; |
| 23 | parser.addHelpOption(); |
| 24 | parser.addVersionOption(); |
| 25 | parser.addPositionalArgument(name: "preview"_L1, |
| 26 | description: "The preview image to show."_L1); |
| 27 | |
| 28 | parser.process(app); |
| 29 | |
| 30 | QPixelTool pixelTool; |
| 31 | |
| 32 | if (!parser.positionalArguments().isEmpty()) { |
| 33 | const QString previewImageFileName = parser.positionalArguments().constFirst(); |
| 34 | if (QFileInfo::exists(file: previewImageFileName)) { |
| 35 | QImage previewImage(previewImageFileName); |
| 36 | if (!previewImage.size().isEmpty()) |
| 37 | pixelTool.setPreviewImage(previewImage); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | pixelTool.show(); |
| 42 | |
| 43 | QObject::connect(sender: &app, signal: &QApplication::lastWindowClosed, |
| 44 | context: &app, slot: &QCoreApplication::quit); |
| 45 | |
| 46 | return QCoreApplication::exec(); |
| 47 | } |
| 48 |
