diff --git a/libs/libkis/BrushPreset.h b/libs/libkis/BrushPreset.h new file mode 100644 --- /dev/null +++ b/libs/libkis/BrushPreset.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2018 Wolthera van Hövell tot Westerflier + * + * 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_BRUSHPRESET_H +#define LIBKIS_BRUSHPRESET_H + +#include +#include "kritalibkis_export.h" +#include "libkis.h" +#include "Resource.h" +#include "kis_paintop_preset.h" + +/** + * @brief The BrushPreset class + * This class describes brush presets. + * Usage: + * @code +import sys +from krita import * + +for item in Application.allBrushPresets(): + print (item.name()+item.brushEngineName()) + +#Getting the data of a single preset: +preset = Application.allBrushPresets()[0] +for key in preset.settings().properties().keys(): + print("---->"+key+" - "+str(preset.settings().property(key))) + * @endcode + */ + +class KRITALIBKIS_EXPORT BrushPreset : public Resource +{ +public: + explicit BrushPreset(KoResource *resource, QObject *parent = 0); + ~BrushPreset() override; + + /** + * @brief brushEngineName + * @return the name of the brush engine + */ + QString brushEngineName() const; + + /** + * @brief settings + * get the settings for this brush preset + * @return the settings in the form of a InfoObject + */ + InfoObject *settings() const; + + /** + * @brief setSettings + * set the brush settings from an InfoObject. + * @param settings the InfoObject containing the settings. + * @return whether it was succesful. + */ + bool setSettings(InfoObject *settings); + + /** + * @brief load + * @return reload the preset. + */ + bool load(); + + /** + * @brief isDirty + * @return whether the preset has been modified or not. + */ + bool isDirty(); +private: + struct Private; + Private *const d; + + KisPaintOpPreset *preset(); + +}; + +#endif // LIBKIS_BRUSHPRESET_H diff --git a/libs/libkis/BrushPreset.cpp b/libs/libkis/BrushPreset.cpp new file mode 100644 --- /dev/null +++ b/libs/libkis/BrushPreset.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2018 Wolthera van Hövell tot Westerflier + * + * 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 "BrushPreset.h" +#include +#include +#include "InfoObject.h" + +struct BrushPreset::Private { + KisPaintOpPreset *BrushPreset {0}; +}; + +BrushPreset::BrushPreset(KoResource *resource, QObject *parent) + : Resource(resource, parent) + , d(new Private()) +{ + d->BrushPreset = dynamic_cast(resource); +} + +BrushPreset::~BrushPreset() +{ + delete d; +} + +QString BrushPreset::brushEngineName() const +{ + return d->BrushPreset->paintOp().id(); +} + +bool BrushPreset::setSettings(InfoObject *settings) +{ + KisPaintOpSettingsSP paintopset = KisPaintOpSettingsSP(dynamic_cast(settings->configuration().data())); + if (paintopset) { + d->BrushPreset->setSettings(paintopset); + return true; + } + return false; +} + +bool BrushPreset::load() +{ + return d->BrushPreset->load(); +} + +bool BrushPreset::isDirty() +{ + return d->BrushPreset->isPresetDirty(); +} + +InfoObject *BrushPreset::settings() const +{ + return new InfoObject(d->BrushPreset->settings()); +} + +KisPaintOpPreset *BrushPreset::preset() +{ + return d->BrushPreset; +} + diff --git a/libs/libkis/BrushTip.h b/libs/libkis/BrushTip.h new file mode 100644 --- /dev/null +++ b/libs/libkis/BrushTip.h @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2018 Wolthera van Hövell tot Westerflier + * + * 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_BRUSHTIP_H +#define LIBKIS_BRUSHTIP_H + +#include +#include "kritalibkis_export.h" +#include "libkis.h" +#include "Resource.h" +#include "kis_brush.h" + +/** + * @brief The BrushTip class + * This represents a brush tip resource in Krita, typically a predefined brush. + * usage: + * @code +import sys +from krita import * + +for item in Application.allBrushTips(): + print (item.name()+" "+str(item.spacing())) + * @endcode + */ +class KRITALIBKIS_EXPORT BrushTip : public Resource +{ +public: + explicit BrushTip(KoResource *resource, QObject *parent = 0); + ~BrushTip() override; + + /** + * @brief brushTipImage + * @return the image of the brush tip as QImage. + */ + QImage brushTipImage() const; + + /** + * @brief spacing + * @return spacing between brushes + */ + double spacing() const; + /** + * @brief setSpacing + * @param spacing between brushes + */ + void setSpacing(double spacing); + /** + * @brief autoSpacingActive + * @return whether auto spacing is active. + */ + bool autoSpacingActive() const; + /** + * @brief autoSpacigCoeff + * @return the spacing for autospacing. + */ + qreal autoSpacigCoeff() const; + /** + * @brief setAutoSpacing + * @param active + * @param coefficient the spacing autospacing should use. + */ + void setAutoSpacing(bool active, qreal coefficient); + + /** + * @brief width + * @return width of the tip. + */ + qint32 width() const; + /** + * @brief height + * @return height of the tip. + */ + qint32 height() const; + /** + * @brief threadingAllowed + * @return whether this brush tip can make use of multithreading. + */ + bool threadingAllowed() const; + + /** + * @brief hasColor + * @return whether the brush tip has color. + */ + bool hasColor() const; + + /** + * @brief scale + * @return scale of the tip. + */ + qreal scale() const; + /** + * @brief setScale + * @param scale the new scale. + */ + void setScale(qreal scale); + /** + * @brief angle + * @return angle of the tip. + */ + qreal angle() const; + /** + * @brief setAngle + * @param angle the new angle of the tip. + */ + void setAngle(qreal angle); + +private: + struct Private; + Private *const d; + + KisBrush *tip(); + +}; + +#endif // LIBKIS_BRUSHTIP_H diff --git a/libs/libkis/BrushTip.cpp b/libs/libkis/BrushTip.cpp new file mode 100644 --- /dev/null +++ b/libs/libkis/BrushTip.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2018 Wolthera van Hövell tot Westerflier + * + * 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 "BrushTip.h" +#include "kis_brush.h" + +struct BrushTip::Private { + KisBrush *brushtip {0}; +}; + +BrushTip::BrushTip(KoResource *resource, QObject *parent) + : Resource(resource, parent) + , d(new Private()) +{ + d->brushtip = dynamic_cast(resource); +} + +BrushTip::~BrushTip() +{ + delete d; +} + +QImage BrushTip::brushTipImage() const +{ + return d->brushtip->image(); +} + +double BrushTip::spacing() const +{ + return d->brushtip->spacing(); +} + +void BrushTip::setSpacing(double spacing) +{ + d->brushtip->setSpacing(spacing); +} + +bool BrushTip::autoSpacingActive() const +{ + return d->brushtip->autoSpacingActive(); +} + +qreal BrushTip::autoSpacigCoeff() const +{ + return d->brushtip->autoSpacingCoeff(); +} + +void BrushTip::setAutoSpacing(bool active, qreal coefficient) +{ + d->brushtip->setAutoSpacing(active, coefficient); +} + +qint32 BrushTip::width() const +{ + return d->brushtip->width(); +} + +qint32 BrushTip::height() const +{ + return d->brushtip->height(); +} + +bool BrushTip::threadingAllowed() const +{ + return d->brushtip->threadingAllowed(); +} + +bool BrushTip::hasColor() const +{ + return d->brushtip->hasColor(); +} + +qreal BrushTip::scale() const +{ + return d->brushtip->scale(); +} + +void BrushTip::setScale(qreal scale) +{ + d->brushtip->setScale(scale); +} + +qreal BrushTip::angle() const +{ + return d->brushtip->angle(); +} + +void BrushTip::setAngle(qreal angle) +{ + d->brushtip->setAngle(angle); +} + +KisBrush *BrushTip::tip() +{ + return d->brushtip; +} + diff --git a/libs/libkis/CMakeLists.txt b/libs/libkis/CMakeLists.txt --- a/libs/libkis/CMakeLists.txt +++ b/libs/libkis/CMakeLists.txt @@ -30,6 +30,11 @@ Shape.cpp GroupShape.cpp + + BrushPreset.cpp + BrushTip.cpp + Pattern.cpp + Gradient.cpp ) add_library(kritalibkis SHARED ${kritalibkis_LIB_SRCS} ) diff --git a/libs/libkis/Gradient.h b/libs/libkis/Gradient.h new file mode 100644 --- /dev/null +++ b/libs/libkis/Gradient.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2018 Wolthera van Hövell tot Westerflier + * + * 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_GRADIENT_H +#define LIBKIS_GRADIENT_H + +#include +#include "kritalibkis_export.h" +#include "libkis.h" +#include "Resource.h" +#include "KoAbstractGradient.h" +#include "ManagedColor.h" + +/** + * @brief The Gradient class + * Wraps gradient resources. + * + * @code +import sys +from krita import * + +for item in Application.allGradients(): + print (item.name()+" "+item.colorAt(0.5).toQString()) + * @endcode + */ +class KRITALIBKIS_EXPORT Gradient : public Resource +{ +public: + explicit Gradient(KoResource *resource, QObject *parent = 0); + ~Gradient() override; + + /** + * @brief toQGradient + * @return QGradient version of the gradient. + */ + QGradient* toQGradient() const; + + /** + * @brief colorAt + * @param t a value between 0 to 1 that represents the position along the gradient. + * @return a ManagedColor object of the color at position t + */ + ManagedColor* colorAt(qreal t) const; + + /** + * @brief spread + * @return QGradient::PadSpread, QGradient::RepeatSpread or QGradient ReflectSpread + */ + QGradient::Spread spread() const; + /** + * @brief setSpread + * set the spread method. + * @param spreadMethod a QGradient::Spread value. + */ + void setSpread(QGradient::Spread spreadMethod); + + /** + * @brief repeatType + * @return QGradient::LinearGradient, QGradient::LinearGradient or QGradient::ConicalGradient + */ + QGradient::Type repeatType() const; + /** + * @brief setRepeatType + * @param type a QGradient repeat type. + */ + void setRepeatType(QGradient::Type type); + +private: + struct Private; + Private *const d; + + KoAbstractGradient *gradient(); + +}; + +#endif // LIBKIS_GRADIENT_H diff --git a/libs/libkis/Gradient.cpp b/libs/libkis/Gradient.cpp new file mode 100644 --- /dev/null +++ b/libs/libkis/Gradient.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2018 Wolthera van Hövell tot Westerflier + * + * 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 "Gradient.h" +#include +#include + +struct Gradient::Private { + KoAbstractGradient *gradient {0}; +}; + +Gradient::Gradient(KoResource *resource, QObject *parent) + : Resource(resource, parent) + , d(new Private()) +{ + d->gradient = dynamic_cast(resource); +} + +Gradient::~Gradient() +{ + delete d; +} + +QGradient* Gradient::toQGradient() const +{ + return d->gradient->toQGradient(); +} + +ManagedColor *Gradient::colorAt(qreal t) const +{ + KoColor c; + d->gradient->colorAt(c, t); + return new ManagedColor(c); +} + +QGradient::Spread Gradient::spread() const +{ + return d->gradient->spread(); +} + +void Gradient::setSpread(QGradient::Spread spreadMethod) +{ + d->gradient->setSpread(spreadMethod); +} + +QGradient::Type Gradient::repeatType() const +{ + return d->gradient->type(); +} + +void Gradient::setRepeatType(QGradient::Type type) +{ + d->gradient->setType(type); +} + +KoAbstractGradient *Gradient::gradient() +{ + return d->gradient; +} diff --git a/libs/libkis/InfoObject.h b/libs/libkis/InfoObject.h --- a/libs/libkis/InfoObject.h +++ b/libs/libkis/InfoObject.h @@ -68,6 +68,7 @@ friend class Filter; friend class Document; + friend class BrushPreset; /** * @brief configuration gives access to the internal configuration object. Must * be used used internally in libkis diff --git a/libs/libkis/Krita.h b/libs/libkis/Krita.h --- a/libs/libkis/Krita.h +++ b/libs/libkis/Krita.h @@ -31,6 +31,11 @@ #include "Notifier.h" class QAction; +class Palette; +class BrushPreset; +class BrushTip; +class Pattern; +class Gradient; /** * Krita is a singleton class that offers the root access to the Krita object hierarchy. @@ -206,6 +211,36 @@ */ QMap resources(const QString &type) const; + /** + * @brief allPalettes + * @return all palette resources as a list of Palettes. + */ + QList allPalettes() const; + + /** + * @brief allBrushPresets + * @return all brush preset as a list of BrushPresets + */ + QList allBrushPresets() const; + + /** + * @brief allBrushTips + * @return all predefined Brush Tips as a list of BrushTips + */ + QList allBrushTips() const; + + /** + * @brief allPatterns + * @return all patterns as a list of Patterns + */ + QList allPatterns() const; + + /** + * @brief allGradients + * @return all gradients as a list of Gradients + */ + QList allGradients() const; + /** * @brief return all recent documents registered in the RecentFiles group of the kritarc diff --git a/libs/libkis/Krita.cpp b/libs/libkis/Krita.cpp --- a/libs/libkis/Krita.cpp +++ b/libs/libkis/Krita.cpp @@ -62,6 +62,11 @@ #include "Filter.h" #include "InfoObject.h" #include "Resource.h" +#include "Palette.h" +#include "BrushPreset.h" +#include "BrushTip.h" +#include "Gradient.h" +#include "Pattern.h" Krita* Krita::s_instance = 0; @@ -300,6 +305,56 @@ return resources; } +QList Krita::allPalettes() const +{ + QList palettes; + KoResourceServer* server = KoResourceServerProvider::instance()->paletteServer(); + Q_FOREACH (KoResource *res, server->resources()) { + palettes.append(new Palette(res)); + } + return palettes; +} + +QList Krita::allBrushPresets() const +{ + QList presets; + KisPaintOpPresetResourceServer* server = KisResourceServerProvider::instance()->paintOpPresetServer(); + Q_FOREACH (KisPaintOpPresetSP res, server->resources()) { + presets.append(new BrushPreset(res.data())); + } + return presets; +} + +QList Krita::allBrushTips() const +{ + QList tips; + KisBrushResourceServer* server = KisBrushServer::instance()->brushServer(); + Q_FOREACH (KisBrushSP res, server->resources()) { + tips.append(new BrushTip(res.data())); + } + return tips; +} + +QList Krita::allPatterns() const +{ + QList patterns; + KoResourceServer* server = KoResourceServerProvider::instance()->patternServer(); + Q_FOREACH (KoResource *res, server->resources()) { + patterns.append(new Pattern(res)); + } + return patterns; +} + +QList Krita::allGradients() const +{ + QList gradients; + KoResourceServer* server = KoResourceServerProvider::instance()->gradientServer(); + Q_FOREACH (KoResource *res, server->resources()) { + gradients.append(new Gradient(res)); + } + return gradients; +} + QStringList Krita::recentDocuments() const { KConfigGroup grp = KSharedConfig::openConfig()->group(QString("RecentFiles")); diff --git a/libs/libkis/ManagedColor.h b/libs/libkis/ManagedColor.h --- a/libs/libkis/ManagedColor.h +++ b/libs/libkis/ManagedColor.h @@ -200,6 +200,7 @@ friend class View; friend class PaletteView; + friend class Gradient; KoColor color() const; struct Private; diff --git a/libs/libkis/Notifier.h b/libs/libkis/Notifier.h --- a/libs/libkis/Notifier.h +++ b/libs/libkis/Notifier.h @@ -27,6 +27,14 @@ #include #include +#include +#include "Palette.h" +#include "Gradient.h" +#include "Resource.h" +#include "Pattern.h" +#include "BrushPreset.h" +#include "BrushTip.h" + /** * The Notifier can be used to be informed of state changes in the Krita application. */ @@ -102,6 +110,34 @@ */ void configurationChanged(); + /** + * @brief resourceChanged + * @param changed + */ + void resourceChanged(Resource* changed); + void resourceAdded(Resource *added); + void resourceRemoved(Resource *removed); + + void paletteChanged(Palette* changed); + void paletteAdded(Palette *added); + void paletteRemoved(Palette *removed); + + void gradientChanged(Gradient* changed); + void gradientAdded(Gradient *added); + void gradientRemoved(Gradient *removed); + + void patternChanged(Pattern* changed); + void patternAdded(Pattern *added); + void patternRemoved(Pattern *removed); + + void brushPresetChanged(BrushPreset* changed); + void brushPresetAdded(BrushPreset *added); + void brushPresetRemoved(BrushPreset *removed); + + void brushTipChanged(BrushTip* changed); + void brushTipAdded(BrushTip *added); + void brushTipRemoved(BrushTip *removed); + private Q_SLOTS: void imageCreated(KisDocument *document); @@ -111,6 +147,12 @@ void windowCreated(KisMainWindow *window); + void resourceChanged(KoResource *resource); + + void resourceAdded(KoResource *resource); + + void resourceRemoved(KoResource *resource); + private: struct Private; diff --git a/libs/libkis/Notifier.cpp b/libs/libkis/Notifier.cpp --- a/libs/libkis/Notifier.cpp +++ b/libs/libkis/Notifier.cpp @@ -19,6 +19,10 @@ #include #include #include +#include +#include +#include +#include #include "View.h" #include "Window.h" #include "Document.h" @@ -45,6 +49,27 @@ connect(KisConfigNotifier::instance(), SIGNAL(configChanged()), SIGNAL(configurationChanged())); + KoResourceServer* paletteServer = KoResourceServerProvider::instance()->paletteServer(false); + QSharedPointer paletteAdapter = QSharedPointer(new KoResourceServerAdapter(paletteServer)); + paletteAdapter->connectToResourceServer(); + connect(paletteAdapter.data(), SIGNAL(resourceChanged(KoResource*)), SLOT(resourceChanged(KoResource*))); + connect(paletteAdapter.data(), SIGNAL(resourceAdded(KoResource*)), SLOT(resourceAdded(KoResource*))); + connect(paletteAdapter.data(), SIGNAL(removingResource(KoResource*)), SLOT(resourceRemoved(KoResource*))); + + KoResourceServer* gradientServer = KoResourceServerProvider::instance()->gradientServer(false); + QSharedPointer gradientAdapter = QSharedPointer(new KoResourceServerAdapter(gradientServer)); + gradientAdapter->connectToResourceServer(); + connect(gradientAdapter.data(), SIGNAL(resourceChanged(KoResource*)), SLOT(resourceChanged(KoResource*))); + connect(gradientAdapter.data(), SIGNAL(resourceAdded(KoResource*)), SLOT(resourceAdded(KoResource*))); + connect(gradientAdapter.data(), SIGNAL(removingResource(KoResource*)), SLOT(resourceRemoved(KoResource*))); + + KoResourceServer* patternServer = KoResourceServerProvider::instance()->patternServer(false); + QSharedPointer patternAdapter = QSharedPointer(new KoResourceServerAdapter(patternServer)); + patternAdapter->connectToResourceServer(); + connect(patternAdapter.data(), SIGNAL(resourceChanged(KoResource*)), SLOT(resourceChanged(KoResource*))); + connect(patternAdapter.data(), SIGNAL(resourceAdded(KoResource*)), SLOT(resourceAdded(KoResource*))); + connect(patternAdapter.data(), SIGNAL(removingResource(KoResource*)), SLOT(resourceRemoved(KoResource*))); + } @@ -88,3 +113,54 @@ emit windowCreated(w); } +void Notifier::resourceChanged(KoResource *resource) +{ + if (dynamic_cast(resource)) { + emit paletteChanged(new Palette(resource)); + } else if (dynamic_cast(resource)) { + emit gradientChanged(new Gradient(resource)); + } else if(dynamic_cast(resource)){ + emit patternChanged(new Pattern(resource)); + } else if(dynamic_cast(resource)){ + emit brushPresetChanged(new BrushPreset(resource)); + } else if(dynamic_cast(resource)){ + emit brushTipChanged(new BrushTip(resource)); + } else { + emit resourceChanged(new Resource(resource)); + } +} + +void Notifier::resourceAdded(KoResource *resource) +{ + if (dynamic_cast(resource)) { + emit paletteAdded(new Palette(resource)); + } else if (dynamic_cast(resource)) { + emit gradientAdded(new Gradient(resource)); + } else if(dynamic_cast(resource)){ + emit patternAdded(new Pattern(resource)); + } else if(dynamic_cast(resource)){ + emit brushPresetAdded(new BrushPreset(resource)); + } else if(dynamic_cast(resource)){ + emit brushTipAdded(new BrushTip(resource)); + } else { + emit resourceAdded(new Resource(resource)); + } +} + +void Notifier::resourceRemoved(KoResource *resource) +{ + if (dynamic_cast(resource)) { + emit paletteRemoved(new Palette(resource)); + } else if (dynamic_cast(resource)) { + emit gradientRemoved(new Gradient(resource)); + } else if(dynamic_cast(resource)){ + emit patternRemoved(new Pattern(resource)); + } else if(dynamic_cast(resource)){ + emit brushPresetRemoved(new BrushPreset(resource)); + } else if(dynamic_cast(resource)){ + emit brushTipRemoved(new BrushTip(resource)); + } else { + emit resourceRemoved(new Resource(resource)); + } +} + diff --git a/libs/libkis/Palette.h b/libs/libkis/Palette.h --- a/libs/libkis/Palette.h +++ b/libs/libkis/Palette.h @@ -51,15 +51,15 @@ * @endcode */ -class KRITALIBKIS_EXPORT Palette : public QObject +class KRITALIBKIS_EXPORT Palette : public Resource { public: - Palette(Resource *resource); + explicit Palette(KoResource *resource, QObject *parent = 0); ~Palette() override; /** * @brief numberOfEntries - * @return + * @return the number of entries. */ int numberOfEntries() const; @@ -181,13 +181,6 @@ */ bool moveGroup(const QString &groupName, const QString &groupNameInsertBefore = QString()); - /** - * @brief save - * save the palette - * @return whether it was successful. - */ - bool save(); - private: friend class PaletteView; struct Private; diff --git a/libs/libkis/Palette.cpp b/libs/libkis/Palette.cpp --- a/libs/libkis/Palette.cpp +++ b/libs/libkis/Palette.cpp @@ -24,8 +24,11 @@ KoColorSet *palette {0}; }; -Palette::Palette(Resource *resource): d(new Private()) { - d->palette = dynamic_cast(resource->resource()); +Palette::Palette(KoResource *resource, QObject *parent): + Resource(resource, parent), + d(new Private()) +{ + d->palette = dynamic_cast(resource); } Palette::~Palette() @@ -143,15 +146,6 @@ return d->palette->moveGroup(groupName, groupNameInsertBefore); } -bool Palette::save() -{ - if (d->palette->filename().size()>0) { - return d->palette->save(); - } - //if there's no filename the palette proly doesn't even exist... - return false; -} - KoColorSet *Palette::colorSet() { return d->palette; diff --git a/libs/libkis/Pattern.h b/libs/libkis/Pattern.h new file mode 100644 --- /dev/null +++ b/libs/libkis/Pattern.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2018 Wolthera van Hövell tot Westerflier + * + * 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_PATTERN_H +#define LIBKIS_PATTERN_H + +#include +#include "kritalibkis_export.h" +#include "libkis.h" +#include "Resource.h" +#include "KoPattern.h" + +/** + * @brief The Pattern class + * wraps Krita patterns. + * + * @code +import sys +from krita import * + +for item in Application.allPatterns(): + print (item.name()+" "+str(item.width())+"x"+str(item.height())) + * @endcode + */ + +class KRITALIBKIS_EXPORT Pattern : public Resource +{ +public: + explicit Pattern(KoResource *resource, QObject *parent = 0); + ~Pattern() override; + + /** + * @brief width + * @return with of the pattern + */ + qint32 width() const; + /** + * @brief height + * @return height of the pattern + */ + qint32 height() const; + + /** + * @brief image + * @return image that patterns. + */ + QImage image() const; + +private: + struct Private; + Private *const d; + + KoPattern *pat(); + +}; + +#endif // LIBKIS_PATTERN_H diff --git a/libs/libkis/Pattern.cpp b/libs/libkis/Pattern.cpp new file mode 100644 --- /dev/null +++ b/libs/libkis/Pattern.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2018 Wolthera van Hövell tot Westerflier + * + * 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 "Pattern.h" +#include "KoPattern.h" + +struct Pattern::Private { + KoPattern *pattern {0}; +}; + +Pattern::Pattern(KoResource *resource, QObject *parent) + : Resource(resource, parent) + , d(new Private()) +{ + d->pattern = dynamic_cast(resource); +} + +Pattern::~Pattern() +{ + delete d; +} + +qint32 Pattern::width() const +{ + return d->pattern->width(); +} + +qint32 Pattern::height() const +{ + return d->pattern->height(); +} + +QImage Pattern::image() const +{ + return d->pattern->image(); +} + +KoPattern *Pattern::pat() +{ + return d->pattern; +} + diff --git a/libs/libkis/Resource.h b/libs/libkis/Resource.h --- a/libs/libkis/Resource.h +++ b/libs/libkis/Resource.h @@ -106,6 +106,14 @@ */ bool setData(QByteArray data); + /** + * @brief save + * @param uniqueName whether or not to use a unique name. + * @return whether saving was possible to do. Can fail because the resource + * isn't a resource or has no filename. + */ + bool save(bool uniqueName=false); + private: friend class PresetChooser; diff --git a/libs/libkis/Resource.cpp b/libs/libkis/Resource.cpp --- a/libs/libkis/Resource.cpp +++ b/libs/libkis/Resource.cpp @@ -17,6 +17,9 @@ */ #include "Resource.h" #include +#include +#include +#include #include #include @@ -118,13 +121,35 @@ return d->resource->loadFromDevice(&buf); } +bool Resource::save(bool uniqueName) +{ + if (uniqueName) { + if (dynamic_cast(d->resource)) { + return KoResourceServerProvider::instance()->patternServer()->addResource(dynamic_cast(d->resource)); + } else if (dynamic_cast(d->resource)) { + return KoResourceServerProvider::instance()->gradientServer()->addResource(dynamic_cast(d->resource)); + } else if (dynamic_cast(d->resource)) { + return KisBrushServer::instance()->brushServer()->addResource(dynamic_cast(d->resource)); + } else if (dynamic_cast(d->resource)) { + return KisResourceServerProvider::instance()->paintOpPresetServer()->addResource(dynamic_cast(d->resource)); + } else if (dynamic_cast(d->resource)) { + return KoResourceServerProvider::instance()->paletteServer()->addResource(dynamic_cast(d->resource)); + } else if (dynamic_cast(d->resource)) { + return KisResourceServerProvider::instance()->workspaceServer()->addResource(dynamic_cast(d->resource)); + } else if (dynamic_cast(d->resource)) { + return KoResourceServerProvider::instance()->svgSymbolCollectionServer()->addResource(dynamic_cast(d->resource)); + } else { + return false; + } + } + if (d->resource->filename().size()>0) { + return d->resource->save(); + } + //If there's no filename, return false. + return false; +} + KoResource *Resource::resource() const { return d->resource; } - - - - - - diff --git a/plugins/extensions/pykrita/plugin/plugins/palette_docker/palette_docker.py b/plugins/extensions/pykrita/plugin/plugins/palette_docker/palette_docker.py --- a/plugins/extensions/pykrita/plugin/plugins/palette_docker/palette_docker.py +++ b/plugins/extensions/pykrita/plugin/plugins/palette_docker/palette_docker.py @@ -27,12 +27,16 @@ # Make a combobox and add palettes self.cmb_palettes = QComboBox() - allPalettes = Application.resources("palette") - for palette_name in allPalettes: - self.cmb_palettes.addItem(palette_name) - self.cmb_palettes.model().sort(0) + self.cmb_palettes.setInsertPolicy(QComboBox.InsertAlphabetically) + allPalettes = Application.allPalettes(); + for palette in allPalettes: + self.cmb_palettes.addItem(palette.name()) - self.currentPalette = Palette(allPalettes[list(allPalettes.keys())[0]]) + Application.notifier().paletteAdded.connect(self.slot_paletteResourceChanged) + Application.notifier().paletteRemoved.connect(self.slot_paletteResourceChanged) + Application.notifier().paletteChanged.connect(self.slot_paletteResourceChanged) + + self.currentPalette = allPalettes[0] self.cmb_palettes.currentTextChanged.connect(self.slot_paletteChanged) layout.addWidget(self.cmb_palettes) # add combobox to the layout self.paletteView = PaletteView() @@ -93,13 +97,31 @@ self.setWidget(widget) # add widget to the docker def slot_paletteChanged(self, name): - self.currentPalette = Palette(Application.resources("palette")[name]) + newPalette = Application.allPalettes()[0] + for palette in Application.allPalettes(): + if palette.name()==name: + newPalette = palette + self.currentPalette = newPalette self.paletteView.setPalette(self.currentPalette) self.slot_fill_combobox() + @pyqtSlot(Palette) + def slot_paletteResourceChanged(self, palette): + entry = self.cmb_palettes.currentEntryText(); + self.cmb_palettes.clear(); + for palette in Application.allPalettes(): + self.cmb_palettes.addItem(palette.name()) + if (palette == self.currentPalette): + if self.cmb_palettes.findText(palette.name())>0: + self.slot_paletteChanged(Application.allPalettes()[0]) + else: + self.slot_paletteChanged(palette.name()) + self.cmb_palettes.setCurrentEntryText(palette.name()) + else: + self.cmb_palettes.setCurrentEntryText(entry) + @pyqtSlot('KoColorSetEntry') def slot_swatchSelected(self, entry): - print("entry " + entry.name) if (self.canvas()) is not None: if (self.canvas().view()) is not None: name = entry.name @@ -204,15 +226,13 @@ # buttons.rejected.connect(dialog.reject()) if dialog.exec_() == QDialog.Accepted: - Resource = Application.resources("palette")[self.cmb_palettes.currentText()] - Resource.setName(paletteName.text()) - self.currentPalette = Palette(Resource) + self.currentPalette.setName(paletteName.text()) print(paletteColumns.value()) self.currentPalette.setColumnCount(paletteColumns.value()) self.paletteView.setPalette(self.currentPalette) self.slot_fill_combobox() self.currentPalette.setComment(paletteComment.toPlainText()) - self.currentPalette.save() + self.currentPalette.save(False) def slot_export_to_gimp_palette(self): palette_exporter_gimppalette.gimpPaletteExporter(self.cmb_palettes.currentText()) diff --git a/plugins/extensions/pykrita/plugin/plugins/palette_docker/palette_exporter_gimppalette.py b/plugins/extensions/pykrita/plugin/plugins/palette_docker/palette_exporter_gimppalette.py --- a/plugins/extensions/pykrita/plugin/plugins/palette_docker/palette_exporter_gimppalette.py +++ b/plugins/extensions/pykrita/plugin/plugins/palette_docker/palette_exporter_gimppalette.py @@ -16,9 +16,12 @@ def __init__(self, name): # We want people to select a palette and a location to save to... self.fileName = QFileDialog.getExistingDirectory() - allPalettes = Application.resources("palette") + newPalette = Application.allPalettes()[0] + for palette in Application.allPalettes(): + if palette.name()==name: + newPalette = palette self.paletteName = name - self.currentPalette = Palette(allPalettes[self.paletteName]) + self.currentPalette = newPalette self.export() done = QMessageBox() done.setWindowTitle("Export successful") diff --git a/plugins/extensions/pykrita/plugin/plugins/palette_docker/palette_exporter_inkscapeSVG.py b/plugins/extensions/pykrita/plugin/plugins/palette_docker/palette_exporter_inkscapeSVG.py --- a/plugins/extensions/pykrita/plugin/plugins/palette_docker/palette_exporter_inkscapeSVG.py +++ b/plugins/extensions/pykrita/plugin/plugins/palette_docker/palette_exporter_inkscapeSVG.py @@ -18,9 +18,12 @@ def __init__(self, name): # We want people to select a palette and a location to save to... self.fileName = QFileDialog.getExistingDirectory() - allPalettes = Application.resources("palette") + newPalette = Application.allPalettes()[0] + for palette in Application.allPalettes(): + if palette.name()==name: + newPalette = palette self.paletteName = name - self.currentPalette = Palette(allPalettes[self.paletteName]) + self.currentPalette = newPalette self.export() done = QMessageBox() done.setWindowTitle("Export successful") diff --git a/plugins/extensions/pykrita/sip/krita/BrushPreset.sip b/plugins/extensions/pykrita/sip/krita/BrushPreset.sip new file mode 100644 --- /dev/null +++ b/plugins/extensions/pykrita/sip/krita/BrushPreset.sip @@ -0,0 +1,15 @@ +class BrushPreset : Resource +{ +%TypeHeaderCode +#include "BrushPreset.h" +%End + BrushPreset(const Resource & __0); +public Q_SLOTS: + QString brushEngineName() const; + InfoObject *settings() const /Factory/; + bool setSettings(InfoObject *settings); + bool load(); + bool isDirty(); +Q_SIGNALS: +private: +}; diff --git a/plugins/extensions/pykrita/sip/krita/BrushTip.sip b/plugins/extensions/pykrita/sip/krita/BrushTip.sip new file mode 100644 --- /dev/null +++ b/plugins/extensions/pykrita/sip/krita/BrushTip.sip @@ -0,0 +1,24 @@ +class BrushTip : Resource +{ +%TypeHeaderCode +#include "BrushTip.h" +%End + BrushTip(const Resource & __0); +public Q_SLOTS: + QImage image() const; + double spacing() const; + void setSpacing(double spacing); + bool autoSpacingActive() const; + qreal autoSpacigCoeff() const; + void setAutoSpacing(bool active, qreal coefficient); + qint32 width() const; + qint32 height() const; + bool threadingAllowed() const; + bool hasColor() const; + qreal scale() const; + void setScale(qreal scale); + qreal angle() const; + void setAngle(qreal angle); +Q_SIGNALS: +private: +}; diff --git a/plugins/extensions/pykrita/sip/krita/Gradient.sip b/plugins/extensions/pykrita/sip/krita/Gradient.sip new file mode 100644 --- /dev/null +++ b/plugins/extensions/pykrita/sip/krita/Gradient.sip @@ -0,0 +1,17 @@ +class Gradient : Resource +{ +%TypeHeaderCode +#include "Gradient.h" +%End + Gradient(const Resource & __0); +public Q_SLOTS: + QGradient* toQGradient() const; + ManagedColor* colorAt(qreal t) const; + QGradient::Spread spread() const; + void setSpread(QGradient::Spread spreadMethod); + QGradient::Type repeatType() const; + void setRepeatType(QGradient::Type type); +Q_SIGNALS: +private: +}; + diff --git a/plugins/extensions/pykrita/sip/krita/Krita.sip b/plugins/extensions/pykrita/sip/krita/Krita.sip --- a/plugins/extensions/pykrita/sip/krita/Krita.sip +++ b/plugins/extensions/pykrita/sip/krita/Krita.sip @@ -29,6 +29,11 @@ Window * activeWindow() const /Factory/; QList windows() const /Factory/; QMap resources(const QString &type) const /Factory/; + QList allPalettes() const /Factory/; + QList allBrushPresets() const /Factory/; + QList allBrushTips() const /Factory/; + QList allPatterns() const /Factory/; + QList allGradients() const /Factory/; QStringList recentDocuments() const; Document * createDocument(int width, int height, const QString &name, const QString &colorModel, const QString &colorDepth, const QString &profile) /Factory/; QList extensions() /Factory/; diff --git a/plugins/extensions/pykrita/sip/krita/Notifier.sip b/plugins/extensions/pykrita/sip/krita/Notifier.sip --- a/plugins/extensions/pykrita/sip/krita/Notifier.sip +++ b/plugins/extensions/pykrita/sip/krita/Notifier.sip @@ -18,4 +18,28 @@ void viewClosed(View *view); void windowCreated(Window *window); void configurationChanged(); + + void resourceAdded(Resource *added); + void resourceChanged(Resource *changed); + void resourceRemoved(Resource *removed); + + void paletteAdded(Palette *added); + void paletteChanged(Palette *changed); + void paletteRemoved(Palette *removed); + + void patternAdded(Pattern *added); + void patternChanged(Pattern *changed); + void patternRemoved(Pattern *removed); + + void gradientAdded(Gradient *added); + void gradientChanged(Gradient *changed); + void gradientRemoved(Gradient *removed); + + void brushTipAdded(BrushTip *added); + void brushTipChanged(BrushTip *changed); + void brushTipRemoved(BrushTip *removed); + + void brushPresetAdded(BrushPreset *added); + void brushPresetChanged(BrushPreset *changed); + void brushPresetRemoved(BrushPreset *removed); }; diff --git a/plugins/extensions/pykrita/sip/krita/Palette.sip b/plugins/extensions/pykrita/sip/krita/Palette.sip --- a/plugins/extensions/pykrita/sip/krita/Palette.sip +++ b/plugins/extensions/pykrita/sip/krita/Palette.sip @@ -13,14 +13,13 @@ }; -class Palette : QObject +class Palette : Resource { %TypeHeaderCode #include "Palette.h" %End Palette(const Palette & __0); public: - Palette(Resource *resource); int numberOfEntries() const; int columnCount(); void setColumnCount(int columns); @@ -40,6 +39,5 @@ bool editEntry(int index, KoColorSetEntry entry, QString groupName); bool changeGroupName(QString oldGroupName, QString newGroupName); bool moveGroup(const QString &groupName, const QString &groupNameInsertBefore); - bool save(); private: }; diff --git a/plugins/extensions/pykrita/sip/krita/Pattern.sip b/plugins/extensions/pykrita/sip/krita/Pattern.sip new file mode 100644 --- /dev/null +++ b/plugins/extensions/pykrita/sip/krita/Pattern.sip @@ -0,0 +1,14 @@ +class Pattern : Resource +{ +%TypeHeaderCode +#include "Pattern.h" +%End + Pattern(const Resource & __0); +public Q_SLOTS: + QImage image() const; + qint32 width() const; + qint32 height() const; +Q_SIGNALS: +private: +}; + diff --git a/plugins/extensions/pykrita/sip/krita/Resource.sip b/plugins/extensions/pykrita/sip/krita/Resource.sip --- a/plugins/extensions/pykrita/sip/krita/Resource.sip +++ b/plugins/extensions/pykrita/sip/krita/Resource.sip @@ -18,6 +18,7 @@ void setImage(QImage image); QByteArray data() const; bool setData(QByteArray data); + bool save(bool uniqueName); public Q_SLOTS: Q_SIGNALS: private: diff --git a/plugins/extensions/pykrita/sip/krita/kritamod.sip b/plugins/extensions/pykrita/sip/krita/kritamod.sip --- a/plugins/extensions/pykrita/sip/krita/kritamod.sip +++ b/plugins/extensions/pykrita/sip/krita/kritamod.sip @@ -44,6 +44,10 @@ %Include Extension.sip %Include PresetChooser.sip %Include Palette.sip +%Include BrushPreset.sip +%Include BrushTip.sip +%Include Gradient.sip +%Include Pattern.sip %Include PaletteView.sip %Include ManagedColor.sip