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

The KoShapeQtQuickLabel class. More...

#include <KoShapeQtQuickLabel.h>

+ Inheritance diagram for KoShapeQtQuickLabel:

Classes

struct  Private
 

Public Types

enum  ScalingType { Fit , FitWidth , FitHeight }
 

Signals

void alignmentChanged ()
 
void documentRectChanged ()
 
void fillColorChanged ()
 
void foregroundColorChanged ()
 
void fullColorChanged ()
 
void minimumRectChanged ()
 
void paddingChanged ()
 
void scalingTypeChanged ()
 
void svgDataChanged ()
 

Public Member Functions

Qt::Alignment alignment () const
 alignment
 
void componentComplete () override
 
QRectF documentRect () const
 
QColor foregroundColor () const
 foregroundColor This is the color that is used as the fill for the KoShapes when fullColor is set false.
 
bool fullColor () const
 fullColor This controls whether the current shape background will be set to the foreground color or whether it will keep the color it received during parsing of SVG data.
 
 KoShapeQtQuickLabel (QQuickItem *parent=nullptr)
 
QRectF minimumRect () const
 minimumRect Minimum size rectangle, defined by either documentRect or loaded SVG contentRect, with padding attached. Use this when you want sensible minimum size. We cannot set this to implicitsize or the like, because implicit width and height need to be used when setting KoShapeQtQuickLabel as a content item to a QQuickControl.
 
int padding () const
 
void paint (QPainter *painter) override
 
ScalingType scalingType () const
 scalingType
 
void setAlignment (const Qt::Alignment align)
 
void setDocumentRect (const QRectF &rect)
 
void setForegroundColor (const QColor &newForegroundColor)
 
void setFullColor (bool newFullColor)
 
void setPadding (int newPadding)
 
void setScalingType (const ScalingType type)
 
void setSvgData (const QString &newSvgData)
 
QString svgData () const
 
 ~KoShapeQtQuickLabel ()
 

Properties

Qt::Alignment alignment
 
QRectF documentRect
 
QColor foregroundColor
 
bool fullColor
 
QRectF minimumRect
 
int padding
 
ScalingType scalingType
 
QString svgData
 

Private Slots

void callUpdateIfComplete ()
 
void updateShapes ()
 

Private Attributes

const QScopedPointer< Privated
 

Detailed Description

The KoShapeQtQuickLabel class.

A QQuickPaintedItem that will load SVG as KoShapes and paint them.

Definition at line 17 of file KoShapeQtQuickLabel.h.

Member Enumeration Documentation

◆ ScalingType

Enumerator
Fit 

Default koshapepainter behaviour, fit whole document into widget bounds.

FitWidth 

Scale document view to document width. Use alignment to position top or bottom on the document.

FitHeight 

Scale document view to document height. Use alignment to position left or right on the document.

Definition at line 34 of file KoShapeQtQuickLabel.h.

34 {
35 Fit,
36 FitWidth,
38 };
@ FitWidth
Scale document view to document width. Use alignment to position top or bottom on the document.
@ Fit
Default koshapepainter behaviour, fit whole document into widget bounds.
@ FitHeight
Scale document view to document height. Use alignment to position left or right on the document.

Constructor & Destructor Documentation

◆ KoShapeQtQuickLabel()

KoShapeQtQuickLabel::KoShapeQtQuickLabel ( QQuickItem * parent = nullptr)

Definition at line 83 of file KoShapeQtQuickLabel.cpp.

84 : QQuickPaintedItem(parent)
85 , d(new Private())
86{
87 setAntialiasing(true);
88 setOpaquePainting(true);
89
90 connect(this, SIGNAL(minimumRectChanged()), this, SLOT(callUpdateIfComplete()));
91}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
const QScopedPointer< Private > d

References callUpdateIfComplete(), connect(), and minimumRectChanged().

◆ ~KoShapeQtQuickLabel()

KoShapeQtQuickLabel::~KoShapeQtQuickLabel ( )

Definition at line 93 of file KoShapeQtQuickLabel.cpp.

94{
95}

Member Function Documentation

◆ alignment()

Qt::Alignment KoShapeQtQuickLabel::alignment ( ) const

alignment

Returns
how to align the document viewport when using FillWidth or FillHeight as the scaling type.

Definition at line 212 of file KoShapeQtQuickLabel.cpp.

213{
214 return d->alignment;
215}

References d.

◆ alignmentChanged

void KoShapeQtQuickLabel::alignmentChanged ( )
signal

◆ callUpdateIfComplete

void KoShapeQtQuickLabel::callUpdateIfComplete ( )
privateslot

Definition at line 242 of file KoShapeQtQuickLabel.cpp.

243{
244 if (isComponentComplete()) {
245 update(boundingRect().toAlignedRect());
246 }
247}
bool update(QSpinBox *spinBox)

◆ componentComplete()

void KoShapeQtQuickLabel::componentComplete ( )
override

Definition at line 224 of file KoShapeQtQuickLabel.cpp.

225{
226 QQuickPaintedItem::componentComplete();
227 updateShapes();
228 setOpaquePainting(fillColor().alpha() == 255);
229}

References updateShapes().

◆ documentRect()

QRectF KoShapeQtQuickLabel::documentRect ( ) const

By default, this label will use the content rect as the document view. When this rectangle is valid, it will be used instead.

Definition at line 249 of file KoShapeQtQuickLabel.cpp.

250{
251 return d->documentRect;
252}

References d.

◆ documentRectChanged

void KoShapeQtQuickLabel::documentRectChanged ( )
signal

◆ fillColorChanged

void KoShapeQtQuickLabel::fillColorChanged ( )
signal

◆ foregroundColor()

QColor KoShapeQtQuickLabel::foregroundColor ( ) const

foregroundColor This is the color that is used as the fill for the KoShapes when fullColor is set false.

Definition at line 152 of file KoShapeQtQuickLabel.cpp.

153{
154 return d->fgColor;
155}

References d.

◆ foregroundColorChanged

void KoShapeQtQuickLabel::foregroundColorChanged ( )
signal

◆ fullColor()

bool KoShapeQtQuickLabel::fullColor ( ) const

fullColor This controls whether the current shape background will be set to the foreground color or whether it will keep the color it received during parsing of SVG data.

Definition at line 186 of file KoShapeQtQuickLabel.cpp.

187{
188 return d->fullColor;
189}

References d.

◆ fullColorChanged

void KoShapeQtQuickLabel::fullColorChanged ( )
signal

◆ minimumRect()

QRectF KoShapeQtQuickLabel::minimumRect ( ) const

minimumRect Minimum size rectangle, defined by either documentRect or loaded SVG contentRect, with padding attached. Use this when you want sensible minimum size. We cannot set this to implicitsize or the like, because implicit width and height need to be used when setting KoShapeQtQuickLabel as a content item to a QQuickControl.

Definition at line 262 of file KoShapeQtQuickLabel.cpp.

263{
264 const QRectF bounds = d->documentRect.isValid()? d->documentRect: d->shapePainter? d->shapePainter->contentRect(): QRectF();
265 return d->addPaddingToBounds(bounds);
266}
#define bounds(x, a, b)

References bounds, and d.

◆ minimumRectChanged

void KoShapeQtQuickLabel::minimumRectChanged ( )
signal

◆ padding()

int KoShapeQtQuickLabel::padding ( ) const

Padding of the documentView to the borders. This will add extra padding to the sides. If there's still paintable shape data in that padding, it will be drawn as well.

Definition at line 167 of file KoShapeQtQuickLabel.cpp.

168{
169 return (d->leftPadding + d->rightPadding + d->topPadding + d->bottomPadding) / 4;
170}

References d.

◆ paddingChanged

void KoShapeQtQuickLabel::paddingChanged ( )
signal

◆ paint()

void KoShapeQtQuickLabel::paint ( QPainter * painter)
override

Definition at line 97 of file KoShapeQtQuickLabel.cpp.

98{
99 if (!d->shapePainter) return;
100 if (!painter->isActive()) return;
101
102 const QRectF bbox = d->documentRect.isValid()? d->documentRect: d->shapePainter->contentRect();
103 const QRectF bounds = QRectF(0, 0, width(), height());
104
105 if (d->shapes.isEmpty()) {
106 return;
107 }
108
109 d->shapePainter->paint(*painter,
110 bounds.toAlignedRect(),
111 d->adjustBBoxToScaling(bbox, bounds));
112
113}

References bounds, and d.

◆ scalingType()

KoShapeQtQuickLabel::ScalingType KoShapeQtQuickLabel::scalingType ( ) const

scalingType

See also
ScalingType enum.

Definition at line 200 of file KoShapeQtQuickLabel.cpp.

201{
202 return d->scalingType;
203}

References d.

◆ scalingTypeChanged

void KoShapeQtQuickLabel::scalingTypeChanged ( )
signal

◆ setAlignment()

void KoShapeQtQuickLabel::setAlignment ( const Qt::Alignment align)

Definition at line 217 of file KoShapeQtQuickLabel.cpp.

218{
219 if (d->alignment == align) return;
220 d->alignment = align;
221 emit alignmentChanged();
222}

References alignmentChanged(), and d.

◆ setDocumentRect()

void KoShapeQtQuickLabel::setDocumentRect ( const QRectF & rect)

Definition at line 254 of file KoShapeQtQuickLabel.cpp.

255{
256 if (d->documentRect == rect) return;
257 d->documentRect = rect;
258 emit documentRectChanged();
259 emit minimumRectChanged();
260}

References d, documentRectChanged(), and minimumRectChanged().

◆ setForegroundColor()

void KoShapeQtQuickLabel::setForegroundColor ( const QColor & newForegroundColor)

Definition at line 157 of file KoShapeQtQuickLabel.cpp.

158{
159 if (d->fgColor == newForegroundColor)
160 return;
161
162 d->fgColor = newForegroundColor;
163 updateShapes();
165}
void foregroundColorChanged()

