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
 
QSizeF paragraphSampleSize () const
 Returns the size of the shape which the paragraph is set as.
 
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 setParagraphSampleSize (const QSizeF size)
 Set the size of the shape the paragraph is set in.
 
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 50 of file KoCssStylePreset.cpp.

52 , d(new Private())
53{
54 setName(name().replace("_", " "));
55 if (name().endsWith(defaultFileExtension())) {
56 const QFileInfo f(name());
57 setName(f.completeBaseName());
58 }
59}
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 61 of file KoCssStylePreset.cpp.

62 : KoResource(rhs)
63 , d(new Private())
64{
65 d->properties = rhs.d->properties;
66 d->sample = rhs.d->sample;
67 d->afterText = rhs.d->afterText;
68 d->beforeText = rhs.d->beforeText;
71 setValid(true);
72}
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 74 of file KoCssStylePreset.cpp.

75{
76
77}

Member Function Documentation

◆ afterText()

QString KoCssStylePreset::afterText ( ) const

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

Definition at line 354 of file KoCssStylePreset.cpp.

355{
356 return d->afterText;
357}

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 231 of file KoCssStylePreset.cpp.

232{
233 QMap<QString, QVariant> m = metadata();
234 QVariant v = m.value(SAMPLE_ALIGN, static_cast<Qt::Alignment::Int>(Qt::AlignHCenter | Qt::AlignVCenter));
235 return static_cast<Qt::Alignment>(v.value<Qt::Alignment::Int>());
236}
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 342 of file KoCssStylePreset.cpp.

343{
344 return d->beforeText;
345}

References d.

◆ clone()

KoResourceSP KoCssStylePreset::clone ( ) const
overridevirtual

Implements KoResource.

Definition at line 395 of file KoCssStylePreset.cpp.

396{
397 return KoResourceSP(new KoCssStylePreset(*this));
398}
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 487 of file KoCssStylePreset.cpp.

488{
489 return ".svg";
490}

◆ description()

QString KoCssStylePreset::description ( ) const

The description associated with this style.

Definition at line 114 of file KoCssStylePreset.cpp.

115{
116 QMap<QString, QVariant> m = metadata();
117 return m[DESCRIPTION].toString();
118}
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 154 of file KoCssStylePreset.cpp.

155{
156 KoSvgTextProperties modifiedProps = d->properties;
157 const QString sample = d->sample;
158 const QString after = d->afterText;
159 const QString before = d->beforeText;
160
161 QScopedPointer<KoSvgTextShape> sampleText(new KoSvgTextShape());
162 sampleText->insertText(0, sample.isEmpty()? name().isEmpty()? SAMPLE_PLACEHOLDER.toString(): name(): sample);
163 const QString type = styleType().isEmpty()? STYLE_TYPE_CHARACTER: styleType();
164
165 bool removeParagraph = type == STYLE_TYPE_CHARACTER;
166
167 // Remove properties that cannot be edited.
168 Q_FOREACH(KoSvgTextProperties::PropertyId p, modifiedProps.properties()) {
169 if (KoSvgTextProperties::propertyIsBlockOnly(p) && removeParagraph) {
170 modifiedProps.removeProperty(p);
171 }
172 }
173 // This one is added after removing, because otherwise, the type is removed...
175 if (storedPPIResolution() > 0) {
177 } else {
179 }
180 // Always remove inline size, it is shape-specific.
182 // Remove fill and stroke for now as we have no widgets for them.
189
190 sampleText->setPropertiesAtPos(-1, modifiedProps);
191
192
193 if (type == STYLE_TYPE_PARAGRAPH) {
194 const QSizeF sampleSize = d->paragraphSampleSize;
195 // For paragraph we'll add a shape, as those will allow wrapping,
196 // without being part of the properties like inline-size is.
197 KoPathShape *inlineShape = new KoPathShape();
198 inlineShape->moveTo(QPointF(0, 0));
199 inlineShape->lineTo(QPointF(sampleSize.width(), 0));
200 inlineShape->lineTo(QPointF(sampleSize.width(), sampleSize.height()));
201 inlineShape->lineTo(QPointF(0, sampleSize.height()));
202 inlineShape->lineTo(QPointF(0, 0));
203 inlineShape->close();
204 sampleText->setShapesInside({inlineShape});
205 sampleText->relayout();
206
207 return sampleText.take();
208 } else {
211 QScopedPointer<KoSvgTextShape> newShape(new KoSvgTextShape());
213 // Set whitespace rule to pre-wrap.
216 newShape->setPropertiesAtPos(-1, paraProps);
217 if (!after.isEmpty()) {
218 newShape->insertText(0, after);
219 }
220 if (!before.isEmpty()) {
221 newShape->insertText(0, before);
222 }
223
224 newShape->insertRichText(newShape->posForIndex(before.size()), sampleText.data());
225 return newShape.take();
226 }
227
228 return nullptr;
229}
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.
@ 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.
@ Visibility
Bool, CSS visibility.
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::Visibility, and KoSvgText::Wrap.

