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++
Create resource view with tagging and search for the fontfamily dropdown.
Wolthera van Hövell tot Westerflier345869126bca
diff --git a/plugins/dockers/textproperties/TextPropertiesDock.cpp b/plugins/dockers/textproperties/TextPropertiesDock.cppindex c97bbcfdab..35b5b1142e 100644--- a/plugins/dockers/textproperties/TextPropertiesDock.cpp+++ b/plugins/dockers/textproperties/TextPropertiesDock.cpp@@ -26,6 +26,7 @@#include <KisResourceModel.h>#include <KisResourceModelProvider.h>#include <KisTagFilterResourceProxyModel.h>+#include <KisTagModel.h>#include <KoCanvasResourcesIds.h>#include <KoSvgTextPropertyData.h>@@ -91,6 +92,7 @@ struct TextPropertiesDock::PrivateFontAxesModel axesModel;KisAllResourcesModel *fontModel{nullptr};KisTagFilterResourceProxyModel *fontTagFilterProxyModel {nullptr};+ KisTagModel *tagModel{nullptr};KisCanvasResourceProvider *provider{nullptr};};@@ -123,12 +125,14 @@ TextPropertiesDock::TextPropertiesDock()d->fontTagFilterProxyModel = new KisTagFilterResourceProxyModel(ResourceType::FontFamilies);d->fontTagFilterProxyModel->setSourceModel(d->fontModel);d->fontTagFilterProxyModel->sort(KisAbstractResourceModel::Name);+ d->tagModel = new KisTagModel(ResourceType::FontFamilies);connect(d->textModel, SIGNAL(axisValuesChanged(const QVariantHash&)), &d->axesModel, SLOT(setAxisValues(const QVariantHash&)));connect(&d->axesModel, SIGNAL(axisValuesChanged()), this, SLOT(slotUpdateAxesValues()));m_quickWidget->rootContext()->setContextProperty("textPropertiesModel", d->textModel);m_quickWidget->rootContext()->setContextProperty("fontFamiliesModel", QVariant::fromValue(d->fontTagFilterProxyModel));+ m_quickWidget->rootContext()->setContextProperty("fontTagModel", QVariant::fromValue(d->tagModel));m_quickWidget->rootContext()->setContextProperty("fontStylesModel", QVariant::fromValue(&d->stylesModel));m_quickWidget->rootContext()->setContextProperty("fontAxesModel", QVariant::fromValue(&d->axesModel));connect(d->textModel, SIGNAL(textPropertyChanged()),@@ -232,4 +236,22 @@ void TextPropertiesDock::slotUpdateAxesValues(){d->textModel->setaxisValues(d->axesModel.axisValues());}++void TextPropertiesDock::slotFontTagActivated(int row)+{+ QModelIndex idx = d->tagModel->index(row, 0);+ if (idx.isValid()) {+ d->fontTagFilterProxyModel->setTagFilter(d->tagModel->tagForIndex(idx));+ }+}++void TextPropertiesDock::slotFontSearchTextChanged(const QString &text)+{+ d->fontTagFilterProxyModel->setSearchText(text);+}++void TextPropertiesDock::slotFontSearchInTag(const bool checked)+{+ d->fontTagFilterProxyModel->setFilterInCurrentTag(checked);+}#include "TextPropertiesDock.moc"diff --git a/plugins/dockers/textproperties/TextPropertiesDock.h b/plugins/dockers/textproperties/TextPropertiesDock.hindex e6ec6bbaf4..96e4dbebfb 100644--- a/plugins/dockers/textproperties/TextPropertiesDock.h+++ b/plugins/dockers/textproperties/TextPropertiesDock.h@@ -34,6 +34,9 @@ public Q_SLOTS:void slotTextPropertiesChanged();void slotUpdateStylesModel();void slotUpdateAxesValues();+ void slotFontTagActivated(int row);+ void slotFontSearchTextChanged(const QString &text);+ void slotFontSearchInTag(const bool checked);void connectAutoEnabler(QObject *watched);private:diff --git a/plugins/dockers/textproperties/qml/FontFamily.qml b/plugins/dockers/textproperties/qml/FontFamily.qmlindex c35d6c0d10..baaf4d1f62 100644--- a/plugins/dockers/textproperties/qml/FontFamily.qml+++ b/plugins/dockers/textproperties/qml/FontFamily.qml@@ -47,6 +47,33 @@ CollapsibleGroupProperty {}}textRole: "name";++ delegate: ItemDelegate {+ required property var model;+ contentItem: Label {+ text: model.name;+ Layout.fillWidth: true;+ height:implicitHeight;+ }+ width: fontResourceView.listWidth;+ highlighted: mainFamilyCmb.highlightedIndex === model.index;+ background: Rectangle { color: highlighted? parent.palette.highlight:"transparent"; }+ }+ popup: Popup {+ y: mainFamilyCmb.height - 1;+ x: mainFamilyCmb.width - width;+ width: contentWidth;+ height: contentHeight;+ padding: 1;++ contentItem: FontResourceView {+ id: fontResourceView;+ fontModel: mainFamilyCmb.delegateModel;+ tagModel: fontTagModel;+ currentIndex: mainFamilyCmb.highlightedIndex;+ }+ palette: mainFamilyCmb.palette;+ }wheelEnabled: true;}diff --git a/plugins/dockers/textproperties/qml/FontResourceView.qml b/plugins/dockers/textproperties/qml/FontResourceView.qmlnew file mode 100644index 0000000000..5154a4d597--- /dev/null+++ b/plugins/dockers/textproperties/qml/FontResourceView.qml@@ -0,0 +1,61 @@+/*+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.0+import QtQuick.Controls 2.15+import QtQuick.Layouts 1.12+import org.krita.flake.text 1.0+++ColumnLayout {+ id: root;+ clip:true;+ property var fontModel;+ property var tagModel;+ property alias currentIndex : view.currentIndex;+ property alias listWidth : view.width;++ RowLayout {+ id: tagAndConfig;++ ComboBox {+ id: tagFilter;+ model: tagModel;+ textRole: "display";+ Layout.fillWidth: true;+ onActivated: {+ mainWindow.slotFontTagActivated(currentIndex);+ }+ }++ }+ Frame {+ Layout.minimumHeight: font.pixelSize*3;+ Layout.preferredHeight: 300;+ Layout.maximumHeight: 500;+ Layout.fillWidth: true;+ clip: true;+ ListView {+ anchors.fill: parent;+ id: view;+ model: fontModel;+ ScrollBar.vertical: ScrollBar {+ }+ }+ }+ RowLayout {+ TextField {+ id: search;+ placeholderText: i18nc("@info:placeholder", "Search...");+ Layout.fillWidth: true;+ onTextEdited: mainWindow.slotFontSearchTextChanged(text);+ }+ CheckBox {+ id: opticalSizeCbx+ text: i18nc("@option:check", "Search in tag")+ onCheckedChanged: mainWindow.slotFontSearchInTag(checked);+ }+ }+}diff --git a/plugins/dockers/textproperties/textproperties.qrc b/plugins/dockers/textproperties/textproperties.qrcindex d39b208585..4190ddca17 100644--- a/plugins/dockers/textproperties/textproperties.qrc+++ b/plugins/dockers/textproperties/textproperties.qrc@@ -34,5 +34,6 @@<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>+ <file alias="FontResourceView.qml">qml/FontResourceView.qml</file></qresource></RCC>