Krita Source Code Documentation
Loading...
Searching...
No Matches
KisApplicationArguments Class Reference

#include <KisApplicationArguments.h>

+ Inheritance diagram for KisApplicationArguments:

Public Member Functions

bool canvasOnly () const
 
KisDocumentcreateDocumentFromArguments () const
 
bool doNewImage () const
 
bool doTemplate () const
 
bool exportAs () const
 
QString exportFileName () const
 
bool exportSequence () const
 
QString fileLayer () const
 
QStringList filenames () const
 
bool fullScreen () const
 
 KisApplicationArguments (const KisApplicationArguments &rhs)
 
 KisApplicationArguments (const QApplication &app)
 
bool noSplash () const
 
void operator= (const KisApplicationArguments &rhs)
 
 Private ()
 
QByteArray serialize ()
 
QString session () const
 
QString windowLayout () const
 
QString workspace () const
 
 ~KisApplicationArguments ()
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Static Public Member Functions

static KisApplicationArguments deserialize (QByteArray &serialized)
 

Public Attributes

bool canvasOnly {false}
 
QString colorDepth {"U8"}
 
QString colorModel {"RGBA"}
 
bool doTemplate {false}
 
int dpiX {72}
 
int dpiY {72}
 
bool exportAs {false}
 
QString exportFileName
 
bool exportSequence {false}
 
QString fileLayer
 
QStringList filenames
 
bool fullScreen {false}
 
int height {5000}
 
bool newImage {false}
 
bool noSplash {false}
 
QString session
 
int width {2000}
 
QString windowLayout
 
QString workspace
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Private Member Functions

 KisApplicationArguments ()
 

Private Attributes

const QScopedPointer< Privated
 

Detailed Description

Definition at line 23 of file KisApplicationArguments.cpp.

Constructor & Destructor Documentation

◆ KisApplicationArguments() [1/3]

KisApplicationArguments::KisApplicationArguments ( const QApplication & app)

Definition at line 63 of file KisApplicationArguments.cpp.

