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++
Refactor font family dropdown to a button with pop-up.
Wolthera van Hövell tot Westerflierb4cd52134613
diff --git a/plugins/dockers/textproperties/CMakeLists.txt b/plugins/dockers/textproperties/CMakeLists.txtindex 1061cd1aa4..83db9d5096 100644--- a/plugins/dockers/textproperties/CMakeLists.txt+++ b/plugins/dockers/textproperties/CMakeLists.txt@@ -4,6 +4,7 @@ set(KRITA_TEXTPROPERTIES_SOURCESFontStyleModel.cppFontAxesModel.cppKoShapeQtQuickLabel.cpp+ TagFilterProxyModelQmlWrapper.cpp)qt_add_resources(KRITA_TEXTPROPERTIES_SOURCES textproperties.qrc)diff --git a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cppnew file mode 100644index 0000000000..50a0835a5c--- /dev/null+++ b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.cpp@@ -0,0 +1,266 @@+/*+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#include "TagFilterProxyModelQmlWrapper.h"++#include <KisResourceModel.h>+#include <KisResourceModelProvider.h>+#include <KisTagFilterResourceProxyModel.h>+#include <KisTagModel.h>+#include <KisTagResourceModel.h>+#include <kis_signal_compressor.h>++#include <resources/KoFontFamily.h>++struct TagFilterProxyModelQmlWrapper::Private {+ Private()+ : tagFilterProxyModel(new KisTagFilterResourceProxyModel(ResourceType::FontFamilies))+ , tagModel(new KisTagModel(ResourceType::FontFamilies))+ , compressor(KisSignalCompressor(100, KisSignalCompressor::POSTPONE))+ {+ tagFilterProxyModel->sort(KisAbstractResourceModel::Name);+ tagFilterProxyModel->setTagFilter(tagModel->tagForIndex(tagModel->index(0, 0)));+ }+ KisTagFilterResourceProxyModel *tagFilterProxyModel {nullptr};+ KisTagModel *tagModel {nullptr};+ KisSignalCompressor compressor;+ QString currentSearchText;+ KoResourceSP currentResource;+};++TagFilterProxyModelQmlWrapper::TagFilterProxyModelQmlWrapper(QObject *parent)+ : QObject(parent)+ , d(new Private())+{++ connect(&d->compressor, SIGNAL(timeout()), this, SLOT(setSearchTextOnModel()));+}++TagFilterProxyModelQmlWrapper::~TagFilterProxyModelQmlWrapper()+{+}++QAbstractItemModel *TagFilterProxyModelQmlWrapper::model() const+{+ return d->tagFilterProxyModel;+}++QAbstractItemModel *TagFilterProxyModelQmlWrapper::sourceModel() const+{+ return d->tagFilterProxyModel->sourceModel();+}++void TagFilterProxyModelQmlWrapper::setSourceModel(QAbstractItemModel *newSourceModel)+{+ if (newSourceModel != d->tagFilterProxyModel->sourceModel()) {+ d->tagFilterProxyModel->setSourceModel(newSourceModel);+ emit sourceModelChanged();+ emit modelChanged();+ emit modelSortUpdated();+ }+}++QAbstractItemModel *TagFilterProxyModelQmlWrapper::tagModel() const+{+ return d->tagModel;+}++void TagFilterProxyModelQmlWrapper::tagActivated(const int &row)+{+ QModelIndex idx = d->tagModel->index(row, 0);+ if (idx.isValid()) {+ KisTagSP tag = d->tagModel->tagForIndex(idx);+ if (tag == d->tagFilterProxyModel->currentTagFilter()) return;+ d->tagFilterProxyModel->setTagFilter(tag);+ emit activeTagChanged();+ }+}++int TagFilterProxyModelQmlWrapper::currentTag() const+{+ return d->tagModel->indexForTag(d->tagFilterProxyModel->currentTagFilter()).row();+}++QString TagFilterProxyModelQmlWrapper::searchText() const+{+ return d->currentSearchText;+}++void TagFilterProxyModelQmlWrapper::setSearchText(const QString &text)+{+ if (d->currentSearchText == text) {+ return;+ }+ d->currentSearchText = text;+ emit searchTextChanged();+ d->compressor.start();+}++void TagFilterProxyModelQmlWrapper::setSearchInTag(const bool &newSearchInTag)+{+ if (d->tagFilterProxyModel->filterInCurrentTag() != newSearchInTag) {+ d->tagFilterProxyModel->setFilterInCurrentTag(newSearchInTag);+ emit searchInTagChanged();+ }+}++bool TagFilterProxyModelQmlWrapper::searchInTag()+{+ return d->tagFilterProxyModel->filterInCurrentTag();+}++void TagFilterProxyModelQmlWrapper::addNewTag(const QString &newTagName, const int &resourceIndex)+{+ KisTagSP tagsp = d->tagModel->tagForUrl(newTagName);+ QModelIndex resourceIdx = d->tagFilterProxyModel->index(resourceIndex, 0);+ if (tagsp.isNull()) {+ QVector<KoResourceSP> vec;+ tagsp = d->tagModel->addTag(newTagName, false, vec);++ }+ // TODO: figure out how to get a tag reactivated again, without doing too much code duplication :|+ if (resourceIdx.isValid()) {+ int resourceId = d->tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::Id).toInt();+ d->tagFilterProxyModel->tagResources(tagsp, {resourceId});+ }++}++void TagFilterProxyModelQmlWrapper::tagResource(const int &tagIndex, const int &resourceIndex)+{+ QModelIndex idx = d->tagModel->index(tagIndex, 0);+ QModelIndex resourceIdx = d->tagFilterProxyModel->index(resourceIndex, 0);+ KisTagSP tagsp;+ if (idx.isValid()) {+ tagsp = d->tagModel->tagForIndex(idx);+ }+ if (tagsp && resourceIdx.isValid()) {+ int resourceId = d->tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::Id).toInt();+ d->tagFilterProxyModel->tagResources(tagsp, {resourceId});+ }+}++void TagFilterProxyModelQmlWrapper::untagResource(const int &tagIndex, const int &resourceIndex)+{+ QModelIndex idx = d->tagModel->index(tagIndex, 0);+ QModelIndex resourceIdx = d->tagFilterProxyModel->index(resourceIndex, 0);+ KisTagSP tagsp;+ if (idx.isValid()) {+ tagsp = d->tagModel->tagForIndex(idx);+ }+ if (tagsp && resourceIdx.isValid()) {+ int resourceId = d->tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::Id).toInt();+ d->tagFilterProxyModel->untagResources(tagsp, {resourceId});+ }+}++QString TagFilterProxyModelQmlWrapper::localizedNameForIndex(+ const int &resourceIndex,+ const QStringList &locales,+ const QString &fallBack)+{+ QModelIndex resourceIdx = d->tagFilterProxyModel->index(resourceIndex, 0);+ QString name = fallBack;+ if (resourceIdx.isValid()) {+ name = d->tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::Name).toString();+ QMap<QString, QVariant> metadata = d->tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::MetaData).toMap();+ QVariantMap localizedNames = metadata.value("localized_font_family").toMap();+ Q_FOREACH(const QString locale, locales) {+ if (localizedNames.keys().contains(locale) ) {+ name = localizedNames.value(locale).toString();+ break;+ }+ }+ }+ return name;+}++QVariantMap TagFilterProxyModelQmlWrapper::metadataForIndex(const int &resourceIndex) const+{+ QModelIndex resourceIdx = d->tagFilterProxyModel->index(resourceIndex, 0);+ return d->tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::MetaData).toMap();+}++QVariantList TagFilterProxyModelQmlWrapper::taggedResourceModel (const int &resourceIndex) const+{+ QVariantList taggedResourceModel;+ QModelIndex resourceIdx = d->tagFilterProxyModel->index(resourceIndex, 0);+ KisTagSP tagsp;+ for (int i = 0; i< d->tagModel->rowCount(); i++) {+ QModelIndex idx = d->tagModel->index(i, 0);+ tagsp = d->tagModel->tagForIndex(idx);+ bool visible = tagsp->id() >= 0;+ bool enabled = false;+ if (resourceIdx.isValid()) {+ int resourceId = d->tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::Id).toInt();+ enabled = d->tagFilterProxyModel->isResourceTagged(tagsp, resourceId) > 0 && visible;+ }+ QVariantMap tag { {"name", tagsp->name()}, {"value", i}, {"visible", visible}, {"enabled", enabled} };+ taggedResourceModel.append(tag);+ }+ return taggedResourceModel;+}++bool TagFilterProxyModelQmlWrapper::showResourceTagged(const int &tagIndex, const int &resourceIndex) const+{+ QModelIndex idx = d->tagModel->index(tagIndex, 0);+ QModelIndex resourceIdx = d->tagFilterProxyModel->index(resourceIndex, 0);+ KisTagSP tagsp;+ if (idx.isValid()) {+ tagsp = d->tagModel->tagForIndex(idx);+ }+ if (tagsp) {+ if (tagsp->id() < 0) return false;+ return true;+ if (resourceIdx.isValid()) {+ int resourceId = d->tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::Id).toInt();+ return d->tagFilterProxyModel->isResourceTagged(tagsp, resourceId);+ }+ }+ return false;+}++int TagFilterProxyModelQmlWrapper::currentIndex() const+{+ return d->tagFilterProxyModel->indexForResource(d->currentResource).row();+}++void TagFilterProxyModelQmlWrapper::setCurrentIndex(const int &index)+{+ QModelIndex resourceIdx = d->tagFilterProxyModel->index(index, 0);+ if (!resourceIdx.isValid()) return;+ KoResourceSP newResource = d->tagFilterProxyModel->resourceForIndex(resourceIdx);+ if (newResource != d->currentResource) {+ d->currentResource = newResource;+ emit currentResourceChanged();+ }+}++void TagFilterProxyModelQmlWrapper::setResourceToFileName(const QString &filename)+{+ QModelIndex index;+ KoResourceSP resource = d->currentResource;+ KisAllResourcesModel *fontModel = dynamic_cast<KisAllResourcesModel*>(d->tagFilterProxyModel->sourceModel());+ if (!fontModel) return;+ QVector<KoResourceSP> resources = fontModel->resourcesForFilename(filename);+ if (!resources.isEmpty()) {+ resource = resources.first();+ }+ if (resource != d->currentResource) {+ d->currentResource = resource;+ emit currentResourceChanged();+ }+}++QString TagFilterProxyModelQmlWrapper::resourceFilename()+{+ return d->currentResource? d->currentResource->filename(): "";+}++void TagFilterProxyModelQmlWrapper::setSearchTextOnModel()+{+ d->tagFilterProxyModel->setSearchText(d->currentSearchText);+ emit modelSortUpdated();+}diff --git a/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.hnew file mode 100644index 0000000000..a2cf8c3146--- /dev/null+++ b/plugins/dockers/textproperties/TagFilterProxyModelQmlWrapper.h@@ -0,0 +1,111 @@+/*+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#ifndef TAGFILTERPROXYMODELQMLWRAPPER_H+#define TAGFILTERPROXYMODELQMLWRAPPER_H++#include <QObject>+#include <QAbstractItemModel>++/**+ * @brief The TagFilterProxyModelQmlWrapper class+ *+ * This class wraps around KisTagFilterResourceProxyModel, providing properties,+ * signal compressors and handling setting the source model.+ */+class TagFilterProxyModelQmlWrapper : public QObject+{+ Q_OBJECT+ Q_PROPERTY(QAbstractItemModel *model READ model NOTIFY modelChanged)+ Q_PROPERTY(QAbstractItemModel *sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)+ Q_PROPERTY(QAbstractItemModel *tagModel READ tagModel NOTIFY tagModelChanged)++ Q_PROPERTY(QString searchText READ searchText WRITE setSearchText NOTIFY searchTextChanged)+ Q_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)+public:+ TagFilterProxyModelQmlWrapper(QObject *parent = nullptr);+ ~TagFilterProxyModelQmlWrapper();+++ /// The tagfilterproxymodel+ QAbstractItemModel *model() const;++ /// The source model.+ QAbstractItemModel *sourceModel() const;+ /// Set the source model on the tag filter proxy model.+ void setSourceModel(QAbstractItemModel *newSourceModel);++ /// Associated tagmodel+ QAbstractItemModel *tagModel() const;++ /// Select tag at row in tag model.+ void tagActivated(const int &row);+ /// Return row of current tag in tag model.+ int currentTag() const;++ /// The current search text on the filter model.+ QString searchText() const;+ void setSearchText(const QString &text);+++ /// Toggle "search in tag".+ void setSearchInTag(const bool &newSearchInTag);++ /// Whether "search in tag is enabled".+ bool searchInTag();++ /// Add new tag+ Q_INVOKABLE void addNewTag(const QString &newTagName, const int &resourceIndex = -1);++ /// Tag the resource+ Q_INVOKABLE void tagResource(const int &tagIndex, const int &resourceIndex);++ /// Untag the resource+ Q_INVOKABLE void untagResource(const int &tagIndex, const int &resourceIndex);++ /// Get localized name for index, retrieved from the resource metadata.+ Q_INVOKABLE QString localizedNameForIndex(const int &resourceIndex, const QStringList &locales, const QString &fallBack = "");+ Q_INVOKABLE QVariantMap metadataForIndex(const int &resourceIndex) const;++ /// Get a variantlist with the tags for the given resource index.+ Q_INVOKABLE QVariantList taggedResourceModel (const int &resourceIndex) const;++ /// Is the resource tagged with the current tagindex.+ Q_INVOKABLE bool showResourceTagged(const int &tagIndex, const int &resourceIndex) const;++ /// Current resource index in tagfilterproxy.+ int currentIndex() const;++ /// Set the resource index in tagfilterproxy.+ void setCurrentIndex(const int &index);++ Q_INVOKABLE void setResourceToFileName(const QString &filename);++ QString resourceFilename();++Q_SIGNALS:+ void sourceModelChanged();+ void modelChanged();+ void searchTextChanged();+ void activeTagChanged();+ void searchInTagChanged();+ void modelSortUpdated();+ void currentResourceChanged();+ void tagModelChanged();++private Q_SLOTS:+ /// Slot to set the search text on the model via a signal compressor.+ /// The search can be quite slow, so the signal compressor can elevate the delay here.+ void setSearchTextOnModel();+private:++ struct Private;+ const QScopedPointer<Private> d;+};++#endif // TAGFILTERPROXYMODELQMLWRAPPER_Hdiff --git a/plugins/dockers/textproperties/TextPropertiesDock.cpp b/plugins/dockers/textproperties/TextPropertiesDock.cppindex 2362107b05..0d6c06bb3b 100644--- a/plugins/dockers/textproperties/TextPropertiesDock.cpp+++ b/plugins/dockers/textproperties/TextPropertiesDock.cpp@@ -19,16 +19,13 @@#include <KisViewManager.h>#include <kis_canvas_resource_provider.h>#include <KisStaticInitializer.h>-#include <kis_signal_compressor.h>#include <KLocalizedContext>#include <KoResourcePaths.h>#include <KisResourceModel.h>#include <KisResourceModelProvider.h>-#include <KisTagFilterResourceProxyModel.h>#include <KisTagModel.h>-#include <KisTagResourceModel.h>#include <KoCanvasResourcesIds.h>#include <KoSvgTextPropertyData.h>@@ -45,199 +42,7 @@#include "FontStyleModel.h"#include "FontAxesModel.h"#include "KoShapeQtQuickLabel.h"--/**- * @brief The TagFilterProxyModelQmlWrapper class- *- * This class wraps around KisTagFilterResourceProxyModel, providing properties,- * signal compressors and handling setting the source model.- */-class TagFilterProxyModelQmlWrapper : public QObject {- Q_OBJECT- Q_PROPERTY(QAbstractItemModel *model READ model NOTIFY modelChanged)- Q_PROPERTY(QAbstractItemModel *sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)- Q_PROPERTY(QString searchText READ searchText WRITE setSearchText NOTIFY searchTextChanged)- Q_PROPERTY(int currentTag READ currentTag WRITE tagActivated NOTIFY activeTagChanged)- Q_PROPERTY(bool searchInTag READ searchInTag WRITE setSearchInTag NOTIFY searchInTagChanged)-public:- TagFilterProxyModelQmlWrapper(QObject *parent = nullptr): QObject(parent)- , m_tagFilterProxyModel(new KisTagFilterResourceProxyModel(ResourceType::FontFamilies, this))- , m_compressor(100, KisSignalCompressor::POSTPONE) {- m_tagFilterProxyModel->sort(KisAbstractResourceModel::Name);- m_tagModel = new KisTagModel(ResourceType::FontFamilies, this);- connect(&m_compressor, SIGNAL(timeout()), this, SLOT(setSearchTextOnModel()));- }-- void tagActivated(const int &row) {- if (row == currentTag()) {- return;- }- QModelIndex idx = m_tagModel->index(row, 0);- if (idx.isValid()) {- m_tagFilterProxyModel->setTagFilter(m_tagModel->tagForIndex(idx));- emit activeTagChanged();- emit modelSortUpdated();- }- }- QString searchText() const {- return m_currentSearchText;- }- void setSearchText(const QString &text) {- if (m_currentSearchText == text) {- return;- }- m_currentSearchText = text;- emit searchTextChanged();- m_compressor.start();- }-- QAbstractItemModel *model() {- return m_tagFilterProxyModel;- }-- QAbstractItemModel *sourceModel() const {- return m_tagFilterProxyModel->sourceModel();- }- void setSourceModel(QAbstractItemModel *newSourceModel) {- if (newSourceModel != m_tagFilterProxyModel->sourceModel()) {- m_tagFilterProxyModel->setSourceModel(newSourceModel);- emit sourceModelChanged();- emit modelChanged();- emit modelSortUpdated();- }- }-- int currentTag() const {- return m_tagModel->indexForTag(m_tagFilterProxyModel->currentTagFilter()).row();- }-- void setSearchInTag(const bool &newSearchInTag) {- if (m_tagFilterProxyModel->filterInCurrentTag() != newSearchInTag) {- m_tagFilterProxyModel->setFilterInCurrentTag(newSearchInTag);- emit searchInTagChanged();- emit modelSortUpdated();- }- }-- bool searchInTag() {- return m_tagFilterProxyModel->filterInCurrentTag();- }-- Q_INVOKABLE void addNewTag(const QString &newTagName, const int &resourceIndex = -1) {- KisTagSP tagsp = m_tagModel->tagForUrl(newTagName);- QModelIndex resourceIdx = m_tagFilterProxyModel->index(resourceIndex, 0);- if (tagsp.isNull()) {- QVector<KoResourceSP> vec;- tagsp = m_tagModel->addTag(newTagName, false, vec);-- }- // TODO: figure out how to get a tag reactivated again, without doing too much code duplication :|- if (resourceIdx.isValid()) {- int resourceId = m_tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::Id).toInt();- m_tagFilterProxyModel->tagResources(tagsp, {resourceId});- }-- }-- Q_INVOKABLE void tagResource(const int &tagIndex, const int &resourceIndex) {- QModelIndex idx = m_tagModel->index(tagIndex, 0);- QModelIndex resourceIdx = m_tagFilterProxyModel->index(resourceIndex, 0);- KisTagSP tagsp;- if (idx.isValid()) {- tagsp = m_tagModel->tagForIndex(idx);- }- if (tagsp && resourceIdx.isValid()) {- int resourceId = m_tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::Id).toInt();- m_tagFilterProxyModel->tagResources(tagsp, {resourceId});- }- }-- Q_INVOKABLE void untagResource(const int &tagIndex, const int &resourceIndex) {- QModelIndex idx = m_tagModel->index(tagIndex, 0);- QModelIndex resourceIdx = m_tagFilterProxyModel->index(resourceIndex, 0);- KisTagSP tagsp;- if (idx.isValid()) {- tagsp = m_tagModel->tagForIndex(idx);- }- if (tagsp && resourceIdx.isValid()) {- int resourceId = m_tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::Id).toInt();- m_tagFilterProxyModel->untagResources(tagsp, {resourceId});- }- }-- Q_INVOKABLE QString localizedNameForIndex(const int &resourceIndex, const QStringList &locales, const QString &fallBack = "") {- QModelIndex resourceIdx = m_tagFilterProxyModel->index(resourceIndex, 0);- QString name = fallBack;- if (resourceIdx.isValid()) {- name = m_tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::Name).toString();- QMap<QString, QVariant> metadata = m_tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::MetaData).toMap();- QVariantMap localizedNames = metadata.value("localized_font_family").toMap();- Q_FOREACH(const QString locale, locales) {- if (localizedNames.keys().contains(locale)) {- name = localizedNames.value(locale).toString();- break;- }- }- }- return name;- }-- Q_INVOKABLE QVariantList taggedResourceModel (const int &resourceIndex) const {- QVariantList taggedResourceModel;- QModelIndex resourceIdx = m_tagFilterProxyModel->index(resourceIndex, 0);- KisTagSP tagsp;- for (int i = 0; i< m_tagModel->rowCount(); i++) {- QModelIndex idx = m_tagModel->index(i, 0);- tagsp = m_tagModel->tagForIndex(idx);- bool visible = tagsp->id() >= 0;- bool enabled = false;- if (resourceIdx.isValid()) {- int resourceId = m_tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::Id).toInt();- enabled = m_tagFilterProxyModel->isResourceTagged(tagsp, resourceId) > 0 && visible;- }- QVariantMap tag {{"name", tagsp->name()}, {"value", i}, {"visible", visible}, {"enabled", enabled} };- taggedResourceModel.append(tag);- }- return taggedResourceModel;- }-- Q_INVOKABLE bool showResourceTagged(const int &tagIndex, const int &resourceIndex) const {- QModelIndex idx = m_tagModel->index(tagIndex, 0);- QModelIndex resourceIdx = m_tagFilterProxyModel->index(resourceIndex, 0);- KisTagSP tagsp;- if (idx.isValid()) {- tagsp = m_tagModel->tagForIndex(idx);- }- if (tagsp) {- if (tagsp->id() < 0) return false;- return true;- if (resourceIdx.isValid()) {- int resourceId = m_tagFilterProxyModel->data(resourceIdx, Qt::UserRole + KisResourceModel::Id).toInt();- return m_tagFilterProxyModel->isResourceTagged(tagsp, resourceId);- }- }- return false;- }--Q_SIGNALS:- void sourceModelChanged();- void modelChanged();- void searchTextChanged();- void activeTagChanged();- void searchInTagChanged();- void modelSortUpdated();--private Q_SLOTS:- void setSearchTextOnModel() {- m_tagFilterProxyModel->setSearchText(m_currentSearchText);- emit modelSortUpdated();- }-private:- KisTagFilterResourceProxyModel *m_tagFilterProxyModel {nullptr};- KisTagModel *m_tagModel{nullptr};- KisSignalCompressor m_compressor;- QString m_currentSearchText;-};+#include "TagFilterProxyModelQmlWrapper.h"/// Strange place to put this, do we have a better spot?KIS_DECLARE_STATIC_INITIALIZER {@@ -291,7 +96,6 @@ struct TextPropertiesDock::PrivateFontStyleModel stylesModel;FontAxesModel axesModel;KisAllResourcesModel *fontModel{nullptr};- KisTagModel *tagModel{nullptr};KisCanvasResourceProvider *provider{nullptr};};@@ -321,7 +125,6 @@ TextPropertiesDock::TextPropertiesDock()m_quickWidget->setMinimumHeight(100);d->fontModel = KisResourceModelProvider::resourceModel(ResourceType::FontFamilies);- d->tagModel = new KisTagModel(ResourceType::FontFamilies);QList<QLocale> locales;QStringList wellFormedBCPNames;@@ -337,7 +140,6 @@ TextPropertiesDock::TextPropertiesDock()m_quickWidget->rootContext()->setContextProperty("textPropertiesModel", d->textModel);m_quickWidget->rootContext()->setContextProperty("fontFamiliesModel", QVariant::fromValue(d->fontModel));- 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));m_quickWidget->rootContext()->setContextProperty("locales", QVariant::fromValue(wellFormedBCPNames));diff --git a/plugins/dockers/textproperties/qml/FontFamily.qml b/plugins/dockers/textproperties/qml/FontFamily.qmlindex 1cc83d1f62..fbfe308ab5 100644--- a/plugins/dockers/textproperties/qml/FontFamily.qml+++ b/plugins/dockers/textproperties/qml/FontFamily.qml@@ -52,21 +52,17 @@ CollapsibleGroupProperty {}FontResourceDropdown {id: mainFamilyCmb;- sourceModel: fontFamilyModel;+ modelWrapper.sourceModel: fontFamilyModel;Layout.fillWidth: true;onActivated: {if (fontFamilies.length >0) {- fontFamilies[0] = currentText;+ fontFamilies[0] = text;} else {- fontFamilies = [ currentText ];+ fontFamilies = [ text ];}}- Connections {- target: mainFamilyCmb.modelWrapper;- function onModelSortUpdated() { mainFamilyCmb.updateCurrentIndex() }- }function updateCurrentIndex() {- currentIndex = find(mainWindow.wwsFontFamilyName(fontFamilies[0]))+ modelWrapper.setResourceToFileName(mainWindow.wwsFontFamilyName(fontFamilies[0]))}}@@ -101,10 +97,10 @@ CollapsibleGroupProperty {property int dIndex: index;FontResourceDropdown {id: fontCmb;- sourceModel: fontFamilyModel;+ modelWrapper.sourceModel: fontFamilyModel;Layout.fillWidth: true;onActivated: {- fontFamilies[fontListDelegate.dIndex] = currentText;+ fontFamilies[fontListDelegate.dIndex] = text;}Component.onCompleted: {if (fontListDelegate.dIndex === 0) {@@ -112,12 +108,8 @@ CollapsibleGroupProperty {}updateCurrentIndex();}- Connections {- target: fontCmb.modelWrapper;- function onModelSortUpdated() { fontCmb.updateCurrentIndex() }- }function updateCurrentIndex() {- currentIndex = find(mainWindow.wwsFontFamilyName(fontFamilies[fontListDelegate.dIndex]))+ modelWrapper.setResourceToFileName(mainWindow.wwsFontFamilyName(fontFamilies[fontListDelegate.dIndex]))}}ToolButton {diff --git a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml b/plugins/dockers/textproperties/qml/FontResourceDropdown.qmlindex 75a53c0797..8aceed0afe 100644--- a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml+++ b/plugins/dockers/textproperties/qml/FontResourceDropdown.qml@@ -8,17 +8,28 @@ import QtQuick.Controls 2.15import QtQuick.Layouts 1.12import org.krita.flake.text 1.0-ComboBox {+Button {id: familyCmb;wheelEnabled: true;//--- Model setup. ---//- property var sourceModel;+property TagFilterProxyModelQmlWrapper modelWrapper : TagFilterProxyModelQmlWrapper{- sourceModel: sourceModel;+ id: modelWrapperId;};- model: modelWrapper.model;- textRole: "name";+ text: modelWrapper.resourceFilename;+ property int highlightedIndex;+ onClicked: {+ if (familyCmbPopup.visible) {+ familyCmbPopup.close();+ } else {+ familyCmbPopup.open();+ }+ }+ signal activated();+ onActivated: {+ familyCmbPopup.close();+ }//--- Delegate setup. ---//Component {@@ -26,24 +37,32 @@ ComboBox {ItemDelegate {id: fontDelegateItem;required property var model;- property string fontName: modelWrapper.localizedNameForIndex(model.index, locales, model.name);+ property string fontName: model.name;+ /// 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.+ property var meta: familyCmb.modelWrapper.metadataForIndex(model.index);width: fontResourceView.listWidth;highlighted: familyCmb.highlightedIndex === model.index;+ Component.onCompleted: {+ fontName = familyCmb.modelWrapper.localizedNameForIndex(model.index, locales, model.name);+ }+contentItem: KoShapeQtQuickLabel {id: fontFamilyDelegate;- property bool colorBitmap : model.metadata.color_bitmap;- property bool colorCLRV0 : model.metadata.color_clrv0;- property bool colorCLRV1 : model.metadata.color_clrv1;- property bool colorSVG : model.metadata.color_svg;- property bool isVariable : model.metadata.is_variable;- property int type : model.metadata.font_type;+ property alias meta: fontDelegateItem.meta;+ property bool colorBitmap : meta.color_bitmap;+ property bool colorCLRV0 : meta.color_clrv0;+ property bool colorCLRV1 : meta.color_clrv1;+ property bool colorSVG : meta.color_svg;+ property bool isVariable : meta.is_variable;+ property int type : meta.font_type;property string fontName: fontDelegateItem.fontName;width: parent.width;height: nameLabel.height * 5;imageScale: 3;imagePadding: nameLabel.height;- svgData: model.metadata.sample_svg;+ svgData: meta.sample_svg;foregroundColor: sysPalette.text;fullColor: colorBitmap || colorCLRV0 || colorCLRV1 || colorSVG;@@ -104,12 +123,32 @@ ComboBox {background: Rectangle {color: highlighted? familyCmb.palette.highlight:"transparent";}++ MouseArea {+ acceptedButtons: Qt.RightButton | Qt.LeftButton;+ anchors.fill: parent;+ hoverEnabled: true;+ onClicked: {+ if (mouse.button === Qt.RightButton) {+ openContextMenu(mouse.x, mouse.y);+ } else {+ familyCmb.modelWrapper.currentIndex = fontDelegateItem.model.index;+ familyCmb.activated();+ }+ }+ onHoveredChanged: familyCmb.highlightedIndex = fontDelegateItem.model.index;++ function openContextMenu(x, y) {+ tagActionsContextMenu.resourceIndex = fontDelegateItem.model.index;+ tagActionsContextMenu.popup()+ }++ }}}- delegate: fontDelegate;//--- Pop up setup ---//- popup: Popup {+ Popup {id: familyCmbPopup;y: familyCmb.height - 1;x: familyCmb.width - width;@@ -120,25 +159,22 @@ ComboBox {contentItem:ColumnLayout {id: fontResourceView;- fontModel: familyCmb.delegateModel;- tagModel: fontTagModel;- currentIndex: familyCmb.currentIndex;clip:true;- property var fontModel;- property var tagModel;- property alias currentIndex : view.currentIndex;+ property alias fontModel : view.model;+ property alias tagModel: tagFilter.model;property alias listWidth : view.width;+ fontModel: familyCmb.modelWrapper.model;+ tagModel: familyCmb.modelWrapper.tagModel;RowLayout {id: tagAndConfig;ComboBox {id: tagFilter;- model: fontResourceView.tagModel;textRole: "display";Layout.fillWidth: true;- currentIndex: modelWrapper.currentTag;- onActivated: modelWrapper.currentTag = currentIndex;+ currentIndex: familyCmb.modelWrapper.currentTag;+ onActivated: familyCmb.modelWrapper.currentTag = currentIndex;}Button {@@ -171,6 +207,10 @@ ComboBox {function updateResourceTaggedModel() {resourceTaggedModel = modelWrapper.taggedResourceModel(tagActionsContextMenu.resourceIndex);}+ function updateAndDismiss() {+ updateResourceTaggedModel();+ dismiss();+ }modal: true;closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent@@ -187,15 +227,16 @@ ComboBox {model: tagActionsContextMenu.resourceTaggedModel;height: contentHeight;width: parent.width;+delegate: ItemDelegate {width: tagAddView.width;text: modelData.name;visible: modelData.visible && !modelData.enabled;height: visible? implicitContentHeight: 0;+onClicked: {modelWrapper.tagResource(modelData.value, tagActionsContextMenu.resourceIndex);- tagActionsContextMenu.updateResourceTaggedModel();- tagActionsContextMenu.close();+ tagActionsContextMenu.updateAndDismiss();}}}@@ -212,8 +253,7 @@ ComboBox {onClicked: {modelWrapper.addNewTag(newTagName.text, tagActionsContextMenu.resourceIndex);newTagName.text = "";- tagActionsContextMenu.updateResourceTaggedModel();- tagActionsContextMenu.dismiss();+ tagActionsContextMenu.updateAndDismiss();}}}@@ -243,15 +283,13 @@ ComboBox {height: visible? implicitContentHeight: 0;onClicked: {modelWrapper.untagResource(modelData.value, tagActionsContextMenu.resourceIndex);- tagActionsContextMenu.updateResourceTaggedModel();- tagActionsContextMenu.dismiss()+ tagActionsContextMenu.updateAndDismiss()}}}}}}-}Frame {Layout.minimumHeight: font.pixelSize*3;@@ -262,7 +300,8 @@ ComboBox {ListView {anchors.fill: parent;id: view;- model: fontResourceView.fontModel;+ currentIndex: familyCmb.modelWrapper.currentIndex;+ delegate: fontDelegate;ScrollBar.vertical: ScrollBar {}}@@ -283,13 +322,8 @@ ComboBox {checked: modelWrapper.searchInTag;}}--}palette: familyCmb.palette;-}--}