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

Add quick option buttons to the text-align widget.

Wolthera van Hövell tot Westerflier486fc482b75d
diff --git a/plugins/dockers/textproperties/qml/TextAlign.qml b/plugins/dockers/textproperties/qml/TextAlign.qml
index 35f1e43f83..fb47ff6ef7 100644
--- a/plugins/dockers/textproperties/qml/TextAlign.qml
+++ b/plugins/dockers/textproperties/qml/TextAlign.qml
@@ -25,6 +25,7 @@ CollapsibleGroupProperty {
textAlignAll = properties.textAlignAll;
textAlignLast = properties.textAlignLast;
textAnchor = properties.textAnchor;
+ setButtonsChecked();
visible = properties.textAlignAllState !== KoSvgTextPropertiesModel.PropertyUnset ||
properties.textAlignLastState !== KoSvgTextPropertiesModel.PropertyUnset ||
properties.textAnchorState !== KoSvgTextPropertiesModel.PropertyUnset;
@@ -52,6 +53,96 @@ CollapsibleGroupProperty {
}
}
+ function setButtonsChecked() {
+ if (properties.textAnchorState !== KoSvgTextPropertiesModel.PropertyUnset) {
+ if (textAnchor === KoSvgText.AnchorStart) {
+ alignStartBtn.checked = true;
+ } else if (textAnchor === KoSvgText.AnchorMiddle) {
+ alignMiddleBtn.checked = true;
+ } else {
+ alignEndBtn.checked = true;
+ }
+ } else if (properties.textAlignAllState !== KoSvgTextPropertiesModel.PropertyUnset) {
+ if (textAlignAll === KoSvgText.AlignLeft) {
+ if (properties.direction === KoSvgText.DirectionLeftToRight) {
+ alignStartBtn.checked = true;
+ } else {
+ alignEndBtn.checked = true;
+ }
+ } else if (textAlignAll === KoSvgText.AlignStart) {
+ alignStartBtn.checked = true;
+ } else if (textAlignAll === KoSvgText.AlignCenter) {
+ alignMiddleBtn.checked = true;
+ } else if (textAlignAll === KoSvgText.AlignEnd) {
+ alignEndBtn.checked = true;
+ } else if (textAlignAll === KoSvgText.AlignRight) {
+ if (properties.direction === KoSvgText.DirectionLeftToRight) {
+ alignEndBtn.checked = true;
+ } else {
+ alignStartBtn.checked = true;
+ }
+ } else { /// AlignJustify
+ if (properties.textAlignLastState !== KoSvgTextPropertiesModel.PropertyUnset) {
+ if (textAlignLast === KoSvgText.AlignLeft) {
+ if (properties.direction === KoSvgText.DirectionLeftToRight) {
+ alignStartBtn.checked = true;
+ } else {
+ alignEndBtn.checked = true;
+ }
+ } else if (textAlignLast === KoSvgText.AlignStart) {
+ alignStartBtn.checked = true;
+ } else if (textAlignLast === KoSvgText.AlignCenter) {
+ alignMiddleBtn.checked = true;
+ } else if (textAlignLast === KoSvgText.AlignEnd) {
+ alignEndBtn.checked = true;
+ } else if (textAlignLast === KoSvgText.AlignRight) {
+ if (properties.direction === KoSvgText.DirectionLeftToRight) {
+ alignEndBtn.checked = true;
+ } else {
+ alignStartBtn.checked = true;
+ }
+ } else {
+ alignStartBtn.checked = true;
+ }
+ }
+ }
+ }
+ }
+
+ function setAlignmentFromButtons() {
+ if (!blockSignals) {
+ if (alignStartBtn.checked) {
+ textAnchor = KoSvgText.AnchorStart;
+ } else if (alignMiddleBtn.checked) {
+ textAnchor = KoSvgText.AnchorMiddle;
+ } else {
+ textAnchor = KoSvgText.AnchorEnd;
+ }
+
+ if (alignJustifyBtn.checked) {
+ textAlignLast = textAlignAll;
+ textAlignAll = KoSvgText.AlignJustify;
+ if (alignStartBtn.checked) {
+ textAlignLast = KoSvgText.AlignStart;
+ } else if (alignMiddleBtn.checked) {
+ textAlignLast = KoSvgText.AlignCenter;
+ } else {
+ textAlignLast = KoSvgText.AlignEnd;
+ }
+ } else if (properties.textAlignAllState !== KoSvgTextPropertiesModel.PropertyUnset) {
+ if (alignStartBtn.checked) {
+ textAlignAll = KoSvgText.AlignStart;
+ } else if (alignMiddleBtn.checked) {
+ textAlignAll = KoSvgText.AlignCenter;
+ } else {
+ textAlignAll = KoSvgText.AlignEnd;
+ }
+ properties.textAlignLastState = KoSvgTextPropertiesModel.PropertyUnset;
+ }
+
+ }
+ }
+
titleItem: RowLayout {
width: parent.width;
height: childrenRect.height;
@@ -63,6 +154,63 @@ CollapsibleGroupProperty {
elide: Text.ElideRight;
Layout.maximumWidth: contentWidth;
}
+
+ ButtonGroup {
+ id: alignGroup;
+ }
+
+ Button {
+ id: alignStartBtn;
+ checkable: true;
+ icon.source: properties.direction === KoSvgText.DirectionLeftToRight? "qrc:///16_light_format-justify-left.svg"
+ : "qrc:///16_light_format-justify-right.svg";
+ icon.height: 16;
+ icon.width: 16;
+ icon.color: palette.text;
+ ButtonGroup.group: alignGroup;
+ Layout.preferredWidth: height;
+ onToggled: setAlignmentFromButtons();
+ }
+ Button {
+ id: alignMiddleBtn;
+ checkable: true;
+ icon.source: "qrc:///16_light_format-justify-center.svg";
+ icon.height: 16;
+ icon.width: 16;
+ icon.color: palette.text;
+ ButtonGroup.group: alignGroup;
+ Layout.preferredWidth: height;
+ onToggled: {
+ setAlignmentFromButtons();
+ }
+ }
+ Button {
+ id: alignEndBtn;
+ checkable: true;
+ icon.source: properties.direction === KoSvgText.DirectionLeftToRight? "qrc:///16_light_format-justify-right.svg"
+ : "qrc:///16_light_format-justify-left.svg";
+ icon.height: 16;
+ icon.width: 16;
+ icon.color: palette.text;
+ ButtonGroup.group: alignGroup;
+ Layout.preferredWidth: height;
+ onToggled: setAlignmentFromButtons();
+ }
+ Item {
+ Layout.fillWidth: true;
+ }
+
+ Button {
+ id: alignJustifyBtn;
+ checkable: true;
+ checked: textAlignAll === KoSvgText.AlignJustify;
+ icon.height: 16;
+ icon.width: 16;
+ icon.color: palette.text;
+ icon.source: "qrc:///16_light_format-justify-fill.svg";
+ Layout.preferredWidth: height;
+ onToggled: setAlignmentFromButtons();
+ }
}
onEnableProperty: properties.textAnchorState = KoSvgTextPropertiesModel.PropertySet;