64 : d(new Private)
65{
66 QCommandLineParser parser;
67 parser.addVersionOption();
68 parser.addHelpOption();
69 parser.addOption(QCommandLineOption(QStringList() << QLatin1String("template"), i18n("Open a new document with a template")));
70 parser.addOption(QCommandLineOption(QStringList() << QLatin1String("new-image"), i18n("Create a new image.\n"
71 "Possible colorspace values are:\n"
72 " * RGBA\n"
73 " * XYZA\n"
74 " * LABA\n"
75 " * CMYKA\n"
76 " * GRAY\n"
77 " * YCbCrA\n"
78 "Possible channel depth arguments are\n"
79 " * U8 (8 bits integer)\n"
80 " * U16 (16 bits integer)\n"
81 " * F16 (16 bits floating point)\n"
82 " * F32 (32 bits floating point)\n"),
83 QLatin1String("colorspace,depth,width,height")));
84 parser.addOption(QCommandLineOption(QStringList() << QLatin1String("workspace"), i18n("The name of the workspace to open Krita with"), QLatin1String("workspace")));
85 parser.addOption(QCommandLineOption(QStringList() << QLatin1String("windowlayout"), i18n("The name of the window layout to open Krita with"), QLatin1String("windowlayout")));
86 parser.addOption(QCommandLineOption(QStringList() << QLatin1String("load-session"), i18n("The name of the session to open Krita with"), QLatin1String("load-session"))); // NB: the argument "session" is already used by QGuiApplication
87 parser.addOption(QCommandLineOption(QStringList() << QLatin1String("canvasonly"), i18n("Start Krita in canvas-only mode")));
88 parser.addOption(QCommandLineOption(QStringList() << QLatin1String("nosplash"), i18n("Do not show the splash screen")));
89 parser.addOption(QCommandLineOption(QStringList() << QLatin1String("fullscreen"), i18n("Start Krita in full-screen mode")));
90 {
91 QCommandLineOption opt(QStringList() << QLatin1String("dpi"), i18n("Override display DPI"), QLatin1String("dpiX,dpiY"));
92 opt.setFlags(QCommandLineOption::HiddenFromHelp);
93 parser.addOption(opt);
94 }
95 parser.addOption(QCommandLineOption(QStringList() << QLatin1String("export"), i18n("Export to the given filename and exit")));
96 parser.addOption(QCommandLineOption(QStringList() << QLatin1String("export-sequence"), i18n("Export animation to the given filename and exit")));
97 parser.addOption(QCommandLineOption(QStringList() << QLatin1String("export-filename"), i18n("Filename for export"), QLatin1String("filename")));
98 parser.addOption(QCommandLineOption(QStringList() << QLatin1String("file-layer"), i18n("File layer to be added to existing or new file"), QLatin1String("file-layer")));
99 parser.addOption(QCommandLineOption(QStringList() << QLatin1String("resource-location"), i18n("A location that overrides the configured location for Krita's resources"), QLatin1String("file-layer")));
100 parser.addPositionalArgument(QLatin1String("[file(s)]"), i18n("File(s) or URL(s) to open"));
101
102 QStringList filteredArgs;
103 {
104 auto checkIsIgnoreEpic = [](const QString &arg) {
105 // List according to https://dev.epicgames.com/docs/services/en-US/Interfaces/Auth/index.html#epicgameslauncher
106 static const QStringList epicIgnoreArgsStart = {
107 QStringLiteral("AUTH_PASSWORD="),
108 QStringLiteral("AUTH_LOGIN="),
109 QStringLiteral("AUTH_TYPE="),
110 QStringLiteral("epicapp="),
111 QStringLiteral("epicenv="),
112 QStringLiteral("epicusername="),
113 QStringLiteral("epicuserid="),
114 QStringLiteral("epiclocale="),
115 QStringLiteral("epicsandboxid="),
116 };
117 static const QStringList epicIgnoreArgsExact = {
118 QStringLiteral("EpicPortal"),
119 };
120#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
121 QStringRef argDashless(&arg);
122#else
123 QStringView argDashless(arg);
124#endif
125 // Strip leading dashes.
126 while (argDashless.startsWith('-')) {
127 argDashless = argDashless.mid(1);
128 }
129 Q_FOREACH(const auto &argToIgnore, epicIgnoreArgsStart) {
130 if (argDashless.startsWith(argToIgnore, Qt::CaseInsensitive)) {
131 return true;
132 }
133 }
134 Q_FOREACH(const auto &argToIgnore, epicIgnoreArgsExact) {
135 if (argDashless.compare(argToIgnore, Qt::CaseInsensitive) == 0) {
136 return true;
137 }
138 }
139 return false;
140 };
141
142 QStringListIterator iter(app.arguments());
143 if (iter.hasNext()) {
144 // First argument is application name.
145 filteredArgs.append(iter.next());
146
147 bool isAfterDoubleDash = false;
148 while (iter.hasNext()) {
149 QString arg = iter.next();
150 if (arg == QLatin1String("--")) {
151 isAfterDoubleDash = true;
152 }
153 if (isAfterDoubleDash || !checkIsIgnoreEpic(arg)) {
154 filteredArgs.append(arg);
155 }
156 }
157 }
158 }
159
160 parser.process(filteredArgs);
161
162 QString dpiValues = parser.value("dpi");
163 if (!dpiValues.isEmpty()) {
164 qWarning() << "The `dpi` argument does nothing!";
165 }
166
167 QString newImageValues = parser.value("new-image");
168 d->newImage = !newImageValues.isEmpty();
169 if (d->newImage) {
170 QStringList v = newImageValues.split(",");
171 if (v.size() != 4) {
172 d->newImage = false;
173 qWarning() << "Cannot create a new image: please specify colormodel, depth, width and height.";
174 }
175 d->colorModel = v[0].toUpper();
176 d->colorDepth = v[1].toUpper();
177 d->width = v[2].toInt();
178 d->height = v[3].toInt();
179 }
180
181 d->fileLayer = parser.value("file-layer");
182 d->exportFileName = parser.value("export-filename");
183 d->workspace = parser.value("workspace");
184 d->windowLayout = parser.value("windowlayout");
185 d->session = parser.value("load-session");
186 d->doTemplate = parser.isSet("template");
187 d->exportAs = parser.isSet("export");
188 d->exportSequence = parser.isSet("export-sequence");
189 d->canvasOnly = parser.isSet("canvasonly");
190 d->noSplash = parser.isSet("nosplash");
191 d->fullScreen = parser.isSet("fullscreen");
192
193 KoResourcePaths::s_overrideAppDataLocation = parser.value("resource-location");
194
195 const QDir currentDir = QDir::current();
196 Q_FOREACH (const QString &filename, parser.positionalArguments()) {
197 d->filenames << currentDir.absoluteFilePath(filename);
198 }
199}
qreal v
QList< QString > QStringList
static QString s_overrideAppDataLocation
getAppDataLocation Use this instead of QStandardPaths::AppDataLocation! The user can configure the lo...
const QScopedPointer< Private > d

References d, KoResourcePaths::s_overrideAppDataLocation, and v.

◆ KisApplicationArguments() [2/3]

KisApplicationArguments::KisApplicationArguments ( const KisApplicationArguments & rhs)

Definition at line 201 of file KisApplicationArguments.cpp.

202 : d(new Private)
203{
204 d->filenames = rhs.filenames();
205 d->dpiX = rhs.d->dpiX;
206 d->dpiY = rhs.d->dpiY;
207 d->doTemplate = rhs.doTemplate();
208 d->exportAs = rhs.exportAs();
209 d->exportFileName = rhs.exportFileName();
210 d->canvasOnly = rhs.canvasOnly();
211 d->workspace = rhs.workspace();
212 d->windowLayout = rhs.windowLayout();
213 d->session = rhs.session();
214 d->noSplash = rhs.noSplash();
215 d->fullScreen = rhs.fullScreen();
216
217}

References canvasOnly, d, doTemplate, exportAs, exportFileName, filenames, fullScreen, noSplash, session, windowLayout, and workspace.

◆ ~KisApplicationArguments()

KisApplicationArguments::~KisApplicationArguments ( )

Definition at line 59 of file KisApplicationArguments.cpp.

60{
61}

◆ KisApplicationArguments() [3/3]

KisApplicationArguments::KisApplicationArguments ( )
private

Definition at line 53 of file KisApplicationArguments.cpp.

54 : d(new Private)
55{
56}

Member Function Documentation

◆ canvasOnly()

bool KisApplicationArguments::canvasOnly ( ) const

◆ createDocumentFromArguments()

KisDocument * KisApplicationArguments::createDocumentFromArguments ( ) const

Definition at line 375 of file KisApplicationArguments.cpp.

376{
378 const KoColorSpace *cs = KoColorSpaceRegistry::instance()->colorSpace(d->colorModel, d->colorDepth, "");
379 if (!cs) {
380 qWarning() << "Could not create the colorspace for the new image. Check the colorspace and depth arguments.";
381 return 0;
382 }
383
384 doc->newImage(i18n("Unnamed"), d->width, d->height, cs, KoColor(QColor(Qt::white), cs), KisConfig::CANVAS_COLOR, 1, "", 100.0);
385 return doc;
386}
bool newImage(const QString &name, qint32 width, qint32 height, const KoColorSpace *cs, const KoColor &bgColor, KisConfig::BackgroundStyle bgStyle, int numberOfLayers, const QString &imageDescription, const double imageResolution)
static KisPart * instance()
Definition KisPart.cpp:131
KisDocument * createDocument() const
Definition KisPart.cpp:230
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)
static KoColorSpaceRegistry * instance()

References KisConfig::CANVAS_COLOR, KoColorSpaceRegistry::colorSpace(), KisPart::createDocument(), d, KoColorSpaceRegistry::instance(), KisPart::instance(), and KisDocument::newImage().

◆ deserialize()

KisApplicationArguments KisApplicationArguments::deserialize ( QByteArray & serialized)
static

Definition at line 271 of file KisApplicationArguments.cpp.

272{
274
275 QBuffer buf(&serialized);
276 buf.open(QIODevice::ReadOnly);
277 QDataStream ds(&buf);
278 ds.setVersion(QDataStream::Qt_5_0);
279 qsizetype fileNamesCount;
280 ds >> fileNamesCount;
281 for(int i = 0; i < fileNamesCount; ++i) {
282 QString s;
283 ds >> s;
284 args.d->filenames << s;
285 }
286 ds >> args.d->dpiX;
287 ds >> args.d->dpiY;
288 ds >> args.d->doTemplate;
289 ds >> args.d->exportAs;
290 ds >> args.d->exportFileName;
291 ds >> args.d->workspace;
292 ds >> args.d->windowLayout;
293 ds >> args.d->session;
294 ds >> args.d->canvasOnly;
295 ds >> args.d->noSplash;
296 ds >> args.d->fullScreen;
297 ds >> args.d->newImage;
298 ds >> args.d->height;
299 ds >> args.d->width;
300 ds >> args.d->height;
301 ds >> args.d->colorModel;
302 ds >> args.d->colorDepth;
303 ds >> args.d->fileLayer;
304
305 buf.close();
306
307 return args;
308}

References d.

◆ doNewImage()

bool KisApplicationArguments::doNewImage ( ) const

Definition at line 370 of file KisApplicationArguments.cpp.

371{
372 return d->newImage;
373}

References d.

◆ doTemplate()

bool KisApplicationArguments::doTemplate ( ) const

◆ exportAs()

bool KisApplicationArguments::exportAs ( ) const

◆ exportFileName()

QString KisApplicationArguments::exportFileName ( ) const

◆ exportSequence()

bool KisApplicationArguments::exportSequence ( ) const

◆ fileLayer()

QString KisApplicationArguments::fileLayer ( ) const

◆ filenames()

QStringList KisApplicationArguments::filenames ( ) const

◆ fullScreen()

bool KisApplicationArguments::fullScreen ( ) const

◆ noSplash()

bool KisApplicationArguments::noSplash ( ) const

◆ operator=()

void KisApplicationArguments::operator= ( const KisApplicationArguments & rhs)

Definition at line 219 of file KisApplicationArguments.cpp.

220{
221 d->filenames = rhs.filenames();
222 d->dpiX = rhs.d->dpiX;
223 d->dpiY = rhs.d->dpiY;
224 d->doTemplate = rhs.doTemplate();
225 d->exportAs = rhs.exportAs();
226 d->exportFileName = rhs.exportFileName();
227 d->canvasOnly = rhs.canvasOnly();
228 d->workspace = rhs.workspace();
229 d->windowLayout = rhs.windowLayout();
230 d->session = rhs.session();
231 d->noSplash = rhs.noSplash();
232 d->fullScreen = rhs.fullScreen();
233}

References canvasOnly, d, doTemplate, exportAs, exportFileName, filenames, fullScreen, noSplash, session, windowLayout, and workspace.

◆ Private()

KisApplicationArguments::Private ( )
inline

Definition at line 25 of file KisApplicationArguments.cpp.

26 {
27 }

◆ serialize()

QByteArray KisApplicationArguments::serialize ( )

Definition at line 235 of file KisApplicationArguments.cpp.

