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

The KoCssStylePreset class. More...

#include <KoCssStylePreset.h>

+ Inheritance diagram for KoCssStylePreset:

Classes

struct  Private
 

Public Member Functions

QString afterText () const
 The text displayed after the sample, only relevant when in character mode.
 
Qt::Alignment alignSample () const
 
QString beforeText () const
 The text displayed before the sample. Only relevant when in Character mode.
 
KoResourceSP clone () const override
 
QString defaultFileExtension () const override
 
QString description () const
 The description associated with this style.
 
KoShapegenerateSampleShape () const
 generateSampleShape This generates the sample textshape from the properties and sample text(s).
 
 KoCssStylePreset (const KoCssStylePreset &rhs)
 
 KoCssStylePreset (const QString &filename)
 
bool loadFromDevice (QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override
 
KoCssStylePresetoperator= (const KoCssStylePreset &rhs)=delete
 
QString primaryFontFamily () const
 primaryFontFamily If a style uses a FontFamily, it may not look as expected when that font family is missing. Typically, we'd use linked resources for this, however, embedding fonts is really complex.
 
KoSvgTextProperties properties (int ppi=72, bool removeKraProps=false) const
 The actual text properties.
 
QPair< QString, QString > resourceType () const override
 
QString sampleSvg () const
 Returns the sample svg metadata. Use updateThumbnail to update it.
 
QString sampleText () const
 The sample text that is being styled by this preset.
 
bool saveToDevice (QIODevice *dev) const override
 
void setAfterText (const QString &text)
 set the after text. Call updateThumbnail to update the sample.
 
void setBeforeText (const QString &text)
 set the before text. Call updateThumbnail to update the sample.
 
void setDescription (const QString &desc)
 
void setProperties (const KoSvgTextProperties &properties)
 set the properties. Call updateThumbnail to update the sample.
 
void setSampleText (const QString &text)
 set the sample. Call updateThumbnail to update the sample.
 
void setStoredPPIResolution (const int ppi)
 
void setStyleType (const QString &type)
 
int storedPPIResolution () const
 
QString styleType () const
 Set the style type, type is either "paragraph" or "character".
 
void updateAlignSample ()
 
void updateThumbnail () override
 updateThumbnail updates the thumbnail for this resource. Reimplement if your thumbnail is something else than the image set with setImage.
 
 ~KoCssStylePreset ()
 
- 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.
 
bool valid () const
 
int version () const
 Get the version of the resource.
 
virtual ~KoResource ()
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Private Attributes

QScopedPointer< Privated
 

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 KoCssStylePreset class.

This is a Resource that represents style data. Internally, the style data is stored inside a text shape, allowing us to showcase the style data in context.

Definition at line 23 of file KoCssStylePreset.h.

Constructor & Destructor Documentation

◆ KoCssStylePreset() [1/2]

KoCssStylePreset::KoCssStylePreset ( const QString & filename)

Definition at line 48 of file KoCssStylePreset.cpp.

50 , d(new Private())
51{
52 setName(name().replace("_", " "));
53 if (name().endsWith(defaultFileExtension())) {
54 const QFileInfo f(name());
55 setName(f.completeBaseName());
56 }
57}
QString defaultFileExtension() const override
QScopedPointer< Private > d
QAction * replace(const QObject *recvr, const char *slot, QObject *parent)
void setName(const QString &name)
QString filename
QString name

References defaultFileExtension(), KoResource::name, and KoResource::setName().

◆ KoCssStylePreset() [2/2]

KoCssStylePreset::KoCssStylePreset ( const KoCssStylePreset & rhs)

Definition at line 59 of file KoCssStylePreset.cpp.

60 : KoResource(rhs)
61 , d(new Private())
62{
63 d->properties = rhs.d->properties;
64 d->sample = rhs.d->sample;
65 d->afterText = rhs.d->afterText;
66 d->beforeText = rhs.d->beforeText;
69 setValid(true);
70}
void setDescription(const QString &desc)
void updateThumbnail() override
updateThumbnail updates the thumbnail for this resource. Reimplement if your thumbnail is something e...
QString description() const
The description associated with this style.
void setValid(bool valid)

References d, description(), setDescription(), KoResource::setValid(), and updateThumbnail().

◆ ~KoCssStylePreset()

KoCssStylePreset::~KoCssStylePreset ( )

Definition at line 72 of file KoCssStylePreset.cpp.

73{
74
75}

Member Function Documentation

◆ afterText()

QString KoCssStylePreset::afterText ( ) const

The text displayed after the sample, only relevant when in character mode.

Definition at line 357 of file KoCssStylePreset.cpp.

358{
359 return d->afterText;
360}

References d.

◆ alignSample()

Qt::Alignment KoCssStylePreset::alignSample ( ) const

Determines the preferred sample alignment based on the text properties. It's set up so that the alignment anchor of the text is shown.

Definition at line 234 of file KoCssStylePreset.cpp.

235{
236 QMap<QString, QVariant> m = metadata();
237 QVariant v = m.value(SAMPLE_ALIGN, static_cast<Qt::Alignment::Int>(Qt::AlignHCenter | Qt::AlignVCenter));
238 return static_cast<Qt::Alignment>(v.value<Qt::Alignment::Int>());
239}
qreal v
const QString SAMPLE_ALIGN
QMap< QString, QVariant > metadata

References KoResource::metadata, SAMPLE_ALIGN, and v.

◆ beforeText()

QString KoCssStylePreset::beforeText ( ) const

The text displayed before the sample. Only relevant when in Character mode.

Definition at line 345 of file KoCssStylePreset.cpp.

346{
347 return d->beforeText;
348}

References d.

◆ clone()

KoResourceSP KoCssStylePreset::clone ( ) const
overridevirtual

Implements KoResource.

Definition at line 387 of file KoCssStylePreset.cpp.

388{
389 return KoResourceSP(new KoCssStylePreset(*this));
390}
KoCssStylePreset(const QString &filename)
QSharedPointer< KoResource > KoResourceSP

References KoCssStylePreset().

◆ defaultFileExtension()

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

Reimplemented from KoResource.

Definition at line 474 of file KoCssStylePreset.cpp.

475{
476 return ".svg";
477}

◆ description()

QString KoCssStylePreset::description ( ) const

The description associated with this style.

Definition at line 112 of file KoCssStylePreset.cpp.

113{
114 QMap<QString, QVariant> m = metadata();
115 return m[DESCRIPTION].toString();
116}
const QString DESCRIPTION

References DESCRIPTION, and KoResource::metadata.

◆ generateSampleShape()

KoShape * KoCssStylePreset::generateSampleShape ( ) const

generateSampleShape This generates the sample textshape from the properties and sample text(s).

For character the sample always needs to be set to be a child to ensure that the character property doesn't include the default props.

Definition at line 152 of file KoCssStylePreset.cpp.

153{
154 KoSvgTextProperties modifiedProps = d->properties;
155 const QString sample = d->sample;
156 const QString after = d->afterText;
157 const QString before = d->beforeText;
158
159 QScopedPointer<KoSvgTextShape> sampleText(new KoSvgTextShape());
160 sampleText->insertText(0, sample.isEmpty()? name().isEmpty()? SAMPLE_PLACEHOLDER.toString(): name(): sample);
161 const QString type = styleType().isEmpty()? STYLE_TYPE_CHARACTER: styleType();
162
163 bool removeParagraph = type == STYLE_TYPE_CHARACTER;
164
165 // Remove properties that cannot be edited.
166 Q_FOREACH(KoSvgTextProperties::PropertyId p, modifiedProps.properties()) {
168 if (removeParagraph) {
169 modifiedProps.removeProperty(p);
170 }
171 } else {
172 if (!removeParagraph) {
173 modifiedProps.removeProperty(p);
174 }
175 }
176
177 }
178 // This one is added after removing, because otherwise, the type is removed...
180 if (storedPPIResolution() > 0) {
182 } else {
184 }
185 // Always remove inline size, it is shape-specific.
187 // Remove fill and stroke for now as we have no widgets for them.
194
195 sampleText->setPropertiesAtPos(-1, modifiedProps);
196
197 if (type == STYLE_TYPE_PARAGRAPH) {
198 // For paragraph we'll add a shape, as those will allow wrapping,
199 // without being part of the properties like inline-size is.
200 KoPathShape *inlineShape = new KoPathShape();
201 inlineShape->moveTo(QPointF(0, 0));
202 inlineShape->lineTo(QPointF(120, 0));
203 inlineShape->lineTo(QPointF(120, 120));
204 inlineShape->lineTo(QPointF(0, 120));
205 inlineShape->lineTo(QPointF(0, 0));
206 inlineShape->close();
207 sampleText->setShapesInside({inlineShape});
208 sampleText->relayout();
209
210 return sampleText.take();
211 } else {
214 QScopedPointer<KoSvgTextShape> newShape(new KoSvgTextShape());
216 // Set whitespace rule to pre-wrap.
219 newShape->setPropertiesAtPos(-1, paraProps);
220 if (!after.isEmpty()) {
221 newShape->insertText(0, after);
222 }
223 if (!before.isEmpty()) {
224 newShape->insertText(0, before);
225 }
226
227 newShape->insertRichText(newShape->posForIndex(before.size()), sampleText.data());
228 return newShape.take();
229 }
230
231 return nullptr;
232}
const Params2D p
const QString STYLE_TYPE_PARAGRAPH
const QString STYLE_TYPE_CHARACTER
const KLocalizedString SAMPLE_PLACEHOLDER
QString sampleText() const
The sample text that is being styled by this preset.
int storedPPIResolution() const
QString styleType() const
Set the style type, type is either "paragraph" or "character".
The position of a path point within a path shape.
Definition KoPathShape.h:63
KoPathPoint * lineTo(const QPointF &p)
Adds a new line segment.
void close()
Closes the current subpath.
KoPathPoint * moveTo(const QPointF &p)
Starts a new Subpath.
@ Visiblity
Bool, CSS visibility.
@ InlineSizeId
KoSvgText::AutoValue.
@ PaintOrder
QVector<KoShape::PaintOrder>
@ KraTextStyleResolution
Int, used to scale style presets to be pixel-relative.
@ Opacity
Double, SVG shape opacity.
@ KraTextStyleType
string, used to identify the style preset type (character or paragraph).
@ TextOrientationId
KoSvgText::TextOrientation.
@ TextCollapseId
KoSvgText::TextSpaceCollapse.
@ StrokeId
KoSvgText::StrokeProperty.
@ FillId
KoSvgText::BackgroundProperty.
@ TextWrapId
KoSvgText::TextWrap.
void removeProperty(PropertyId id)
QList< PropertyId > properties() const
static bool propertyIsBlockOnly(KoSvgTextProperties::PropertyId id)
static const KoSvgTextProperties & defaultProperties()
void setProperty(PropertyId id, const QVariant &value)
@ Preserve
Do not collapse any space.
Definition KoSvgText.h:99

