From kde-kimageshop Thu Oct 12 11:59:28 2017 From: Boudewijn Rempt Date: Thu, 12 Oct 2017 11:59:28 +0000 To: kde-kimageshop Subject: [krita/krita/3.3] libs/ui: FEATURE: Add a command-line option to create a new image Message-Id: X-MARC-Message: https://marc.info/?l=kde-kimageshop&m=150780958530036 Git commit 206a1102a2bffa1d207706cf442389bc45757028 by Boudewijn Rempt. Committed on 12/10/2017 at 11:59. Pushed by rempt into branch 'krita/3.3'. FEATURE: Add a command-line option to create a new image CCMAIL: kimageshop@kde.org M +30 -22 libs/ui/KisApplication.cpp M +18 -17 libs/ui/KisApplication.h M +72 -1 libs/ui/KisApplicationArguments.cpp M +4 -0 libs/ui/KisApplicationArguments.h https://commits.kde.org/krita/206a1102a2bffa1d207706cf442389bc45757028 diff --git a/libs/ui/KisApplication.cpp b/libs/ui/KisApplication.cpp index 1ce65826d83..4a684797843 100644 --- a/libs/ui/KisApplication.cpp +++ b/libs/ui/KisApplication.cpp @@ -1,23 +1,22 @@ -/* This file is part of the KDE project - Copyright (C) 1998, 1999 Torben Weis - Copyright (C) 2009 Thomas Zander - Copyright (C) 2012 Boudewijn Rempt - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public Licen= se - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ +/* + * Copyright (C) 1998, 1999 Torben Weis + * Copyright (C) 2012 Boudewijn Rempt + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public Licen= se + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ = #include "KisApplication.h" = @@ -371,6 +370,7 @@ bool KisApplication::start(const KisApplicationArgument= s &args) processEvents(); initializeGlobals(args); = + const bool doNewImage =3D args.doNewImage(); const bool doTemplate =3D args.doTemplate(); const bool print =3D args.print(); const bool exportAs =3D args.exportAs(); @@ -384,7 +384,7 @@ bool KisApplication::start(const KisApplicationArgument= s &args) // TODO: fix print & exportAsPdf to work without mainwindow shown const bool showmainWindow =3D !exportAs; // would be !batchRun; = - const bool showSplashScreen =3D !m_batchRun && qEnvironmentVariableIsE= mpty("NOSPLASH");// && qgetenv("XDG_CURRENT_DESKTOP") !=3D "GNOME"; + const bool showSplashScreen =3D !m_batchRun && qEnvironmentVariableIsE= mpty("NOSPLASH"); if (showSplashScreen && d->splashScreen) { d->splashScreen->show(); d->splashScreen->repaint(); @@ -448,6 +448,15 @@ bool KisApplication::start(const KisApplicationArgumen= ts &args) setSplashScreenLoadingText(QString()); // done loading, so clear out l= abel processEvents(); = + // Create a new image, if needed + if (doNewImage) { + KisDocument *doc =3D args.image(); + if (doc) { + KisPart::instance()->addDocument(doc); + m_mainWindow->addViewAndNotifyLoadingCompleted(doc); + } + } + // Get the command line arguments which we have to parse int argsCount =3D args.filenames().count(); if (argsCount > 0) { @@ -467,7 +476,6 @@ bool KisApplication::start(const KisApplicationArgument= s &args) // now try to load } else { - if (exportAs) { QString outputMimetype =3D KisMimeDatabase::mimeTypeFo= rFile(exportFileName); if (outputMimetype =3D=3D "application/octetstream") { diff --git a/libs/ui/KisApplication.h b/libs/ui/KisApplication.h index f4db0791277..b101437b66a 100644 --- a/libs/ui/KisApplication.h +++ b/libs/ui/KisApplication.h @@ -1,21 +1,22 @@ -/* This file is part of the KDE project - Copyright (C) 1998, 1999 Torben Weis - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public Licen= se - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +/* + * Copyright (C) 1998, 1999 Torben Weis + * Copyright (C) 2012 Boudewijn Rempt + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public Licen= se + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. -*/ + */ = #ifndef KIS_APPLICATION_H #define KIS_APPLICATION_H diff --git a/libs/ui/KisApplicationArguments.cpp b/libs/ui/KisApplicationAr= guments.cpp index 94ee37756bf..0ff503ef99a 100644 --- a/libs/ui/KisApplicationArguments.cpp +++ b/libs/ui/KisApplicationArguments.cpp @@ -29,6 +29,10 @@ #include = #include +#include +#include +#include +#include = struct Q_DECL_HIDDEN KisApplicationArguments::Private { @@ -48,6 +52,12 @@ struct Q_DECL_HIDDEN KisApplicationArguments::Private bool canvasOnly {false}; bool noSplash {false}; bool fullScreen {false}; + + bool newImage {false}; + QString colorModel {"RGBA"}; + QString colorDepth {"U8"}; + int width {2000}; + int height {5000}; }; = = @@ -69,6 +79,20 @@ KisApplicationArguments::KisApplicationArguments(const Q= Application &app) parser.addHelpOption(); parser.addOption(QCommandLineOption(QStringList() << QLatin1String("pr= int"), i18n("Only print and exit"))); parser.addOption(QCommandLineOption(QStringList() << QLatin1String("te= mplate"), i18n("Open a new document with a template"))); + parser.addOption(QCommandLineOption(QStringList() << QLatin1String("ne= w-image"), i18n("Create a new image on startup.\n" + = "Possible colorspace values are:\n" + = " * RGBA\n" + = " * XYZA\n" + = " * LABA\n" + = " * CMYKA\n" + = " * GRAY\n" + = " * YCbCrA\n" + = "Possible channel depth arguments are\n" + = " * U8 (8 bits integer)\n" + = " * U16 (16 bits integer)\n" + = " * F16 (16 bits floating point)\n" + = " * F32 (32 bits floating point)\n"), + QLatin1String("colorspace,depth,wi= dth,height"))); parser.addOption(QCommandLineOption(QStringList() << QLatin1String("wo= rkspace"), i18n("The name of the workspace to open Krita with"), QLatin1Str= ing("workspace"))); parser.addOption(QCommandLineOption(QStringList() << QLatin1String("ca= nvasonly"), i18n("Start Krita in canvas-only mode"))); parser.addOption(QCommandLineOption(QStringList() << QLatin1String("no= splash"), i18n("Do not show the splash screen"))); @@ -97,9 +121,23 @@ KisApplicationArguments::KisApplicationArguments(const = QApplication &app) } } = + QString newImageValues =3D parser.value("new-image"); + d->newImage =3D !newImageValues.isEmpty(); + if (d->newImage) { + QStringList v =3D newImageValues.split(","); + if (v.size() !=3D 4) { + d->newImage =3D false; + qWarning() << "Cannot create a new image: please specify color= model, depth, width and height."; + } + d->colorModel =3D v[0].toUpper(); + d->colorDepth =3D v[1].toUpper(); + d->width =3D v[2].toInt(); + d->height =3D v[3].toInt(); + } + + d->exportFileName =3D parser.value("export-filename"); d->workspace =3D parser.value("workspace"); - d->doTemplate =3D parser.isSet("template"); d->print =3D parser.isSet("print"); d->exportAs =3D parser.isSet("export"); @@ -169,6 +207,14 @@ QByteArray KisApplicationArguments::serialize() ds << d->canvasOnly; ds << d->noSplash; ds << d->fullScreen; + ds << d->newImage; + ds << d->height; + ds << d->width; + ds << d->height; + ds << d->colorModel; + ds << d->colorDepth; + + = buf.close(); = @@ -201,6 +247,12 @@ KisApplicationArguments KisApplicationArguments::deser= ialize(QByteArray &seriali ds >> args.d->canvasOnly; ds >> args.d->noSplash; ds >> args.d->fullScreen; + ds >> args.d->newImage; + ds >> args.d->height; + ds >> args.d->width; + ds >> args.d->height; + ds >> args.d->colorModel; + ds >> args.d->colorDepth; = buf.close(); = @@ -266,3 +318,22 @@ bool KisApplicationArguments::fullScreen() const { return d->fullScreen; } + +bool KisApplicationArguments::doNewImage() const +{ + return d->newImage; +} + +KisDocument *KisApplicationArguments::image() const +{ + KisDocument *doc =3D KisPart::instance()->createDocument(); + qDebug() << d->colorDepth << d->colorDepth; + const KoColorSpace *cs =3D KoColorSpaceRegistry::instance()->colorSpac= e(d->colorModel, d->colorDepth, ""); + if (!cs) { + qWarning() << "Could not create the colorspace for the new image. = Check the colorspace and depth arguments."; + return 0; + } + + doc->newImage(i18n("Unnamed"), d->width, d->height, cs, KoColor(QColor= (Qt::white), cs), false, 1, "", 100.0); + return doc; +} diff --git a/libs/ui/KisApplicationArguments.h b/libs/ui/KisApplicationArgu= ments.h index b3ae335f25e..9d24cb8cf73 100644 --- a/libs/ui/KisApplicationArguments.h +++ b/libs/ui/KisApplicationArguments.h @@ -24,6 +24,7 @@ class QApplication; class QByteArray; class QStringList; +class KisDocument; = #include "kritaui_export.h" = @@ -52,6 +53,9 @@ public: bool canvasOnly() const; bool noSplash() const; bool fullScreen() const; + bool doNewImage() const; + KisDocument *image() const; + = private: =20