Krita Source Code Documentation
Loading...
Searching...
No Matches
KoSvgSymbol Struct Reference

#include <KoSvgSymbolCollectionResource.h>

Public Member Functions

QImage icon (int size)
 
 KoSvgSymbol ()
 
 KoSvgSymbol (const KoSvgSymbol &rhs)
 
 KoSvgSymbol (const QString &_title)
 
bool operator== (const KoSvgSymbol &rhs) const
 
 ~KoSvgSymbol ()
 

Public Attributes

QString id
 
KoShapeshape {0}
 
QString title
 

Detailed Description

Definition at line 26 of file KoSvgSymbolCollectionResource.h.

Constructor & Destructor Documentation

◆ KoSvgSymbol() [1/3]

KoSvgSymbol::KoSvgSymbol ( )
inline

Definition at line 27 of file KoSvgSymbolCollectionResource.h.

27{}

◆ KoSvgSymbol() [2/3]

KoSvgSymbol::KoSvgSymbol ( const QString & _title)
inline

Definition at line 28 of file KoSvgSymbolCollectionResource.h.

29 : title(_title) {}

◆ KoSvgSymbol() [3/3]

KoSvgSymbol::KoSvgSymbol ( const KoSvgSymbol & rhs)
inline

Definition at line 31 of file KoSvgSymbolCollectionResource.h.

32 : id(rhs.id),
33 title(rhs.title),
34 shape(rhs.shape->cloneShape())
35 {
36 }
virtual KoShape * cloneShape() const
creates a deep copy of the shape or shape's subtree
Definition KoShape.cpp:200

◆ ~KoSvgSymbol()

KoSvgSymbol::~KoSvgSymbol ( )
inline

Definition at line 38 of file KoSvgSymbolCollectionResource.h.

39 {
40 delete shape;
41 }

Member Function Documentation

◆ icon()

QImage KoSvgSymbol::icon ( int size = 0)

Definition at line 32 of file KoSvgSymbolCollectionResource.cpp.

33{
34 KoShapeGroup *group = dynamic_cast<KoShapeGroup*>(shape);
36
37 QRectF rc = group->boundingRect().normalized();
38
39 if (size == 0) {
40 size = 128;
41 }
42
43 int maxDim = qMax(rc.width(), rc.height());
44 // no need to customize it, most of the time the code being able to set the size
45 // doesn't even know where this image will end up
46 // because it's saved into the database and then used in widgets
47 const qreal margin = 0.05;
48
49 QImage image(size, size, QImage::Format_ARGB32_Premultiplied);
50 qreal symbolScale = (qreal)(size*(1.0 - 2*margin))/maxDim;
51 QPainter gc(&image);
52 gc.setRenderHint(QPainter::Antialiasing, true);
53 image.fill(Qt::gray);
54
55// debugFlake << "Going to render. Original bounding rect:" << group->boundingRect()
56// << "Normalized: " << rc
57// << "Scale W" << 256 / rc.width() << "Scale H" << 256 / rc.height();
58 gc.translate(size*margin, size*margin); // go inwards (towards the center, or bottom-right corner) by one margin
59 gc.scale(symbolScale, symbolScale);
60 gc.translate(-rc.x(), -rc.y());
61
62 gc.translate((maxDim - rc.width())/2.0, (maxDim - rc.height())/2.0);
64 gc.end();
65 return image;
66}
QRectF boundingRect() const override
a group's boundingRect
static void renderSingleShape(KoShape *shape, QPainter &painter)
renderSingleShape renders a shape on painter. This method includes all the needed steps for painting ...
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References KoShapeGroup::boundingRect(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, KoShapeManager::renderSingleShape(), and shape.

◆ operator==()

bool KoSvgSymbol::operator== ( const KoSvgSymbol & rhs) const
inline

Definition at line 48 of file KoSvgSymbolCollectionResource.h.

48 {
49 return title == rhs.title;
50 }

References title.

Member Data Documentation

◆ id

QString KoSvgSymbol::id

Definition at line 43 of file KoSvgSymbolCollectionResource.h.

◆ shape

KoShape* KoSvgSymbol::shape {0}

Definition at line 45 of file KoSvgSymbolCollectionResource.h.

45{0};

◆ title

QString KoSvgSymbol::title

Definition at line 44 of file KoSvgSymbolCollectionResource.h.


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