236{
237 QBuffer buf;
238 buf.open(QIODevice::WriteOnly);
239 QDataStream ds(&buf);
240 ds.setVersion(QDataStream::Qt_5_0);
241 // explicitly declare the type of the size variable
242 const qsizetype fileNamesCount = d->filenames.count();
243 ds << fileNamesCount;
244 Q_FOREACH (const QString &filename, d->filenames) {
245 ds << filename;
246 }
247 ds << d->dpiX;
248 ds << d->dpiY;
249 ds << d->doTemplate;
250 ds << d->exportAs;
251 ds << d->exportFileName;
252 ds << d->workspace;
253 ds << d->windowLayout;
254 ds << d->session;
255 ds << d->canvasOnly;
256 ds << d->noSplash;
257 ds << d->fullScreen;
258 ds << d->newImage;
259 ds << d->height;
260 ds << d->width;
261 ds << d->height;
262 ds << d->colorModel;
263 ds << d->colorDepth;
264 ds << d->fileLayer;
265
266 buf.close();
267
268 return buf.data();
269}

References d.

◆ session()

QString KisApplicationArguments::session ( ) const

◆ windowLayout()

QString KisApplicationArguments::windowLayout ( ) const

◆ workspace()

QString KisApplicationArguments::workspace ( ) const

Member Data Documentation

◆ canvasOnly

bool KisApplicationArguments::canvasOnly {false}

Definition at line 40 of file KisApplicationArguments.cpp.

40{false};

◆ colorDepth

QString KisApplicationArguments::colorDepth {"U8"}

Definition at line 46 of file KisApplicationArguments.cpp.

46{"U8"};

◆ colorModel

QString KisApplicationArguments::colorModel {"RGBA"}

Definition at line 45 of file KisApplicationArguments.cpp.

45{"RGBA"};

◆ d

const QScopedPointer<Private> KisApplicationArguments::d
private

Definition at line 52 of file KisApplicationArguments.h.

◆ doTemplate

bool KisApplicationArguments::doTemplate {false}

Definition at line 32 of file KisApplicationArguments.cpp.

32{false};

◆ dpiX

int KisApplicationArguments::dpiX {72}

Definition at line 30 of file KisApplicationArguments.cpp.

30{72};

◆ dpiY

int KisApplicationArguments::dpiY {72}

Definition at line 31 of file KisApplicationArguments.cpp.

31{72};

◆ exportAs

bool KisApplicationArguments::exportAs {false}

Definition at line 33 of file KisApplicationArguments.cpp.

33{false};

◆ exportFileName

QString KisApplicationArguments::exportFileName

Definition at line 35 of file KisApplicationArguments.cpp.

◆ exportSequence

bool KisApplicationArguments::exportSequence {false}

Definition at line 34 of file KisApplicationArguments.cpp.

34{false};

◆ fileLayer

QString KisApplicationArguments::fileLayer

Definition at line 39 of file KisApplicationArguments.cpp.

◆ filenames

QStringList KisApplicationArguments::filenames

Definition at line 29 of file KisApplicationArguments.cpp.

◆ fullScreen

bool KisApplicationArguments::fullScreen {false}

Definition at line 42 of file KisApplicationArguments.cpp.

42{false};

◆ height

int KisApplicationArguments::height {5000}

Definition at line 48 of file KisApplicationArguments.cpp.

48{5000};

◆ newImage

bool KisApplicationArguments::newImage {false}

Definition at line 44 of file KisApplicationArguments.cpp.

44{false};

◆ noSplash

bool KisApplicationArguments::noSplash {false}

Definition at line 41 of file KisApplicationArguments.cpp.

41{false};

◆ session

QString KisApplicationArguments::session

Definition at line 38 of file KisApplicationArguments.cpp.

◆ width

int KisApplicationArguments::width {2000}

Definition at line 47 of file KisApplicationArguments.cpp.

47{2000};

◆ windowLayout

QString KisApplicationArguments::windowLayout

Definition at line 37 of file KisApplicationArguments.cpp.

◆ workspace

QString KisApplicationArguments::workspace

Definition at line 36 of file KisApplicationArguments.cpp.


The documentation for this class was generated from the following files: