diff --git a/plugins/extensions/pykrita/libkis/Filter.h b/plugins/extensions/pykrita/libkis/Filter.h index a5ca7802ca..05f1d920ac 100644 --- a/plugins/extensions/pykrita/libkis/Filter.h +++ b/plugins/extensions/pykrita/libkis/Filter.h @@ -1,89 +1,97 @@ /* * Copyright (c) 2016 Boudewijn Rempt * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef LIBKIS_FILTER_H #define LIBKIS_FILTER_H #include #include "kritalibkis_export.h" #include "libkis.h" /** * Filter: represents a filter and its configuration. A filter is identified by * an internal name. The configuration for each filter is defined as an InfoObject: * a map of name and value pairs. * * Currently available filters are: * * 'autocontrast', 'blur', 'bottom edge detections', 'brightnesscontrast', 'burn', 'colorbalance', 'colortoalpha', 'colortransfer', * 'desaturate', 'dodge', 'emboss', 'emboss all directions', 'emboss horizontal and vertical', 'emboss horizontal only', * 'emboss laplascian', 'emboss vertical only', 'gaussian blur', 'gaussiannoisereducer', 'gradientmap', 'halftone', 'hsvadjustment', * 'indexcolors', 'invert', 'left edge detections', 'lens blur', 'levels', 'maximize', 'mean removal', 'minimize', 'motion blur', * 'noise', 'normalize', 'oilpaint', 'perchannel', 'phongbumpmap', 'pixelize', 'posterize', 'raindrops', 'randompick', * 'right edge detections', 'roundcorners', 'sharpen', 'smalltiles', 'sobel', 'threshold', 'top edge detections', 'unsharp', * 'wave', 'waveletnoisereducer'] */ class KRITALIBKIS_EXPORT Filter : public QObject { Q_OBJECT Q_DISABLE_COPY(Filter) Q_PROPERTY(InfoObject* Configuration READ configuration WRITE setConfiguration) public: /** * @brief Filter: create an empty filter object. Until a name is set, the filter cannot * be applied. */ explicit Filter(); virtual ~Filter(); public Q_SLOTS: /** * @brief name the internal name of this filter. * @return the name. */ QString name() const; /** * @brief setName set the filter's name to the given name. */ void setName(const QString &name); + + /** + * @return the configuration object for the filter + */ InfoObject* configuration() const; + + /** + * @brief setConfiguration set the configuration object for the filter + */ void setConfiguration(InfoObject* value); /** * @brief Apply the filter to the given node. * @param node the node to apply the filter to * @params x, y, w, h: describe the rectangle the filter should be apply. * This is always in image pixel coordinates and not relative to the x, y * of the node. * @return true if the filter was applied succesfully, or * false if the filter could not be applied because the node is locked or * does not have an editable paint device. */ bool apply(Node *node, int x, int y, int w, int h); private: struct Private; Private *const d; }; #endif // LIBKIS_FILTER_H diff --git a/plugins/extensions/pykrita/libkis/Generator.cpp b/plugins/extensions/pykrita/libkis/Generator.cpp index af53d74f4b..267cb78d98 100644 --- a/plugins/extensions/pykrita/libkis/Generator.cpp +++ b/plugins/extensions/pykrita/libkis/Generator.cpp @@ -1,53 +1,53 @@ /* * Copyright (c) 2016 Boudewijn Rempt * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "Generator.h" struct Generator::Private { Private() {} }; Generator::Generator(QObject *parent) : QObject(parent) , d(new Private) { } Generator::~Generator() { delete d; } InfoObject* Generator::configuration() const { return 0; } void Generator::setConfiguration(InfoObject* value) { } -Node* Generator::CreateNode() +Node* Generator::createNode() { return 0; } diff --git a/plugins/extensions/pykrita/libkis/Generator.h b/plugins/extensions/pykrita/libkis/Generator.h index 6ca8a769e3..730fbcbd92 100644 --- a/plugins/extensions/pykrita/libkis/Generator.h +++ b/plugins/extensions/pykrita/libkis/Generator.h @@ -1,56 +1,55 @@ /* * Copyright (c) 2016 Boudewijn Rempt * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef LIBKIS_GENERATOR_H #define LIBKIS_GENERATOR_H #include #include "kritalibkis_export.h" #include "libkis.h" /** * Generator */ class KRITALIBKIS_EXPORT Generator : public QObject { Q_OBJECT Q_DISABLE_COPY(Generator) Q_PROPERTY(InfoObject* Configuration READ configuration WRITE setConfiguration) public: explicit Generator(QObject *parent = 0); virtual ~Generator(); InfoObject* configuration() const; void setConfiguration(InfoObject* value); - public Q_SLOTS: - Node* CreateNode(); + Node* createNode(); private: struct Private; const Private *const d; }; #endif // LIBKIS_GENERATOR_H diff --git a/plugins/extensions/pykrita/libkis/Krita.cpp b/plugins/extensions/pykrita/libkis/Krita.cpp index 4313126a38..cedc18badd 100644 --- a/plugins/extensions/pykrita/libkis/Krita.cpp +++ b/plugins/extensions/pykrita/libkis/Krita.cpp @@ -1,318 +1,338 @@ /* * Copyright (c) 2016 Boudewijn Rempt * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "Krita.h" #include +#include +#include +#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "View.h" #include "Document.h" #include "Window.h" #include "ViewExtension.h" #include "DockWidgetFactoryBase.h" #include "Filter.h" #include "InfoObject.h" - -#include +#include "Generator.h" Krita* Krita::s_instance = 0; struct Krita::Private { Private() {} QList viewExtensions; bool batchMode {false}; Notifier *notifier{new Notifier()}; }; Krita::Krita(QObject *parent) : QObject(parent) , d(new Private) { qRegisterMetaType(); } Krita::~Krita() { qDeleteAll(d->viewExtensions); delete d->notifier; delete d; } QList Krita::actions() const { QList actionList; KisMainWindow *mainWindow = KisPart::instance()->currentMainwindow(); if (!mainWindow) { return actionList; } KActionCollection *actionCollection = mainWindow->actionCollection(); Q_FOREACH(QAction *action, actionCollection->actions()) { actionList << new Action(action->objectName(), action); } return actionList; } Action *Krita::action(const QString &name) const { KisMainWindow *mainWindow = KisPart::instance()->currentMainwindow(); if (!mainWindow) { return 0; } KActionCollection *actionCollection = mainWindow->actionCollection(); QAction *action = actionCollection->action(name); if (action) { return new Action(name, action); } return 0; } Document* Krita::activeDocument() const { KisMainWindow *mainWindow = KisPart::instance()->currentMainwindow(); if (!mainWindow) { return 0; } KisView *view = mainWindow->activeView(); if (!view) { return 0; } KisDocument *document = view->document(); return new Document(document); } void Krita::setActiveDocument(Document* value) { Q_FOREACH(KisView *view, KisPart::instance()->views()) { if (view->document() == value->document().data()) { view->activateWindow(); break; } } } bool Krita::batchmode() const { return d->batchMode; } void Krita::setBatchmode(bool value) { d->batchMode = value; } QList Krita::documents() const { QList ret; foreach(QPointer doc, KisPart::instance()->documents()) { ret << new Document(doc); } return ret; } QStringList Krita::filters() const { - return KisFilterRegistry::instance()->keys(); + QStringList ls = KisFilterRegistry::instance()->keys(); + qSort(ls); + return ls; } Filter *Krita::filter(const QString &name) const { if (!filters().contains(name)) return 0; Filter *filter = new Filter(); filter->setName(name); KisFilterSP f = KisFilterRegistry::instance()->value(name); KisFilterConfigurationSP fc = f->defaultConfiguration(0); InfoObject *info = new InfoObject(fc); filter->setConfiguration(info); return filter; } -QList Krita::generators() const +QStringList Krita::generators() const { - return QList (); + QStringList ls = KisGeneratorRegistry::instance()->keys(); + qSort(ls); + return ls; } +Generator *Krita::generator(const QString &name) const +{ + if (!generators().contains(name)) return 0; + + Generator *generator = new Generator(); + generator->setName(name); + KisGeneratorSP f = KisGeneratorRegistry::instance()->value(name); + KisGeneratorConfigurationSP fc = f->defaultConfiguration(0); + InfoObject *info = new InfoObject(fc); + generator->setConfiguration(info); + return generator; +} + + Notifier* Krita::notifier() const { return d->notifier; } InfoObject* Krita::preferences() const { return 0; } void Krita::setPreferences(InfoObject* value) { } QString Krita::version() const { return KritaVersionWrapper::versionString(true); } QList Krita::views() const { QList ret; foreach(QPointer view, KisPart::instance()->views()) { ret << new View(view); } return ret; } Window *Krita::activeWindow() const { KisMainWindow *mainWindow = KisPart::instance()->currentMainwindow(); if (!mainWindow) { return 0; } return new Window(mainWindow); } QList Krita::windows() const { QList ret; foreach(QPointer mainWin, KisPart::instance()->mainWindows()) { ret << new Window(mainWin); } return ret; } QList Krita::resources() const { return QList (); } void Krita::setResources(QList value) { } void Krita::addDockWidget(DockWidget *dockWidget) { } bool Krita::closeApplication() { qDebug() << "closeApplication called"; return false; } Document* Krita::createDocument(int width, int height, const QString &name, const QString &colorModel, const QString &colorDepth, const QString &profile) { KisDocument *document = KisPart::instance()->createDocument(); KisPart::instance()->addDocument(document); const KoColorSpace *cs = KoColorSpaceRegistry::instance()->colorSpace(colorModel, colorDepth, profile); QColor qc(Qt::white); qc.setAlpha(0); KoColor bgColor(qc, cs); document->newImage(name, width, height, cs, bgColor, true, 1, "", 100.0); return new Document(document, true); } Document* Krita::openDocument(const QString &filename) { KisDocument *document = KisPart::instance()->createDocument(); KisPart::instance()->addDocument(document); document->openUrl(QUrl::fromLocalFile(filename), KisDocument::OPEN_URL_FLAG_DO_NOT_ADD_TO_RECENT_FILES); return new Document(document); } Window* Krita::openWindow() { return 0; } Action *Krita::createAction(const QString &text) { KisAction *action = new KisAction(text, this); KisPart::instance()->addScriptAction(action); return new Action(action->objectName(), action); } void Krita::addViewExtension(ViewExtension* viewExtension) { d->viewExtensions.append(viewExtension); } QList< ViewExtension* > Krita::viewExtensions() { return d->viewExtensions; } void Krita::addDockWidgetFactory(DockWidgetFactoryBase* factory) { KoDockRegistry::instance()->add(factory); } Krita* Krita::instance() { if (!s_instance) { s_instance = new Krita; } return s_instance; } /** * Scripter.fromVariant(variant) * variant is a QVariant * returns instance of QObject-subclass * * This is a helper method for PyQt because PyQt cannot cast a variant to a QObject or QWidget */ QObject *Krita::fromVariant(const QVariant& v) { if (v.canConvert< QWidget* >()) { QObject* obj = qvariant_cast< QWidget* >(v); return obj; } else if (v.canConvert< QObject* >()) { QObject* obj = qvariant_cast< QObject* >(v); return obj; } else return 0; } diff --git a/plugins/extensions/pykrita/libkis/Krita.h b/plugins/extensions/pykrita/libkis/Krita.h index 602c8bbce2..1c868135a4 100644 --- a/plugins/extensions/pykrita/libkis/Krita.h +++ b/plugins/extensions/pykrita/libkis/Krita.h @@ -1,209 +1,210 @@ /* * Copyright (c) 2016 Boudewijn Rempt * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef LIBKIS_KRITA_H #define LIBKIS_KRITA_H #include #include "kritalibkis_export.h" #include "libkis.h" #include "ViewExtension.h" #include "Document.h" #include "Window.h" #include "View.h" #include "Action.h" #include "Notifier.h" class QAction; /** * Krita is a singleton class that offers the root access to the Krita object hierarchy. * * The Krita.instance() is aliased as two builtins: Scripter and Application. */ class KRITALIBKIS_EXPORT Krita : public QObject { Q_OBJECT public: explicit Krita(QObject *parent = 0); virtual ~Krita(); /** * @return the currently active document, if there is one. */ Document* activeDocument() const; /** * @brief setActiveDocument activates the first view that shows the given document * @param value the document we want to activate */ void setActiveDocument(Document* value); /** * @brief batchmode determines whether the script is run in batch mode. If batchmode * is true, scripts should now show messageboxes or dialog boxes. * * Note that this separate from Document.setBatchmode(), which determines whether * export/save option dialogs are shown. * * @return true if the script is run in batchmode */ bool batchmode() const; /** * @brief setBatchmode sets the the batchmode to @param value; if true, scripts should * not show dialogs or messageboxes. */ void setBatchmode(bool value); /** * @return return a list of all actions for the currently active mainWindow. */ QList actions() const; Action *action(const QString &name) const; /** * @return a list of all open Documents */ QList documents() const; /** * @brief Filters are identified by an internal name. This function returns a list * of all existing registered filters. * @return a list of all registered filters */ QStringList filters() const; /** * @brief filter construct a Filter object with a default configuration. * @param name the name of the filter. Use Krita.instance().filters() to get * a list of all possible filters. * @return the filter or None if there is no such filter. */ Filter *filter(const QString &name) const; - QList generators() const; + QStringList generators() const; + Generator *generator(const QString &name) const; Notifier* notifier() const; InfoObject* preferences() const; void setPreferences(InfoObject* value); /** * @brief version Determine the version of Krita * * Usage: print(Application.version ()) * * @return the version string including git sha1 if Krita was built from git */ QString version() const; /** * @return a list of all views. A Document can be shown in more than one view. */ QList views() const; /** * @return the currently active window or None if there is no window */ Window * activeWindow() const; /** * @return a list of all windows */ QList windows() const; QList resources() const; void setResources(QList value); public Q_SLOTS: void addDockWidget(DockWidget *dockWidget); bool closeApplication(); /** * @brief createDocument creates a new document and image and registers the document with the Krita application. * * The document will have one transparent layer. * * @param width the width in pixels * @param height the height in pixels * @param name the name of the image (not the filename of the document) * @param colorModel A string describing the color model of the image: *
    *
  • A: Alpha mask
  • *
  • RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)
  • *
  • XYZA: XYZ with alpha channel
  • *
  • LABA: LAB with alpha channel
  • *
  • CMYKA: CMYK with alpha channel
  • *
  • GRAYA: Gray with alpha channel
  • *
  • YCbCrA: YCbCr with alpha channel
  • *