References d, foregroundColorChanged(), and updateShapes().

◆ setFullColor()

void KoShapeQtQuickLabel::setFullColor ( bool newFullColor)

Definition at line 191 of file KoShapeQtQuickLabel.cpp.

192{
193 if (d->fullColor == newFullColor)
194 return;
195 d->fullColor = newFullColor;
196
197 emit fullColorChanged();
198}

References d, and fullColorChanged().

◆ setPadding()

void KoShapeQtQuickLabel::setPadding ( int newPadding)

Definition at line 172 of file KoShapeQtQuickLabel.cpp.

173{
174 const int currentPadding = (d->leftPadding + d->rightPadding + d->topPadding + d->bottomPadding) / 4;
175 if (currentPadding == newPadding)
176 return;
177 d->leftPadding = newPadding;
178 d->rightPadding = newPadding;
179 d->topPadding = newPadding;
180 d->bottomPadding = newPadding;
181
182 emit paddingChanged();
183 emit minimumRectChanged();
184}

References d, minimumRectChanged(), and paddingChanged().

◆ setScalingType()

void KoShapeQtQuickLabel::setScalingType ( const ScalingType type)

Definition at line 205 of file KoShapeQtQuickLabel.cpp.

206{
207 if (d->scalingType == type) return;
208 d->scalingType = type;
209 emit scalingTypeChanged();
210}

References d, and scalingTypeChanged().

◆ setSvgData()

void KoShapeQtQuickLabel::setSvgData ( const QString & newSvgData)

Definition at line 120 of file KoShapeQtQuickLabel.cpp.

121{
122 if (d->svgData == newSvgData)
123 return;
124 d->svgData = newSvgData;
125
126 QDomDocument doc = SvgParser::createDocumentFromSvg(d->svgData);
127 KoDocumentResourceManager resourceManager;
128 SvgParser p(&resourceManager);
129 QRectF bb = QRectF( 0, 0, 200, 200);
130 QSizeF sz = bb.size();
131 p.setResolution(bb, 72);
132 p.setFillStrokeInheritByDefault(true);
133
134 QList<KoShape*> shapes = p.parseSvg(doc.documentElement(), &sz);
135
136 // TODO: Evaluate if this can't be faster.
137 d->shapePainter.reset(new KoShapePainter());
138
139 if (!d->shapes.isEmpty()) {
140 qDeleteAll(d->shapes);
141 }
142
143 d->shapes = shapes;
144 d->shapePainter->setShapes(d->shapes);
145
146 updateShapes();
147
148 emit svgDataChanged();
149 emit minimumRectChanged();
150}
const Params2D p
static QDomDocument createDocumentFromSvg(QIODevice *device, QString *errorMsg=0, int *errorLine=0, int *errorColumn=0)

References SvgParser::createDocumentFromSvg(), d, minimumRectChanged(), p, svgDataChanged(), and updateShapes().

◆ svgData()

QString KoShapeQtQuickLabel::svgData ( ) const

Definition at line 115 of file KoShapeQtQuickLabel.cpp.

116{
117 return d->svgData;
118}

References d.

◆ svgDataChanged

void KoShapeQtQuickLabel::svgDataChanged ( )
signal

◆ updateShapes

void KoShapeQtQuickLabel::updateShapes ( )
privateslot

Definition at line 231 of file KoShapeQtQuickLabel.cpp.

232{
233 if (!d->fullColor) {
235 for (int i = 0; i < d->shapes.size(); i++) {
236 d->shapes.at(i)->setBackground(bg);
237 }
238 }
240}
A simple solid color shape background.

References callUpdateIfComplete(), and d.

Member Data Documentation

◆ d

const QScopedPointer<Private> KoShapeQtQuickLabel::d
private

Definition at line 128 of file KoShapeQtQuickLabel.h.

Property Documentation

◆ alignment

Qt::Alignment KoShapeQtQuickLabel::alignment
readwrite

Definition at line 25 of file KoShapeQtQuickLabel.h.

◆ documentRect

QRectF KoShapeQtQuickLabel::documentRect
readwrite

Definition at line 26 of file KoShapeQtQuickLabel.h.

◆ foregroundColor

QColor KoShapeQtQuickLabel::foregroundColor
readwrite

Definition at line 21 of file KoShapeQtQuickLabel.h.

◆ fullColor

bool KoShapeQtQuickLabel::fullColor
readwrite

Definition at line 23 of file KoShapeQtQuickLabel.h.

◆ minimumRect

QRectF KoShapeQtQuickLabel::minimumRect
read

Definition at line 27 of file KoShapeQtQuickLabel.h.

◆ padding

int KoShapeQtQuickLabel::padding
readwrite

Definition at line 22 of file KoShapeQtQuickLabel.h.

◆ scalingType

ScalingType KoShapeQtQuickLabel::scalingType
readwrite

Definition at line 24 of file KoShapeQtQuickLabel.h.

◆ svgData

QString KoShapeQtQuickLabel::svgData
readwrite

Definition at line 20 of file KoShapeQtQuickLabel.h.


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