[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-kimageshop
Subject:    [krita] libs/ui: FEATURE: Add a command-line option to create a new image
From:       Boudewijn Rempt <null () kde ! org>
Date:       2017-10-12 11:55:57
Message-ID: E1e2c5l-0001JV-5X () code ! kde ! org
[Download RAW message or body]

Git commit 5f36b38630f073cb3439773f546920fa51de6420 by Boudewijn Rempt.
Committed on 12/10/2017 at 11:55.
Pushed by rempt into branch 'master'.

FEATURE: Add a command-line option to create a new image

CCMAIL: kimageshop@kde.org

M  +31   -22   libs/ui/KisApplication.cpp
M  +18   -17   libs/ui/KisApplication.h
M  +70   -1    libs/ui/KisApplicationArguments.cpp
M  +4    -0    libs/ui/KisApplicationArguments.h

https://commits.kde.org/krita/5f36b38630f073cb3439773f546920fa51de6420

diff --git a/libs/ui/KisApplication.cpp b/libs/ui/KisApplication.cpp
index 0fef183724c..9a6597a658c 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 <weis@kde.org>
-   Copyright (C) 2009 Thomas Zander <zander@kde.org>
-   Copyright (C) 2012 Boudewijn Rempt <boud@valdyas.org>
-
-   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 License
-   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 <weis@kde.org>
+ * Copyright (C) 2012 Boudewijn Rempt <boud@valdyas.org>
+ *
+ * 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 License
+ * 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"
 
@@ -384,6 +383,7 @@ bool KisApplication::start(const KisApplicationArguments &args)
     processEvents();
     initializeGlobals(args);
 
+    const bool doNewImage = args.doNewImage();
     const bool doTemplate = args.doTemplate();
     const bool print = args.print();
     const bool exportAs = args.exportAs();
@@ -397,7 +397,7 @@ bool KisApplication::start(const KisApplicationArguments &args)
     // TODO: fix print & exportAsPdf to work without mainwindow shown
     const bool showmainWindow = !exportAs; // would be !batchRun;
 
-    const bool showSplashScreen = !m_batchRun && \
qEnvironmentVariableIsEmpty("NOSPLASH");// &&  qgetenv("XDG_CURRENT_DESKTOP") != \
"GNOME"; +    const bool showSplashScreen = !m_batchRun && \
qEnvironmentVariableIsEmpty("NOSPLASH");  if (showSplashScreen && d->splashScreen) {
         d->splashScreen->show();
         d->splashScreen->repaint();
@@ -475,6 +475,16 @@ bool KisApplication::start(const KisApplicationArguments &args)
     connect(this, &KisApplication::aboutToQuit, \
&KisSpinBoxUnitManagerFactory::clearUnitManagerBuilder); //ensure the builder is \
                destroyed when the application leave.
     //the new syntax slot syntax allow to connect to a non q_object static method.
 
+
+    // Create a new image, if needed
+    if (doNewImage) {
+        KisDocument *doc = args.image();
+        if (doc) {
+            KisPart::instance()->addDocument(doc);
+            m_mainWindow->addViewAndNotifyLoadingCompleted(doc);
+        }
+    }
+
     // Get the command line arguments which we have to parse
     int argsCount = args.filenames().count();
     if (argsCount > 0) {
@@ -494,7 +504,6 @@ bool KisApplication::start(const KisApplicationArguments &args)
                 // now try to load
             }
             else {
-
                 if (exportAs) {
                     QString outputMimetype = \
KisMimeDatabase::mimeTypeForFile(exportFileName);  if (outputMimetype == \
                "application/octetstream") {
diff --git a/libs/ui/KisApplication.h b/libs/ui/KisApplication.h
index c3dfac8a87e..de7e9371025 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 <weis@kde.org>
-
-   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 License
-   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 <weis@kde.org>
+ * Copyright (C) 2012 Boudewijn Rempt <boud@valdyas.org>
+ *
+ * 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 License
+ * 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/KisApplicationArguments.cpp index 94ee37756bf..b843c765cd5 100644
--- a/libs/ui/KisApplicationArguments.cpp
+++ b/libs/ui/KisApplicationArguments.cpp
@@ -29,6 +29,8 @@
 #include <QBuffer>
 
 #include <klocalizedstring.h>
+#include <KisPart.h>
+#include <KisDocument.h>
 
 struct Q_DECL_HIDDEN KisApplicationArguments::Private
 {
@@ -48,6 +50,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 +77,20 @@ KisApplicationArguments::KisApplicationArguments(const \
QApplication &app)  parser.addHelpOption();
     parser.addOption(QCommandLineOption(QStringList() << QLatin1String("print"), \
                i18n("Only print and exit")));
     parser.addOption(QCommandLineOption(QStringList() << QLatin1String("template"), \
i18n("Open a new document with a template"))); +    \
parser.addOption(QCommandLineOption(QStringList() << QLatin1String("new-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,width,height")));  \
parser.addOption(QCommandLineOption(QStringList() << QLatin1String("workspace"), \
                i18n("The name of the workspace to open Krita with"), \
                QLatin1String("workspace")));
     parser.addOption(QCommandLineOption(QStringList() << \
                QLatin1String("canvasonly"), i18n("Start Krita in canvas-only \
                mode")));
     parser.addOption(QCommandLineOption(QStringList() << QLatin1String("nosplash"), \
i18n("Do not show the splash screen"))); @@ -97,9 +119,23 @@ \
KisApplicationArguments::KisApplicationArguments(const QApplication &app)  }
     }
 
+    QString newImageValues = parser.value("new-image");
+    d->newImage = !newImageValues.isEmpty();
+    if (d->newImage) {
+        QStringList v = newImageValues.split(",");
+        if (v.size() != 4) {
+            d->newImage = false;
+            qWarning() << "Cannot create a new image: please specify colormodel, \
depth, width and height."; +        }
+        d->colorModel = v[0].toUpper();
+        d->colorDepth = v[1].toUpper();
+        d->width = v[2].toInt();
+        d->height = v[3].toInt();
+    }
+
+
     d->exportFileName = parser.value("export-filename");
     d->workspace = parser.value("workspace");
-
     d->doTemplate = parser.isSet("template");
     d->print = parser.isSet("print");
     d->exportAs = parser.isSet("export");
@@ -169,6 +205,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 +245,12 @@ KisApplicationArguments \
KisApplicationArguments::deserialize(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 +316,22 @@ bool KisApplicationArguments::fullScreen() const
 {
     return d->fullScreen;
 }
+
+bool KisApplicationArguments::doNewImage() const
+{
+    return d->newImage;
+}
+
+KisDocument *KisApplicationArguments::image() const
+{
+    KisDocument *doc = KisPart::instance()->createDocument();
+    qDebug() << d->colorDepth << d->colorDepth;
+    const KoColorSpace *cs = \
KoColorSpaceRegistry::instance()->colorSpace(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/KisApplicationArguments.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:
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic