diff --git a/libs/libkis/Action.cpp b/libs/libkis/Action.cpp deleted file mode 100644 index faafc23113..0000000000 --- a/libs/libkis/Action.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* - * 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 "Action.h" - - -struct Action::Private { - Private() {} - QAction *action {0}; -}; - -Action::Action(QObject *parent) - : QObject(parent) - , d(new Private) -{ - d->action = new KisAction(this); - connect(d->action, SIGNAL(triggered(bool)), SIGNAL(triggered(bool))); -} - -Action::Action(const QString &name, QAction *action, QObject *parent) - : QObject(parent) - , d(new Private) -{ - d->action = action; - d->action->setObjectName(name); - connect(d->action, SIGNAL(triggered(bool)), SIGNAL(triggered(bool))); -} - -Action::~Action() -{ - delete d; -} - - -bool Action::operator==(const Action &other) const -{ - return (d->action == other.d->action); -} - -bool Action::operator!=(const Action &other) const -{ - return !(operator==(other)); -} - - -QString Action::text() const -{ - if (!d->action) return ""; - return d->action->text(); -} - -void Action::setText(QString text) -{ - if (!d->action) return; - d->action->setText(text); -} - -QString Action::name() const -{ - if (!d->action) return ""; - return d->action->objectName(); -} - -void Action::setName(QString name) -{ - if (!d->action) return; - d->action->setObjectName(name); -} - -bool Action::isCheckable() const -{ - if (!d->action) return false; - return d->action->isCheckable(); -} - -void Action::setCheckable(bool value) -{ - if (!d->action) return; - d->action->setCheckable(value); -} - -bool Action::isChecked() const -{ - if (!d->action) return false; - return d->action->isChecked(); -} - -void Action::setChecked(bool value) -{ - if (!d->action) return; - d->action->setChecked(value); -} - -QString Action::shortcut() const -{ - if (!d->action) return QString(); - return d->action->shortcut().toString(); -} - -void Action::setShortcut(QString value) -{ - if (!d->action) return; - d->action->setShortcut(QKeySequence::fromString(value)); -} - -bool Action::isVisible() const -{ - if (!d->action) return false; - return d->action->isVisible(); -} - -void Action::setVisible(bool value) -{ - if (!d->action) return; - d->action->setVisible(value); -} - -bool Action::isEnabled() const -{ - if (!d->action) return false; - return d->action->isEnabled(); -} - -void Action::setEnabled(bool value) -{ - if (!d->action) return; - d->action->setEnabled(value); -} - -void Action::setToolTip(QString tooltip) -{ - if (!d->action) return; - d->action->setToolTip(tooltip); -} - -QString Action::tooltip() const -{ - return d->action->toolTip(); -} - -void Action::trigger() -{ - d->action->trigger(); -} diff --git a/libs/libkis/Action.h b/libs/libkis/Action.h deleted file mode 100644 index 9546fc644d..0000000000 --- a/libs/libkis/Action.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * 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_ACTION_H -#define LIBKIS_ACTION_H - -#include - -#include "kritalibkis_export.h" -#include "libkis.h" - -/** - * Action encapsulates a KisAction. By default, actions are put in the Tools/Scripts menu. - */ -class KRITALIBKIS_EXPORT Action : public QObject -{ - Q_OBJECT - -public: - /** - * @brief Action Create a new action object - * @param parent the parent if it's in a QObject hierarchy - */ - explicit Action(QObject *parent = 0); - - /** - * @brief Action Create a new action object - * @param name the name of the action - * @param action the QAction it wraps - * @param parent the parent if it's in a QObject hierarchy - */ - Action(const QString &name, QAction *action, QObject *parent = 0); - ~Action() override; - - bool operator==(const Action &other) const; - bool operator!=(const Action &other) const; - -public Q_SLOTS: - - /** - * @return the user-visible text of the action. - */ - QString text() const; - - /** - * set the user-visible text of the action to @param text. - */ - void setText(QString text); - - /** - * @return the internal name of the action. - */ - QString name() const; - - /** - * set the name of the action to @param name. This is not the user-visible name, but the internal one - */ - void setName(QString name); - - /** - * @return true if the action is checkable, false if it isn't* - */ - bool isCheckable() const; - - /** - * Set the action action checkable if @param value is true, unchecked if it's false - */ - void setCheckable(bool value); - - /** - * @return true if the action is checked, false if it isn't - */ - bool isChecked() const; - - /** - * Set the action checked if @param value is true, unchecked if it's false - */ - void setChecked(bool value); - - /** - * Return the action's shortcut as a string - */ - QString shortcut() const; - - /** - * set the action's shortcut to the given string. - * @code - * action.setShortcut("CTRL+SHIFT+S") - * @endcode - */ - void setShortcut(QString value); - - bool isVisible() const; - /** - * @brief setVisible determines whether the action will be visible in the scripting menu. - * @param value true if the action is to be shown in the menu, false otherwise - */ - void setVisible(bool value); - - /** - * @return true if the action is enabled, false if not - */ - bool isEnabled() const; - - /** - * Set the action enabled or disabled according to @param value - */ - void setEnabled(bool value); - - /** - * Set the tooltip to the given @param tooltip - */ - void setToolTip(QString tooltip); - - /** - * @return the tooltip text - */ - QString tooltip() const; - - /** - * Trigger this action - */ - void trigger(); - -Q_SIGNALS: - - /** - * Emitted whenever the action is triggered. - */ - void triggered(bool); - -private: - struct Private; - Private *const d; - -}; - - -#endif // LIBKIS_ACTION_H diff --git a/libs/libkis/CMakeLists.txt b/libs/libkis/CMakeLists.txt index 3f150e3fbf..2d6ed39361 100644 --- a/libs/libkis/CMakeLists.txt +++ b/libs/libkis/CMakeLists.txt @@ -1,50 +1,49 @@ set(kritalibkis_LIB_SRCS - Action.cpp Canvas.cpp Channel.cpp DockWidget.cpp DockWidgetFactoryBase.cpp Document.cpp Filter.cpp InfoObject.cpp Krita.cpp ManagedColor.cpp Node.cpp Notifier.cpp PresetChooser Palette.cpp PaletteView.cpp Resource.cpp Selection.cpp View.cpp Extension.cpp Window.cpp GroupLayer.cpp CloneLayer.cpp FileLayer.cpp FilterLayer.cpp FillLayer.cpp VectorLayer.cpp FilterMask.cpp SelectionMask.cpp Shape.cpp GroupShape.cpp LibKisUtils.cpp ) add_library(kritalibkis SHARED ${kritalibkis_LIB_SRCS} ) generate_export_header(kritalibkis) target_link_libraries(kritalibkis kritaui kritaimage kritaversion) target_link_libraries(kritalibkis LINK_INTERFACE_LIBRARIES kritaimage kritaui) set_target_properties(kritalibkis PROPERTIES VERSION ${GENERIC_KRITA_LIB_VERSION} SOVERSION ${GENERIC_KRITA_LIB_SOVERSION} ) install(TARGETS kritalibkis ${INSTALL_TARGETS_DEFAULT_ARGS}) add_subdirectory(tests) diff --git a/libs/libkis/Krita.cpp b/libs/libkis/Krita.cpp index a90f5ec0ea..6efee08c65 100644 --- a/libs/libkis/Krita.cpp +++ b/libs/libkis/Krita.cpp @@ -1,423 +1,416 @@ /* * 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 #include #include #include #include #include #include #include #include #include #include #include #include #include "View.h" #include "Document.h" #include "Window.h" #include "Extension.h" #include "DockWidgetFactoryBase.h" #include "Filter.h" #include "InfoObject.h" #include "Resource.h" Krita* Krita::s_instance = 0; struct Krita::Private { Private() {} QList extensions; bool batchMode {false}; Notifier *notifier{new Notifier()}; }; Krita::Krita(QObject *parent) : QObject(parent) , d(new Private) { qRegisterMetaType(); connect(KisPart::instance(), SIGNAL(sigWindowAdded(KisMainWindow*)), SLOT(mainWindowAdded(KisMainWindow*))); } Krita::~Krita() { qDeleteAll(d->extensions); delete d->notifier; delete d; } -QList Krita::actions() const +QList Krita::actions() const { - QList actionList; KisMainWindow *mainWindow = KisPart::instance()->currentMainwindow(); if (!mainWindow) { - return actionList; + return QList(); } KActionCollection *actionCollection = mainWindow->actionCollection(); - Q_FOREACH(QAction *action, actionCollection->actions()) { - actionList << new Action(action->objectName(), action); - } - return actionList; + return actionCollection->actions(); } -Action *Krita::action(const QString &name) const +QAction *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; + return action; } 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 { QStringList ls = KisFilterRegistry::instance()->keys(); std::sort(ls.begin(), ls.end()); 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(); InfoObject *info = new InfoObject(fc); filter->setConfiguration(info); return filter; } QStringList Krita::colorModels() const { QSet colorModelsIds; QList ids = KoColorSpaceRegistry::instance()->colorModelsList(KoColorSpaceRegistry::AllColorSpaces); Q_FOREACH(KoID id, ids) { colorModelsIds << id.id(); } return colorModelsIds.toList();; } QStringList Krita::colorDepths(const QString &colorModel) const { QSet colorDepthsIds; QList ids = KoColorSpaceRegistry::instance()->colorDepthList(colorModel, KoColorSpaceRegistry::AllColorSpaces); Q_FOREACH(KoID id, ids) { colorDepthsIds << id.id(); } return colorDepthsIds.toList();; } QStringList Krita::filterStrategies() const { return KisFilterStrategyRegistry::instance()->keys(); } QStringList Krita::profiles(const QString &colorModel, const QString &colorDepth) const { QSet profileNames; QString id = KoColorSpaceRegistry::instance()->colorSpaceId(colorModel, colorDepth); QList profiles = KoColorSpaceRegistry::instance()->profilesFor(id); Q_FOREACH(const KoColorProfile *profile, profiles) { profileNames << profile->name(); } return profileNames.toList(); } bool Krita::addProfile(const QString &profilePath) { KoColorSpaceEngine *iccEngine = KoColorSpaceEngineRegistry::instance()->get("icc"); return iccEngine->addProfile(profilePath); } Notifier* Krita::notifier() const { return d->notifier; } 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; } QMap Krita::resources(const QString &type) const { QMap resources = QMap (); if (type.toLower() == "pattern") { KoResourceServer* server = KoResourceServerProvider::instance()->patternServer(); Q_FOREACH (KoResource *res, server->resources()) { resources[res->name()] = new Resource(res); } } else if (type.toLower() == "gradient") { KoResourceServer* server = KoResourceServerProvider::instance()->gradientServer(); Q_FOREACH (KoResource *res, server->resources()) { resources[res->name()] = new Resource(res); } } else if (type.toLower() == "brush") { KisBrushResourceServer* server = KisBrushServer::instance()->brushServer(); Q_FOREACH (KisBrushSP res, server->resources()) { resources[res->name()] = new Resource(res.data()); } } else if (type.toLower() == "preset") { KisPaintOpPresetResourceServer* server = KisResourceServerProvider::instance()->paintOpPresetServer(); Q_FOREACH (KisPaintOpPresetSP res, server->resources()) { resources[res->name()] = new Resource(res.data()); } } else if (type.toLower() == "palette") { KoResourceServer* server = KoResourceServerProvider::instance()->paletteServer(); Q_FOREACH (KoResource *res, server->resources()) { resources[res->name()] = new Resource(res); } } else if (type.toLower() == "workspace") { KoResourceServer< KisWorkspaceResource >* server = KisResourceServerProvider::instance()->workspaceServer(); Q_FOREACH (KoResource *res, server->resources()) { resources[res->name()] = new Resource(res); } } return resources; } QStringList Krita::recentDocuments() const { KConfigGroup grp = KSharedConfig::openConfig()->group(QString("RecentFiles")); QStringList keys = grp.keyList(); QStringList recentDocuments; for(int i = 0; i <= keys.filter("File").count(); i++) recentDocuments << grp.readEntry(QString("File%1").arg(i), QString("")); return recentDocuments; } Document* Krita::createDocument(int width, int height, const QString &name, const QString &colorModel, const QString &colorDepth, const QString &profile, double resolution) { KisDocument *document = KisPart::instance()->createDocument(); KisPart::instance()->addDocument(document); const KoColorSpace *cs = KoColorSpaceRegistry::instance()->colorSpace(colorModel, colorDepth, profile); Q_ASSERT(cs); QColor qc(Qt::white); qc.setAlpha(0); KoColor bgColor(qc, cs); if (!document->newImage(name, width, height, cs, bgColor, true, 1, "", double(resolution / 72) )) { qDebug() << "Could not create a new image"; return 0; } Q_ASSERT(document->image()); qDebug() << document->image()->objectName(); return new Document(document); } Document* Krita::openDocument(const QString &filename) { KisDocument *document = KisPart::instance()->createDocument(); KisPart::instance()->addDocument(document); document->openUrl(QUrl::fromLocalFile(filename), KisDocument::DontAddToRecent); return new Document(document); } Window* Krita::openWindow() { KisMainWindow *mw = KisPart::instance()->createMainWindow(); return new Window(mw); } void Krita::addExtension(Extension* extension) { d->extensions.append(extension); } QList< Extension* > Krita::extensions() { return d->extensions; } void Krita::writeSetting(const QString &group, const QString &name, const QString &value) { KConfigGroup grp = KSharedConfig::openConfig()->group(group); grp.writeEntry(name, value); } QString Krita::readSetting(const QString &group, const QString &name, const QString &defaultValue) { KConfigGroup grp = KSharedConfig::openConfig()->group(group); return grp.readEntry(name, defaultValue); } QIcon Krita::icon(QString &iconName) const { return KisIconUtils::loadIcon(iconName); } 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; } void Krita::mainWindowAdded(KisMainWindow *kisWindow) { Q_FOREACH(Extension *extension, d->extensions) { Window window(kisWindow); extension->createActions(&window); } } diff --git a/libs/libkis/Krita.h b/libs/libkis/Krita.h index 5fd47153fb..200e7d8e40 100644 --- a/libs/libkis/Krita.h +++ b/libs/libkis/Krita.h @@ -1,344 +1,343 @@ /* * 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 #include "kritalibkis_export.h" #include "libkis.h" #include "Extension.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); ~Krita() override; public Q_SLOTS: /** * @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 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; + QList actions() const; /** * @return the action that has been registered under the given name, or 0 if no such action exists. */ - Action *action(const QString &name) const; + QAction *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; /** * @brief colorModels creates a list with all color models id's registered. * @return a list of all color models or a empty list if there is no such color models. */ QStringList colorModels() const; /** * @brief colorDepths creates a list with the names of all color depths * compatible with the given color model. * @param colorModel the id of a color model. * @return a list of all color depths or a empty list if there is no such * color depths. */ QStringList colorDepths(const QString &colorModel) const; /** * @brief filterStrategies Retrieves all installed filter strategies. A filter * strategy is used when transforming (scaling, shearing, rotating) an image to * calculate the value of the new pixels. You can use th * @return the id's of all available filters. */ QStringList filterStrategies() const; /** * @brief profiles creates a list with the names of all color profiles compatible * with the given color model and color depth. * @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
  • *