References KoPathShape::close(), d, KoSvgTextProperties::defaultProperties(), KoSvgTextProperties::FillId, KoSvgTextProperties::InlineSizeId, KoSvgTextProperties::KraTextStyleResolution, KoSvgTextProperties::KraTextStyleType, KoPathShape::lineTo(), KoPathShape::moveTo(), KoResource::name, KoSvgTextProperties::Opacity, p, KoSvgTextProperties::PaintOrder, KoSvgText::Preserve, KoSvgTextProperties::properties(), KoSvgTextProperties::propertyIsBlockOnly(), KoSvgTextProperties::removeProperty(), SAMPLE_PLACEHOLDER, sampleText(), KoSvgTextProperties::setProperty(), storedPPIResolution(), KoSvgTextProperties::StrokeId, STYLE_TYPE_CHARACTER, STYLE_TYPE_PARAGRAPH, styleType(), KoSvgTextProperties::TextCollapseId, KoSvgTextProperties::TextOrientationId, KoSvgTextProperties::TextWrapId, KoSvgTextProperties::Visiblity, and KoSvgText::Wrap.

◆ loadFromDevice()

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

Implements KoResource.

Definition at line 392 of file KoCssStylePreset.cpp.

393{
394 Q_UNUSED(resourcesInterface)
395 if (!dev->isOpen()) dev->open(QIODevice::ReadOnly);
396 QString errorMsg;
397 int errorLine = 0;
398 int errorColumn = 0;
399 QDomDocument xmlDocument = SvgParser::createDocumentFromSvg(dev, &errorMsg, &errorLine, &errorColumn);
400 if (xmlDocument.isNull()) {
401
402 errorFlake << "Parsing error in " << filename() << "! Aborting!" << Qt::endl
403 << " In line: " << errorLine << ", column: " << errorColumn << Qt::endl
404 << " Error message: " << errorMsg << Qt::endl;
405 errorFlake << "Parsing error in the main document at line" << errorLine
406 << ", column" << errorColumn << Qt::endl
407 << "Error message: " << errorMsg;
408
409 return false;
410 }
411
413 SvgParser parser(&manager);
414 parser.setResolution(QRectF(0,0,100,100), 72); // initialize with default values
415 parser.setResolveTextPropertiesForTopLevel(false);
416 QSizeF fragmentSize;
417
418 QList<KoShape*> shapes = parser.parseSvg(xmlDocument.documentElement(), &fragmentSize);
419
420 Q_FOREACH(KoShape *shape, shapes) {
421 KoSvgTextShape *textShape = dynamic_cast<KoSvgTextShape*>(shape);
422 if (textShape) {
423 setName(textShape->additionalAttribute(TITLE));
427 if (node.properties()) {
428 KoSvgTextProperties props = *(node.properties());
432 }
434 QStringList fonts = props.property(KoSvgTextProperties::FontFamiliesId).toStringList();
435 addMetaData(PRIMARY_FONT_FAMILY, fonts.value(0));
436 }
437 setProperties(props);
438
439 QPair<int, int> pos = textShape->findRangeForNodeIndex(node);
440 pos.first = textShape->indexForPos(pos.first);
441 pos.second = textShape->indexForPos(pos.second);
442
443 d->sample = textShape->plainText().mid(pos.first, pos.second-pos.first);
444 d->beforeText = textShape->plainText().mid(0, pos.first);
445 d->afterText = textShape->plainText().mid(pos.second);
446 }
447
449
451 setValid(true);
452 return true;
453 }
454 }
455
456
457 return false;
458}
#define errorFlake
Definition FlakeDebug.h:17
const QString TITLE
const QString DESC
const QString STYLE_TYPE
const QString PRIMARY_FONT_FAMILY
const QString STORED_PPI
void setProperties(const KoSvgTextProperties &properties)
set the properties. Call updateThumbnail to update the sample.
QString additionalAttribute(const QString &name) const
Definition KoShape.cpp:1279
The KoSvgTextNodeIndex class.
KoSvgTextProperties * properties()
properties The properties for this node as a pointer.
QVariant property(PropertyId id, const QVariant &defaultValue=QVariant()) const
bool hasProperty(PropertyId id) const
QPair< int, int > findRangeForNodeIndex(const KoSvgTextNodeIndex &node) const
findRangeForNodeIndex Find the start and end cursor position for a given nodeIndex.
KoSvgTextNodeIndex findNodeIndexForPropertyId(KoSvgTextProperties::PropertyId propertyId)
findNodeIndexForPropertyId
int indexForPos(int pos) const
indexForPos get the string index for a given cursor position.
static QDomDocument createDocumentFromSvg(QIODevice *device, QString *errorMsg=0, int *errorLine=0, int *errorColumn=0)
void addMetaData(QString key, QVariant value)
store the given key, value pair in the resource

References KoShape::additionalAttribute(), KoResource::addMetaData(), SvgParser::createDocumentFromSvg(), d, DESC, DESCRIPTION, errorFlake, KoResource::filename, KoSvgTextShape::findNodeIndexForPropertyId(), KoSvgTextShape::findRangeForNodeIndex(), KoSvgTextProperties::FontFamiliesId, KoSvgTextProperties::hasProperty(), KoSvgTextShape::indexForPos(), KoSvgTextProperties::KraTextStyleResolution, KoSvgTextProperties::KraTextStyleType, SvgParser::parseSvg(), KoSvgTextShape::plainText, PRIMARY_FONT_FAMILY, KoSvgTextNodeIndex::properties(), KoSvgTextProperties::property(), KoResource::setName(), setProperties(), SvgParser::setResolution(), SvgParser::setResolveTextPropertiesForTopLevel(), KoResource::setValid(), STORED_PPI, STYLE_TYPE, STYLE_TYPE_PARAGRAPH, styleType(), TITLE, and updateThumbnail().

◆ operator=()

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

◆ primaryFontFamily()

QString KoCssStylePreset::primaryFontFamily ( ) const

primaryFontFamily If a style uses a FontFamily, it may not look as expected when that font family is missing. Typically, we'd use linked resources for this, however, embedding fonts is really complex.

Returns
the primary font family for this style, will return empty if the style does not require a font family.

Definition at line 241 of file KoCssStylePreset.cpp.

242{
243 QMap<QString, QVariant> m = metadata();
244 return m.value(PRIMARY_FONT_FAMILY).toString();
245}

References KoResource::metadata, and PRIMARY_FONT_FAMILY.

◆ properties()

KoSvgTextProperties KoCssStylePreset::properties ( int ppi = 72,
bool removeKraProps = false ) const

The actual text properties.

Definition at line 77 of file KoCssStylePreset.cpp.

78{
80 const int storedPPI = storedPPIResolution();
81 if (storedPPI > 0 && ppi > 0) {
82 const double scale = double(storedPPI)/double(ppi);
83 props.scaleAbsoluteValues(scale, scale);
84 }
85 if (removeKraProps) {
89 }
90 // remove fill and stroke for now.
97 return props;
98}
@ KraTextVersionId
Int, used for handling incorrectly saved files.
void scaleAbsoluteValues(const double scaleInline=1.0, const double scaleBlock=1.0)
scaleAbsoluteValues This scales all absolute values stored in these text properties....

References d, KoSvgTextProperties::FillId, KoSvgTextProperties::KraTextStyleResolution, KoSvgTextProperties::KraTextStyleType, KoSvgTextProperties::KraTextVersionId, KoSvgTextProperties::Opacity, KoSvgTextProperties::PaintOrder, KoSvgTextProperties::properties(), KoSvgTextProperties::removeProperty(), KoSvgTextProperties::scaleAbsoluteValues(), storedPPIResolution(), KoSvgTextProperties::StrokeId, KoSvgTextProperties::TextOrientationId, and KoSvgTextProperties::Visiblity.

◆ resourceType()

QPair< QString, QString > KoCssStylePreset::resourceType ( ) const
overridevirtual
Returns
the resource type

Implements KoResource.

Definition at line 510 of file KoCssStylePreset.cpp.

511{
512 return QPair<QString, QString>(ResourceType::CssStyles, "");
513}
const QString CssStyles

References ResourceType::CssStyles.

◆ sampleSvg()

QString KoCssStylePreset::sampleSvg ( ) const

Returns the sample svg metadata. Use updateThumbnail to update it.

Definition at line 369 of file KoCssStylePreset.cpp.

370{
371 QMap<QString, QVariant> m = metadata();
372 return m[SAMPLE_SVG].toString();
373}
const QString SAMPLE_SVG

References KoResource::metadata, and SAMPLE_SVG.

◆ sampleText()

QString KoCssStylePreset::sampleText ( ) const

The sample text that is being styled by this preset.

Definition at line 140 of file KoCssStylePreset.cpp.

141{
142 return d->sample;
143}

References d.

◆ saveToDevice()

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

Reimplemented from KoResource.

Definition at line 460 of file KoCssStylePreset.cpp.

461{
462 QScopedPointer<KoShape> shape(generateSampleShape());
463 if (!shape) return false;
464
465 QMap<QString, QVariant> m = metadata();
466 shape->setAdditionalAttribute(DESC, m[DESCRIPTION].toString());
467 shape->setAdditionalAttribute(TITLE, name());
468
469 const QRectF boundingRect = shape->boundingRect();
470 SvgWriter writer({shape.take()});
471 return writer.save(*dev, boundingRect.size());
472}
KoShape * generateSampleShape() const
generateSampleShape This generates the sample textshape from the properties and sample text(s).
Implements exporting shapes to SVG.
Definition SvgWriter.h:33
bool save(QIODevice &outputDevice, const QSizeF &pageSize)
Writes svg to specified output device.
Definition SvgWriter.cpp:82
QString toString(const QString &value)

References DESC, DESCRIPTION, generateSampleShape(), KoResource::metadata, KoResource::name, SvgWriter::save(), and TITLE.

◆ setAfterText()

void KoCssStylePreset::setAfterText ( const QString & text)

set the after text. Call updateThumbnail to update the sample.

Definition at line 362 of file KoCssStylePreset.cpp.

363{
364 if (d->afterText == text) return;
365 d->afterText = text;
366 setDirty(true);
367}
void setDirty(bool value)
Mark the preset as modified but not saved.

References d, and KoResource::setDirty().

◆ setBeforeText()

void KoCssStylePreset::setBeforeText ( const QString & text)

set the before text. Call updateThumbnail to update the sample.

Definition at line 350 of file KoCssStylePreset.cpp.

351{
352 if (d->beforeText == text) return;
353 d->beforeText = text;
354 setDirty(true);
355}

References d, and KoResource::setDirty().

◆ setDescription()

void KoCssStylePreset::setDescription ( const QString & desc)

Definition at line 118 of file KoCssStylePreset.cpp.

119{
120 QMap<QString, QVariant> m = metadata();
121 if (m[DESCRIPTION].toString() == desc) return;
123 setDirty(true);
124}

References KoResource::addMetaData(), DESCRIPTION, KoResource::metadata, and KoResource::setDirty().

◆ setProperties()

void KoCssStylePreset::setProperties ( const KoSvgTextProperties & properties)

set the properties. Call updateThumbnail to update the sample.

Definition at line 100 of file KoCssStylePreset.cpp.

101{
102 if (d->properties == properties)
103 return;
104 d->properties = properties;
105 QStringList fonts = d->properties.property(KoSvgTextProperties::FontFamiliesId).toStringList();
106 //TODO: Apparantly we cannot remove metadata, only set it to nothing...
107 addMetaData(PRIMARY_FONT_FAMILY, fonts.value(0));
108 setValid(true);
109 setDirty(true);
110}
KoSvgTextProperties properties(int ppi=72, bool removeKraProps=false) const
The actual text properties.

References KoResource::addMetaData(), d, KoSvgTextProperties::FontFamiliesId, PRIMARY_FONT_FAMILY, KoSvgTextProperties::properties(), properties(), KoResource::setDirty(), and KoResource::setValid().

◆ setSampleText()

void KoCssStylePreset::setSampleText ( const QString & text)

set the sample. Call updateThumbnail to update the sample.

Definition at line 145 of file KoCssStylePreset.cpp.

146{
147 if (d->sample == text) return;
148 d->sample = text;
149 setDirty(true);
150}

References d, and KoResource::setDirty().

◆ setStoredPPIResolution()

void KoCssStylePreset::setStoredPPIResolution ( const int ppi)

Definition at line 381 of file KoCssStylePreset.cpp.

382{
384}

References KoResource::addMetaData(), and STORED_PPI.

◆ setStyleType()

void KoCssStylePreset::setStyleType ( const QString & type)

Definition at line 132 of file KoCssStylePreset.cpp.

133{
134 QMap<QString, QVariant> m = metadata();
135 if (m[STYLE_TYPE].toString() == type) return;
136 addMetaData(STYLE_TYPE, type);
137 setDirty(true);
138}

References KoResource::addMetaData(), KoResource::metadata, KoResource::setDirty(), and STYLE_TYPE.

◆ storedPPIResolution()

int KoCssStylePreset::storedPPIResolution ( ) const

The resolution that this style is tied to. if this is above 0, then the properties absolute values are scaled by to fit the document resolution. This allows for pixel-relative styles to be created.

Definition at line 375 of file KoCssStylePreset.cpp.

376{
377 QMap<QString, QVariant> m = metadata();
378 return m.value(STORED_PPI, 0).toInt();
379}

References KoResource::metadata, and STORED_PPI.

◆ styleType()

QString KoCssStylePreset::styleType ( ) const

Set the style type, type is either "paragraph" or "character".

Definition at line 126 of file KoCssStylePreset.cpp.

127{
128 QMap<QString, QVariant> m = metadata();
129 return m.value(STYLE_TYPE, STYLE_TYPE_PARAGRAPH).toString();
130}

References KoResource::metadata, STYLE_TYPE, and STYLE_TYPE_PARAGRAPH.

◆ updateAlignSample()

void KoCssStylePreset::updateAlignSample ( )

Definition at line 247 of file KoCssStylePreset.cpp.

248{
249 Qt::AlignmentFlag hComponent = Qt::AlignHCenter;
250 Qt::AlignmentFlag vComponent = Qt::AlignVCenter;
251
252 const KoSvgTextProperties props = d->properties;
253 const QString type = styleType().isEmpty()? props.property(KoSvgTextProperties::KraTextStyleType).toString(): styleType();
254 if (type == STYLE_TYPE_PARAGRAPH) {
257 const bool textAlignLast = props.hasProperty(KoSvgTextProperties::TextAlignLastId);
258 if (props.hasProperty(KoSvgTextProperties::TextAlignAllId) || textAlignLast) {
260 : KoSvgText::TextAlign(props.property(KoSvgTextProperties::TextAlignAllId).toInt());
261
262 if (mode == KoSvgText::HorizontalTB) {
263 vComponent = Qt::AlignTop;
264 if (align == KoSvgText::AlignStart || align == KoSvgText::AlignLastAuto) {
266 hComponent = Qt::AlignLeft;
267 } else {
268 hComponent = Qt::AlignRight;
269 }
270 } else if (align == KoSvgText::AlignEnd) {
272 hComponent = Qt::AlignRight;
273 } else {
274 hComponent = Qt::AlignLeft;
275 }
276 } else if (align == KoSvgText::AlignLeft) {
277 hComponent = Qt::AlignLeft;
278 } else if (align == KoSvgText::AlignRight) {
279 hComponent = Qt::AlignRight;
280 }
281 } else {
282 hComponent = mode == KoSvgText::VerticalRL? Qt::AlignRight: Qt::AlignLeft;
283 if (align == KoSvgText::AlignStart || align == KoSvgText::AlignLastAuto) {
285 vComponent = Qt::AlignTop;
286 } else {
287 vComponent = Qt::AlignBottom;
288 }
289 } else if (align == KoSvgText::AlignEnd) {
291 vComponent = Qt::AlignBottom;
292 } else {
293 vComponent = Qt::AlignTop;
294 }
295 } else if (align == KoSvgText::AlignLeft) {
296 vComponent = Qt::AlignTop;
297 } else if (align == KoSvgText::AlignRight) {
298 vComponent = Qt::AlignBottom;
299 }
300 }
301 } else {
303
304 if (mode == KoSvgText::HorizontalTB) {
305 vComponent = Qt::AlignTop;
306 if (anchor == KoSvgText::AnchorStart) {
308 hComponent = Qt::AlignLeft;
309 } else {
310 hComponent = Qt::AlignRight;
311 }
312 } else if (anchor == KoSvgText::AnchorEnd) {
314 hComponent = Qt::AlignRight;
315 } else {
316 hComponent = Qt::AlignLeft;
317 }
318 } else {
319 hComponent = Qt::AlignHCenter;
320 }
321 } else {
322 hComponent = mode == KoSvgText::VerticalRL? Qt::AlignRight: Qt::AlignLeft;
323 if (anchor == KoSvgText::AnchorStart) {
325 vComponent = Qt::AlignTop;
326 } else {
327 vComponent = Qt::AlignBottom;
328 }
329 } else if (anchor == KoSvgText::AnchorEnd) {
331 vComponent = Qt::AlignBottom;
332 } else {
333 vComponent = Qt::AlignTop;
334 }
335 } else {
336 vComponent = Qt::AlignVCenter;
337 }
338 }
339 }
340 }
341
342 addMetaData(SAMPLE_ALIGN, static_cast<Qt::Alignment::Int>(hComponent | vComponent));
343}
@ TextAnchorId
KoSvgText::TextAnchor.
@ TextAlignAllId
KoSvgText::TextAlign.
@ WritingModeId
KoSvgText::WritingMode.
@ DirectionId
KoSvgText::Direction.
@ TextAlignLastId
KoSvgText::TextAlign.
QVariant propertyOrDefault(PropertyId id) const
int toInt(const QString &str, bool *ok=nullptr)
@ AlignLastAuto
Definition KoSvgText.h:163
TextAnchor
Where the text is anchored for SVG 1.1 text and 'inline-size'.
Definition KoSvgText.h:79
@ AnchorEnd
Anchor right for LTR, left for RTL.
Definition KoSvgText.h:82
@ AnchorStart
Anchor left for LTR, right for RTL.
Definition KoSvgText.h:80
Direction
Base direction used by Bidi algorithm.
Definition KoSvgText.h:48
@ DirectionLeftToRight
Definition KoSvgText.h:49
@ HorizontalTB
Definition KoSvgText.h:38

