Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Add width and height for CssStylePreset preview generation.
Wolthera van Hövell tot Westerflier764f4383fb13
diff --git a/libs/flake/resources/KoCssStylePreset.cpp b/libs/flake/resources/KoCssStylePreset.cppindex 02a3751403..1d956e8071 100644--- a/libs/flake/resources/KoCssStylePreset.cpp+++ b/libs/flake/resources/KoCssStylePreset.cpp@@ -43,6 +43,8 @@ struct KoCssStylePreset::Private {QString beforeText;QString sample = SAMPLE_PLACEHOLDER.toString();QString afterText;++ QSizeF paragraphSampleSize = QSizeF(120, 120);};KoCssStylePreset::KoCssStylePreset(const QString &filename)@@ -194,14 +196,16 @@ KoShape* KoCssStylePreset::generateSampleShape() constsampleText->setPropertiesAtPos(-1, modifiedProps);+if (type == STYLE_TYPE_PARAGRAPH) {+ const QSizeF sampleSize = d->paragraphSampleSize;// For paragraph we'll add a shape, as those will allow wrapping,// without being part of the properties like inline-size is.KoPathShape *inlineShape = new KoPathShape();inlineShape->moveTo(QPointF(0, 0));- inlineShape->lineTo(QPointF(120, 0));- inlineShape->lineTo(QPointF(120, 120));- inlineShape->lineTo(QPointF(0, 120));+ inlineShape->lineTo(QPointF(sampleSize.width(), 0));+ inlineShape->lineTo(QPointF(sampleSize.width(), sampleSize.height()));+ inlineShape->lineTo(QPointF(0, sampleSize.height()));inlineShape->lineTo(QPointF(0, 0));inlineShape->close();sampleText->setShapesInside({inlineShape});@@ -372,6 +376,17 @@ QString KoCssStylePreset::sampleSvg() constreturn m[SAMPLE_SVG].toString();}+QSizeF KoCssStylePreset::paragraphSampleSize() const+{+ return d->paragraphSampleSize;+}++void KoCssStylePreset::setParagraphSampleSize(const QSizeF size)+{+ d->paragraphSampleSize = size;+ setDirty(true);+}+int KoCssStylePreset::storedPPIResolution() const{QMap<QString, QVariant> m = metadata();@@ -443,6 +458,11 @@ bool KoCssStylePreset::loadFromDevice(QIODevice *dev, KisResourcesInterfaceSP red->sample = textShape->plainText().mid(pos.first, pos.second-pos.first);d->beforeText = textShape->plainText().mid(0, pos.first);d->afterText = textShape->plainText().mid(pos.second);++ if (!textShape->shapesInside().isEmpty() && styleType == STYLE_TYPE_PARAGRAPH) {+ d->paragraphSampleSize = textShape->shapesInside().first()->size();+ }+}addMetaData(STYLE_TYPE, styleType);diff --git a/libs/flake/resources/KoCssStylePreset.h b/libs/flake/resources/KoCssStylePreset.hindex 05ce3d94ec..cd2c95750c 100644--- a/libs/flake/resources/KoCssStylePreset.h+++ b/libs/flake/resources/KoCssStylePreset.h@@ -63,6 +63,11 @@ public:/// Returns the sample svg metadata. Use updateThumbnail to update it.QString sampleSvg() const;+ /// Returns the size of the shape which the paragraph is set as.+ QSizeF paragraphSampleSize() const;+ /// Set the size of the shape the paragraph is set in.+ void setParagraphSampleSize(const QSizeF size);+/*** The resolution that this style is tied to.* if this is above 0, then the properties absolute values are scaled bydiff --git a/plugins/dockers/textproperties/CssStylePresetEditDialog.cpp b/plugins/dockers/textproperties/CssStylePresetEditDialog.cppindex ba6b5f43ea..c0108df108 100644--- a/plugins/dockers/textproperties/CssStylePresetEditDialog.cpp+++ b/plugins/dockers/textproperties/CssStylePresetEditDialog.cpp@@ -25,7 +25,7 @@ CssStylePresetEditDialog::CssStylePresetEditDialog(QWidget *parent), m_model(new KoSvgTextPropertiesModel()){- setMinimumSize(600, 400);+ setMinimumSize(600, 450);setModal(true);m_quickWidget = new KisQQuickWidget(this);@@ -78,6 +78,9 @@ void CssStylePresetEditDialog::setCurrentResource(KoCssStylePresetSP resource)m_quickWidget->rootObject()->setProperty("beforeSample", m_currentResource->beforeText());m_quickWidget->rootObject()->setProperty("sampleText", m_currentResource->sampleText());m_quickWidget->rootObject()->setProperty("afterSample", m_currentResource->afterText());+ const QSizeF paragraphSampleSize = m_currentResource->paragraphSampleSize();+ m_quickWidget->rootObject()->setProperty("sampleWidth", paragraphSampleSize.width());+ m_quickWidget->rootObject()->setProperty("sampleHeight", paragraphSampleSize.height());const int storedPPI = m_currentResource->storedPPIResolution();m_quickWidget->rootObject()->setProperty("makePixelRelative", storedPPI > 0);}@@ -112,9 +115,15 @@ void CssStylePresetEditDialog::slotUpdateTextProperties()const QString after = m_quickWidget->rootObject()->property("afterSample").toString();const QString styleType = m_quickWidget->rootObject()->property("styleType").toString();+ const int sampleHeight = m_quickWidget->rootObject()->property("sampleHeight").toInt();+ const int sampleWidth = m_quickWidget->rootObject()->property("sampleWidth").toInt();+ const QSizeF sampleSize = QSizeF(sampleWidth, sampleHeight);++bool shouldUpdateSample = (before != m_currentResource->beforeText()|| sample != m_currentResource->sampleText()- || after != m_currentResource->afterText());+ || after != m_currentResource->afterText())+ || sampleSize != m_currentResource->paragraphSampleSize();KoSvgTextPropertyData textData = m_model->textData.get();@@ -123,6 +132,11 @@ void CssStylePresetEditDialog::slotUpdateTextProperties()m_currentResource->setBeforeText(before);m_currentResource->setSampleText(sample);m_currentResource->setAfterText(after);++ if (styleType == "paragraph") {+ m_currentResource->setParagraphSampleSize(sampleSize);+ }+m_currentResource->setProperties(textData.commonProperties);m_currentResource->updateThumbnail();m_quickWidget->rootObject()->setProperty("presetSample", m_currentResource->sampleSvg());diff --git a/plugins/dockers/textproperties/qml/CssStylePresetEdit.qml b/plugins/dockers/textproperties/qml/CssStylePresetEdit.qmlindex 08846b5796..bb2b996548 100644--- a/plugins/dockers/textproperties/qml/CssStylePresetEdit.qml+++ b/plugins/dockers/textproperties/qml/CssStylePresetEdit.qml@@ -21,6 +21,8 @@ Control {property double canvasDPI: 72.0;property double pixelRelativeDPI: 72.0;property alias makePixelRelative: pixelRelativeCheck.checked;+ property alias sampleWidth: sampleWidthSpn.value;+ property alias sampleHeight: sampleHeightSpn.value;property var locales: [];property KoSvgTextPropertiesModel textProperties: KoSvgTextPropertiesModel{};@@ -166,6 +168,37 @@ Control {visible: styleType !== "paragraph";}}+ RowLayout {+ Layout.columnSpan: 2;+ Layout.fillWidth: true;+ visible: styleType === "paragraph";+ Label {+ Layout.preferredWidth: implicitWidth;+ text: i18nc("@label:spinbox", "Width:");+ }+ Kis.IntParseSpinBox {+ id: sampleWidthSpn;+ Layout.fillWidth: true;+ from: 0;+ to: 999;+ value: 100;+ onValueChanged: mainWindow.slotUpdateTextProperties();+ }++ Label {+ Layout.preferredWidth: implicitWidth;+ text: i18nc("@label:spinbox", "Height:");+ }++ Kis.IntParseSpinBox {+ id: sampleHeightSpn;+ Layout.fillWidth: true;+ from: 0;+ to: 999;+ value: 100;+ onValueChanged: mainWindow.slotUpdateTextProperties();+ }+ }Item {Layout.fillHeight: true;Layout.fillWidth: true;