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

The resource type for gamut masks used by the artistic color selector. More...

#include <KoGamutMask.h>

+ Inheritance diagram for KoGamutMask:

Classes

struct  Private
 

Public Member Functions

void clearPreview ()
 
KoResourceSP clone () const override
 
bool coordIsClear (const QPointF &coord, bool preview)
 
QString defaultFileExtension () const override
 
QString description () const
 
 KoGamutMask ()
 
 KoGamutMask (const KoGamutMask &rhs)
 
 KoGamutMask (const QString &filename)
 
 KoGamutMask (KoGamutMask *rhs)
 
QList< KoShape * > koShapes () const
 
bool loadFromDevice (QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override
 
QSizeF maskSize ()
 
QTransform maskToViewTransform (qreal viewSize)
 
KoGamutMaskoperator= (const KoGamutMask &rhs)=delete
 
void paint (QPainter &painter, bool preview)
 
void paintStroke (QPainter &painter, bool preview)
 
QPair< QString, QString > resourceType () const override
 
int rotation ()
 
bool saveToDevice (QIODevice *dev) const override
 
void setDescription (QString description)
 
void setMaskShapes (QList< KoShape * > shapes)
 
void setPreviewMaskShapes (QList< KoShape * > shapes)
 
void setRotation (int rotation)
 
void setTitle (QString title)
 
QString title () const
 
QTransform viewToMaskTransform (qreal viewSize)
 
 ~KoGamutMask () override
 
- Public Member Functions inherited from KoResource
bool active () const
 
void addMetaData (QString key, QVariant value)
 store the given key, value pair in the resource
 
virtual void clearSideLoadedResources ()
 
virtual QList< KoResourceLoadResultembeddedResources (KisResourcesInterfaceSP globalResourcesInterface) const
 
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)
 
virtual QList< KoResourceLoadResultlinkedResources (KisResourcesInterfaceSP globalResourcesInterface) const
 
bool load (KisResourcesInterfaceSP resourcesInterface)
 
QString md5Sum (bool generateIfEmpty=true) const
 
QMap< QString, QVariant > metadata () const
 get a map with all the metadata
 
virtual QString name () const
 
KoResourceoperator= (const KoResource &rhs)=delete
 
bool permanent () const
 
virtual QList< int > requiredCanvasResources () 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)
 
virtual QList< KoResourceLoadResultsideLoadedResources (KisResourcesInterfaceSP globalResourcesInterface) const
 
KoResourceSignature signature () const
 
QString storageLocation () const
 
QList< KoResourceLoadResulttakeSideLoadedResources (KisResourcesInterfaceSP globalResourcesInterface)
 
virtual QImage thumbnail () const
 thumbnail the thumbnail image to use in resource selectors
 
virtual QString thumbnailPath () const
 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.
 
virtual void updateThumbnail ()
 updateThumbnail updates the thumbnail for this resource. Reimplement if your thumbnail is something else than the image set with setImage.
 
bool valid () const
 
int version () const
 Get the version of the resource.
 
virtual ~KoResource ()
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Private Member Functions

void setMaskShapesToVector (QList< KoShape * > shapes, QVector< KoGamutMaskShape * > &targetVector)
 

Private Attributes

Private *const d
 

Additional Inherited Members

- 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}
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Detailed Description

The resource type for gamut masks used by the artistic color selector.

Definition at line 43 of file KoGamutMask.h.

Constructor & Destructor Documentation

◆ KoGamutMask() [1/4]

KoGamutMask::KoGamutMask ( const QString & filename)

Definition at line 87 of file KoGamutMask.cpp.

89 , d(new Private)
90{
91 d->maskSize = QSizeF(144.0,144.0);
92 setRotation(0);
93}
void setRotation(int rotation)
Private *const d
Definition KoGamutMask.h:95
QString filename

References d, KoGamutMask::Private::maskSize, and setRotation().

◆ KoGamutMask() [2/4]

KoGamutMask::KoGamutMask ( )

Definition at line 95 of file KoGamutMask.cpp.

96 : KoResource(QString())
97 , d(new Private)
98{
99 d->maskSize = QSizeF(144.0,144.0);
100 setRotation(0);
101}

References d, KoGamutMask::Private::maskSize, and setRotation().

◆ KoGamutMask() [3/4]

KoGamutMask::KoGamutMask ( KoGamutMask * rhs)

Definition at line 103 of file KoGamutMask.cpp.

104 : KoGamutMask(*rhs)
105{
106}

◆ KoGamutMask() [4/4]

KoGamutMask::KoGamutMask ( const KoGamutMask & rhs)

Definition at line 108 of file KoGamutMask.cpp.

109 : QObject(0)
110 , KoResource(rhs)
111 , d(new Private)
112{
113 setTitle(rhs.title());
115 d->maskSize = rhs.d->maskSize;
116
117 QList<KoShape*> newShapes;
118 for(KoShape* sh: rhs.koShapes()) {
119 newShapes.append(sh->cloneShape());
120 }
121 setMaskShapes(newShapes);
122}
QString title() const
void setMaskShapes(QList< KoShape * > shapes)
void setDescription(QString description)
void setTitle(QString title)
QString description() const
QList< KoShape * > koShapes() const

References d, description(), koShapes(), KoGamutMask::Private::maskSize, setDescription(), setMaskShapes(), setTitle(), and title().

◆ ~KoGamutMask()

KoGamutMask::~KoGamutMask ( )
override

Definition at line 129 of file KoGamutMask.cpp.

130{
131 qDeleteAll(d->maskShapes);
132 qDeleteAll(d->previewShapes);
133 delete d;
134}
QVector< KoGamutMaskShape * > maskShapes
QVector< KoGamutMaskShape * > previewShapes

References d, KoGamutMask::Private::maskShapes, and KoGamutMask::Private::previewShapes.

Member Function Documentation

◆ clearPreview()

void KoGamutMask::clearPreview ( )

Definition at line 432 of file KoGamutMask.cpp.

433{
434 d->previewShapes.clear();
435}

References d, and KoGamutMask::Private::previewShapes.

◆ clone()

KoResourceSP KoGamutMask::clone ( ) const
overridevirtual

Implements KoResource.

Definition at line 124 of file KoGamutMask.cpp.

125{
126 return KoResourceSP(new KoGamutMask(*this));
127}
QSharedPointer< KoResource > KoResourceSP

References KoGamutMask().

◆ coordIsClear()

bool KoGamutMask::coordIsClear ( const QPointF & coord,
bool preview )

Definition at line 136 of file KoGamutMask.cpp.

137{
138 QVector<KoGamutMaskShape*>* shapeVector;
139
140 if (preview && !d->previewShapes.isEmpty()) {
141 shapeVector = &d->previewShapes;
142 } else {
143 shapeVector = &d->maskShapes;
144 }
145
146 for(KoGamutMaskShape* shape: *shapeVector) {
147 if (shape->coordIsClear(coord) == true) {
148 return true;
149 }
150 }
151
152 return false;
153}

References d, KoGamutMask::Private::maskShapes, and KoGamutMask::Private::previewShapes.

◆ defaultFileExtension()

QString KoGamutMask::defaultFileExtension ( ) const
overridevirtual
Returns
the default file extension which should be used when saving the resource

Reimplemented from KoResource.

Definition at line 396 of file KoGamutMask.cpp.

397{
398 return ".kgm";
399}

◆ description()

QString KoGamutMask::description ( ) const

Definition at line 385 of file KoGamutMask.cpp.

386{
387 QMap<QString, QVariant> m = metadata();
388 return m["description"].toString();
389}
QMap< QString, QVariant > metadata

References KoResource::metadata.

◆ koShapes()

QList< KoShape * > KoGamutMask::koShapes ( ) const

Definition at line 326 of file KoGamutMask.cpp.

327{
328 QList<KoShape*> shapes;
329 for(KoGamutMaskShape* maskShape: d->maskShapes) {
330 shapes.append(maskShape->koShape());
331 }
332
333 return shapes;
334}

References d, and KoGamutMask::Private::maskShapes.

◆ loadFromDevice()

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

Implements KoResource.

Definition at line 216 of file KoGamutMask.cpp.

217{
218 Q_UNUSED(resourcesInterface);
219
220 if (!dev->isOpen()) dev->open(QIODevice::ReadOnly);
221
222 d->data = dev->readAll();
223
224 // TODO: test
225 KIS_ASSERT_RECOVER_RETURN_VALUE(d->data.size() != 0, false);
226
227 if (filename().isNull()) {
228 warnFlake << "Cannot load gamut mask" << name() << "there is no filename set";
229 return false;
230 }
231
232 if (d->data.isNull()) {
233 QFile file(filename());
234 if (file.size() == 0) {
235 warnFlake << "Cannot load gamut mask" << name() << "there is no data available";
236 return false;
237 }
238
239 if (!file.open(QIODevice::ReadOnly)) {
240 warnFlake << "Cannot load gamut mask" << name() << ":" << file.errorString();
241 return false;
242 }
243 d->data = file.readAll();
244 file.close();
245 }
246
247 QBuffer buf(&d->data);
248 buf.open(QBuffer::ReadOnly);
249
250 QScopedPointer<KoStore> store(KoStore::createStore(&buf, KoStore::Read, "application/x-krita-gamutmask", KoStore::Zip));
251 if (!store || store->bad()) return false;
252
253 bool storeOpened = store->open("gamutmask.svg");
254 if (!storeOpened) { return false; }
255
256 QByteArray data;
257 data.resize(store->size());
258 QByteArray ba = store->read(store->size());
259 store->close();
260
261 if (ba.size() == 0) { // empty gamutmask.svg is possible when the first temporary resource is saved
263 d->maskSize = QSizeF(0, 0);
264 d->title = "";
265 } else {
266
267 QString errorMsg;
268 int errorLine = 0;
269 int errorColumn = 0;
270
271 QDomDocument xmlDocument = SvgParser::createDocumentFromSvg(ba, &errorMsg, &errorLine, &errorColumn);
272 if (xmlDocument.isNull()) {
273
274 errorFlake << "Parsing error in " << filename() << "! Aborting!" << Qt::endl
275 << " In line: " << errorLine << ", column: " << errorColumn << Qt::endl
276 << " Error message: " << errorMsg << Qt::endl;
277 errorFlake << "Parsing error in the main document at line" << errorLine
278 << ", column" << errorColumn << Qt::endl
279 << "Error message: " << errorMsg;
280
281 return false;
282 }
283
285 SvgParser parser(&manager);
286 parser.setResolution(QRectF(0,0,100,100), 72); // initialize with default values
287 QSizeF fragmentSize;
288
289 QList<KoShape*> shapes = parser.parseSvg(xmlDocument.documentElement(), &fragmentSize);
290
291 d->maskSize = fragmentSize;
292
293 d->title = parser.documentTitle();
294 setName(d->title);
295 setDescription(parser.documentDescription());
296
297 setMaskShapes(shapes);
298
299 }
300
301
302
303 if (store->open("preview.png")) {
304 KoStoreDevice previewDev(store.data());
305 previewDev.open(QIODevice::ReadOnly);
306
307 QImage preview = QImage();
308 preview.load(&previewDev, "PNG");
309 setImage(preview);
310
311 (void)store->close();
312 }
313
314 buf.close();
315
316 setValid(true);
317
318 return true;
319}
#define warnFlake
Definition FlakeDebug.h:16
#define errorFlake
Definition FlakeDebug.h:17
@ Read
Definition KoStore.h:29
@ Zip
Definition KoStore.h:30
static KoStore * createStore(const QString &fileName, Mode mode, const QByteArray &appIdentification=QByteArray(), Backend backend=Auto, bool writeMimetype=true)
Definition KoStore.cpp:39
static QDomDocument createDocumentFromSvg(QIODevice *device, QString *errorMsg=0, int *errorLine=0, int *errorColumn=0)
#define KIS_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:85
typedef void(QOPENGLF_APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC)(GLuint buffer)
void setValid(bool valid)
void setName(const QString &name)
void setImage(const QImage &image)
QString name

References SvgParser::createDocumentFromSvg(), KoStore::createStore(), d, KoGamutMask::Private::data, SvgParser::documentDescription(), SvgParser::documentTitle(), errorFlake, KoResource::filename, KIS_ASSERT_RECOVER_RETURN_VALUE, KoGamutMask::Private::maskSize, KoResource::name, KoStoreDevice::open(), SvgParser::parseSvg(), KoStore::Read, setDescription(), KoResource::setImage(), setMaskShapes(), KoResource::setName(), SvgParser::setResolution(), KoResource::setValid(), KoGamutMask::Private::title, void(), warnFlake, and KoStore::Zip.

◆ maskSize()

QSizeF KoGamutMask::maskSize ( )

Definition at line 411 of file KoGamutMask.cpp.

412{
413 return d->maskSize;
414}

References d, and KoGamutMask::Private::maskSize.

◆ maskToViewTransform()

QTransform KoGamutMask::maskToViewTransform ( qreal viewSize)

Definition at line 185 of file KoGamutMask.cpp.

186{
187 // apply mask rotation before drawing
188 QPointF centerPoint(viewSize*0.5, viewSize*0.5);
189
190 QTransform transform;
191 transform.translate(centerPoint.x(), centerPoint.y());
192 transform.rotate(rotation());
193 transform.translate(-centerPoint.x(), -centerPoint.y());
194
195 qreal scale = viewSize/(maskSize().width());
196 transform.scale(scale, scale);
197
198 return transform;
199}
QSizeF maskSize()

References maskSize(), and rotation().

◆ operator=()

KoGamutMask & KoGamutMask::operator= ( const KoGamutMask & rhs)
delete

◆ paint()

void KoGamutMask::paint ( QPainter & painter,
bool preview )

Definition at line 155 of file KoGamutMask.cpp.

156{
157 QVector<KoGamutMaskShape*>* shapeVector;
158
159 if (preview && !d->previewShapes.isEmpty()) {
160 shapeVector = &d->previewShapes;
161 } else {
162 shapeVector = &d->maskShapes;
163 }
164
165 for(KoGamutMaskShape* shape: *shapeVector) {
166 shape->paint(painter);
167 }
168}

References d, KoGamutMask::Private::maskShapes, and KoGamutMask::Private::previewShapes.

◆ paintStroke()

void KoGamutMask::paintStroke ( QPainter & painter,
bool preview )

Definition at line 170 of file KoGamutMask.cpp.

171{
172 QVector<KoGamutMaskShape*>* shapeVector;
173
174 if (preview && !d->previewShapes.isEmpty()) {
175 shapeVector = &d->previewShapes;
176 } else {
177 shapeVector = &d->maskShapes;
178 }
179
180 for(KoGamutMaskShape* shape: *shapeVector) {
181 shape->paintStroke(painter);
182 }
183}

References d, KoGamutMask::Private::maskShapes, and KoGamutMask::Private::previewShapes.

◆ resourceType()

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

Implements KoResource.

Definition at line 60 of file KoGamutMask.h.

61 {
62 return QPair<QString, QString>(ResourceType::GamutMasks, "");
63 }
const QString GamutMasks

References ResourceType::GamutMasks.

◆ rotation()

int KoGamutMask::rotation ( )

Definition at line 401 of file KoGamutMask.cpp.

402{
403 return d->rotation;
404}

References d, and KoGamutMask::Private::rotation.

◆ saveToDevice()

bool KoGamutMask::saveToDevice ( QIODevice * dev) const
overridevirtual

Reimplemented from KoResource.

Definition at line 336 of file KoGamutMask.cpp.