References KoResource::addMetaData(), KoSvgText::AlignEnd, KoSvgText::AlignLastAuto, KoSvgText::AlignLeft, KoSvgText::AlignRight, KoSvgText::AlignStart, KoSvgText::AnchorEnd, KoSvgText::AnchorStart, d, KoSvgTextProperties::DirectionId, KoSvgText::DirectionLeftToRight, KoSvgTextProperties::hasProperty(), KoSvgText::HorizontalTB, KoSvgTextProperties::KraTextStyleType, KoSvgTextProperties::properties(), KoSvgTextProperties::property(), KoSvgTextProperties::propertyOrDefault(), SAMPLE_ALIGN, STYLE_TYPE_PARAGRAPH, styleType(), KoSvgTextProperties::TextAlignAllId, KoSvgTextProperties::TextAlignLastId, KoSvgTextProperties::TextAnchorId, KoSvgText::VerticalRL, and KoSvgTextProperties::WritingModeId.

◆ updateThumbnail()

void KoCssStylePreset::updateThumbnail ( )
overridevirtual

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

generate SVG sample.

Reimplemented from KoResource.

Definition at line 490 of file KoCssStylePreset.cpp.

491{
492 QScopedPointer<KoSvgTextShape> shape (dynamic_cast<KoSvgTextShape*>(generateSampleShape()));
493 if (!shape) return;
494 QImage img(256,
495 256,
496 QImage::Format_ARGB32);
497 img.fill(Qt::white);
498
499 KoShapePainter painter;
500 painter.setShapes({shape.data()});
501 painter.paint(img);
502
504 addMetaData(SAMPLE_SVG, generateSVG(shape.data()));
506
507 setImage(img);
508}
QString generateSVG(const KoSvgTextShape *shape)
void setShapes(const QList< KoShape * > &shapes)
void paint(QPainter &painter)
void setImage(const QImage &image)

References KoResource::addMetaData(), generateSampleShape(), generateSVG(), KoShapePainter::paint(), SAMPLE_SVG, KoResource::setImage(), KoShapePainter::setShapes(), and updateAlignSample().

Member Data Documentation

◆ d

QScopedPointer<Private> KoCssStylePreset::d
private

Definition at line 108 of file KoCssStylePreset.h.


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