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

Enable editing white-space property in the text properties docker.

Wolthera van Hövell tot Westerflierf6512bda90e2
diff --git a/libs/flake/text/KoSvgText.h b/libs/flake/text/KoSvgText.h
index 99e47495c4..a98d33ff98 100644
--- a/libs/flake/text/KoSvgText.h
+++ b/libs/flake/text/KoSvgText.h
@@ -104,6 +104,7 @@ enum TextSpaceCollapse {
PreserveSpaces ///< Preserve spaces, convert tabs and linebreaks to spaces,
///< required for 'xml:space="preserve"' emulation.
};
+Q_ENUM_NS(TextSpaceCollapse)
/// Part of "white-space", in practice we only support wrap and nowrap.
enum TextWrap {
@@ -117,6 +118,7 @@ enum TextWrap {
Pretty ///< select algorithm that gives the best looking result, may require
///< looking ahead.
};
+Q_ENUM_NS(TextWrap)
/// Part of "white-space"
enum TextSpaceTrim {
@@ -125,6 +127,7 @@ enum TextSpaceTrim {
DiscardBefore = 0x2, ///< Trim white space before the start of the element.
DiscardAfter = 0x4 ///< Trim white space after the end of the element.
};
+Q_ENUM_NS(TextSpaceTrim)
/// Whether to break words.
enum WordBreak {
diff --git a/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp b/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp
index d8d3669875..cd02a8788f 100644
--- a/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp
+++ b/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp
@@ -291,6 +291,10 @@ KoSvgTextPropertiesModel::KoSvgTextPropertiesModel(lager::cursor<KoSvgTextProper
, LAGER_QT(languageState) {textData.zoom(propertyModifyState(KoSvgTextProperties::TextLanguage))}
, LAGER_QT(fontSizeAdjust) {textData.zoom(createTextProperty(KoSvgTextProperties::FontSizeAdjustId)).zoom(autoValueSimplified)}
, LAGER_QT(fontSizeAdjustState) {textData.zoom(propertyModifyState(KoSvgTextProperties::FontSizeAdjustId))}
+ , LAGER_QT(textCollapse){textData.zoom(createTextProperty(KoSvgTextProperties::TextCollapseId)).zoom(variant_to<int>)}
+ , LAGER_QT(textCollapseState) {textData.zoom(propertyModifyState(KoSvgTextProperties::TextCollapseId))}
+ , LAGER_QT(textWrap){textData.zoom(createTextProperty(KoSvgTextProperties::TextWrapId)).zoom(variant_to<int>)}
+ , LAGER_QT(textWrapState) {textData.zoom(propertyModifyState(KoSvgTextProperties::TextWrapId))}
, LAGER_QT(spanSelection) {textData[&KoSvgTextPropertyData::spanSelection]}
{
lager::watch(textData, std::bind(&KoSvgTextPropertiesModel::textPropertyChanged, this));
diff --git a/libs/flake/text/lager/KoSvgTextPropertiesModel.h b/libs/flake/text/lager/KoSvgTextPropertiesModel.h
index dbbfb29d1d..f0a7cadc59 100644
--- a/libs/flake/text/lager/KoSvgTextPropertiesModel.h
+++ b/libs/flake/text/lager/KoSvgTextPropertiesModel.h
@@ -209,6 +209,11 @@ public:
LAGER_QT_CURSOR(qreal, fontSizeAdjust);
LAGER_QT_CURSOR(PropertyState, fontSizeAdjustState);
+ LAGER_QT_CURSOR(int, textCollapse);
+ LAGER_QT_CURSOR(PropertyState, textCollapseState);
+ LAGER_QT_CURSOR(int, textWrap);
+ LAGER_QT_CURSOR(PropertyState, textWrapState);
+
/// We're selecting a span of text instead of the whole paragraph.
LAGER_QT_CURSOR(bool, spanSelection);
diff --git a/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml b/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml
index 75cd1e70c8..eaa551c679 100644
--- a/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml
+++ b/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml
@@ -101,9 +101,8 @@ ColumnLayout {
}
DominantBaseline {
}
- /*
WhiteSpace {
- }*/
+ }
UnderlinePosition {
}
HangingPunctuation {
diff --git a/plugins/dockers/textproperties/qml/WhiteSpace.qml b/plugins/dockers/textproperties/qml/WhiteSpace.qml
index c53b801ed9..b025dfc29a 100644
--- a/plugins/dockers/textproperties/qml/WhiteSpace.qml
+++ b/plugins/dockers/textproperties/qml/WhiteSpace.qml
@@ -3,43 +3,104 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
-import QtQuick 2.0
-import QtQuick.Controls 2.0
-import QtQuick.Layouts 1.12
+import QtQuick 2.15
+import QtQuick.Controls 2.15
+import QtQuick.Layouts 1.15
+import org.krita.flake.text 1.0
TextPropertyBase {
+ propertyName: i18nc("@label:spinbox", "White Space");
+ toolTip: i18nc("@info:tooltip",
+ "The CSS white space rule controls how multiples of spaces are handled, and whether the text can wrap.");
+ searchTerms: i18nc("comma separated search terms for the white-space property, matching is case-insensitive",
+ "white-space, collapse, pre-formatted");
+ propertyType: TextPropertyBase.Mixed;
+ property int whiteSpace: 0;
+
+ readonly property int wsNormal: 0;
+ readonly property int wsPre: 1;
+ readonly property int wsNoWrap: 2;
+ readonly property int wsPreWrap: 3;
+ readonly property int wsBreakSpace: 4;
+ readonly property int wsPreLine: 5;
+
+ onPropertiesUpdated: {
+ blockSignals = true;
+ if (properties.textWrap !== KoSvgText.NoWrap) {
+ if (properties.textCollapse === KoSvgText.Preserve) {
+ whiteSpace = wsPreWrap;
+ } else if (properties.textCollapse === KoSvgText.PreserveBreaks) {
+ whiteSpace = wsPreLine;
+ } else {
+ whiteSpace = wsNormal;
+ }
+ } else {
+ if (properties.textCollapse === KoSvgText.Preserve) {
+ whiteSpace = wsPre;
+ } else {
+ whiteSpace = wsNoWrap;
+ }
+ }
+ visible = properties.textCollapseState !== KoSvgTextPropertiesModel.PropertyUnset
+ blockSignals = false;
+ }
+
+ onWhiteSpaceChanged: {
+ whiteSpaceCmb.currentIndex = whiteSpaceCmb.indexOfValue(whiteSpace);
+ if (!blockSignals) {
+ if (whiteSpace === wsNormal) {
+ properties.textCollapse = KoSvgText.Collapse;
+ properties.textWrap = KoSvgText.Wrap;
+ } else if (whiteSpace === wsPre) {
+ properties.textCollapse = KoSvgText.Preserve;
+ properties.textWrap = KoSvgText.NoWrap;
+ } else if (whiteSpace === wsNoWrap) {
+ properties.textCollapse = KoSvgText.Collapse;
+ properties.textWrap = KoSvgText.NoWrap;
+ } else if (whiteSpace === wsPreWrap) {
+ properties.textCollapse = KoSvgText.Preserve;
+ properties.textWrap = KoSvgText.Wrap;
+ } else if (whiteSpace === wsBreakSpace) {
+ properties.textCollapse = KoSvgText.PreserveBreaks;
+ properties.textWrap = KoSvgText.Wrap;
+ } else if (whiteSpace === wsPreLine) {
+ properties.textCollapse = KoSvgText.PreserveBreaks;
+ properties.textWrap = KoSvgText.Wrap;
+ }
+ }
+ }
+
+ onEnableProperty: properties.textCollapseState = KoSvgTextPropertiesModel.PropertySet;
RowLayout {
spacing: columnSpacing;
width: parent.width;
- Item {
- width: firstColumnWidth;
- height: firstColumnWidth;
- ToolButton {
- id: revert;
- icon.width: 22;
- icon.height: 22;
- display: AbstractButton.IconOnly
- icon.source: "qrc:///light_view-refresh.svg"
- }
+ RevertPropertyButton {
+ revertState: properties.textCollapseState;
+ onClicked: properties.textCollapseState = KoSvgTextPropertiesModel.PropertyUnset;
}
Label {
- text: i18nc("@label:listbox", "White Space:")
+ text: propertyName;
+ elide: Text.ElideRight;
+ Layout.fillWidth: true;
+ font.italic: properties.textCollapseState === KoSvgTextPropertiesModel.PropertyTriState;
}
-
ComboBox {
- id: wordBreakCmb
+ id: whiteSpaceCmb
model: [
- i18nc("@label:inlistbox", "Normal"),
- i18nc("@label:inlistbox", "Pre"),
- i18nc("@label:inlistbox", "No Wrap"),
- i18nc("@label:inlistbox", "Pre Wrap"),
- i18nc("@label:inlistbox", "Break Spaces"),
- i18nc("@label:inlistbox", "Pre Line")
+ {text:i18nc("@label:inlistbox", "Normal"), value: wsNormal},
+ {text:i18nc("@label:inlistbox", "Pre"), value: wsPre},
+ {text:i18nc("@label:inlistbox", "No Wrap"), value: wsNoWrap},
+ {text:i18nc("@label:inlistbox", "Pre Wrap"), value: wsPreWrap},
+ {text:i18nc("@label:inlistbox", "Pre Line"), value: wsPreLine}
]
Layout.fillWidth: true;
+ onActivated: whiteSpace = currentValue;
+ textRole: "text";
+ valueRole: "value";
+ wheelEnabled: true;
}
}
}