◆ loadFromDevice()

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

Implements KoResource.

Definition at line 400 of file KoCssStylePreset.cpp.

401{
402 Q_UNUSED(resourcesInterface)
403 if (!dev->isOpen()) dev->open(QIODevice::ReadOnly);
404 QString errorMsg;
405 int errorLine = 0;
406 int errorColumn = 0;
407 QDomDocument xmlDocument = SvgParser::createDocumentFromSvg(dev, &errorMsg, &errorLine, &errorColumn);
408 if (xmlDocument.isNull()) {
409
410 errorFlake << "Parsing error in " << filename() << "! Aborting!" << Qt::endl
411 << " In line: " << errorLine << ", column: " << errorColumn << Qt::endl
412 << " Error message: " << errorMsg << Qt::endl;
413 errorFlake << "Parsing error in the main document at line" << errorLine
414 << ", column" << errorColumn << Qt::endl
415 << "Error message: " << errorMsg;
416
417 return false;
418 }
419
421 SvgParser parser(&manager);
422 parser.setResolution(QRectF(0,0,100,100), 72); // initialize with default values
423 parser.setResolveTextPropertiesForTopLevel(false);
424 QSizeF fragmentSize;
425
426 QList<KoShape*> shapes = parser.parseSvg(xmlDocument.documentElement(), &fragmentSize);
427
428 Q_FOREACH(KoShape *shape, shapes) {
429 KoSvgTextShape *textShape = dynamic_cast<KoSvgTextShape*>(shape);
430 if (textShape) {
431 setName(textShape->additionalAttribute(TITLE));
435 if (node.properties()) {
436 KoSvgTextProperties props = *(node.properties());
440 }
442 QStringList fonts = props.property(KoSvgTextProperties::FontFamiliesId).toStringList();
443 addMetaData(PRIMARY_FONT_FAMILY, fonts.value(0));
444 }
445 setProperties(props);
446
447 QPair<int, int> pos = textShape->findRangeForNodeIndex(node);
448 pos.first = textShape->indexForPos(pos.first);
449 pos.second = textShape->indexForPos(pos.second);
450
451 d->sample = textShape->plainText().mid(pos.first, pos.second-pos.first);
452 d->beforeText = textShape->plainText().mid(0, pos.first);
453 d->afterText = textShape->plainText().mid(pos.second);
454
455 if (!textShape->shapesInside().isEmpty() && styleType == STYLE_TYPE_PARAGRAPH) {
456 d->paragraphSampleSize = textShape->shapesInside().first()->size();
457 }
458
459 }
460
462
464 setValid(true);
465 return true;
466 }
467 }
468
469
470 return false;
471}
#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:1087
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.
QList< KoShape * > shapesInside
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(), KoSvgTextShape::shapesInside, STORED_PPI, STYLE_TYPE, STYLE_TYPE_PARAGRAPH, styleType(), TITLE, and updateThumbnail().

◆ operator=()

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

◆ paragraphSampleSize()

QSizeF KoCssStylePreset::paragraphSampleSize ( ) const

Returns the size of the shape which the paragraph is set as.

Definition at line 372 of file KoCssStylePreset.cpp.

373{
374 return d->paragraphSampleSize;
375}

References d.

◆ 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 238 of file KoCssStylePreset.cpp.

239{
240 QMap<QString, QVariant> m = metadata();
241 return m.value(PRIMARY_FONT_FAMILY).toString();
242}

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 79 of file KoCssStylePreset.cpp.

80{
82 const int storedPPI = storedPPIResolution();
83 if (storedPPI > 0 && ppi > 0) {
84 const double scale = double(storedPPI)/double(ppi);
85 props.scaleAbsoluteValues(scale, scale);
86 }
87 if (removeKraProps) {
91 }
92 // remove fill and stroke for now.
99 return props;
100}
@ 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::Visibility.

◆ resourceType()

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

Implements KoResource.

Definition at line 523 of file KoCssStylePreset.cpp.

524{
525 return QPair<QString, QString>(ResourceType::CssStyles, "");
526}
const QString CssStyles

References ResourceType::CssStyles.

◆ sampleSvg()

QString KoCssStylePreset::sampleSvg ( ) const

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

Definition at line 366 of file KoCssStylePreset.cpp.

367{
368 QMap<QString, QVariant> m = metadata();
369 return m[SAMPLE_SVG].toString();
370}
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 142 of file KoCssStylePreset.cpp.

143{
144 return d->sample;
145}

References d.

◆ saveToDevice()

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

Reimplemented from KoResource.

Definition at line 473 of file KoCssStylePreset.cpp.

474{
475 QScopedPointer<KoShape> shape(generateSampleShape());
476 if (!shape) return false;
477
478 QMap<QString, QVariant> m = metadata();
479 shape->setAdditionalAttribute(DESC, m[DESCRIPTION].toString());
480 shape->setAdditionalAttribute(TITLE, name());
481
482 const QRectF boundingRect = shape->boundingRect();
483 SvgWriter writer({shape.take()});
484 return writer.save(*dev, boundingRect.size());
485}
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 359 of file KoCssStylePreset.cpp.

360{
361 if (d->afterText == text) return;
362 d->afterText = text;
363 setDirty(true);
364}
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 347 of file KoCssStylePreset.cpp.

348{
349 if (d->beforeText == text) return;
350 d->beforeText = text;
351 setDirty(true);
352}

References d, and KoResource::setDirty().

◆ setDescription()

void KoCssStylePreset::setDescription ( const QString & desc)

Definition at line 120 of file KoCssStylePreset.cpp.

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

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

◆ setParagraphSampleSize()

void KoCssStylePreset::setParagraphSampleSize ( const QSizeF size)

Set the size of the shape the paragraph is set in.

Definition at line 377 of file KoCssStylePreset.cpp.

378{
379 d->paragraphSampleSize = size;
380 setDirty(true);
381}
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References d, and KoResource::setDirty().

◆ setProperties()

void KoCssStylePreset::setProperties ( const KoSvgTextProperties & properties)

set the properties. Call updateThumbnail to update the sample.

Definition at line 102 of file KoCssStylePreset.cpp.

103{
104 if (d->properties == properties)
105 return;
106 d->properties = properties;
107 QStringList fonts = d->properties.property(KoSvgTextProperties::FontFamiliesId).toStringList();
108 //TODO: Apparantly we cannot remove metadata, only set it to nothing...
109 addMetaData(PRIMARY_FONT_FAMILY, fonts.value(0));
110 setValid(true);
111 setDirty(true);
112}
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 147 of file KoCssStylePreset.cpp.

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

References d, and KoResource::setDirty().

◆ setStoredPPIResolution()

void KoCssStylePreset::setStoredPPIResolution ( const int ppi)

Definition at line 389 of file KoCssStylePreset.cpp.

390{
392}

References KoResource::addMetaData(), and STORED_PPI.

◆ setStyleType()

void KoCssStylePreset::setStyleType ( const QString & type)

Definition at line 134 of file KoCssStylePreset.cpp.

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

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 383 of file KoCssStylePreset.cpp.

384{
385 QMap<QString, QVariant> m = metadata();
386 return m.value(STORED_PPI, 0).toInt();
387}

References KoResource::metadata, and STORED_PPI.

◆ styleType()

QString KoCssStylePreset::styleType ( ) const

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

Definition at line 128 of file KoCssStylePreset.cpp.

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

References KoResource::metadata, STYLE_TYPE, and STYLE_TYPE_PARAGRAPH.

◆ updateAlignSample()

void KoCssStylePreset::updateAlignSample ( )

