Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • app
  • src
commandlineparser.cpp
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16*/
17
18#include "commandlineparser.h"
19
20#include <QTextStream>
21
22#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
23const auto qEndl = Qt::endl;
24#else
25const auto qEndl = endl;
26#endif
27
28CommandLineParser::CommandLineParser() : mParser(), mInputPath(), mOutputPaths(), mCamera()
29{
30 mParser.setApplicationDescription(tr("Pencil2D is an animation/drawing software for Mac OS X, Windows, and Linux. "
31 "It lets you create traditional hand-drawn animation (cartoon) using both bitmap and vector graphics."));
32 mParser.addHelpOption();
33 mParser.addVersionOption();
34 mParser.addPositionalArgument("input", tr("Path to the input pencil file."));
35
36 QCommandLineOption exportOutOption(QStringList() << "o" << "export",
37 tr("Render the file to <output_path>"),
38 tr("output_path"));
39 mParser.addOption(exportOutOption);
40
41 // for backwards compatibility
42 QCommandLineOption exportSeqOption(QStringList() << "export-sequence",
43 tr("Render the file to <output_path>"),
44 tr("output_path"));
45#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
46 exportSeqOption.setFlags(QCommandLineOption::HiddenFromHelp);
47#endif
48 mParser.addOption(exportSeqOption);
49
50 QCommandLineOption cameraOption(QStringList() << "camera",
51 tr("Name of the camera layer to use"),
52 tr("layer_name"));
53 mParser.addOption(cameraOption);
54
55 QCommandLineOption widthOption(QStringList() << "width",
56 tr("Width of the output frames"),
57 tr("integer"));
58 mParser.addOption(widthOption);
59
60 QCommandLineOption heightOption(QStringList() << "height",
61 tr("Height of the output frames"),
62 tr("integer"));
63 mParser.addOption(heightOption);
64
65 QCommandLineOption startOption(QStringList() << "start",
66 tr("The first frame you want to include in the exported movie"),
67 tr("frame"));
68 mParser.addOption(startOption);
69
70 QCommandLineOption endOption(QStringList() << "end",
71 tr("The last frame you want to include in the exported movie. "
72 "Can also be last or last-sound to automatically use the last "
73 "frame containing animation or sound, respectively"),
74 tr("frame"));
75 mParser.addOption(endOption);
76
77 QCommandLineOption transparencyOption(QStringList() << "transparency",
78 tr("Render transparency when possible"));
79 mParser.addOption(transparencyOption);
80}
81
82void CommandLineParser::process(QStringList arguments)
83{
84 QTextStream out(stdout);
85 QTextStream err(stderr);
86
87 arguments.removeOne("-NSDocumentRevisionsDebugMode");
88
89 mParser.process(arguments);
90
91 QStringList posArgs = mParser.positionalArguments();
92 if (!posArgs.isEmpty())
93 {
94 mInputPath = posArgs.at(0);
95 }
96
97 mOutputPaths << mParser.values("export") << mParser.values("export-sequence");
98
99 if (!mParser.value("width").isEmpty())
100 {
101 bool ok = false;
102 mWidth = mParser.value("width").toInt(&ok);
103 if (!ok)
104 {
105 err << tr("Warning: width value %1 is not an integer, ignoring.").arg(mParser.value("width")) << qEndl;
106 mWidth = -1;
107 }
108 }
109
110 if (!mParser.value("height").isEmpty())
111 {
112 bool ok = false;
113 mHeight = mParser.value("height").toInt(&ok);
114 if (!ok)
115 {
116 err << tr("Warning: height value %1 is not an integer, ignoring.").arg(mParser.value("height")) << qEndl;
117 mHeight = -1;
118 }
119 }
120
121 if (!mParser.value("start").isEmpty())
122 {
123 bool ok = false;
124 mStartFrame = mParser.value("start").toInt(&ok);
125 if (!ok)
126 {
127 err << tr("Warning: start value %1 is not an integer, ignoring.").arg(mParser.value("start")) << qEndl;
128 mStartFrame = 1;
129 }
130 if (mStartFrame < 1)
131 {
132 err << tr("Warning: start value must be at least 1, ignoring.") << qEndl;
133 mStartFrame = 1;
134 }
135 }
136
137 if (!mParser.value("end").isEmpty())
138 {
139 if (mParser.value("end") == "last")
140 {
141 mEndFrame = -1;
142 }
143 else if (mParser.value("end") == "last-sound")
144 {
145 mEndFrame = -2;
146 }
147 else
148 {
149 bool ok = false;
150 mEndFrame = mParser.value("end").toInt(&ok);
151 if (!ok)
152 {
153 err << tr("Warning: end value %1 is not an integer, last or last-sound, ignoring.").arg(mParser.value("end")) << qEndl;
154 mEndFrame = -1;
155 }
156 }
157 if (mEndFrame > -1 && mEndFrame < mStartFrame)
158 {
159 err << tr("Warning: end value %1 is smaller than start value %2, ignoring.").arg(mEndFrame).arg(mStartFrame) << qEndl;
160 mEndFrame = mStartFrame;
161 }
162 }
163
164 mTransparency = mParser.isSet("transparency");
165
166 mCamera = mParser.value("camera");
167}
QCommandLineOption
QCommandLineOption::HiddenFromHelp
HiddenFromHelp
QCommandLineParser::isSet
bool isSet(const QString &name) const const
QCommandLineParser::positionalArguments
QStringList positionalArguments() const const
QCommandLineParser::process
void process(const QStringList &arguments)
QCommandLineParser::value
QString value(const QString &optionName) const const
QCommandLineParser::values
QStringList values(const QString &optionName) const const
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString::isEmpty
bool isEmpty() const const
QString::toInt
int toInt(bool *ok, int base) const const
QStringList
Qt::endl
QTextStream & endl(QTextStream &stream)
QTextStream
Generated on Thu Jun 5 2025 14:06:43 for Pencil2D by doxygen 1.9.6 based on revision 4c63407997b2c03e5048716586dec6fbbb755173