Skip to content

armgit / krita

Public Imported from GitHub
0

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++

Implement a unit converter for the text properties docker.

Wolthera van Hövell tot Westerflierbdb8fb24cfbc
diff --git a/libs/flake/text/KoSvgText.cpp b/libs/flake/text/KoSvgText.cpp
index 1a026d2016..9dabf127b8 100644
--- a/libs/flake/text/KoSvgText.cpp
+++ b/libs/flake/text/KoSvgText.cpp
@@ -933,10 +933,8 @@ void CssLengthPercentage::convertToAbsolute(const KoSvgText::FontMetrics metrics
if (u == Percentage) {
u = percentageUnit;
}
- // FontMetrics is in freetype pixels, but we also don't know the resolution, which we need to calculate pt.
- // So the first multiplier handles the potential resolution difference, the second multiplier the freetype pixel.
- const qreal fontSizeMultiplier = 1/((metrics.fontSize/64.0)/fontSize);
- const qreal ftMultiplier = fontSizeMultiplier/64.0;
+
+ const qreal ftMultiplier = fontSize / metrics.fontSize;
if (u == Em) {
value = value * fontSize;
} else if (u == Ex) {
diff --git a/plugins/dockers/textproperties/CMakeLists.txt b/plugins/dockers/textproperties/CMakeLists.txt
index 7d7b00a4fa..9e60258e5c 100644
--- a/plugins/dockers/textproperties/CMakeLists.txt
+++ b/plugins/dockers/textproperties/CMakeLists.txt
@@ -7,6 +7,7 @@ set(KRITA_TEXTPROPERTIES_SOURCES
TagFilterProxyModelQmlWrapper.cpp
OpenTypeFeatureModel.cpp
LocaleHandler.cpp
+ CssQmlUnitConverter.cpp
)
qt_add_resources(KRITA_TEXTPROPERTIES_SOURCES textproperties.qrc)
diff --git a/plugins/dockers/textproperties/CssQmlUnitConverter.cpp b/plugins/dockers/textproperties/CssQmlUnitConverter.cpp
new file mode 100644
index 0000000000..4ecf8a4851
--- /dev/null
+++ b/plugins/dockers/textproperties/CssQmlUnitConverter.cpp
@@ -0,0 +1,352 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include "CssQmlUnitConverter.h"
+#include <QVariant>
+#include <KoUnit.h>
+#include <KoSvgText.h>
+#include <KoSvgTextProperties.h>
+#include <lager/KoSvgTextPropertiesModel.h>
+#include <KLocalizedString>
+
+struct CssQmlUnitConverter::Private {
+ QMap<int, int> dataUnitMap;
+
+ qreal dpi{72.0};
+ qreal dataMultiplier{1.0};
+ qreal dataValue{0.0};
+ int dataUnit{0};
+ int userUnit{0};
+ qreal percentageReference;
+
+ KoUnit absoluteUnitConverter;
+
+ // fontmetrics
+ KoCSSFontInfo fontInfo;
+ int fontLineGap = 0;
+ KoSvgText::FontMetrics metrics;
+};
+
+// Map of absolute values.
+// by making this a map, it always stays order in the order of KoUnit::type.
+const QMap<KoUnit::Type, CssQmlUnitConverter::UserUnits> koUnitMap = {
+ {KoUnit::Millimeter, CssQmlUnitConverter::UserUnits::Mm},
+ {KoUnit::Point, CssQmlUnitConverter::UserUnits::Pt},
+ {KoUnit::Inch, CssQmlUnitConverter::UserUnits::Inch},
+ {KoUnit::Centimeter, CssQmlUnitConverter::UserUnits::Cm},
+ {KoUnit::Pixel, CssQmlUnitConverter::UserUnits::Px},
+};
+
+const qreal koUnitFactor = 1/72.0;
+
+CssQmlUnitConverter::CssQmlUnitConverter(QObject *parent)
+ : QObject(parent)
+ , d(new Private)
+{
+ d->absoluteUnitConverter = KoUnit(KoUnit::Point, d->dpi);
+ d->fontInfo = KoSvgTextProperties::defaultProperties().cssFontInfo();
+ d->metrics = KoSvgTextProperties::defaultProperties().metrics(false);
+}
+
+CssQmlUnitConverter::~CssQmlUnitConverter()
+{
+}
+
+void CssQmlUnitConverter::setDataUnitMap(const QVariantList &unitMap)
+{
+ QMap<int, int> map;
+ Q_FOREACH(QVariant var, unitMap) {
+ QVariantMap m = var.toMap();
+ bool ok = false;
+ const int user = m.value("user").toInt(&ok);
+ const int data = m.value("data").toInt(&ok);
+ if (!ok) {
+ qWarning() << Q_FUNC_INFO << "unitMap has wrong format";
+ return;
+ }
+ map.insert(user, data);
+ }
+
+ if (d->dataUnitMap != map) {
+ d->dataUnitMap = map;
+ emit userUnitModelChanged();
+ }
+}
+
+void CssQmlUnitConverter::setFontMetricsFromTextPropertiesModel(KoSvgTextPropertiesModel *textPropertiesModel, bool isFontSize, bool isLineHeight)
+{
+ KoSvgTextProperties main;
+ if (textPropertiesModel) {
+ KoSvgTextPropertyData data = textPropertiesModel->textData.get();
+ main = data.commonProperties;
+ // remove fontsize or lineheight for those specific properties, so the calculation is normal.
+ if (isFontSize) {
+ main.removeProperty(KoSvgTextProperties::FontSizeId);
+ } else if (isLineHeight) {
+ main.removeProperty(KoSvgTextProperties::LineHeightId);
+ }
+ main.inheritFrom(data.inheritedProperties);
+ }
+ KoCSSFontInfo info = main.cssFontInfo();
+ if (info.size < 0) return;
+ if (d->fontInfo == info) {
+ return;
+ }
+ d->fontInfo = main.cssFontInfo();
+ d->metrics = main.metrics(false);
+ d->fontLineGap = d->metrics.lineGap;
+ d->metrics = main.applyLineHeight(d->metrics);
+}
+
+void CssQmlUnitConverter::setFromNormalLineHeight()
+{
+ const qreal multiplier = d->fontInfo.size / d->metrics.fontSize;
+ qreal normalLineHeight = (d->metrics.ascender - d->metrics.descender + d->fontLineGap)*multiplier;
+ setDataValue(convertToRelativeValue(normalLineHeight, UserUnits(d->dataUnitMap.key(d->dataUnit))));
+}
+
+void CssQmlUnitConverter::setDataValueAndUnit(const qreal value, const int unit)
+{
+ if (qFuzzyCompare(d->dataValue, value) && d->dataUnit == unit) {
+ return;
+ }
+ d->dataUnit = unit;
+ d->dataValue = value;
+ d->userUnit = d->dataUnitMap.key(d->dataUnit);
+
+ emit dataValueChanged();
+ emit dataUnitChanged();
+ emit userUnitChanged();
+ emit userValueChanged();
+}
+
+qreal CssQmlUnitConverter::dpi() const
+{
+ return d->dpi;
+}
+
+void CssQmlUnitConverter::setDpi(qreal newDpi)
+{
+ if (qFuzzyCompare(d->dpi, newDpi))
+ return;
+ d->dpi = newDpi;
+ d->absoluteUnitConverter.setFactor(newDpi * koUnitFactor);
+ emit dpiChanged();
+}
+
+qreal CssQmlUnitConverter::dataMultiplier() const
+{
+ return d->dataMultiplier;
+}
+
+void CssQmlUnitConverter::setDataMultiplier(qreal newDataMultiplier)
+{
+ if (qFuzzyCompare(d->dataMultiplier, newDataMultiplier))
+ return;
+ d->dataMultiplier = newDataMultiplier;
+ emit dataMultiplierChanged();
+}
+
+qreal CssQmlUnitConverter::dataValue() const
+{
+ return d->dataValue;
+}
+
+void CssQmlUnitConverter::setDataValue(qreal newDataValue)
+{
+ if (qFuzzyCompare(d->dataValue, newDataValue))
+ return;
+ d->dataValue = newDataValue;
+ emit dataValueChanged();
+ emit userValueChanged();
+}
+
+int CssQmlUnitConverter::dataUnit() const
+{
+ return d->dataUnit;
+}
+
+void CssQmlUnitConverter::setDataUnit(int newDataUnit)
+{
+ if (d->dataUnit == newDataUnit)
+ return;
+ if (d->dataUnitMap.key(d->dataUnit) == d->userUnit)
+ return;
+ setUserUnit(d->dataUnitMap.key(d->dataUnit));
+}
+
+qreal CssQmlUnitConverter::userValue() const
+{
+ const bool isAbsolute = koUnitMap.values().contains(UserUnits(d->userUnit));
+ return (isAbsolute? d->absoluteUnitConverter.toUserValue(d->dataValue): d->dataValue) * d->dataMultiplier;
+}
+
+void CssQmlUnitConverter::setUserValue(qreal newUserValue)
+{
+ if (qFuzzyCompare(userValue(), newUserValue))
+ return;
+ const bool isAbsolute = koUnitMap.values().contains(UserUnits(d->userUnit));
+ d->dataValue = (isAbsolute? d->absoluteUnitConverter.fromUserValue(newUserValue): newUserValue) / d->dataMultiplier;
+ emit userValueChanged();
+ emit dataValueChanged();
+}
+
+int CssQmlUnitConverter::userUnit() const
+{
+ return d->userUnit;
+}
+
+void CssQmlUnitConverter::setUserUnit(int newUserUnit)
+{
+ if (d->userUnit == newUserUnit)
+ return;
+ UserUnits newType = UserUnits(newUserUnit);
+ const bool newIsAbsolute = koUnitMap.values().contains(newType);
+ const bool oldIsAbsolute = koUnitMap.values().contains(UserUnits(d->userUnit));
+
+ const qreal currentAbsoluteValue = oldIsAbsolute?
+ d->absoluteUnitConverter.fromUserValue(d->dataValue):
+ convertFromRelativeValue(d->dataValue, UserUnits(d->userUnit));
+
+ if (newIsAbsolute && oldIsAbsolute) {
+ KoUnit newUnitConverter(koUnitMap.key(newType), d->dpi * koUnitFactor);
+ d->absoluteUnitConverter = newUnitConverter;
+ emit userValueChanged();
+ } else if (newIsAbsolute) {
+ KoUnit newUnitConverter(koUnitMap.key(newType), d->dpi* koUnitFactor);
+ d->absoluteUnitConverter = newUnitConverter;
+ d->dataUnit = d->dataUnitMap.value(UserUnits::Pt);
+ emit dataUnitChanged();
+ setDataValue(currentAbsoluteValue);
+ } else { // old value was absolute, and new value is relative, or both values are relative.
+ d->dataUnit = d->dataUnitMap.value(newUserUnit);
+ emit dataUnitChanged();
+ setDataValue(convertToRelativeValue(currentAbsoluteValue, newType));
+ }
+
+ d->userUnit = newUserUnit;
+ emit userUnitChanged();
+}
+
+QVariantList CssQmlUnitConverter::userUnitModel() const
+{
+ QVariantList userUnitModel;
+
+ const QString descriptionKey = "description";
+ const QString valueKey = "value";
+ Q_FOREACH(const int key, d->dataUnitMap.keys()) {
+ UserUnits keyUnit = UserUnits(key);
+
+ if (keyUnit == Pt) {
+ Q_FOREACH(KoUnit::Type koUnitKey, koUnitMap.keys()) {
+ QVariantMap unit;
+ unit.insert(descriptionKey, KoUnit::unitDescription(koUnitKey));
+ unit.insert(valueKey, koUnitMap.value(koUnitKey));
+ userUnitModel.append(unit);
+ }
+ } else {
+ QVariantMap unit;
+ if (keyUnit == Em) {
+ unit.insert(descriptionKey, i18nc("@label:inlistbox", "Font Size (em)"));
+ } else if (keyUnit == Ex) {
+ unit.insert(descriptionKey, i18nc("@label:inlistbox", "X Height (ex)"));
+ } else if (keyUnit == Cap) {
+ unit.insert(descriptionKey, i18nc("@label:inlistbox", "Cap Height (cap)"));
+ } else if (keyUnit == Ch) {
+ unit.insert(descriptionKey, i18nc("@label:inlistbox", "Proportional Advance (ch)"));
+ } else if (keyUnit == Ic) {
+ unit.insert(descriptionKey, i18nc("@label:inlistbox", "Ideographic Advance (ic)"));
+ } else if (keyUnit == Lh) {
+ unit.insert(descriptionKey, i18nc("@label:inlistbox", "Line Height (lh)"));
+ } else if (keyUnit == Spaces) {
+ unit.insert(descriptionKey, i18nc("@label:inlistbox", "Spaces (Sp)"));
+ } else if (keyUnit == Lines) {
+ unit.insert(descriptionKey, i18nc("@label:inlistbox", "Lines (Ln)"));
+ } else if (keyUnit == Percentage) {
+ unit.insert(descriptionKey, i18nc("@label:inlistbox", "Percentage (%)"));
+ }
+ unit.insert(valueKey, keyUnit);
+ userUnitModel.append(unit);
+ }
+ }
+
+ return userUnitModel;
+}
+
+QString CssQmlUnitConverter::symbol() const
+{
+ UserUnits unit = UserUnits(d->userUnit);
+ const bool isAbsolute = koUnitMap.values().contains(unit);
+ if (isAbsolute) {
+ return d->absoluteUnitConverter.symbol();
+ }
+ if (unit == Em) {
+ return QString("em");
+ } else if (unit == Ex) {
+ return QString("ex");
+ } else if (unit == Cap) {
+ return QString("cap");
+ } else if (unit == Ch) {
+ return QString("ch");
+ } else if (unit == Ic) {
+ return QString("ic");
+ } else if (unit == Lh) {
+ return QString("lh");
+ } else if (unit == Lines) {
+ return QString("Ln");
+ } else if (unit == Spaces) {
+ return QString("Sp");
+ } else if (unit == Percentage) {
+ return QString("%");
+ }
+ return QString();
+}
+
+qreal CssQmlUnitConverter::percentageReference() const
+{
+ return d->percentageReference;
+}
+
+void CssQmlUnitConverter::setPercentageReference(qreal newPercentageReference)
+{
+ if (qFuzzyCompare(d->percentageReference, newPercentageReference))
+ return;
+ d->percentageReference = newPercentageReference;
+ emit percentageReferenceChanged();
+}
+
+qreal metricsMultiplier(const CssQmlUnitConverter::UserUnits type, const KoSvgText::FontMetrics metrics, const qreal fontSize, const qreal percentageReference) {
+ const qreal multiplier = fontSize / metrics.fontSize;
+ if (type == CssQmlUnitConverter::Em) {
+ return fontSize;
+ } else if (type == CssQmlUnitConverter::Ex) {
+ return metrics.xHeight * multiplier;
+ } else if (type == CssQmlUnitConverter::Cap) {
+ return metrics.capHeight * multiplier;
+ } else if (type == CssQmlUnitConverter::Ch) {
+ return metrics.zeroAdvance * multiplier;
+ } else if (type == CssQmlUnitConverter::Ic) {
+ return metrics.ideographicAdvance * multiplier;
+ } else if (type == CssQmlUnitConverter::Lh) {
+ return (metrics.ascender - metrics.descender + metrics.lineGap) * multiplier;
+ } else if (type == CssQmlUnitConverter::Lines) {
+ return (metrics.ascender - metrics.descender) * multiplier;
+ } else if (type == CssQmlUnitConverter::Spaces) {
+ return metrics.spaceAdvance * multiplier;
+ } else if (type == CssQmlUnitConverter::Percentage) {
+ return percentageReference;
+ }
+ return 1.0;
+}
+
+qreal CssQmlUnitConverter::convertToRelativeValue(const qreal value, const UserUnits type) const
+{
+ return value / metricsMultiplier(type, d->metrics, d->fontInfo.size, d->percentageReference);
+}
+
+qreal CssQmlUnitConverter::convertFromRelativeValue(const qreal value, const UserUnits type) const
+{
+ return value * metricsMultiplier(type, d->metrics, d->fontInfo.size, d->percentageReference);
+}
diff --git a/plugins/dockers/textproperties/CssQmlUnitConverter.h b/plugins/dockers/textproperties/CssQmlUnitConverter.h
new file mode 100644
index 0000000000..d403abcebb
--- /dev/null
+++ b/plugins/dockers/textproperties/CssQmlUnitConverter.h
@@ -0,0 +1,151 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef CSSQMLUNITCONVERTER_H
+#define CSSQMLUNITCONVERTER_H
+
+#include <QObject>
+
+class KoSvgTextPropertiesModel;
+/**
+ * @brief The CssQmlUnitConverter class
+ *
+ * This handles converter to and from various units.
+ * For the absolute units, KoUnit is used internally.
+ * For the font-relative units, it will use the fontMetrics;
+ */
+class CssQmlUnitConverter : public QObject
+{
+ Q_OBJECT
+
+ /// The DPI used to calculate pixel to physical properties
+ Q_PROPERTY(qreal dpi READ dpi WRITE setDpi NOTIFY dpiChanged)
+
+ /// Data multiplier is used if for some reason the user-value needs to be multiplied by a certain factor.
+ Q_PROPERTY(qreal dataMultiplier READ dataMultiplier WRITE setDataMultiplier NOTIFY dataMultiplierChanged)
+
+ /// dataValue and dataUnit represent the data as used by the text properties.
+ Q_PROPERTY(qreal dataValue READ dataValue WRITE setDataValue NOTIFY dataValueChanged)
+ Q_PROPERTY(int dataUnit READ dataUnit WRITE setDataUnit NOTIFY dataUnitChanged)
+
+ /// userValue and userUnit represent the user-visible data. This can include synthetic units like px and mm from pt.
+ Q_PROPERTY(qreal userValue READ userValue WRITE setUserValue NOTIFY userValueChanged)
+ Q_PROPERTY(int userUnit READ userUnit WRITE setUserUnit NOTIFY userUnitChanged)
+
+ /// A model for the available user units.
+ Q_PROPERTY(QVariantList userUnitModel READ userUnitModel NOTIFY userUnitModelChanged)
+
+ /// The symbol.
+ Q_PROPERTY(QString symbol READ symbol NOTIFY userUnitChanged)
+
+ /// value to represent 100%
+ Q_PROPERTY(qreal percentageReference READ percentageReference WRITE setPercentageReference NOTIFY percentageReferenceChanged)
+
+public:
+ CssQmlUnitConverter(QObject *parent = nullptr);
+
+ ~CssQmlUnitConverter();
+
+ enum UserUnits {
+ Px, ///< Pixels, dpi relative
+ Pt, ///< Points, 1/72th
+ Mm, ///< Millimeters
+ Cm, ///< Centimeters
+ Inch,///< Inches.
+ //
+ Percentage,
+ // Font Relative
+ Em, ///< FontSize
+ Ex, ///< Font x-height
+ Cap,///< Cap height
+ Ch, ///< avarage proportional advance
+ Ic, ///< avarage full-width advance
+ Lh, ///< line-height
+ // unique for certain properties
+ Lines, ///< Used by lineHeight
+ Spaces, ///< Used by tabs
+ };
+
+ Q_ENUM(UserUnits)
+
+ /**
+ * @brief setDataUnitMap
+ * @param map -- variant list of VariantMaps, where "data" is an int representing a dataUnit,
+ * and "user" is an int representing a value in the UserUnits enum.
+ */
+ Q_INVOKABLE void setDataUnitMap(const QVariantList &unitMap);
+
+ /**
+ * @brief setFontMetricsFromTextPropertiesModel
+ * Set the current font metrics from the text properties model.
+ * @param textPropertiesModel
+ */
+ Q_INVOKABLE void setFontMetricsFromTextPropertiesModel(KoSvgTextPropertiesModel *textPropertiesModel, bool isFontSize = false, bool isLineHeight = false);
+
+ /**
+ * @brief setFromNormalLineHeight
+ * set the current value from line-height:normal metrics.
+ */
+ Q_INVOKABLE void setFromNormalLineHeight();
+
+ /**
+ * @brief setDataValueAndUnit
+ * set data unit and value in one go.
+ */
+ Q_INVOKABLE void setDataValueAndUnit(const qreal value, const int unit);
+
+ qreal dpi() const;
+ void setDpi(qreal newDpi);
+
+ qreal dataMultiplier() const;
+ void setDataMultiplier(qreal newDataMultiplier);
+
+ qreal dataValue() const;
+ void setDataValue(qreal newDataValue);
+
+ int dataUnit() const;
+ void setDataUnit(int newDataUnit);
+
+ qreal userValue() const;
+ void setUserValue(qreal newUserValue);
+
+ int userUnit() const;
+ void setUserUnit(int newUserUnit);
+
+ QVariantList userUnitModel() const;
+
+ QString symbol() const;
+
+ qreal percentageReference() const;
+ void setPercentageReference(qreal newPercentageReference);
+
+Q_SIGNALS:
+
+ void dpiChanged();
+ void dataMultiplierChanged();
+
+ void dataValueChanged();
+
+ void dataUnitChanged();
+
+ void userValueChanged();
+
+ void userUnitChanged();
+
+ void userUnitModelChanged();
+
+ void percentageReferenceChanged();
+
+private:
+ // Converts from a relative value (font or percentage) to pt.
+ qreal convertFromRelativeValue(const qreal value, const UserUnits type) const;
+ // Converts from pt to the given relative value (font or percentage).
+ qreal convertToRelativeValue(const qreal value, const UserUnits type)const ;
+
+ struct Private;
+ const QScopedPointer<Private> d;
+};
+
+#endif // CSSQMLUNITCONVERTER_H
diff --git a/plugins/dockers/textproperties/TextPropertiesDock.cpp b/plugins/dockers/textproperties/TextPropertiesDock.cpp
index ad9c6302d5..28ed16c922 100644
--- a/plugins/dockers/textproperties/TextPropertiesDock.cpp
+++ b/plugins/dockers/textproperties/TextPropertiesDock.cpp
@@ -48,6 +48,7 @@
#include "OpenTypeFeatureModel.h"
#include "TagFilterProxyModelQmlWrapper.h"
#include "LocaleHandler.h"
+#include "CssQmlUnitConverter.h"
/// Strange place to put this, do we have a better spot?
KIS_DECLARE_STATIC_INITIALIZER {
@@ -67,6 +68,7 @@ KIS_DECLARE_STATIC_INITIALIZER {
qmlRegisterType<FontAxesModel>("org.krita.flake.text", 1, 0, "FontAxesModel");
qmlRegisterType<OpenTypeFeatureModel>("org.krita.flake.text", 1, 0, "OpenTypeFeatureModel");
qmlRegisterType<KoShapeQtQuickLabel>("org.krita.flake.text", 1, 0, "KoShapeQtQuickLabel");
+ qmlRegisterType<CssQmlUnitConverter>("org.krita.flake.text", 1, 0, "CssQmlUnitConverter");
qmlRegisterType<TagFilterProxyModelQmlWrapper>("org.krita.flake.text", 1, 0, "TagFilterProxyModelQmlWrapper");
qmlRegisterType<LocaleHandler>("org.krita.flake.text", 1, 0, "LocaleHandler");
}
@@ -107,6 +109,8 @@ struct TextPropertiesDock::Private
FontAxesModel axesModel;
KisResourceModel *fontModel{nullptr};
KisCanvasResourceProvider *provider{nullptr};
+
+ qreal currentDpi{72.0};
};
TextPropertiesDock::TextPropertiesDock()
@@ -150,6 +154,7 @@ TextPropertiesDock::TextPropertiesDock()
m_quickWidget->rootContext()->setContextProperty("fontStylesModel", QVariant::fromValue(&d->stylesModel));
m_quickWidget->rootContext()->setContextProperty("fontAxesModel", QVariant::fromValue(&d->axesModel));
m_quickWidget->rootContext()->setContextProperty("locales", QVariant::fromValue(wellFormedBCPNames));
+ m_quickWidget->rootContext()->setContextProperty("canvasDPI", QVariant::fromValue(d->currentDpi));
connect(d->textModel, SIGNAL(textPropertyChanged()),
this, SLOT(slotTextPropertiesChanged()));
m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
@@ -192,6 +197,10 @@ void TextPropertiesDock::setCanvas(KoCanvasBase *canvas)
KIS_ASSERT(canvas);
m_canvas = dynamic_cast<KisCanvas2*>(canvas);
+ if (m_canvas && m_canvas->currentImage()) {
+ d->currentDpi = m_canvas->currentImage()->xRes() * 72.0;
+ m_quickWidget->rootContext()->setContextProperty("canvasDPI", QVariant::fromValue(d->currentDpi));
+ }
}
void TextPropertiesDock::unsetCanvas()
diff --git a/plugins/dockers/textproperties/qml/BaselineShift.qml b/plugins/dockers/textproperties/qml/BaselineShift.qml
index eb434394dd..8667d612e9 100644
--- a/plugins/dockers/textproperties/qml/BaselineShift.qml
+++ b/plugins/dockers/textproperties/qml/BaselineShift.qml
@@ -16,27 +16,27 @@ TextPropertyBase {
searchTerms: i18nc("comma separated search terms for the baseline-shift property, matching is case-insensitive",
"baseline-shift, superscript, subscript");
- property alias baselineShiftValue: baselineShiftSpn.value;
- property alias baselineShiftUnit: baselineShiftUnitCmb.comboBoxUnit;
+ property alias baselineShiftValue: baselineShiftUnitCmb.dataValue;
+ property alias baselineShiftUnit: baselineShiftUnitCmb.dataUnit;
property int baselineShiftMode;
onPropertiesUpdated: {
blockSignals = true;
- baselineShiftValue = properties.baselineShiftValue.value * baselineShiftSpn.multiplier;
baselineShiftMode = properties.baselineShiftMode;
- baselineShiftUnit = properties.baselineShiftValue.unitType;
+ baselineShiftUnitCmb.dpi = canvasDPI;
+ baselineShiftUnitCmb.setTextProperties(properties);
+ baselineShiftUnitCmb.setDataValueAndUnit(properties.baselineShiftValue.unitType, properties.baselineShiftValue.value)
visible = properties.baselineShiftState !== KoSvgTextPropertiesModel.PropertyUnset
blockSignals = false;
}
onBaselineShiftValueChanged: {
if (!blockSignals) {
- properties.baselineShiftValue.value = baselineShiftValue / baselineShiftSpn.multiplier;
+ properties.baselineShiftValue.value = baselineShiftValue;
}
}
onBaselineShiftUnitChanged: {
- baselineShiftUnitCmb.currentIndex = baselineShiftUnitCmb.indexOfValue(baselineShiftUnit);
if (!blockSignals) {
properties.baselineShiftValue.unitType = baselineShiftUnit;
}
@@ -107,18 +107,30 @@ TextPropertyBase {
}
Layout.fillWidth: true;
Layout.fillHeight: true;
+ PaletteControl {
+ id: baselinePalette;
+ colorGroup: baselineShiftSpn.enabled? SystemPalette.Active: SystemPalette.Disabled;
+ }
DoubleSpinBox {
id: baselineShiftSpn
width: parent.width;
- enabled: baselineShiftMode == 3;
+ enabled: baselineShiftMode === KoSvgText.ShiftLengthPercentage;
from: -999 * multiplier;
to: 999 * multiplier;
+ onValueChanged: baselineShiftUnitCmb.userValue = value;
+ palette: baselinePalette.palette;
}
}
UnitComboBox {
id: baselineShiftUnitCmb;
spinBoxControl: baselineShiftSpn;
+ palette: baselinePalette.palette;
+ Layout.preferredWidth: minimumUnitBoxWidth;
+ Layout.maximumWidth: implicitWidth;
+ enabled: baselineShiftMode === KoSvgText.ShiftLengthPercentage;
+ dpi:dpi;
+ onUserValueChanged: baselineShiftSpn.value = userValue;
}
}
}
diff --git a/plugins/dockers/textproperties/qml/FontSize.qml b/plugins/dockers/textproperties/qml/FontSize.qml
index 9684bf6c68..9c37f60d7e 100644
--- a/plugins/dockers/textproperties/qml/FontSize.qml
+++ b/plugins/dockers/textproperties/qml/FontSize.qml
@@ -16,25 +16,25 @@ TextPropertyBase {
searchTerms: i18nc("comma separated search terms for the fontsize property, matching is case-insensitive",
"size, small, big, medium");
- property alias fontSize: fontSizeSpn.value;
- property alias fontSizeUnit: fontSizeUnitCmb.comboBoxUnit;
+ property alias fontSize: fontSizeUnitCmb.dataValue;
+ property alias fontSizeUnit: fontSizeUnitCmb.dataUnit;
onPropertiesUpdated: {
blockSignals = true;
- fontSize = properties.fontSize.value * fontSizeSpn.multiplier;
- fontSizeUnit = properties.fontSize.unitType;
+ fontSizeUnitCmb.dpi = canvasDPI;
+ fontSizeUnitCmb.setTextProperties(properties);
+ fontSizeUnitCmb.setDataValueAndUnit(properties.fontSize.value, properties.fontSize.unitType);
visible = properties.fontSizeState !== KoSvgTextPropertiesModel.PropertyUnset;
blockSignals = false;
}
onFontSizeChanged: {
if (!blockSignals) {
- properties.fontSize.value = fontSize / fontSizeSpn.multiplier;
+ properties.fontSize.value = fontSize;
}
}
onFontSizeUnitChanged: {
- fontSizeUnitCmb.currentIndex = fontSizeUnitCmb.indexOfValue(fontSizeUnit);
if (!blockSignals) {
- properties.fontSize.unitType = fontSizeUnitCmb.comboBoxUnit;
+ properties.fontSize.unitType = fontSizeUnit;
}
}
@@ -62,16 +62,21 @@ TextPropertyBase {
Layout.fillWidth: true;
from: 0;
- to: 999 * multiplier;
+ to: 99999 * multiplier;
stepSize: 100;
+
+ onValueChanged: fontSizeUnitCmb.userValue = value;
}
UnitComboBox {
id: fontSizeUnitCmb;
spinBoxControl: fontSizeSpn;
isFontSize: true;
+ isLineHeight: false;
Layout.preferredWidth: minimumUnitBoxWidth;
Layout.maximumWidth: implicitWidth;
+
+ onUserValueChanged: fontSizeSpn.value = userValue;
}
}
}
diff --git a/plugins/dockers/textproperties/qml/LetterSpacing.qml b/plugins/dockers/textproperties/qml/LetterSpacing.qml
index a7770b36e7..9f095a5ffc 100644
--- a/plugins/dockers/textproperties/qml/LetterSpacing.qml
+++ b/plugins/dockers/textproperties/qml/LetterSpacing.qml
@@ -15,24 +15,24 @@ TextPropertyBase {
"Letter spacing controls the spacing between visible clusters of characters.");
searchTerms: i18nc("comma separated search terms for the letter-spacing property, matching is case-insensitive",
"letter-spacing, tracking, kerning");
- property alias letterSpacing: letterSpacingSpn.value;
- property alias letterSpacingUnit: letterSpacingUnitCmb.comboBoxUnit;
+ property alias letterSpacing: letterSpacingUnitCmb.dataValue;
+ property alias letterSpacingUnit: letterSpacingUnitCmb.dataUnit;
onPropertiesUpdated: {
blockSignals = true;
- letterSpacing = properties.letterSpacing.value * letterSpacingSpn.multiplier;
- letterSpacingUnit = properties.letterSpacing.unitType;
+ letterSpacingUnitCmb.dpi = canvasDPI;
+ letterSpacingUnitCmb.setTextProperties(properties);
+ letterSpacingUnitCmb.setDataValueAndUnit(properties.letterSpacing.value, properties.letterSpacing.unitType);
visible = properties.letterSpacingState !== KoSvgTextPropertiesModel.PropertyUnset;
blockSignals = false;
}
onLetterSpacingChanged: {
if (!blockSignals) {
- properties.letterSpacing.value = letterSpacing / letterSpacingSpn.multiplier;
+ properties.letterSpacing.value = letterSpacing;
}
}
onLetterSpacingUnitChanged: {
- letterSpacingUnitCmb.currentIndex = letterSpacingUnitCmb.indexOfValue(letterSpacingUnit);
if (!blockSignals) {
properties.letterSpacing.unitType = letterSpacingUnit;
}
@@ -62,12 +62,15 @@ TextPropertyBase {
Layout.fillWidth: true;
from: -999 * multiplier;
to: 999 * multiplier;
+ onValueChanged: letterSpacingUnitCmb.userValue = value;
}
UnitComboBox {
id: letterSpacingUnitCmb
spinBoxControl: letterSpacingSpn;
isFontSize: false;
+ dpi:dpi;
+ onUserValueChanged: letterSpacingSpn.value = userValue;
Layout.preferredWidth: minimumUnitBoxWidth;
Layout.maximumWidth: implicitWidth;
allowPercentage: false; // CSS-Text-4 has percentages for letter-spacing, but so does SVG 1.1, and they both are implemented differently.
diff --git a/plugins/dockers/textproperties/qml/LineHeight.qml b/plugins/dockers/textproperties/qml/LineHeight.qml
index d3f2d29662..bdcfcdb1f1 100644
--- a/plugins/dockers/textproperties/qml/LineHeight.qml
+++ b/plugins/dockers/textproperties/qml/LineHeight.qml
@@ -16,33 +16,57 @@ TextPropertyBase {
searchTerms: i18nc("comma separated search terms for the line-height property, matching is case-insensitive",
"line-height, line-spacing");
property alias isNormal: lineHeightNormalCbx.checked;
- property alias lineHeight: lineHeightSpn.value;
- property int lineHeightUnit: LineHeightModel.Lines;
+ property alias lineHeight: converter.dataValue;
+ property alias lineHeightUnit: converter.dataUnit;
+ property var unitMap: [
+ { user: CssQmlUnitConverter.Pt, data: LineHeightModel.Absolute},
+ { user: CssQmlUnitConverter.Em, data: LineHeightModel.Em},
+ { user: CssQmlUnitConverter.Ex, data: LineHeightModel.Ex},
+ { user: CssQmlUnitConverter.Cap, data: LineHeightModel.Cap},
+ { user: CssQmlUnitConverter.Ch, data: LineHeightModel.Ch},
+ { user: CssQmlUnitConverter.Ic, data: LineHeightModel.Ic},
+ { user: CssQmlUnitConverter.Lh, data: LineHeightModel.Lh},
+ { user: CssQmlUnitConverter.Percentage, data: LineHeightModel.Percentage},
+ { user: CssQmlUnitConverter.Lines, data: LineHeightModel.Lines},
+ ]
+
+ CssQmlUnitConverter {
+ id: converter;
+ dpi: dpi;
+ dataMultiplier: lineHeightSpn.multiplier;
+
+ onUserValueChanged: lineHeightSpn.value = userValue;
+ onUserUnitChanged: lineHeightUnitCmb.currentIndex = lineHeightUnitCmb.indexOfValue(userUnit);
+ }
onPropertiesUpdated: {
blockSignals = true;
isNormal = properties.lineHeight.isNormal;
- lineHeight = properties.lineHeight.value * lineHeightSpn.multiplier;
- lineHeightUnit = properties.lineHeight.unit;
+ converter.dpi = canvasDPI;
+ converter.setFontMetricsFromTextPropertiesModel(properties, false, true);
+ converter.percentageReference = properties.resolvedFontSize(false);
+ converter.setDataValueAndUnit(properties.lineHeight.value, properties.lineHeight.unitType);
visible = properties.lineHeightState !== KoSvgTextPropertiesModel.PropertyUnset;
blockSignals = false;
}
onLineHeightUnitChanged: {
- lineHeightUnitCmb.currentIndex = lineHeightUnitCmb.indexOfValue(lineHeightUnit)
- if (!blockSignals) {
+ if (!blockSignals && !isNormal) {
properties.lineHeight.unit = lineHeightUnit
}
}
onIsNormalChanged: {
if (!blockSignals) {
+ if (isNormal) {
+ converter.setFromNormalLineHeight();
+ }
properties.lineHeight.isNormal = isNormal;
}
}
onLineHeightChanged: {
- if (!blockSignals) {
- properties.lineHeight.value = lineHeight / lineHeightSpn.multiplier;
+ if (!blockSignals && !isNormal) {
+ properties.lineHeight.value = lineHeight;
}
}
@@ -50,6 +74,7 @@ TextPropertyBase {
Component.onCompleted: {
mainWindow.connectAutoEnabler(lineHeightSpnArea);
+ converter.setDataUnitMap(unitMap);
}
GridLayout {
@@ -81,65 +106,48 @@ TextPropertyBase {
width: firstColumnWidth;
height: 1;
}
- MouseArea {
- id: lineHeightSpnArea;
- function autoEnable() {
- lineHeightNormalCbx.checked = false;
- }
- Layout.fillWidth: true;
+ RowLayout {
Layout.fillHeight: true;
- DoubleSpinBox {
- id: lineHeightSpn
- width: parent.width;
- enabled: !lineHeightNormalCbx.checked;
- from: 0;
- to: 999 * multiplier;
- }
- }
+ Layout.fillWidth: true;
+ Layout.columnSpan: 2;
+ MouseArea {
+ id: lineHeightSpnArea;
+ function autoEnable() {
+ lineHeightNormalCbx.checked = false;
+ }
+ Layout.fillWidth: true;
+ Layout.fillHeight: true;
+ DoubleSpinBox {
+ id: lineHeightSpn
+ width: parent.width;
+ enabled: !lineHeightNormalCbx.checked;
+ from: 0;
+ to: 999 * multiplier;
- SqueezedComboBox {
- id: lineHeightUnitCmb;
- property QtObject spinBoxControl: lineHeightSpn;
- model: [
- { text: i18nc("@label:inlistbox", "Pt"), value: LineHeightModel.Absolute},
- { text: i18nc("@label:inlistbox", "Em"), value: LineHeightModel.Em},
- { text: i18nc("@label:inlistbox", "Ex"), value: LineHeightModel.Ex},
- { text: i18nc("@label:inlistbox", "Cap"), value: LineHeightModel.Cap},
- { text: i18nc("@label:inlistbox", "Ch"), value: LineHeightModel.Ch},
- { text: i18nc("@label:inlistbox", "Ic"), value: LineHeightModel.Ic},
- { text: i18nc("@label:inlistbox", "Lh"), value: LineHeightModel.Lh},
- { text: i18nc("@label:inlistbox", "%"), value: LineHeightModel.Percentage},
- { text: i18nc("@label:inlistbox", "Lines"), value: LineHeightModel.Lines},
- ]
- textRole: "text";
- valueRole: "value";
- enabled: !lineHeightNormalCbx.checked;
- wheelEnabled: true;
-
- onActivated: {
- var currentValueInPt = 0;
- if (lineHeightUnit === LineHeightModel.Absolute) {
- currentValueInPt = spinBoxControl.value;
- } else if (lineHeightUnit === LineHeightModel.Ex) {
- currentValueInPt = spinBoxControl.value * properties.resolvedXHeight(false);
- } else if (lineHeightUnit === LineHeightModel.Percentage) {
- currentValueInPt = (spinBoxControl.value / 100) * properties.resolvedFontSize(false);
- } else { // EM, Lines
- currentValueInPt = spinBoxControl.value * properties.resolvedFontSize(false);
+ onValueChanged: converter.userValue = value;
+ palette: lineHeightPalette.palette;
}
+ }
- var newValue = 0;
- if (currentValue === LineHeightModel.Absolute) {
- newValue = currentValueInPt
- } else if (currentValue === LineHeightModel.Ex) {
- newValue = currentValueInPt / properties.resolvedXHeight(false);
- } else if (currentValue === LineHeightModel.Percentage) {
- newValue = (currentValueInPt / properties.resolvedFontSize(false)) * 100;
- } else { // Em, Lines
- newValue = currentValueInPt / properties.resolvedFontSize(false);
+ SqueezedComboBox {
+ id: lineHeightUnitCmb;
+ model: converter.userUnitModel;
+ textRole: "description";
+ valueRole: "value";
+ displayText: converter.symbol;
+ enabled: !lineHeightNormalCbx.checked;
+
+ Layout.preferredWidth: height+indicator.width;
+ Layout.maximumWidth: implicitWidth;
+
+ PaletteControl {
+ id: lineHeightPalette;
+ colorGroup: lineHeightUnitCmb.enabled? SystemPalette.Active: SystemPalette.Disabled;
}
- lineHeightUnit = currentValue;
- spinBoxControl.value = newValue;
+ palette: lineHeightPalette.palette;
+ wheelEnabled: true;
+
+ onCurrentValueChanged: if (currentValue !== undefined) {converter.userUnit = currentValue}
}
}
}
diff --git a/plugins/dockers/textproperties/qml/TabSize.qml b/plugins/dockers/textproperties/qml/TabSize.qml
index e6453d96f5..32076787cb 100644
--- a/plugins/dockers/textproperties/qml/TabSize.qml
+++ b/plugins/dockers/textproperties/qml/TabSize.qml
@@ -15,30 +15,51 @@ TextPropertyBase {
"Tab Size allows defining the size of tabulation characters.");
searchTerms: i18nc("comma separated search terms for the tab-size property, matching is case-insensitive",
"tab-size");
- property alias tabSize: tabSizeSpn.value;
- property int tabSizeUnit: TabSizeModel.Spaces;
+ property alias tabSize: converter.dataValue;
+ property alias tabSizeUnit: converter.dataUnit;
+
+ property var unitMap: [
+ { user: CssQmlUnitConverter.Pt, data: TabSizeModel.Absolute},
+ { user: CssQmlUnitConverter.Em, data: TabSizeModel.Em},
+ { user: CssQmlUnitConverter.Ex, data: TabSizeModel.Ex},
+ { user: CssQmlUnitConverter.Cap, data: TabSizeModel.Cap},
+ { user: CssQmlUnitConverter.Ch, data: TabSizeModel.Ch},
+ { user: CssQmlUnitConverter.Ic, data: TabSizeModel.Ic},
+ { user: CssQmlUnitConverter.Lh, data: TabSizeModel.Lh},
+ { user: CssQmlUnitConverter.Spaces, data: TabSizeModel.Spaces},
+ ]
+
+ CssQmlUnitConverter {
+ id: converter;
+ dpi: dpi;
+ dataMultiplier: tabSizeSpn.multiplier;
+ userValue: tabSizeSpn.value;
+ userUnit: tabSizeUnitCmb.currentValue;
+ }
onPropertiesUpdated: {
blockSignals = true;
- tabSize = properties.tabSize.value * tabSizeSpn.multiplier;
- tabSizeUnit = properties.tabSize.unit;
+ converter.dpi = canvasDPI;
+ converter.setFontMetricsFromTextPropertiesModel(properties);
+ converter.setDataValueAndUnit(properties.tabSize.unit, properties.tabSize.value);
visible = properties.tabSizeState !== KoSvgTextPropertiesModel.PropertyUnset;
blockSignals = false;
}
onTabSizeChanged: {
if (!blockSignals) {
- properties.tabSize.value = tabSize / tabSizeSpn.multiplier;
+ properties.tabSize.value = tabSize;
}
}
onTabSizeUnitChanged: {
- tabSizeUnitCmb.currentIndex = tabSizeUnitCmb.indexOfValue(tabSizeUnit);
if (!blockSignals) {
properties.tabSize.unit = tabSizeUnit;
}
}
+ Component.onCompleted: converter.setDataUnitMap(unitMap);
+
onEnableProperty: properties.tabSizeState = KoSvgTextPropertiesModel.PropertySet;
GridLayout {
@@ -70,51 +91,15 @@ TextPropertyBase {
from: 0;
to: 100 * multiplier;
}
- ComboBox {
+ SqueezedComboBox {
id: tabSizeUnitCmb;
- property QtObject spinBoxControl: tabSizeSpn;
- model: [
- {text: i18nc("@label:inlistbox", "Spaces"), value: TabSizeModel.Spaces},
- {text: i18nc("@label:inlistbox", "Pt"), value: TabSizeModel.Absolute},
- {text: i18nc("@label:inlistbox", "Em"), value: TabSizeModel.Em},
- {text: i18nc("@label:inlistbox", "Ex"), value: TabSizeModel.Ex},
- {text: i18nc("@label:inlistbox", "Cap"), value: TabSizeModel.Cap},
- {text: i18nc("@label:inlistbox", "Ch"), value: TabSizeModel.Ch},
- {text: i18nc("@label:inlistbox", "Ic"), value: TabSizeModel.Ic},
- {text: i18nc("@label:inlistbox", "Lh"), value: TabSizeModel.Lh}
- ]
- textRole: "text";
+ model:converter.userUnitModel;
+ textRole: "description";
valueRole: "value";
- Layout.fillWidth: true;
+ displayText: converter.symbol;
wheelEnabled: true;
-
- onActivated: {
- if (currentValue === TabSizeModel.Spaces) {
- tabSizeUnit = currentValue;
- spinBoxControl.value = properties.tabSize.value * tabSizeSpn.multiplier;
- } else {
-
- var currentValueInPt = 0;
- if (tabSizeUnit === TabSizeModel.Absolute) {
- currentValueInPt = spinBoxControl.value;
- } else if (tabSizeUnit === TabSizeModel.Ex) {
- currentValueInPt = spinBoxControl.value * properties.resolvedXHeight(false);
- } else { // EM, Lines
- currentValueInPt = spinBoxControl.value * properties.resolvedFontSize(false);
- }
-
- var newValue = 0;
- if (currentValue === TabSizeModel.Absolute) {
- newValue = currentValueInPt
- } else if (currentValue === TabSizeModel.Ex) {
- newValue = currentValueInPt / properties.resolvedXHeight(false);
- } else { // Em
- newValue = currentValueInPt / properties.resolvedFontSize(false);
- }
- tabSizeUnit = currentValue;
- spinBoxControl.value = newValue;
- }
- }
+ Layout.preferredWidth: height+indicator.width;
+ Layout.maximumWidth: implicitWidth;
}
}
diff --git a/plugins/dockers/textproperties/qml/TextIndent.qml b/plugins/dockers/textproperties/qml/TextIndent.qml
index 0b1da07398..2b1388d79b 100644
--- a/plugins/dockers/textproperties/qml/TextIndent.qml
+++ b/plugins/dockers/textproperties/qml/TextIndent.qml
@@ -16,15 +16,16 @@ CollapsibleGroupProperty {
searchTerms: i18nc("comma separated search terms for the text-indent property, matching is case-insensitive",
"text-indent");
- property alias textIndentValue: textIndentSpn.value;
+ property alias textIndentValue: textIndentUnitCmb.dataValue;
property alias hanging: indentHangingCkb.checked;
property alias eachLine: eachLineCkb.checked;
- property alias textIndentUnit: textIndentUnitCmb.comboBoxUnit;
+ property alias textIndentUnit: textIndentUnitCmb.dataUnit;
onPropertiesUpdated: {
blockSignals = true;
- textIndentValue = properties.textIndent.length.value * textIndentSpn.multiplier;
- textIndentUnit = properties.textIndent.length.unitType;
+ textIndentUnitCmb.dpi = canvasDPI;
+ textIndentUnitCmb.setTextProperties(properties);
+ textIndentUnitCmb.setDataValueAndUnit(properties.textIndent.value, properties.textIndent.unitType);
hanging = properties.textIndent.hanging;
eachLine = properties.textIndent.eachLine;
visible = properties.textIndentState !== KoSvgTextPropertiesModel.PropertyUnset;
@@ -33,12 +34,11 @@ CollapsibleGroupProperty {
onTextIndentValueChanged: {
if (!blockSignals) {
- properties.textIndent.length.value = textIndentValue / textIndentSpn.multiplier;
+ properties.textIndent.length.value = textIndentValue;
}
}
onTextIndentUnitChanged: {
- textIndentUnitCmb.currentIndex = textIndentUnitCmb.indexOfValue(textIndentUnit);
if (!blockSignals) {
properties.textIndent.length.unitType = textIndentUnit;
}
@@ -77,12 +77,14 @@ CollapsibleGroupProperty {
Layout.fillWidth: true;
from: 0;
to: 999 * multiplier;
+ onValueChanged: textIndentUnitCmb.userValue = value;
}
/// Note: percentage calculation in the default unitcombobox isn't great for textIndent as it assumes 100% = fontsize,
/// While spec-wise, it's the inline length that defines percentage.
UnitComboBox {
id: textIndentUnitCmb;
spinBoxControl: textIndentSpn;
+ onUserValueChanged: textIndentSpn.value = userValue;
Layout.preferredWidth: minimumUnitBoxWidth;
Layout.maximumWidth: implicitWidth;
}
diff --git a/plugins/dockers/textproperties/qml/TextPropertyBase.qml b/plugins/dockers/textproperties/qml/TextPropertyBase.qml
index d42c4e30cc..04cfcbe1d0 100644
--- a/plugins/dockers/textproperties/qml/TextPropertyBase.qml
+++ b/plugins/dockers/textproperties/qml/TextPropertyBase.qml
@@ -23,6 +23,7 @@ Column {
property KoSvgTextPropertiesModel properties : textPropertiesModel;
+ property double dpi: canvasDPI;
signal propertiesUpdated; ///< Used by each text property panel to update the data on the controls.
signal enableProperty; ///< Set the property to a default value.
property bool blockSignals; ///< When setting the data on the controls, this needs to be enabled and checked while returning data from the controls.
diff --git a/plugins/dockers/textproperties/qml/UnitComboBox.qml b/plugins/dockers/textproperties/qml/UnitComboBox.qml
index 84cc7ca940..6ac16a71bf 100644
--- a/plugins/dockers/textproperties/qml/UnitComboBox.qml
+++ b/plugins/dockers/textproperties/qml/UnitComboBox.qml
@@ -8,73 +8,56 @@ import QtQuick.Controls 2.15
import org.krita.flake.text 1.0
SqueezedComboBox {
+ id: root;
property QtObject spinBoxControl;
property bool isFontSize: false;
- property int comboBoxUnit;
+ property bool isLineHeight: false;
+ property alias dataUnit: converter.dataUnit;
+ property alias dataValue: converter.dataValue;
+ property alias dpi: converter.dpi;
+ property alias userValue: converter.userValue;
property bool allowPercentage: true;
+
wheelEnabled: true;
property int minimumUnitBoxWidth: height+indicator.width;
- property string ptString: i18nc("@label:inlistbox", "Pt");
- property string emString: i18nc("@label:inlistbox", "Em");
- property string exString: i18nc("@label:inlistbox", "Ex");
- property string chString: i18nc("@label:inlistbox", "Ch");
- property string capString: i18nc("@label:inlistbox", "Cap");
- property string icString: i18nc("@label:inlistbox", "Ic");
- property string lhString: i18nc("@label:inlistbox", "Lh");
- property string prcString: i18nc("@label:inlistbox", "%");
+ displayText: converter.symbol;
+
+ function setTextProperties(properties) {
+ converter.setFontMetricsFromTextPropertiesModel(properties, root.isFontSize, root.isLineHeight);
+ }
+ function setDataValueAndUnit(value, unit) {
+ converter.setDataValueAndUnit(value, unit);
+ }
+
+
+ CssQmlUnitConverter {
+ id: converter;
+ dataMultiplier: spinBoxControl.multiplier;
+
+ onUserUnitChanged: root.currentIndex = root.indexOfValue(userUnit);
+ }
Component.onCompleted: {
- if (!allowPercentage) {
+ var userUnitModel = [
+ { user: CssQmlUnitConverter.Pt, data: 0},
+ { user: CssQmlUnitConverter.Em, data: 2},
+ { user: CssQmlUnitConverter.Ex, data: 3},
+ { user: CssQmlUnitConverter.Cap, data: 4},
+ { user: CssQmlUnitConverter.Ch, data: 5},
+ { user: CssQmlUnitConverter.Ic, data: 6},
+ { user: CssQmlUnitConverter.Lh, data: 7}
+ ];
+ if (allowPercentage) {
// Not great, but listmodels don't seem to allow adding i18n strings as properties, because they are in functions?
- model = [
- {text: ptString, value: 0},
- {text: emString, value: 2},
- {text: exString, value: 3},
- {text: capString, value: 4},
- {text: chString, value: 5},
- {text: icString, value: 6},
- {text: lhString, value: 7}
- ];
+ userUnitModel.push( { user: CssQmlUnitConverter.Percentage, data: 1})
}
+ converter.setDataUnitMap(userUnitModel);
}
- model: [
- {text: ptString, value: 0},
- {text: emString, value: 2},
- {text: exString, value: 3},
- {text: capString, value: 4},
- {text: chString, value: 5},
- {text: icString, value: 6},
- {text: lhString, value: 7},
- {text: prcString, value: 1}
- ]
- textRole: "text";
+ model: converter.userUnitModel;
+ textRole: "description";
valueRole: "value";
- onActivated: {
- var currentValueInPt = 0;
- if (comboBoxUnit === 0) {
- currentValueInPt = spinBoxControl.value;
- } else if (comboBoxUnit === 2) {
- currentValueInPt = spinBoxControl.value * properties.resolvedFontSize(isFontSize);
- } else if (comboBoxUnit === 3) {
- currentValueInPt = spinBoxControl.value * properties.resolvedXHeight(isFontSize);
- } else if (comboBoxUnit === 1) {
- currentValueInPt = (spinBoxControl.value / 100) * properties.resolvedFontSize(isFontSize);
- }
-
- var newValue = 0;
- if (currentValue === 0) {
- newValue = currentValueInPt
- } else if (currentValue === 2) {
- newValue = currentValueInPt / properties.resolvedFontSize(isFontSize);
- } else if (currentValue === 3) {
- newValue = currentValueInPt / properties.resolvedXHeight(isFontSize);
- } else if (currentValue === 1) {
- newValue = (currentValueInPt / properties.resolvedFontSize(isFontSize)) * 100;
- }
- comboBoxUnit = currentValue;
- spinBoxControl.value = newValue;
- }
+ onCurrentValueChanged: converter.userUnit = currentValue;
}
diff --git a/plugins/dockers/textproperties/qml/WordSpacing.qml b/plugins/dockers/textproperties/qml/WordSpacing.qml
index 7aeb3877fe..3406c825ce 100644
--- a/plugins/dockers/textproperties/qml/WordSpacing.qml
+++ b/plugins/dockers/textproperties/qml/WordSpacing.qml
@@ -15,25 +15,24 @@ TextPropertyBase {
"Word spacing controls the size of word-break characters, such as the space character.");
searchTerms: i18nc("comma separated search terms for the word-spacing property, matching is case-insensitive",
"word-spacing, tracking, white space,");
- property alias wordSpacing: wordSpacingSpn.value;
- visible: properties.wordSpacingState !== KoSvgTextPropertiesModel.PropertyUnset;
- property alias wordSpacingUnit: wordSpacingUnitCmb.comboBoxUnit;
+ property alias wordSpacing: wordSpacingUnitCmb.dataValue;
+ property alias wordSpacingUnit: wordSpacingUnitCmb.dataUnit;
onPropertiesUpdated: {
blockSignals = true;
- wordSpacing = properties.wordSpacing.value * wordSpacingSpn.multiplier;
- wordSpacingUnit = properties.wordSpacing.unitType;
+ wordSpacingUnitCmb.dpi = canvasDPI;
+ wordSpacingUnitCmb.setTextProperties(properties);
+ wordSpacingUnitCmb.setDataValueAndUnit(properties.wordSpacing.value, properties.wordSpacing.unitType);
visible = properties.wordSpacingState !== KoSvgTextPropertiesModel.PropertyUnset;
blockSignals = false;
}
onWordSpacingChanged: {
if (!blockSignals) {
- properties.wordSpacing.value = wordSpacing / wordSpacingSpn.multiplier;
+ properties.wordSpacing.value = wordSpacing;
}
}
onWordSpacingUnitChanged: {
- wordSpacingUnitCmb.currentIndex = wordSpacingUnitCmb.indexOfValue(wordSpacingUnit);
if (!blockSignals) {
properties.wordSpacing.unitType = wordSpacingUnit;
}
@@ -63,12 +62,16 @@ TextPropertyBase {
Layout.fillWidth: true;
from: -999 * multiplier;
to: 999 * multiplier;
+
+ onValueChanged: wordSpacingUnitCmb.userValue = value;
}
UnitComboBox {
id: wordSpacingUnitCmb
spinBoxControl: wordSpacingSpn;
isFontSize: false;
+ dpi: dpi;
+ onUserValueChanged: wordSpacingSpn.value = userValue;
Layout.preferredWidth: minimumUnitBoxWidth;
Layout.maximumWidth: implicitWidth;
allowPercentage: false; // CSS-Text-4 has percentages for word-spacing, but so does SVG 1.1, and they both are implemented differently.