Definition at line 244 of file KoCssStylePreset.cpp.

245{
246 Qt::AlignmentFlag hComponent = Qt::AlignHCenter;
247 Qt::AlignmentFlag vComponent = Qt::AlignVCenter;
248
249 const KoSvgTextProperties props = d->properties;
250 const QString type = styleType().isEmpty()? props.property(KoSvgTextProperties::KraTextStyleType).toString(): styleType();
251 if (type == STYLE_TYPE_PARAGRAPH) {
254 const bool textAlignLast = props.hasProperty(KoSvgTextProperties::TextAlignLastId);
255 if (props.hasProperty(KoSvgTextProperties::TextAlignAllId) || textAlignLast) {
257 : KoSvgText::TextAlign(props.property(KoSvgTextProperties::TextAlignAllId).toInt());
258
259 if (mode == KoSvgText::HorizontalTB) {
260 vComponent = Qt::AlignTop;
261 if (align == KoSvgText::AlignStart || align == KoSvgText::AlignLastAuto) {
263 hComponent = Qt::AlignLeft;
264 } else {
265 hComponent = Qt::AlignRight;
266 }
267 } else if (align == KoSvgText::AlignEnd) {
269 hComponent = Qt::AlignRight;
270 } else {
271 hComponent = Qt::AlignLeft;
272 }
273 } else if (align == KoSvgText::AlignLeft) {
274 hComponent = Qt::AlignLeft;
275 } else if (align == KoSvgText::AlignRight) {
276 hComponent = Qt::AlignRight;
277 }
278 } else {
279 hComponent = mode == KoSvgText::VerticalRL? Qt::AlignRight: Qt::AlignLeft;
280 if (align == KoSvgText::AlignStart || align == KoSvgText::AlignLastAuto) {
282 vComponent = Qt::AlignTop;
283 } else {
284 vComponent = Qt::AlignBottom;
285 }
286 } else if (align == KoSvgText::AlignEnd) {
288 vComponent = Qt::AlignBottom;
289 } else {
290 vComponent = Qt::AlignTop;
291 }
292 } else if (align == KoSvgText::AlignLeft) {
293 vComponent = Qt::AlignTop;
294 } else if (align == KoSvgText::AlignRight) {
295 vComponent = Qt::AlignBottom;
296 }
297 }
298 } else {
300
301 if (mode == KoSvgText::HorizontalTB) {
302 vComponent = Qt::AlignTop;
303 if (anchor == KoSvgText::AnchorStart) {
305 hComponent = Qt::AlignLeft;
306 } else {
307 hComponent = Qt::AlignRight;
308 }
309 } else if (anchor == KoSvgText::AnchorEnd) {
311 hComponent = Qt::AlignRight;
312 } else {
313 hComponent = Qt::AlignLeft;
314 }
315 } else {
316 hComponent = Qt::AlignHCenter;
317 }
318 } else {
319 hComponent = mode == KoSvgText::VerticalRL? Qt::AlignRight: Qt::AlignLeft;
320 if (anchor == KoSvgText::AnchorStart) {
322 vComponent = Qt::AlignTop;
323 } else {
324 vComponent = Qt::AlignBottom;
325 }
326 } else if (anchor == KoSvgText::AnchorEnd) {
328 vComponent = Qt::AlignBottom;
329 } else {
330 vComponent = Qt::AlignTop;
331 }
332 } else {
333 vComponent = Qt::AlignVCenter;
334 }
335 }
336 }
337 }
338
339 addMetaData(SAMPLE_ALIGN, static_cast<Qt::Alignment::Int>(hComponent | vComponent));
340}
@ 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 503 of file KoCssStylePreset.cpp.

504{
505 QScopedPointer<KoSvgTextShape> shape (dynamic_cast<KoSvgTextShape*>(generateSampleShape()));
506 if (!shape) return;
507 QImage img(256,
508 256,
509 QImage::Format_ARGB32);
510 img.fill(Qt::white);
511
512 KoShapePainter painter;
513 painter.setShapes({shape.data()});
514 painter.paint(img);
515
517 addMetaData(SAMPLE_SVG, generateSVG(shape.data()));
519
520 setImage(img);
521}
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 113 of file KoCssStylePreset.h.


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