1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the tools applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include "qpixeltool.h"
30
31#include <qapplication.h>
32#include <qcommandlineparser.h>
33#include <qcommandlineoption.h>
34#include <qfileinfo.h>
35
36QT_USE_NAMESPACE
37
38static bool isOptionSet(int argc, char *argv[], const char *option)
39{
40 for (int i = 1; i < argc; ++i) {
41 if (!qstrcmp(str1: argv[i], str2: option))
42 return true;
43 }
44 return false;
45}
46
47int main(int argc, char **argv)
48{
49 if (isOptionSet(argc, argv, option: "--no-scaling"))
50 QCoreApplication::setAttribute(attribute: Qt::AA_DisableHighDpiScaling);
51
52 QApplication app(argc, argv);
53 QCoreApplication::setApplicationName(QLatin1String("PixelTool"));
54 QCoreApplication::setApplicationVersion(QLatin1String(QT_VERSION_STR));
55 QCoreApplication::setOrganizationName(QLatin1String("QtProject"));
56
57 QCommandLineParser parser;
58 parser.addHelpOption();
59 parser.addVersionOption();
60 QCommandLineOption noScalingDummy(QStringLiteral("no-scaling"),
61 QStringLiteral("Set Qt::AA_DisableHighDpiScaling."));
62 parser.addOption(commandLineOption: noScalingDummy);
63 parser.addPositionalArgument(name: QLatin1String("preview"),
64 description: QLatin1String("The preview image to show."));
65
66 parser.process(app);
67
68 QPixelTool pixelTool;
69
70 if (!parser.positionalArguments().isEmpty()) {
71 const QString previewImageFileName = parser.positionalArguments().constFirst();
72 if (QFileInfo(previewImageFileName).exists()) {
73 QImage previewImage(previewImageFileName);
74 if (!previewImage.size().isEmpty())
75 pixelTool.setPreviewImage(previewImage);
76 }
77 }
78
79 pixelTool.show();
80
81 QObject::connect(sender: &app, signal: &QApplication::lastWindowClosed,
82 context: &app, slot: &QCoreApplication::quit);
83
84 return app.exec();
85}
86

source code of qttools/src/pixeltool/main.cpp