* @return a list with valid names */ QStringList profiles(const QString &colorModel, const QString &colorDepth) const; /** * @brief addProfile load the given profile into the profile registry. * @param profilePath the path to the profile. * @return true if adding the profile succeeded. */ bool addProfile(const QString &profilePath); /** * @brief notifier the Notifier singleton emits signals when documents are opened and * closed, the configuration changes, views are opened and closed or windows are opened. * @return the notifier object */ Notifier *notifier() const; /** * @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; /** * @brief resources returns a list of Resource objects of the given type * @param type Valid types are: * *
    *
  • pattern
  • *
  • gradient
  • *
  • brush
  • *
  • preset
  • *
  • palette
  • *
  • workspace
  • *
*/ QMap resources(const QString &type) const; /** * @brief return all recent documents registered in the RecentFiles group of the kritarc */ QStringList recentDocuments() const; /** * @brief createDocument creates a new document and image and registers * the document with the Krita application. * * Unless you explicitly call Document::close() the document wil remain * known to the Krita document registry. The document and its image will * only be deleted when Krita exits. * * The document will have one transparent layer. * * To create a new document and show it, do something like: @code from Krita import * def add_document_to_window(): d = Application.createDocument(100, 100, "Test", "RGBA", "U8", "", 120.0) Application.activeWindow().addView(d) add_document_to_window() @endcode * * @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. * @param resolution the resolution in points per inch. * @return the created document. */ Document *createDocument(int width, int height, const QString &name, const QString &colorModel, const QString &colorDepth, const QString &profile, double resolution); /** * @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); /** * @brief openWindow create a new main window. The window is not shown by default. */ Window *openWindow(); /** * @brief addExtension add the given plugin to Krita. There will be a single instance of each Extension in the Krita process. * @param extension the extension to add. */ void addExtension(Extension* extension); /** * return a list with all registered extension objects. */ QList extensions(); /** * @brief addDockWidgetFactory Add the given docker factory to the application. For scripts * loaded on startup, this means that every window will have one of the dockers created by the * factory. * @param factory The factory object. */ void addDockWidgetFactory(DockWidgetFactoryBase* factory ); /** * @brief writeSetting write the given setting under the given name to the kritarc file in * the given settings group. * @param group The group the setting belongs to. If empty, then the setting is written in the * general section * @param name The name of the setting * @param value The value of the setting. Script settings are always written as strings. */ void writeSetting(const QString &group, const QString &name, const QString &value); /** * @brief readSetting read the given setting value from the kritarc file. * @param group The group the setting is part of. If empty, then the setting is read from * the general group. * @param name The name of the setting * @param defaultValue The default value of the setting * @return a string representing the setting. */ QString readSetting(const QString &group, const QString &name, const QString &defaultValue); /** * @brief icon * This allows you to get icons from Krita's internal icons. * @param iconName name of the icon. * @return the icon related to this name. */ QIcon icon(QString &iconName) const; /** * @brief instance retrieve the singleton instance of the Application object. */ static Krita* instance(); // Internal only: for use with mikro.py static QObject *fromVariant(const QVariant& v); private Q_SLOTS: void mainWindowAdded(KisMainWindow *window); private: struct Private; Private *const d; static Krita* s_instance; }; Q_DECLARE_METATYPE(Notifier*); #endif // LIBKIS_KRITA_H diff --git a/libs/libkis/Window.cpp b/libs/libkis/Window.cpp index 59d273e1b1..b95ae35b10 100644 --- a/libs/libkis/Window.cpp +++ b/libs/libkis/Window.cpp @@ -1,151 +1,153 @@ /* * 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 "Window.h" #include #include +#include +#include #include #include #include #include #include #include #include -#include + struct Window::Private { Private() {} QPointer window; }; Window::Window(KisMainWindow *window, QObject *parent) : QObject(parent) , d(new Private) { d->window = window; connect(window, SIGNAL(destroyed(QObject*)), SIGNAL(windowClosed())); } Window::~Window() { delete d; } bool Window::operator==(const Window &other) const { return (d->window == other.d->window); } bool Window::operator!=(const Window &other) const { return !(operator==(other)); } QMainWindow *Window::qwindow() const { return d->window; } QList Window::views() const { QList ret; if (d->window) { foreach(QPointer view, KisPart::instance()->views()) { if (view->mainWindow() == d->window) { ret << new View(view); } } } return ret; } View *Window::addView(Document *document) { if (d->window) { KisView *view = d->window->newView(document->document()); return new View(view); } return 0; } void Window::showView(View *view) { if (views().contains(view)) { KisView *v = view->view(); d->window->showView(v); } } View *Window::activeView() const { if (d->window) { return new View(d->window->activeView()); } return 0; } void Window::activate() { if (d->window) { d->window->activateWindow(); } } void Window::close() { if (d->window) { KisPart::instance()->removeMainWindow(d->window); d->window->close(); } } -Action *Window::createAction(const QString &id, const QString &text, const QString &menuLocation) +QAction *Window::createAction(const QString &id, const QString &text, const QString &menuLocation) { KisAction *action = d->window->viewManager()->actionManager()->createAction(id); action->setText(text); action->setObjectName(id); if (!menuLocation.isEmpty()) { QAction *found = 0; QList candidates = d->window->menuBar()->actions(); Q_FOREACH(const QString &name, menuLocation.split("/")) { Q_FOREACH(QAction *candidate, candidates) { if (candidate->objectName() == name) { found = candidate; candidates = candidate->menu()->actions(); break; } } if (candidates.isEmpty()) { break; } } if (found && found->menu()) { found->menu()->addAction(action); } } - return new Action(action->objectName(), action); + return action; } diff --git a/libs/libkis/Window.h b/libs/libkis/Window.h index 53c5f13942..b0b0bebf58 100644 --- a/libs/libkis/Window.h +++ b/libs/libkis/Window.h @@ -1,112 +1,110 @@ /* * 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_WINDOW_H #define LIBKIS_WINDOW_H #include #include #include #include "kritalibkis_export.h" #include "libkis.h" #include -class Action; - /** * Window represents one Krita mainwindow. A window can have any number * of views open on any number of documents. */ class KRITALIBKIS_EXPORT Window : public QObject { Q_OBJECT public: explicit Window(KisMainWindow *window, QObject *parent = 0); ~Window() override; bool operator==(const Window &other) const; bool operator!=(const Window &other) const; public Q_SLOTS: /** * Return a handle to the QMainWindow widget. This is useful * to e.g. parent dialog boxes and message box. */ QMainWindow *qwindow() const; /** * @return a list of open views in this window */ QList views() const; /** * Open a new view on the given document in this window */ View *addView(Document *document); /** * Make the given view active in this window. If the view * does not belong to this window, nothing happens. */ void showView(View *view); /** * @return the currently active view or 0 if no view is active */ View *activeView() const; /** * @brief activate activates this Window. */ void activate(); /** * @brief close the active window and all its Views. If there * are no Views left for a given Document, that Document will * also be closed. */ void close(); /** - * @brief createAction creates an Action object and adds it to the action + * @brief createAction creates a QAction object and adds it to the action * manager for this Window. * @param id The unique id for the action. This will be used to * propertize the action if any .action file is present * @param text The user-visible text of the action. If empty, the text from the * .action file is used. * @param menu a /-separated string that describes which menu the action should * be places in. Default is "tools/scripts" * @return the new action. */ - Action *createAction(const QString &id, const QString &text = QString(), const QString &menuLocation = QString("tools/scripts")); + QAction *createAction(const QString &id, const QString &text = QString(), const QString &menuLocation = QString("tools/scripts")); Q_SIGNALS: /// Emitted when the window is closed. void windowClosed(); private: struct Private; Private *const d; }; #endif // LIBKIS_WINDOW_H diff --git a/libs/libkis/libkis.h b/libs/libkis/libkis.h index 62c67a6bd2..fba3852456 100644 --- a/libs/libkis/libkis.h +++ b/libs/libkis/libkis.h @@ -1,37 +1,36 @@ #include #include #include #include #include #include -class Action; class Canvas; class Channel; class ColorDepth; class ColorManager; class ColorModel; class ColorProfile; class DockWidget; class DockWidgetFactoryBase; class Document; class Filter; class InfoObject; class Krita; class Node; class Notifier; class Resource; class Selection; class View; class Extension; class Window; class Shape; class GroupShape; class PaintLayer; class CloneLayer; class GroupLayer; class FilterLayer; class FillLayer; class FileLayer; class VectorLayer; diff --git a/plugins/extensions/pykrita/sip/krita/Action.sip b/plugins/extensions/pykrita/sip/krita/Action.sip deleted file mode 100644 index f5f1e1c4bb..0000000000 --- a/plugins/extensions/pykrita/sip/krita/Action.sip +++ /dev/null @@ -1,37 +0,0 @@ -class Action : QObject -{ -%TypeHeaderCode -#include "Action.h" -%End - -public: - explicit Action(QObject *parent /TransferThis/ = 0); - Action(const QString &name, QAction* action, QObject *parent /TransferThis/ = 0); - virtual ~Action(); - bool operator==(const Action &other) const; - bool operator!=(const Action &other) const; -public Q_SLOTS: - QString text() const; - void setText(QString text); - QString name() const; - void setName(QString value); - bool isCheckable() const; - void setCheckable(bool value); - bool isChecked() const; - void setChecked(bool value); - QString shortcut() const; - void setShortcut(QString value); - bool isVisible() const; - void setVisible(bool value); - bool isEnabled() const; - void setEnabled(bool value); - void setToolTip(QString tooltip); - QString tooltip() const; - void trigger(); - -Q_SIGNALS: - void triggered(bool); -private: - private: - Action(const Action &); // Generated -}; diff --git a/plugins/extensions/pykrita/sip/krita/Krita.sip b/plugins/extensions/pykrita/sip/krita/Krita.sip index 1d77a00b20..9132ce4eff 100644 --- a/plugins/extensions/pykrita/sip/krita/Krita.sip +++ b/plugins/extensions/pykrita/sip/krita/Krita.sip @@ -1,63 +1,63 @@ class Krita : QObject { %TypeHeaderCode #include "Krita.h" %End public: Krita(QObject* parent /TransferThis/ = 0); virtual ~Krita(); public Q_SLOTS: 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 actions() const; + QAction *action(const QString & name) const; QList documents() const /Factory/; QStringList filters() const; Filter * filter(const QString &name) const /Factory/; QStringList colorModels() const; QStringList colorDepths(const QString &colorModel) const; QStringList filterStrategies() const; QStringList profiles(const QString &colorModel, const QString &ColorDepth) const; bool addProfile(const QString &profilePath); Notifier * notifier() const; QString version() const; QList views() const /Factory/; Window * activeWindow() const /Factory/; QList windows() const /Factory/; QMap resources(const QString &type) const /Factory/; QStringList recentDocuments() const; Document * createDocument(int width, int height, const QString &name, const QString &colorModel, const QString &colorDepth, const QString &profile, double resolution) /Factory/; QList extensions() /Factory/; Document * openDocument(const QString &filename) /Factory/; Window * openWindow(); QIcon icon(QString &iconName) const; void addExtension(Extension* _extension /GetWrapper/); %MethodCode Py_BEGIN_ALLOW_THREADS sipCpp->addExtension(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 void writeSetting(const QString &group, const QString &name, const QString &value); QString readSetting(const QString &group, const QString &name, const QString &defaultValue); static Krita * instance(); static QObject * fromVariant(const QVariant & v); private: Krita(const Krita &); // Generated }; diff --git a/plugins/extensions/pykrita/sip/krita/kritamod.sip b/plugins/extensions/pykrita/sip/krita/kritamod.sip index 1968925406..0fcd6abe0a 100644 --- a/plugins/extensions/pykrita/sip/krita/kritamod.sip +++ b/plugins/extensions/pykrita/sip/krita/kritamod.sip @@ -1,50 +1,49 @@ %Module PyKrita.krita %ModuleHeaderCode #pragma GCC visibility push(default) %End %Import QtCore/QtCoremod.sip %Import QtGui/QtGuimod.sip %Import QtXml/QtXmlmod.sip %Import QtWidgets/QtWidgetsmod.sip %Include Conversions.sip %Include Shape.sip %Include GroupShape.sip -%Include Action.sip %Include Canvas.sip %Include Channel.sip %Include DockWidgetFactoryBase.sip %Include DockWidget.sip %Include Document.sip %Include Filter.sip %Include InfoObject.sip %Include Extension.sip %Include View.sip %Include Window.sip %Include Krita.sip %Include Node.sip %Include GroupLayer.sip %Include CloneLayer.sip %Include FilterLayer.sip %Include FileLayer.sip %Include FillLayer.sip %Include VectorLayer.sip %Include FilterMask.sip %Include SelectionMask.sip %Include Notifier.sip %Include Resource.sip %Include Selection.sip %Include Extension.sip %Include PresetChooser.sip %Include Palette.sip %Include PaletteView.sip %Include ManagedColor.sip %Include KisCubicCurve.sip