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 autoenabler for fontstyle properties and add tristate icon.

Wolthera van Hövell tot Westerflier53a17b03f095
diff --git a/plugins/dockers/textproperties/TextPropertiesDock.cpp b/plugins/dockers/textproperties/TextPropertiesDock.cpp
index b0b76be53d..0f445b070f 100644
--- a/plugins/dockers/textproperties/TextPropertiesDock.cpp
+++ b/plugins/dockers/textproperties/TextPropertiesDock.cpp
@@ -44,6 +44,35 @@ KIS_DECLARE_STATIC_INITIALIZER {
qmlRegisterUncreatableMetaObject(KoSvgText::staticMetaObject, "org.krita.flake.text", 1, 0, "KoSvgText", "Error: Namespace with enums");
}
+
+/// This will call the 'autoEnable' function on any "watched" QObject.
+/// Within QML, this should be used with a MouseArea that holds the disabled QtQuickControl
+/// The autoEnable function on this MouseArea should enable the QtQuick control.
+/// This is because disabled QtQuickControls never receive mouse events.
+struct TextPropertyAutoEnabler : public QObject {
+ Q_OBJECT
+public:
+ TextPropertyAutoEnabler (QObject *watched, QObject *parent)
+ : QObject(parent), m_watched(watched) {
+ watched->installEventFilter(this);
+ }
+
+ bool eventFilter(QObject *watched, QEvent *event) override {
+ if (watched != m_watched) return false;
+
+ if (event->type() == QEvent::MouseButtonPress ||
+ event->type() == QEvent::TabletPress ||
+ event->type() == QEvent::TouchBegin) {
+
+ QMetaObject::invokeMethod(m_watched, "autoEnable");
+ }
+
+ return false;
+ }
+private:
+ QObject *m_watched;
+};
+
struct TextPropertiesDock::Private
{
KoSvgTextPropertiesModel *textModel {new KoSvgTextPropertiesModel()};
@@ -128,6 +157,13 @@ void TextPropertiesDock::unsetCanvas()
m_canvas = 0;
}
+void TextPropertiesDock::connectAutoEnabler(QObject *watched)
+{
+ KIS_SAFE_ASSERT_RECOVER_RETURN(watched);
+
+ TextPropertyAutoEnabler *enabler = new TextPropertyAutoEnabler(watched, this);
+}
+
void TextPropertiesDock::slotCanvasTextPropertiesChanged()
{
KoSvgTextPropertyData data = d->provider->textPropertyData();
@@ -147,3 +183,4 @@ void TextPropertiesDock::slotTextPropertiesChanged()
d->provider->setTextPropertyData(textData);
}
}
+#include "TextPropertiesDock.moc"
diff --git a/plugins/dockers/textproperties/TextPropertiesDock.h b/plugins/dockers/textproperties/TextPropertiesDock.h
index eb67d35093..1a17632d93 100644
--- a/plugins/dockers/textproperties/TextPropertiesDock.h
+++ b/plugins/dockers/textproperties/TextPropertiesDock.h
@@ -27,9 +27,12 @@ public:
void setCanvas(KoCanvasBase *canvas) override;
void unsetCanvas() override;
+
+
public Q_SLOTS:
void slotCanvasTextPropertiesChanged();
void slotTextPropertiesChanged();
+ void connectAutoEnabler(QObject *watched);
private:
QPointer<KisCanvas2> m_canvas;
diff --git a/plugins/dockers/textproperties/icons/light_edit-undo-tristate.svg b/plugins/dockers/textproperties/icons/light_edit-undo-tristate.svg
new file mode 100644
index 0000000000..6c5f483416
--- /dev/null
+++ b/plugins/dockers/textproperties/icons/light_edit-undo-tristate.svg
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ viewBox="0 0 22 22"
+ version="1.1"
+ id="svg2"
+ height="22"
+ width="22"
+ sodipodi:docname="light_edit-undo-tristate.svg"
+ inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <defs
+ id="defs9" />
+ <sodipodi:namedview
+ id="namedview7"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:showpageshadow="2"
+ inkscape:pageopacity="0.0"
+ inkscape:pagecheckerboard="0"
+ inkscape:deskcolor="#d1d1d1"
+ showgrid="true"
+ inkscape:zoom="34.947"
+ inkscape:cx="7.5972186"
+ inkscape:cy="2.2891808"
+ inkscape:window-width="1920"
+ inkscape:window-height="1010"
+ inkscape:window-x="0"
+ inkscape:window-y="0"
+ inkscape:window-maximized="1"
+ inkscape:current-layer="svg2">
+ <inkscape:grid
+ type="xygrid"
+ id="grid1986" />
+ </sodipodi:namedview>
+ <metadata
+ id="metadata7">
+ <rdf:RDF>
+ <cc:Work>
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:date>2021</dc:date>
+ <dc:creator>
+ <cc:Agent>
+ <dc:title>Wolthera van Hövell tot Westerflier</dc:title>
+ </cc:Agent>
+ </dc:creator>
+ <cc:license
+ rdf:resource="http://creativecommons.org/licenses/by-sa/4.0/" />
+ </cc:Work>
+ <cc:License
+ rdf:about="http://creativecommons.org/licenses/by-sa/4.0/">
+ <cc:permits
+ rdf:resource="http://creativecommons.org/ns#Reproduction" />
+ <cc:permits
+ rdf:resource="http://creativecommons.org/ns#Distribution" />
+ <cc:requires
+ rdf:resource="http://creativecommons.org/ns#Notice" />
+ <cc:requires
+ rdf:resource="http://creativecommons.org/ns#Attribution" />
+ <cc:permits
+ rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
+ <cc:requires
+ rdf:resource="http://creativecommons.org/ns#ShareAlike" />
+ </cc:License>
+ </rdf:RDF>
+ </metadata>
+ <path
+ id="path824"
+ d="M 10.5,5 V 7 H 11 c 2.761426,0 4.999998,2.2385763 4.999998,5 0,2.761424 -2.238572,5 -4.999998,5 H 9 v 2 h 2 c 3.865996,0 6.999997,-3.134007 6.999997,-7 0,-3.8659932 -3.134001,-7 -6.999997,-7 z"
+ style="vector-effect:none;fill:#d2d2d2;fill-opacity:1;stroke:none;stroke-width:4;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:3.2;stroke-opacity:0.550633"
+ sodipodi:nodetypes="ccsssccsssc" />
+ <path
+ id="path842"
+ style="fill:#d2d2d2;fill-opacity:0.66000003;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ d="M 9,2 5,6 9,10 V 8.4140625 L 6.5859375,6 9,3.5859375 Z"
+ sodipodi:nodetypes="ccccccc" />
+ <path
+ id="path842-9"
+ style="fill:#d2d2d2;fill-opacity:0.33000001;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ d="M 5,2 1,6 5,10 V 8.4140625 L 2.5859375,6 5,3.5859375 Z"
+ sodipodi:nodetypes="ccccccc" />
+ <path
+ id="path842-1"
+ d="m 9,6 4,4 V 2 Z"
+ style="fill:#d2d2d2;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
+</svg>
diff --git a/plugins/dockers/textproperties/qml/DoubleSpinBox.qml b/plugins/dockers/textproperties/qml/DoubleSpinBox.qml
index 44ebc7003d..c1708a9660 100644
--- a/plugins/dockers/textproperties/qml/DoubleSpinBox.qml
+++ b/plugins/dockers/textproperties/qml/DoubleSpinBox.qml
@@ -10,6 +10,7 @@ import QtQuick.Controls 2.15
// Simple double spinbox based on Qt example implementation, should proly be switched to spinbox slider at some point.
SpinBox {
editable: true;
+ wheelEnabled: true;
property int decimals: 2;
property int multiplier: Math.pow(10, decimals);
diff --git a/plugins/dockers/textproperties/qml/FontStyle.qml b/plugins/dockers/textproperties/qml/FontStyle.qml
index 5d580536a7..6ad0451bdd 100644
--- a/plugins/dockers/textproperties/qml/FontStyle.qml
+++ b/plugins/dockers/textproperties/qml/FontStyle.qml
@@ -38,6 +38,11 @@ CollapsibleGroupProperty {
|| properties.fontStyleState !== KoSvgTextPropertiesModel.PropertyUnset
|| properties.fontWidthState !== KoSvgTextPropertiesModel.PropertyUnset;
blockSignals = false;
+
+ fontWeightSpn.enabled = properties.fontWeightState !== KoSvgTextPropertiesModel.PropertyTriState;
+ fontStretchSpn.enabled = properties.fontWidthState !== KoSvgTextPropertiesModel.PropertyTriState;
+ fontSlantCmb.enabled = properties.fontStyleState !== KoSvgTextPropertiesModel.PropertyTriState;
+ opticalSizeCbx.enabled = properties.fontOpticalSizeLinkState !== KoSvgTextPropertiesModel.PropertyTriState;
}
onFontWeightChanged: {
if (!blockSignals) {
@@ -61,6 +66,13 @@ CollapsibleGroupProperty {
properties.fontWeightState = KoSvgTextPropertiesModel.PropertySet;
}
+ Component.onCompleted: {
+ mainWindow.connectAutoEnabler(fontWeightArea);
+ mainWindow.connectAutoEnabler(fontStretchArea);
+ mainWindow.connectAutoEnabler(fontSlantArea);
+ mainWindow.connectAutoEnabler(fontOpticalArea);
+ }
+
titleItem: ComboBox {
id: styleCmb;
Layout.fillWidth: true;
@@ -85,12 +97,24 @@ CollapsibleGroupProperty {
elide: Text.ElideRight;
}
- SpinBox {
- id: fontWeightSpn
- from: 0;
- to: 1000;
- editable: true;
- Layout.fillWidth: true
+ MouseArea {
+ id: fontWeightArea;
+ function autoEnable() {
+ fontWeightSpn.enabled = true;
+ }
+ Layout.fillWidth: true;
+ Layout.fillHeight: true;
+
+ SpinBox {
+ id: fontWeightSpn
+ from: 0;
+ to: 1000;
+ editable: true;
+ width: parent.width;
+
+ wheelEnabled: true;
+
+ }
}
@@ -106,12 +130,21 @@ CollapsibleGroupProperty {
elide: Text.ElideRight;
}
- SpinBox {
- id: fontStretchSpn
- from: 0;
- to: 200;
- editable: true;
- Layout.fillWidth: true
+ MouseArea {
+ id: fontStretchArea;
+ function autoEnable() {
+ fontStretchSpn.enabled = true;
+ }
+ Layout.fillWidth: true;
+ Layout.fillHeight: true;
+ SpinBox {
+ id: fontStretchSpn
+ from: 0;
+ to: 200;
+ editable: true;
+ width: parent.width;
+ wheelEnabled: true;
+ }
}
RevertPropertyButton {
@@ -126,17 +159,27 @@ CollapsibleGroupProperty {
elide: Text.ElideRight;
}
- ComboBox {
- id: fontSlantCmb
- model: [
- {text: i18nc("@label:inlistbox", "Normal"), value: KoSvgTextPropertiesModel.StyleNormal},
- {text: i18nc("@label:inlistbox", "Italic"), value: KoSvgTextPropertiesModel.StyleItalic},
- {text: i18nc("@label:inlistbox", "Oblique"), value: KoSvgTextPropertiesModel.StyleOblique}
- ]
- Layout.fillWidth: true
- textRole: "text";
- valueRole: "value";
- onActivated: fontSlant = currentValue;
+ MouseArea {
+ id: fontSlantArea;
+ function autoEnable() {
+ fontSlantCmb.enabled = true;
+ }
+ Layout.fillWidth: true;
+ Layout.fillHeight: true;
+ ComboBox {
+ id: fontSlantCmb
+ model: [
+ {text: i18nc("@label:inlistbox", "Normal"), value: KoSvgTextPropertiesModel.StyleNormal},
+ {text: i18nc("@label:inlistbox", "Italic"), value: KoSvgTextPropertiesModel.StyleItalic},
+ {text: i18nc("@label:inlistbox", "Oblique"), value: KoSvgTextPropertiesModel.StyleOblique}
+ ]
+ Layout.fillWidth: true
+ textRole: "text";
+ valueRole: "value";
+ onActivated: fontSlant = currentValue;
+ wheelEnabled: true;
+ width: parent.width;
+ }
}
RevertPropertyButton {
@@ -146,10 +189,18 @@ CollapsibleGroupProperty {
Item {
width: 1;
height: 1;}
+ MouseArea {
+ id: fontOpticalArea;
+ function autoEnable() {
+ opticalSizeCbx.enabled = true;
+ }
+ Layout.fillWidth: true;
+ Layout.fillHeight: true;
CheckBox {
id: opticalSizeCbx
text: i18nc("@option:check", "Optical Size")
- Layout.fillWidth: true
+ width: parent.width;
+ }
}
}
diff --git a/plugins/dockers/textproperties/qml/RevertPropertyButton.qml b/plugins/dockers/textproperties/qml/RevertPropertyButton.qml
index 0721c751e1..806b6a56dc 100644
--- a/plugins/dockers/textproperties/qml/RevertPropertyButton.qml
+++ b/plugins/dockers/textproperties/qml/RevertPropertyButton.qml
@@ -19,11 +19,11 @@ Item {
id: revert;
icon.width: 22;
icon.height: 22;
- icon.color: revertState === KoSvgTextPropertiesModel.PropertyTriState? sysPalette.highlight: sysPalette.text;
+ icon.color: /*revertState === KoSvgTextPropertiesModel.PropertyTriState? sysPalette.highlight:*/ sysPalette.text;
enabled: revertState !== KoSvgTextPropertiesModel.PropertyUnset && revertState !== KoSvgTextPropertiesModel.PropertyInherited;
- opacity: enabled? 1.0: 0.5;
+ opacity: enabled? 1.0: 0.3;
display: AbstractButton.IconOnly
- icon.source: parent.inheritable? "qrc:///light_edit-undo.svg": "qrc:///22_light_trash-empty.svg";
+ icon.source: parent.inheritable? revertState === KoSvgTextPropertiesModel.PropertyTriState? "qrc:///light_edit-undo-tristate.svg": "qrc:///light_edit-undo.svg": "qrc:///22_light_trash-empty.svg";
onClicked: parent.clicked();
}
}
diff --git a/plugins/dockers/textproperties/qml/TextPropertyBase.qml b/plugins/dockers/textproperties/qml/TextPropertyBase.qml
index b5e4f9b36f..fa8ebe994d 100644
--- a/plugins/dockers/textproperties/qml/TextPropertyBase.qml
+++ b/plugins/dockers/textproperties/qml/TextPropertyBase.qml
@@ -32,6 +32,10 @@ Column {
property string toolTip;
property string searchTerms;
+ function autoEnable() {
+ enabled = true;
+ }
+
MenuSeparator {
width: parent.width;
}
diff --git a/plugins/dockers/textproperties/textproperties.qrc b/plugins/dockers/textproperties/textproperties.qrc
index 9c95a34b54..d39b208585 100644
--- a/plugins/dockers/textproperties/textproperties.qrc
+++ b/plugins/dockers/textproperties/textproperties.qrc
@@ -33,5 +33,6 @@
<file alias="TextPropertyBaseList.qml">qml/TextPropertyBaseList.qml</file>
<file alias="UnitComboBox.qml">qml/UnitComboBox.qml</file>
<file alias="DoubleSpinBox.qml">qml/DoubleSpinBox.qml</file>
+ <file alias="light_edit-undo-tristate.svg">icons/light_edit-undo-tristate.svg</file>
</qresource>
</RCC>