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++
Overhaul the font resource dropdown so it has a textinput.
Wolthera van Hövell tot Westerflier4b69181f8b97
diff --git a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cppindex f59c92f6d4..2aede96df8 100644--- a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp+++ b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp@@ -293,6 +293,7 @@ void TagFilterProxyModelQmlWrapper::setCurrentIndex(const int &index)void TagFilterProxyModelQmlWrapper::setResourceToFileName(const QString &filename){if (!d->allResourceModel) return;+ if (d->currentResource && d->currentResource->filename() == filename) return;KoResourceSP resource = d->currentResource;QVector<KoResourceSP> resources = d->allResourceModel->resourcesForFilename(filename);if (!resources.isEmpty()) {diff --git a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.hindex 483c2b779f..319d229a23 100644--- a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h+++ b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h@@ -28,7 +28,7 @@ class TagFilterProxyModelQmlWrapper : public QObjectQ_PROPERTY(int currentTag READ currentTag WRITE tagActivated NOTIFY activeTagChanged)Q_PROPERTY(bool searchInTag READ searchInTag WRITE setSearchInTag NOTIFY searchInTagChanged)Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentResourceChanged)- Q_PROPERTY(QString resourceFilename READ resourceFilename NOTIFY currentResourceChanged)+ Q_PROPERTY(QString resourceFilename READ resourceFilename WRITE setResourceToFileName NOTIFY currentResourceChanged)Q_PROPERTY(KoResourceSP currentResource READ currentResource NOTIFY currentResourceChanged)public:TagFilterProxyModelQmlWrapper(QObject *parent = nullptr);@@ -95,7 +95,7 @@ public:void setCurrentIndex(const int &index);/// Set current resource to resource file name.- Q_INVOKABLE void setResourceToFileName(const QString &filename);+ void setResourceToFileName(const QString &filename);/// File name of the current resource.QString resourceFilename();diff --git a/plugins/dockers/textproperties/qml/FontFamily.qml b/plugins/dockers/textproperties/qml/FontFamily.qmlindex 1a678068f7..eb3501d847 100644--- a/plugins/dockers/textproperties/qml/FontFamily.qml+++ b/plugins/dockers/textproperties/qml/FontFamily.qml@@ -78,22 +78,18 @@ CollapsibleGroupProperty {locales: root.locales;onActivated: {if (fontFamilies.length >0) {- fontFamilies[0] = text;+ fontFamilies[0] = fontFileName;} else {- fontFamilies = [ text ];+ fontFamilies = [ fontFileName ];}}- Kis.ThemedControl {- id: mainCmbPalette;- }- palette: mainCmbPalette.palette;function updateCurrentIndex() {var name = mainWindow.wwsFontFamilyName(fontFamilies[0]);if (name !== modelWrapper.resourceFilename) {modelWrapper.currentTag = 0;modelWrapper.currentIndex = -1;}- modelWrapper.setResourceToFileName(name)+ fontFileName = name;}}}@@ -130,22 +126,15 @@ CollapsibleGroupProperty {Layout.fillWidth: true;locales: root.locales;onActivated: {- fontFamilies[fontListDelegate.dIndex] = text;- }- Kis.ThemedControl {- id: fontCmbPalette;+ fontFamilies[fontListDelegate.dIndex] = fontFileName;}- palette: fontCmbPalette.palette;Component.onCompleted: {if (fontListDelegate.dIndex === 0) {modelWrapper = mainFamilyCmb.modelWrapper;- } else {- updateCurrentIndex();+ fontFileName = mainWindow.wwsFontFamilyName(fontFamilies[fontListDelegate.dIndex]);}}- function updateCurrentIndex() {- modelWrapper.setResourceToFileName(mainWindow.wwsFontFamilyName(fontFamilies[fontListDelegate.dIndex]))- }+ fontFileName: mainWindow.wwsFontFamilyName(fontFamilies[fontListDelegate.dIndex]);}ToolButton {id: removeFont;diff --git a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml b/plugins/dockers/textproperties/qml/FontResourceDropdown.qmlindex f7b44d1a45..a76fadbefe 100644--- a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml+++ b/plugins/dockers/textproperties/qml/FontResourceDropdown.qml@@ -16,11 +16,21 @@ Button {//--- Model setup. ---//- property TagFilterProxyModelQmlWrapper modelWrapper : TagFilterProxyModelQmlWrapper{- id: modelWrapperId;- resourceType: "fontfamilies";- };+ property alias modelWrapper : resourceView.modelWrapper;++ Connections {+ target: modelWrapper;+ function onResourceFilenameChanged() {+ familyCmb.fontFileName = modelWrapper.resourceFilename;+ }+ }+property var locales: [];+ property alias fontFileName: textInput.text;+ topPadding: 0;+ bottomPadding: 0;+ leftPadding: (familyCmb.mirrored ? padding + indicator.width + spacing : 0);+ rightPadding: (!familyCmb.mirrored ? padding + indicator.width + spacing : 0);Kis.ThemedControl {id: palControl;@@ -30,42 +40,131 @@ Button {/// Ideally we'd have the max popup height be Window-height - y-pos-of-item-to-window./// But that's pretty hard to calculate (map to global is screen relative, but there's/// no way to get window.y relative to screen), so we'll just use 300 as the maximum.- property int maxPopupHeight: Math.min(Window.height, 300) - height*3;+ property int maxPopupHeight: Math.min(Window.height, 500) - height*3;++ contentItem: Kis.InformingTextInput {+ id: textInput;++ warnColor: palControl.theme.window.neutralBackgroundColor;+ warnColorBorder: palControl.theme.window.neutralTextColor;+ readOnly: !familyCmb.enabled;++ onEditingFinished: {+ if (familyCmbPopup.visible) {+ resourceView.applyHighlightedIndex();+ }++ testInput();+ familyCmb.activated();+ }+ onTextChanged: {+ testInput();+ }++ onTextEdited: {+ stopWarning();+ modelWrapper.searchText = text;+ resourceView.showTagging = false;+ resourceView.showSearch = false;+ familyCmbPopup.open();+ }++ onActiveFocusChanged: {+ if (activeFocus) {+ selectAll();+ }+ }++ warningTimeOut: activeFocus? 1000: 0;++ function testInput() {+ let test = mainWindow.wwsFontFamilyName(text, true);++ if (test === "") {+ if (!activeFocus) {+ startWarning();+ }+ } else {+ stopWarning();+ text = test;+ modelWrapper.resourceFilename = text;+ }+ }++ Keys.onDownPressed: {+ resourceView.downPress();+ }+ Keys.onUpPressed: {+ resourceView.upPress();+ }+ }++ indicator: Image {+ id: imgIndicator+ x: familyCmb.mirrored ? familyCmb.padding : familyCmb.width - width - familyCmb.padding+ y: familyCmb.topPadding + (familyCmb.availableHeight - height) / 2+ source: familyCmb.palette.button.hslLightness < 0.5? "qrc:///light_groupOpened.svg": "qrc:///dark_groupOpened.svg";+ width: 12;+ height: 12;+ fillMode: Image.Pad;+ clip: true;+ }- text: modelWrapper.resourceFilename;- property int highlightedIndex;onClicked: {if (familyCmbPopup.visible) {familyCmbPopup.close();} else {+ resourceView.showTagging = true;+ resourceView.showSearch = true;familyCmbPopup.open();}}signal activated();onActivated: {familyCmbPopup.close();+ modelWrapper.searchText = "";}//--- Delegate setup. ---//Component {id: fontDelegateItemDelegate {+ /**+ Ideally we'd just use required properties for the metadata etc.+ However, when changing the modelwrapper in the font list,+ there's a short moment where the model data is unavailable, so+ instead we ensure we're not accessing undefined objects.++ Not great, would like a better solution...+ */id: fontDelegateItem;required property var model;- property string fontName: model.name;- property var meta: model.metadata;+ property string name: typeof model.name !== "undefined"? model.name: "";+ property int index: model.index;+ property string fontName: name;+ property var metadata: model.metadata;// TODO: change this to use the text locale, if possible.property string sample: "";+ onMetadataChanged: {+ updateNameAndSample();+ }+Component.onCompleted: {- fontName = modelWrapper.localizedNameFromMetadata(meta, familyCmb.locales, model.name);- sample = modelWrapper.localizedSampleFromMetadata(meta, familyCmb.locales, "");+ updateNameAndSample();+ }++ function updateNameAndSample() {+ if (typeof metadata == "undefined") return;+ fontName = modelWrapper.localizedNameFromMetadata(metadata, familyCmb.locales, name);+ sample = modelWrapper.localizedSampleFromMetadata(metadata, familyCmb.locales, "");}/// When updating the model wrapper, the "model" doesn't always update on the delegate, so we need to manually load/// the metadata from the modelwrapper.width: ListView.view.width;- highlighted: familyCmb.highlightedIndex === model.index;+ highlighted: resourceView.highlightedIndex === model.index;+ property bool selected: resourceView.modelWrapper.currentIndex === model.index;palette: familyCmb.palette;@@ -90,8 +189,8 @@ Button {Binding {target: fontFamilyDelegateproperty: "meta"- when: fontDelegateItem && typeof fontDelegateItem !== 'undefined';- value: fontDelegateItem.meta;+ when: fontDelegateItem && typeof fontDelegateItem !== 'undefined' && typeof fontDelegateItem.metadata !== 'undefined';+ value: fontDelegateItem.metadata;}property var meta: ({});@@ -208,20 +307,25 @@ Button {acceptedButtons: Qt.RightButton | Qt.LeftButton;anchors.fill: parent;hoverEnabled: true;+ // Itemdelegate can also handle hovers, but we don't use those.+ preventStealing: true;onClicked: {if (mouse.button === Qt.RightButton) {resourceView.openContextMenu(mouse.x, mouse.y, parent.model.name, parent.model.index);} else {- familyCmb.modelWrapper.currentIndex = parent.model.index;+ resourceView.applyHighlightedIndex();familyCmb.activated();}}- onHoveredChanged: familyCmb.highlightedIndex = parent.model.index;+ onContainsMouseChanged: {+ if(containsMouse) {+ resourceView.highlightedIndex = parent.index;+ }+ }ToolTip.text: fontDelegateItem.fontName;ToolTip.visible: containsMouse;ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval;-}}}@@ -231,7 +335,7 @@ Button {id: familyCmbPopup;y: familyCmb.height - 1;x: familyCmb.width - width;- width: contentWidth;+ width: Math.max(contentWidth, familyCmb.width);height: Math.min(contentItem.implicitHeight, familyCmb.maxPopupHeight - topMargin - bottomMargin)padding: 2;@@ -239,7 +343,7 @@ Button {contentItem: ResourceView {id: resourceView;- modelWrapper: familyCmb.modelWrapper;+ resourceType: "fontfamilies";resourceDelegate: fontDelegate;palette: familyCmbPopup.palette;addResourceRow.visible: false;diff --git a/plugins/dockers/textproperties/qml/ResourceView.qml b/plugins/dockers/textproperties/qml/ResourceView.qmlindex c28dbaebe5..ddb8e26ab5 100644--- a/plugins/dockers/textproperties/qml/ResourceView.qml+++ b/plugins/dockers/textproperties/qml/ResourceView.qml@@ -11,18 +11,60 @@ import org.krita.components 1.0 as KisControl {id: control;- property TagFilterProxyModelQmlWrapper modelWrapper: TagFilterProxyModelQmlWrapper{- id: modelWrapperId;+ property TagFilterProxyModelQmlWrapper modelWrapper: TagFilterProxyModelQmlWrapper {+ resourceType: control.resourceType;};- property alias resourceType : modelWrapperId.resourceType;- property alias currentIndex : modelWrapperId.currentIndex;- property alias currentResource : modelWrapperId.currentResource;++ Connections {+ target: modelWrapper;+ function onCurrentIndexChanged() {+ control.highlightedIndex = modelWrapper.currentIndex;+ }+ function onResourceTypeChanged() {+ control.resourceType = modelWrapper.resourceType;+ }+ }++ /*+ \qmlProperty resourceType+ A string corresponding to KisResourceTypes.h ResourceType.+ Used to set the resource model and tagging models.++ Because modelwrapper can change, we cannot use aliasing here.+ */+ property string resourceType;+ onResourceTypeChanged: modelWrapper.resourceType = resourceType;+++ /*++ */+ property alias highlightedIndex : view.currentIndex;property alias resourceDelegate : view.delegate;property alias addResourceRow: addResourceRow;property alias additionalAddResourceRow: addResourceRow.data;+ property alias showTagging: tagAndConfig.visible;+ property alias showSearch: searchBar.visible;++ function downPress() {+ highlightedIndex += 1;+ }+ function upPress() {+ highlightedIndex -= 1;+ }++ function applyHighlightedIndex() {+ if (modelWrapper) {+ modelWrapper.currentIndex = highlightedIndex;+ }+ }++ Keys.onDownPressed: downPress();+ Keys.onUpPressed: upPress();+function openContextMenu(x, y, resourceName, resourceIndex) {tagActionsContextMenu.resourceName = resourceName;tagActionsContextMenu.resourceIndex = resourceIndex;@@ -35,11 +77,12 @@ Control {anchors.fill: parent;property alias resourceModel : view.model;property alias tagModel: tagFilter.model;- resourceModel: visible? modelWrapper.model: null;+ resourceModel: modelWrapper.model;tagModel: modelWrapper.tagModel;RowLayout {id: tagAndConfig;+ height: visible? implicitHeight: 0;ComboBox {id: tagFilter;@@ -184,12 +227,18 @@ Control {ListView {anchors.fill: parent;id: view;- currentIndex: modelWrapper.currentIndex;+ currentIndex: 0;++ Keys.onDownPressed: control.downPress();+ Keys.onUpPressed: control.upPress();+ScrollBar.vertical: ScrollBar {}}}RowLayout {+ id: searchBar;+ height: visible? implicitHeight: 0;Layout.preferredHeight: childrenRect.height;TextField {id: search;diff --git a/plugins/dockers/textproperties/qml/TextProperties.qml b/plugins/dockers/textproperties/qml/TextProperties.qmlindex 075967d472..e6d74e16c1 100644--- a/plugins/dockers/textproperties/qml/TextProperties.qml+++ b/plugins/dockers/textproperties/qml/TextProperties.qml@@ -122,7 +122,7 @@ Control {signal applyPreset;onApplyPreset: {- canvasObserver.applyPreset(currentResource);+ canvasObserver.applyPreset(modelWrapper.currentResource);}resourceDelegate: ItemDelegate {@@ -130,8 +130,8 @@ Control {required property var model;property var meta: model.metadata;width: ListView.view.width;- highlighted: delegateMouseArea.containsMouse;- property bool selected: presetView.currentIndex === model.index;+ highlighted: presetView.highlightedIndex === model.index;+ property bool selected: presetView.modelWrapper.currentIndex === model.index;palette: presetView.palette;contentItem: KoShapeQtQuickLabel {implicitHeight: nameLabel.height * 4;@@ -179,17 +179,23 @@ Control {acceptedButtons: Qt.RightButton | Qt.LeftButton;anchors.fill: parent;hoverEnabled: true;+ preventStealing: true;onClicked: {if (mouse.button === Qt.RightButton) {presetView.openContextMenu(mouse.x, mouse.y, parent.model.name, parent.model.index);} else {- presetView.modelWrapper.currentIndex = parent.model.index;+ presetView.applyHighlightedIndex();}}onDoubleClicked: {- presetView.modelWrapper.currentIndex = parent.model.index;+ presetView.applyHighlightedIndex();presetView.applyPreset();}+ onContainsMouseChanged: {+ if (containsMouse) {+ presetView.highlightedIndex = parent.model.index;+ }+ }readonly property string missingFontName : i18nc("%1 is name of a font family", "Font Family \"%1\" is missing on this machine. This style preset may not work correctly.", presetDelegate.meta.primary_font_family);ToolTip.text: (typeof presetDelegate.meta.description !== 'undefined'? presetDelegate.model.name + "\n" + presetDelegate.meta.description: presetDelegate.model.name) + (missingFamily.visible? "\n"+ missingFontName: "");@@ -227,14 +233,14 @@ Control {icon.color: palette.text;icon.width: 16;icon.height: 16;- onClicked: canvasObserver.editPreset(presetView.currentResource);+ onClicked: canvasObserver.editPreset(presetView.modelWrapper.currentResource);hoverEnabled: true;Kis.ThemedControl {id: editPalette;}palette: editPalette.palette;- enabled: presetView.currentIndex >= 0;+ enabled: presetView.modelWrapper.currentIndex >= 0;ToolTip.visible: hovered;ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval;ToolTip.text: text;@@ -246,14 +252,14 @@ Control {icon.color: palette.text;icon.width: 16;icon.height: 16;- onClicked: canvasObserver.cloneAndEditPreset(presetView.currentResource);+ onClicked: canvasObserver.cloneAndEditPreset(presetView.modelWrapper.currentResource);hoverEnabled: true;Kis.ThemedControl {id: cloneButtonPalette;}palette: cloneButtonPalette.palette;- enabled: presetView.currentIndex >= 0;+ enabled: presetView.modelWrapper.currentIndex >= 0;ToolTip.visible: hovered;ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval;ToolTip.text: text;diff --git a/qmlmodules/components/CMakeLists.txt b/qmlmodules/components/CMakeLists.txtindex bf5509c5dc..e24fe7f2dc 100644--- a/qmlmodules/components/CMakeLists.txt+++ b/qmlmodules/components/CMakeLists.txt@@ -86,6 +86,7 @@ ecm_target_qml_sources(kritaqmlcomponents SOURCESqml/curvewidget/CurveWidget.qmlqml/AngleSelector.qml+ qml/InformingTextInput.qml)if (QT_MAJOR_VERSION STREQUAL "6")diff --git a/qmlmodules/components/qml/InformingTextInput.qml b/qmlmodules/components/qml/InformingTextInput.qmlnew file mode 100644index 0000000000..f1b041da14--- /dev/null+++ b/qmlmodules/components/qml/InformingTextInput.qml@@ -0,0 +1,135 @@+/*+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.15+import QtQuick.Controls 2.15+import org.krita.components 1.0 as Kis+import "overlays"++/**+ \qmltype InformingTextInput++ This is a FocusScope containing a text input and a warningOverlay.++ \qml+ Button {+ id: button;+ contentItem: InformingTextInput {+ id: textInput;+ onEditingFinished: {+ let valid: button.validate(textInput.text);+ if (valid) {+ stopWarning()+ } else {+ startWarning()+ }+ }+ }++ /// Assume this does something more useful than check+ /// if text is literally the string "Valid".+ funcion validate(text) {+ text == "Valid";+ }+ }+ \endqml++ */+TextField {+ id: root++ // Forwarded aliases.++ /*+ \qmlproperty backgroundColor+ Color of the background.+ */+ property alias backgroundColor: bgColor.color;++ /*+ \qmlproperty backgroundBorderColor+ Color of the border when not in focus.+ */+ property color backgroundBorderColor: theme.window.midShadeColor;++ /*+ \qmlproperty warn+ Whether the warning overlay is visible;+ */+ property alias warn: warningOverlay.warn;+ /*+ \qmlproperty warnColor+ Color of the warn bgcolor, defaults to negativeTextColor;+ */+ property alias warnColor: warningOverlay.color;+ /*+ \qmlproperty warnColorBorder+ Color of the border when warning, defaults to negativeTextColor;+ */+ property color warnColorBorder: theme.window.negativeTextColor;++ /*+ \qmlproperty warningTimeOut+ The time out till it shows the warning. This is 2000 ms by default+ to ensure that the warning doesn't pop-up too early.+ */+ property alias warningTimeOut: warningTimer.interval;++ color: theme.view.textColor;+ selectedTextColor: theme.selection.textColor;+ selectionColor: theme.selection.backgroundColor;+ /// Start warning. This calls a timer.+ function startWarning() {+ warningTimer.start();+ }+ /// Stop warning.+ function stopWarning() {+ warningTimer.stop();+ warn = false;+ }++ Kis.Theme {+ id: theme;+ window.state: root.enabled? SystemPalette.Active: SystemPalette.Disabled;+ button.state: root.enabled? SystemPalette.Active: SystemPalette.Disabled;+ selection.state: root.enabled? SystemPalette.Active: SystemPalette.Disabled;+ }++ background: Rectangle {+ id: bgColor;+ radius: 1;+ color: theme.view.backgroundColor;+ WarningOverlay {+ id: warningOverlay;+ anchors.fill: parent;+ clip: true;++ radius: bgColor.radius;+ showWarningSign: width - textMetrics.boundingRect.width > 24 * (root.horizontalAlignment === Qt.AlignHCenter ? 2 : 1)+ warningSignAlignment: Qt.AlignRight;+ color: theme.window.negativeBackgroundColor;+ }++ Rectangle {+ anchors.fill: parent;+ color: "transparent";+ radius: bgColor.radius;+ border.width: 1;+ border.color: warningOverlay.warn? root.warnColorBorder: root.activeFocus ? theme.view.focusColor : backgroundBorderColor;+ }+ }++ Timer {+ id: warningTimer+ interval: 2000;+ onTriggered: warningOverlay.warn = true+ }++ TextMetrics {+ id: textMetrics+ font: root.font+ text: root.text;+ }+}diff --git a/qmlmodules/components/qml/overlays/WarningOverlay.qml b/qmlmodules/components/qml/overlays/WarningOverlay.qmlindex 74db7acd48..590ac80d8f 100644--- a/qmlmodules/components/qml/overlays/WarningOverlay.qml+++ b/qmlmodules/components/qml/overlays/WarningOverlay.qml@@ -38,6 +38,8 @@ Item {*/property alias radius: background.radius+ property alias color: background.color;+states: [State {name: "warning"@@ -142,7 +144,7 @@ Item {Rectangle {id: backgroundanchors.fill: parent- color: theme.view.negativeBackgroundColor;+ color: theme.window.negativeBackgroundColor;opacity: 0Kis.Theme {@@ -161,7 +163,7 @@ Item {Image {anchors.fill: parentanchors.margins: 4- source: "qrc:///16_light_warning.svg"+ source: root.color.hslLightness < 0.5? "qrc:///16_light_warning.svg": "qrc:///16_dark_warning.svg";}}}