337{
338 KoStore* store(KoStore::createStore(dev, KoStore::Write, "application/x-krita-gamutmask", KoStore::Zip));
339 if (!store || store->bad()) return false;
340
341 QList<KoShape*> shapes = koShapes();
342
343 std::sort(shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);
344
345 if (!store->open("gamutmask.svg")) {
346 return false;
347 }
348
349 KoStoreDevice storeDev(store);
350 storeDev.open(QIODevice::WriteOnly);
351
352 SvgWriter writer(shapes);
353 writer.setDocumentTitle(d->title);
354 writer.setDocumentDescription(description());
355
356 writer.save(storeDev, d->maskSize);
357
358 if (!store->close()) { return false; }
359
360
361 if (!store->open("preview.png")) {
362 return false;
363 }
364
365 KoStoreDevice previewDev(store);
366 previewDev.open(QIODevice::WriteOnly);
367
368 image().save(&previewDev, "PNG");
369 if (!store->close()) { return false; }
370
371 return store->finalize();
372}
static bool compareShapeZIndex(KoShape *s1, KoShape *s2)
Definition KoShape.cpp:388
@ Write
Definition KoStore.h:29
Implements exporting shapes to SVG.
Definition SvgWriter.h:33
QImage image

References KoStore::bad(), KoStore::close(), KoShape::compareShapeZIndex(), KoStore::createStore(), d, description(), KoStore::finalize(), KoResource::image, koShapes(), KoGamutMask::Private::maskSize, KoStore::open(), KoStoreDevice::open(), SvgWriter::save(), SvgWriter::setDocumentDescription(), SvgWriter::setDocumentTitle(), KoGamutMask::Private::title, KoStore::Write, and KoStore::Zip.

◆ setDescription()

void KoGamutMask::setDescription ( QString description)

Definition at line 391 of file KoGamutMask.cpp.

392{
393 addMetaData("description", description);
394}
void addMetaData(QString key, QVariant value)
store the given key, value pair in the resource

References KoResource::addMetaData(), and description().

◆ setMaskShapes()

void KoGamutMask::setMaskShapes ( QList< KoShape * > shapes)

Definition at line 321 of file KoGamutMask.cpp.

322{
324}
void setMaskShapesToVector(QList< KoShape * > shapes, QVector< KoGamutMaskShape * > &targetVector)

References d, KoGamutMask::Private::maskShapes, and setMaskShapesToVector().

◆ setMaskShapesToVector()

void KoGamutMask::setMaskShapesToVector ( QList< KoShape * > shapes,
QVector< KoGamutMaskShape * > & targetVector )
private

Definition at line 421 of file KoGamutMask.cpp.

422{
423 targetVector.clear();
424
425 for(KoShape* sh: shapes) {
426 KoGamutMaskShape* maskShape = new KoGamutMaskShape(sh);
427 targetVector.append(maskShape);
428 }
429}

◆ setPreviewMaskShapes()

void KoGamutMask::setPreviewMaskShapes ( QList< KoShape * > shapes)

Definition at line 416 of file KoGamutMask.cpp.

417{
419}

References d, KoGamutMask::Private::previewShapes, and setMaskShapesToVector().

◆ setRotation()

void KoGamutMask::setRotation ( int rotation)

Definition at line 406 of file KoGamutMask.cpp.

407{
409}

References d, KoGamutMask::Private::rotation, and rotation().

◆ setTitle()

void KoGamutMask::setTitle ( QString title)

Definition at line 379 of file KoGamutMask.cpp.

380{
381 d->title = title;
382 setName(title);
383}

References d, KoResource::setName(), KoGamutMask::Private::title, and title().

◆ title()

QString KoGamutMask::title ( ) const

Definition at line 374 of file KoGamutMask.cpp.

375{
376 return d->title;
377}

References d, and KoGamutMask::Private::title.

◆ viewToMaskTransform()

QTransform KoGamutMask::viewToMaskTransform ( qreal viewSize)

Definition at line 201 of file KoGamutMask.cpp.

202{
203 QPointF centerPoint(viewSize*0.5, viewSize*0.5);
204
205 QTransform transform;
206 qreal scale = viewSize/(maskSize().width());
207 transform.scale(1/scale, 1/scale);
208
209 transform.translate(centerPoint.x(), centerPoint.y());
210 transform.rotate(-rotation());
211 transform.translate(-centerPoint.x(), -centerPoint.y());
212
213 return transform;
214}

References maskSize(), and rotation().

Member Data Documentation

◆ d

Private* const KoGamutMask::d
private

Definition at line 95 of file KoGamutMask.h.


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