* @param colorDepth A string describing the color depth of the image: *
    *
  • U8: unsigned 8 bits integer, the most common type
  • *
  • U16: unsigned 16 bits integer
  • *
  • F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR
  • *
  • F32: 32 bits floating point
  • *
* @param profile The name of an icc profile that is known to Krita. If an empty string is passed, the default is * taken. * @return the created document. */ Document *createDocument(int width, int height, const QString &name, const QString &colorModel, const QString &colorDepth, const QString &profile); /** * @brief openDocument creates a new Document, registers it with the Krita application and loads the given file. * @param filename the file to open in the document * @return the document */ Document *openDocument(const QString &filename); Window *openWindow(); /** * @brief createAction creates an action with the given text and passes it to Krita. Every newly created * mainwindow will create an instance of this action. * @param text the user-visible text * @return the QAction you can connect a slot to. */ Action *createAction(const QString &text); void addViewExtension(ViewExtension* viewExtension); QList viewExtensions(); void addDockWidgetFactory(DockWidgetFactoryBase* factory ); static Krita* instance(); static QObject *fromVariant(const QVariant& v); private: struct Private; Private *const d; static Krita* s_instance; }; Q_DECLARE_METATYPE(Notifier*); #endif // LIBKIS_KRITA_H diff --git a/plugins/extensions/pykrita/sip/krita/Generator.sip b/plugins/extensions/pykrita/sip/krita/Generator.sip index e522f5eae1..db61caa1a6 100644 --- a/plugins/extensions/pykrita/sip/krita/Generator.sip +++ b/plugins/extensions/pykrita/sip/krita/Generator.sip @@ -1,15 +1,15 @@ class Generator : QObject { %TypeHeaderCode #include "Generator.h" %End Generator(const Generator & __0); public: Generator(QObject* parent /TransferThis/ = 0); virtual ~Generator(); InfoObject * configuration() const; void setConfiguration(InfoObject* value); public Q_SLOTS: - Node * CreateNode(); + Node * createNode(); private: }; diff --git a/plugins/extensions/pykrita/sip/krita/Krita.sip b/plugins/extensions/pykrita/sip/krita/Krita.sip index 1de4be6279..ced71babea 100644 --- a/plugins/extensions/pykrita/sip/krita/Krita.sip +++ b/plugins/extensions/pykrita/sip/krita/Krita.sip @@ -1,58 +1,59 @@ class Krita : QObject { %TypeHeaderCode #include "Krita.h" %End public: public: Krita(QObject* parent /TransferThis/ = 0); virtual ~Krita(); Document * activeDocument() const /Factory/; void setActiveDocument(Document* value); bool batchmode() const; void setBatchmode(bool value); QList actions() const /Factory/; Action * action(const QString & name) const; QList documents() const /Factory/; QStringList filters() const; Filter * filter(const QString &name) const /Factory/; - QList generators() const /Factory/; + QStringList generators() const /Factory/; + Generator * generator(const QString &name) const /Factory/; Notifier * notifier() const /Factory/; InfoObject * preferences() const /Factory/; void setPreferences(InfoObject* value); QString version() const; QList views() const /Factory/; Window * activeWindow() const /Factory/; QList windows() const /Factory/; QList resources() const /Factory/; void setResources(QList value); public Q_SLOTS: void addDockWidget(DockWidget* dockWidget); bool closeApplication(); Document * createDocument(int width, int height, const QString &name, const QString &colorModel, const QString &colorDepth, const QString &profile) /Factory/; Document * openDocument(const QString &filename) /Factory/; Window * openWindow(); Action * createAction(const QString & text); void addViewExtension(ViewExtension* _viewExtension /GetWrapper/); %MethodCode Py_BEGIN_ALLOW_THREADS sipCpp->addViewExtension(a0); Py_END_ALLOW_THREADS sipTransferTo(a0Wrapper, Py_None); %End void addDockWidgetFactory(DockWidgetFactoryBase* _factory /GetWrapper/); %MethodCode Py_BEGIN_ALLOW_THREADS sipCpp->addDockWidgetFactory(a0); Py_END_ALLOW_THREADS sipTransferTo(a0Wrapper, Py_None); %End static Krita * instance(); static QObject * fromVariant(const QVariant & v); private: Krita(const Krita &); // Generated };