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 429 of file KoGamutMask.cpp.

430{
431 d->previewShapes.clear();
432}

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 393 of file KoGamutMask.cpp.

394{
395 return ".kgm";
396}

◆ description()

QString KoGamutMask::description ( ) const

Definition at line 382 of file KoGamutMask.cpp.

383{
384 QMap<QString, QVariant> m = metadata();
385 return m["description"].toString();
386}
QMap< QString, QVariant > metadata

References KoResource::metadata.

◆ koShapes()

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

Definition at line 323 of file KoGamutMask.cpp.

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

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 file.open(QIODevice::ReadOnly);
240 d->data = file.readAll();
241 file.close();
242 }
243
244 QBuffer buf(&d->data);
245 buf.open(QBuffer::ReadOnly);
246
247 QScopedPointer<KoStore> store(KoStore::createStore(&buf, KoStore::Read, "application/x-krita-gamutmask", KoStore::Zip));
248 if (!store || store->bad()) return false;
249
250 bool storeOpened = store->open("gamutmask.svg");
251 if (!storeOpened) { return false; }
252
253 QByteArray data;
254 data.resize(store->size());
255 QByteArray ba = store->read(store->size());
256 store->close();
257
258 if (ba.size() == 0) { // empty gamutmask.svg is possible when the first temporary resource is saved
260 d->maskSize = QSizeF(0, 0);
261 d->title = "";
262 } else {
263
264 QString errorMsg;
265 int errorLine = 0;
266 int errorColumn = 0;
267
268 QDomDocument xmlDocument = SvgParser::createDocumentFromSvg(ba, &errorMsg, &errorLine, &errorColumn);
269 if (xmlDocument.isNull()) {
270
271 errorFlake << "Parsing error in " << filename() << "! Aborting!" << Qt::endl
272 << " In line: " << errorLine << ", column: " << errorColumn << Qt::endl
273 << " Error message: " << errorMsg << Qt::endl;
274 errorFlake << "Parsing error in the main document at line" << errorLine
275 << ", column" << errorColumn << Qt::endl
276 << "Error message: " << errorMsg;
277
278 return false;
279 }
280
282 SvgParser parser(&manager);
283 parser.setResolution(QRectF(0,0,100,100), 72); // initialize with default values
284 QSizeF fragmentSize;
285
286 QList<KoShape*> shapes = parser.parseSvg(xmlDocument.documentElement(), &fragmentSize);
287
288 d->maskSize = fragmentSize;
289
290 d->title = parser.documentTitle();
291 setName(d->title);
292 setDescription(parser.documentDescription());
293
294 setMaskShapes(shapes);
295
296 }
297
298
299
300 if (store->open("preview.png")) {
301 KoStoreDevice previewDev(store.data());
302 previewDev.open(QIODevice::ReadOnly);
303
304 QImage preview = QImage();
305 preview.load(&previewDev, "PNG");
306 setImage(preview);
307
308 (void)store->close();
309 }
310
311 buf.close();
312
313 setValid(true);
314
315 return true;
316}
#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 408 of file KoGamutMask.cpp.

409{
410 return d->maskSize;
411}

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 398 of file KoGamutMask.cpp.

399{
400 return d->rotation;
401}

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

◆ saveToDevice()

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

Reimplemented from KoResource.

Definition at line 333 of file KoGamutMask.cpp.

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

389{
390 addMetaData("description", description);
391}
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 318 of file KoGamutMask.cpp.

319{
321}
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 418 of file KoGamutMask.cpp.

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

◆ setPreviewMaskShapes()

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

Definition at line 413 of file KoGamutMask.cpp.

414{
416}

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

◆ setRotation()

void KoGamutMask::setRotation ( int rotation)

Definition at line 403 of file KoGamutMask.cpp.

404{
406}

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

◆ setTitle()

void KoGamutMask::setTitle ( QString title)

Definition at line 376 of file KoGamutMask.cpp.

377{
378 d->title = title;
379 setName(title);
380}

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

◆ title()

QString KoGamutMask::title ( ) const

Definition at line 371 of file KoGamutMask.cpp.

372{
373 return d->title;
374}

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: