Krita Source Code Documentation
Loading...
Searching...
No Matches
KisMyPaintPaintOpPreset Class Reference

#include <MyPaintPaintOpPreset.h>

+ Inheritance diagram for KisMyPaintPaintOpPreset:

Classes

class  Private
 

Public Member Functions

void apply (KisPaintOpSettingsSP settings)
 
MyPaintBrush * brush ()
 
KoResourceSP clone () const override
 
QByteArray getJsonData ()
 
 KisMyPaintPaintOpPreset (const KisMyPaintPaintOpPreset &rhs)
 
 KisMyPaintPaintOpPreset (const QString &fileName="")
 
bool loadFromDevice (QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override
 
QPair< QString, QString > resourceType () const override
 
void setColor (const KoColor color, const KoColorSpace *colorSpace)
 
QString thumbnailPath () const override
 thumbnailPath returns the path to a separate thumbnail image, outside the actual resource file itself. If the path is relative, it is supposed start in the same location as the resource itself. If it's absolute, that is, it starts with "/", it is from the root of the storage.
 
void updateThumbnail () override
 updateThumbnail updates the thumbnail for this resource. Reimplement if your thumbnail is something else than the image set with setImage.
 
virtual ~KisMyPaintPaintOpPreset ()
 
- Public Member Functions inherited from KisPaintOpPreset
KoCanvasResourcesInterfaceSP canvasResourcesInterface () const
 
void clearSideLoadedResources () override
 
KoResourceSP clone () const override
 
KisPaintOpPresetSP cloneWithResourcesSnapshot (KisResourcesInterfaceSP globalResourcesInterface, KoCanvasResourcesInterfaceSP canvasResourcesInterface, KoResourceCacheInterfaceSP cacheInterface) const
 
KisPaintOpPresetSP createMaskingPreset () const
 
QString defaultFileExtension () const override
 
QList< KoResourceLoadResultembeddedResources (KisResourcesInterfaceSP globalResourcesInterface) const override
 
void fromXML (const QDomElement &elt, KisResourcesInterfaceSP resourcesInterface)
 
bool hasLocalResourcesSnapshot () const
 
bool hasMaskingPreset () const
 
 KisPaintOpPreset ()
 
 KisPaintOpPreset (const KisPaintOpPreset &rhs)
 
 KisPaintOpPreset (const QString &filename)
 
QList< KoResourceLoadResultlinkedResources (KisResourcesInterfaceSP globalResourcesInterface) const override
 
bool loadFromDevice (QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override
 
QString name () const override
 
KisPaintOpPresetoperator= (const KisPaintOpPreset &rhs)=delete
 
KoID paintOp () const
 return the id of the paintop plugin
 
 Private (KisPaintOpPreset *q)
 
void regenerateResourceCache (KoResourceCacheInterfaceSP cacheInterface)
 
bool removable () const
 
QList< int > requiredCanvasResources () const override
 
KoResourceCacheInterfaceSP resourceCacheInterface () const
 
KisResourcesInterfaceSP resourcesInterface () const
 
QPair< QString, QString > resourceType () const override
 
bool sanityCheckResourceCacheIsValid (KoResourceCacheInterfaceSP cacheInterface) const
 
bool saveToDevice (QIODevice *dev) const override
 
void setCanvasResourcesInterface (KoCanvasResourcesInterfaceSP canvasResourcesInterface)
 
void setPaintOp (const KoID &paintOp)
 set the id of the paintop plugin
 
void setResourceCacheInterface (KoResourceCacheInterfaceSP cacheInterface)
 
void setResourcesInterface (KisResourcesInterfaceSP resourcesInterface)
 
void setSettings (KisPaintOpSettingsSP settings)
 replace the current settings object with the specified settings
 
KisPaintOpSettingsSP settings () const
 return the settings that define this paintop preset
 
QList< KoResourceLoadResultsideLoadedResources (KisResourcesInterfaceSP globalResourcesInterface) const override
 
void toXML (QDomDocument &doc, QDomElement &elt) const
 
QList< KisUniformPaintOpPropertySPuniformProperties ()
 
void updateLinkedResourcesMetaData ()
 
QPointer< KisPaintOpPresetUpdateProxyupdateProxy () const
 
QPointer< KisPaintOpPresetUpdateProxyupdateProxyNoCreate () const
 
 ~KisPaintOpPreset () override
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 
- Public Member Functions inherited from KoResource
bool active () const
 
void addMetaData (QString key, QVariant value)
 store the given key, value pair in the resource
 
QString filename () const
 
QImage image () const
 
bool isDirty () const
 
virtual bool isEphemeral () const
 
virtual bool isSerializable () const
 
 KoResource ()
 
 KoResource (const KoResource &rhs)
 
 KoResource (const QString &filename)
 
bool load (KisResourcesInterfaceSP resourcesInterface)
 
QString md5Sum (bool generateIfEmpty=true) const
 
QMap< QString, QVariant > metadata () const
 get a map with all the metadata
 
KoResourceoperator= (const KoResource &rhs)=delete
 
bool permanent () const
 
QList< KoResourceLoadResultrequiredResources (KisResourcesInterfaceSP globalResourcesInterface) const
 
int resourceId () const
 
bool save ()
 
void setActive (bool active)
 
void setDirty (bool value)
 Mark the preset as modified but not saved.
 
void setFilename (const QString &filename)
 
void setImage (const QImage &image)
 
void setMD5Sum (const QString &md5sum)
 Set the md5sum of this resource. It must be in hex-encoded string format.
 
void setName (const QString &name)
 
void setPermanent (bool permanent)
 
void setResourceId (int id)
 
void setStorageLocation (const QString &location)
 
void setValid (bool valid)
 
void setVersion (int version)
 
KoResourceSignature signature () const
 
QString storageLocation () const
 
QList< KoResourceLoadResulttakeSideLoadedResources (KisResourcesInterfaceSP globalResourcesInterface)
 
virtual QImage thumbnail () const
 thumbnail the thumbnail image to use in resource selectors
 
bool valid () const
 
int version () const
 Get the version of the resource.
 
virtual ~KoResource ()
 

Private Attributes

Private *const d
 

Additional Inherited Members

- Public Attributes inherited from KisPaintOpPreset
KisPaintOpSettingsSP settings {0}
 
KisPaintOpSettings::UpdateListenerSP settingsUpdateListener
 
QList< KoResourceLoadResultsideLoadedResources
 
QScopedPointer< KisPaintOpPresetUpdateProxyupdateProxy
 
QString version
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 
- Public Attributes inherited from KoResource
bool active {true}
 
QString filename
 
QImage image
 
QString md5sum
 
QMap< QString, QVariant > metadata
 
bool modified {false}
 
QString name
 
bool permanent {false}
 
int resourceId {-1}
 
QString storageLocation
 
bool valid {false}
 
int version {-1}
 

Detailed Description

Definition at line 18 of file MyPaintPaintOpPreset.h.

Constructor & Destructor Documentation

◆ KisMyPaintPaintOpPreset() [1/2]

KisMyPaintPaintOpPreset::KisMyPaintPaintOpPreset ( const QString & fileName = "")

Definition at line 34 of file MyPaintPaintOpPreset.cpp.

35 : KisPaintOpPreset(fileName)
36 , d(new Private)
37{
38 d->brush = mypaint_brush_new();
39 mypaint_brush_from_defaults(d->brush);
40}

References KisMyPaintPaintOpPreset::Private::brush, and d.

◆ KisMyPaintPaintOpPreset() [2/2]

KisMyPaintPaintOpPreset::KisMyPaintPaintOpPreset ( const KisMyPaintPaintOpPreset & rhs)

Definition at line 42 of file MyPaintPaintOpPreset.cpp.

43 : KisPaintOpPreset(rhs)
44 , d(new Private(*rhs.d))
45{
46 d->brush = mypaint_brush_new();
47
48 if (d->json.isEmpty()) {
49 mypaint_brush_from_defaults(d->brush);
50 } else {
51 mypaint_brush_from_string(d->brush, d->json);
52 }
53}

References KisMyPaintPaintOpPreset::Private::brush, d, and KisMyPaintPaintOpPreset::Private::json.

◆ ~KisMyPaintPaintOpPreset()

KisMyPaintPaintOpPreset::~KisMyPaintPaintOpPreset ( )
virtual

Definition at line 55 of file MyPaintPaintOpPreset.cpp.

55 {
56
57 mypaint_brush_unref(d->brush);
58 delete d;
59}

References KisMyPaintPaintOpPreset::Private::brush, and d.

Member Function Documentation

◆ apply()

void KisMyPaintPaintOpPreset::apply ( KisPaintOpSettingsSP settings)

Definition at line 88 of file MyPaintPaintOpPreset.cpp.

88 {
89
90 if(settings->getProperty(MYPAINT_JSON).isNull()) {
91 mypaint_brush_from_defaults(d->brush);
92 }
93 else {
94 QByteArray ba = settings->getProperty(MYPAINT_JSON).toByteArray();
95 mypaint_brush_from_string(d->brush, ba);
96 }
97
98 mypaint_brush_new_stroke(d->brush);
99}
const QString MYPAINT_JSON
bool isNull() const
KisPaintOpSettingsSP settings

References KisMyPaintPaintOpPreset::Private::brush, d, KisSharedPtr< T >::isNull(), MYPAINT_JSON, and KisPaintOpPreset::settings.

◆ brush()

MyPaintBrush * KisMyPaintPaintOpPreset::brush ( )

Definition at line 101 of file MyPaintPaintOpPreset.cpp.

101 {
102
103 return d->brush;
104}

References KisMyPaintPaintOpPreset::Private::brush, and d.

◆ clone()

KoResourceSP KisMyPaintPaintOpPreset::clone ( ) const
overridevirtual

Implements KoResource.

Definition at line 61 of file MyPaintPaintOpPreset.cpp.

62{
63 return toQShared(new KisMyPaintPaintOpPreset(*this));
64}
KisMyPaintPaintOpPreset(const QString &fileName="")
QSharedPointer< T > toQShared(T *ptr)

References KisMyPaintPaintOpPreset(), and toQShared().

◆ getJsonData()

QByteArray KisMyPaintPaintOpPreset::getJsonData ( )

Definition at line 190 of file MyPaintPaintOpPreset.cpp.

190 {
191
192 return d->json;
193}

References d, and KisMyPaintPaintOpPreset::Private::json.

◆ loadFromDevice()

bool KisMyPaintPaintOpPreset::loadFromDevice ( QIODevice * dev,
KisResourcesInterfaceSP resourcesInterface )
overridevirtual

See a comment in namespace deprecated_remove_after_krita6 in MyPaintStandardOptionData.cpp

we just round-trip the save operation to save the property out to the json object

Implements KoResource.

Definition at line 106 of file MyPaintPaintOpPreset.cpp.

107{
108 if (!dev->isSequential())
109 dev->seek(0); // ensure we do read *all* the bytes
110
111 std::array<png_byte, 8> signature;
112 dev->peek(reinterpret_cast<char*>(signature.data()), 8);
113
114#if PNG_LIBPNG_VER < 10400
115 if (png_check_sig(signature, 8)) {
116#else
117 if (png_sig_cmp(signature.data(), 0, 8) == 0) {
118#endif
119 // this is a koresource
121 apply(settings());
122 // correct filename
123 const QString f = filename();
124 if (f.endsWith(".myb", Qt::CaseInsensitive)) {
125 setFilename(QFileInfo(f).completeBaseName().append(KisPaintOpPreset::defaultFileExtension()));
126 }
127 return true;
128 } else {
129 warnPlugins << "Failed loading MyPaint preset from KoResource serialization";
130 return false;
131 }
132 }
133
134 const QByteArray ba(dev->readAll());
135 d->json = ba;
136 // mypaint can handle invalid json files too, so this is the only way to find out if it was correct mypaint file or not...
137 // if the json is incorrect, the brush will get the default mypaint brush settings
138 // which looks like a round brush with low opacity and high spacing
139 bool success = mypaint_brush_from_string(d->brush, ba);
140 const float isEraser = mypaint_brush_get_base_value(d->brush, MYPAINT_BRUSH_SETTING_ERASER);
141
143 s->setProperty("paintop", "mypaintbrush");
144 s->setProperty("filename", this->filename());
145 s->setProperty(MYPAINT_JSON, this->getJsonData());
146 s->setProperty("EraserMode", qRound(isEraser));
147
148
149 {
155 auto recoverDeprecatedProperty = [] (auto data, KisPaintOpSettingsSP settings) {
158
159 data.read(settings.data());
160 data.write(settings.data());
161 };
162
163 recoverDeprecatedProperty(MyPaintRadiusLogarithmicData(), s);
164 recoverDeprecatedProperty(MyPaintOpacityData(), s);
165 recoverDeprecatedProperty(MyPaintHardnessData(), s);
166 }
167
168
169 if (!metadata().contains("paintopid")) {
170 addMetaData("paintopid", "mypaintbrush");
171 }
172
173 this->setSettings(s);
174 setName(QFileInfo(filename()).baseName());
175 setValid(success);
176
177 return success;
178}
void apply(KisPaintOpSettingsSP settings)
#define warnPlugins
Definition kis_debug.h:93
KisResourcesInterfaceSP resourcesInterface() const
QString defaultFileExtension() const override
bool loadFromDevice(QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override
void setSettings(KisPaintOpSettingsSP settings)
replace the current settings object with the specified settings
void setValid(bool valid)
void setName(const QString &name)
void addMetaData(QString key, QVariant value)
store the given key, value pair in the resource
void setFilename(const QString &filename)
QString filename
QMap< QString, QVariant > metadata
KoResourceSignature signature() const

References KoResource::addMetaData(), apply(), KisMyPaintPaintOpPreset::Private::brush, d, KisSharedPtr< T >::data(), KisPaintOpPreset::defaultFileExtension(), KoResource::filename, getJsonData(), KisMyPaintPaintOpPreset::Private::json, KisPaintOpPreset::loadFromDevice(), KoResource::metadata, MYPAINT_JSON, KisPaintOpPreset::resourcesInterface(), KoResource::setFilename(), KoResource::setName(), KisPaintOpPreset::setSettings(), KisPaintOpPreset::settings, KoResource::setValid(), KoResource::signature(), and warnPlugins.

◆ resourceType()

QPair< QString, QString > KisMyPaintPaintOpPreset::resourceType ( ) const
inlineoverridevirtual
Returns
the resource type

Implements KoResource.

Definition at line 34 of file MyPaintPaintOpPreset.h.

34 {
36 }
const QString MyPaintPaintOpPresets
const QString PaintOpPresets

References ResourceSubType::MyPaintPaintOpPresets, and ResourceType::PaintOpPresets.

◆ setColor()

void KisMyPaintPaintOpPreset::setColor ( const KoColor color,
const KoColorSpace * colorSpace )

Definition at line 66 of file MyPaintPaintOpPreset.cpp.

66 {
67
68 float hue, saturation, value;
69#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
70 qreal r = 0, g = 0, b = 0;
71#else
72 float r = 0, g = 0, b = 0;
73#endif
74 QColor dstColor;
75
76 if (colorSpace->colorModelId() == RGBAColorModelID) {
77 colorSpace->toQColor(color.data(), &dstColor);
78 dstColor.getRgbF(&r, &g, &b);
79 }
80
81 RGBToHSV(r, g, b, &hue, &saturation, &value);
82
83 mypaint_brush_set_base_value(d->brush, MYPAINT_BRUSH_SETTING_COLOR_H, (hue)/360);
84 mypaint_brush_set_base_value(d->brush, MYPAINT_BRUSH_SETTING_COLOR_S, (saturation));
85 mypaint_brush_set_base_value(d->brush, MYPAINT_BRUSH_SETTING_COLOR_V, (value));
86}
float value(const T *src, size_t ch)
void RGBToHSV(float r, float g, float b, float *h, float *s, float *v)
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
virtual void toQColor(const quint8 *src, QColor *c) const =0
virtual KoID colorModelId() const =0
quint8 * data()
Definition KoColor.h:144

References KisMyPaintPaintOpPreset::Private::brush, KoColorSpace::colorModelId(), d, KoColor::data(), RGBAColorModelID, RGBToHSV(), KoColorSpace::toQColor(), and value().

◆ thumbnailPath()

QString KisMyPaintPaintOpPreset::thumbnailPath ( ) const
overridevirtual

thumbnailPath returns the path to a separate thumbnail image, outside the actual resource file itself. If the path is relative, it is supposed start in the same location as the resource itself. If it's absolute, that is, it starts with "/", it is from the root of the storage.

Returns
an empty string if the thumbnail is part of the resource

Reimplemented from KoResource.

Definition at line 185 of file MyPaintPaintOpPreset.cpp.

186{
187 return QFileInfo(filename()).baseName() + "_prev.png";
188}

References KoResource::filename.

◆ updateThumbnail()

void KisMyPaintPaintOpPreset::updateThumbnail ( )
overridevirtual

updateThumbnail updates the thumbnail for this resource. Reimplement if your thumbnail is something else than the image set with setImage.

Reimplemented from KoResource.

Definition at line 180 of file MyPaintPaintOpPreset.cpp.

181{
182 d->icon = thumbnail();
183}
virtual QImage thumbnail() const
thumbnail the thumbnail image to use in resource selectors

References d, KisMyPaintPaintOpPreset::Private::icon, and KoResource::thumbnail().

Member Data Documentation

◆ d

Private* const KisMyPaintPaintOpPreset::d
private

Definition at line 45 of file MyPaintPaintOpPreset.h.


The documentation for this class was generated from the following files: