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++
Make it so that each font dropdown has its own resource proxy.
Wolthera van Hövell tot Westerflier7875b2e30061
diff --git a/libs/resources/KisTagFilterResourceProxyModel.cpp b/libs/resources/KisTagFilterResourceProxyModel.cppindex e5ff66890d..5db9d1b5d8 100644--- a/libs/resources/KisTagFilterResourceProxyModel.cpp+++ b/libs/resources/KisTagFilterResourceProxyModel.cpp@@ -217,6 +217,11 @@ void KisTagFilterResourceProxyModel::setTagFilter(const KisTagSP tag)updateTagFilter();}+KisTagSP KisTagFilterResourceProxyModel::currentTagFilter() const+{+ return d->currentTagFilter;+}+void KisTagFilterResourceProxyModel::setStorageFilter(bool useFilter, int storageId){Q_EMIT beforeFilterChanges();@@ -306,6 +311,11 @@ void KisTagFilterResourceProxyModel::setFilterInCurrentTag(bool filterInCurrentTupdateTagFilter();}+bool KisTagFilterResourceProxyModel::filterInCurrentTag() const+{+ return d->filteringWithinCurrentTag;+}+bool KisTagFilterResourceProxyModel::tagResources(const KisTagSP tag, const QVector<int> &resourceIds){return d->tagResourceModel->tagResources(tag, resourceIds);diff --git a/libs/resources/KisTagFilterResourceProxyModel.h b/libs/resources/KisTagFilterResourceProxyModel.hindex ee0a9fdff4..b5da40e89a 100644--- a/libs/resources/KisTagFilterResourceProxyModel.h+++ b/libs/resources/KisTagFilterResourceProxyModel.h@@ -68,6 +68,12 @@ public:*/void setTagFilter(const KisTagSP tag);+ /**+ * @brief currentTagFilter+ * @return return the current tag that's being used to filter.+ */+ KisTagSP currentTagFilter() const;+void setStorageFilter(bool useFilter, int storageId);@@ -81,6 +87,8 @@ public:void setFilterInCurrentTag(bool filterInCurrentTag);+ bool filterInCurrentTag() const;+bool tagResources(const KisTagSP tag, const QVector<int> &resourceIds);bool untagResources(const KisTagSP tag, const QVector<int> &resourceIds);int isResourceTagged(const KisTagSP tag, const int resourceId);diff --git a/plugins/dockers/textproperties/TextPropertiesDock.cpp b/plugins/dockers/textproperties/TextPropertiesDock.cppindex d1b1746730..1b47c29938 100644--- a/plugins/dockers/textproperties/TextPropertiesDock.cpp+++ b/plugins/dockers/textproperties/TextPropertiesDock.cpp@@ -19,6 +19,7 @@#include <KisViewManager.h>#include <kis_canvas_resource_provider.h>#include <KisStaticInitializer.h>+#include <kis_signal_compressor.h>#include <KLocalizedContext>@@ -44,6 +45,103 @@#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(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(bool newSearchInTag) {+ if (m_tagFilterProxyModel->filterInCurrentTag() != newSearchInTag) {+ m_tagFilterProxyModel->setFilterInCurrentTag(newSearchInTag);+ emit searchInTagChanged();+ emit modelSortUpdated();+ }+ }++ bool searchInTag() {+ return m_tagFilterProxyModel->filterInCurrentTag();+ }++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;+};+/// Strange place to put this, do we have a better spot?KIS_DECLARE_STATIC_INITIALIZER {qmlRegisterType<KoSvgTextPropertiesModel>("org.krita.flake.text", 1, 0, "KoSvgTextPropertiesModel");@@ -58,6 +156,7 @@ KIS_DECLARE_STATIC_INITIALIZER {qmlRegisterType<FontStyleModel>("org.krita.flake.text", 1, 0, "FontStyleModel");qmlRegisterType<FontAxesModel>("org.krita.flake.text", 1, 0, "FontAxesModel");qmlRegisterType<KoShapeQtQuickLabel>("org.krita.flake.text", 1, 0, "KoShapeQtQuickLabel");+ qmlRegisterType<TagFilterProxyModelQmlWrapper>("org.krita.flake.text", 1, 0, "TagFilterProxyModelQmlWrapper");}@@ -95,7 +194,6 @@ struct TextPropertiesDock::PrivateFontStyleModel stylesModel;FontAxesModel axesModel;KisAllResourcesModel *fontModel{nullptr};- KisTagFilterResourceProxyModel *fontTagFilterProxyModel {nullptr};KisTagModel *tagModel{nullptr};KisCanvasResourceProvider *provider{nullptr};};@@ -126,9 +224,6 @@ TextPropertiesDock::TextPropertiesDock()m_quickWidget->setMinimumHeight(100);d->fontModel = KisResourceModelProvider::resourceModel(ResourceType::FontFamilies);- d->fontTagFilterProxyModel = new KisTagFilterResourceProxyModel(ResourceType::FontFamilies);- d->fontTagFilterProxyModel->setSourceModel(d->fontModel);- d->fontTagFilterProxyModel->sort(KisAbstractResourceModel::Name);d->tagModel = new KisTagModel(ResourceType::FontFamilies);QList<QLocale> locales;@@ -144,7 +239,7 @@ TextPropertiesDock::TextPropertiesDock()m_quickWidget->rootContext()->setContextProperty("textPropertiesModel", d->textModel);- m_quickWidget->rootContext()->setContextProperty("fontFamiliesModel", QVariant::fromValue(d->fontTagFilterProxyModel));+ 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));@@ -258,24 +353,6 @@ 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 <KoFontRegistry.h>QString TextPropertiesDock::wwsFontFamilyName(QString familyName){diff --git a/plugins/dockers/textproperties/TextPropertiesDock.h b/plugins/dockers/textproperties/TextPropertiesDock.hindex 8c44795e04..d757d3c567 100644--- a/plugins/dockers/textproperties/TextPropertiesDock.h+++ b/plugins/dockers/textproperties/TextPropertiesDock.h@@ -34,9 +34,6 @@ public Q_SLOTS:void slotTextPropertiesChanged();void slotUpdateStylesModel();void slotUpdateAxesValues();- void slotFontTagActivated(int row);- void slotFontSearchTextChanged(const QString &text);- void slotFontSearchInTag(const bool checked);QString wwsFontFamilyName(QString familyName);void connectAutoEnabler(QObject *watched);diff --git a/plugins/dockers/textproperties/qml/FontFamily.qml b/plugins/dockers/textproperties/qml/FontFamily.qmlindex b19916abc1..1cc83d1f62 100644--- a/plugins/dockers/textproperties/qml/FontFamily.qml+++ b/plugins/dockers/textproperties/qml/FontFamily.qml@@ -29,7 +29,7 @@ CollapsibleGroupProperty {onFontFamiliesChanged: {if (blockSignals) {if (fontFamilies.length >0) {- mainFamilyCmb.currentIndex = mainFamilyCmb.find(mainWindow.wwsFontFamilyName(fontFamilies[0]));+ mainFamilyCmb.updateCurrentIndex();}familyListView.model = fontFamilies;} else {@@ -52,7 +52,7 @@ CollapsibleGroupProperty {}FontResourceDropdown {id: mainFamilyCmb;- model: fontFamilyModel;+ sourceModel: fontFamilyModel;Layout.fillWidth: true;onActivated: {if (fontFamilies.length >0) {@@ -61,6 +61,13 @@ CollapsibleGroupProperty {fontFamilies = [ currentText ];}}+ Connections {+ target: mainFamilyCmb.modelWrapper;+ function onModelSortUpdated() { mainFamilyCmb.updateCurrentIndex() }+ }+ function updateCurrentIndex() {+ currentIndex = find(mainWindow.wwsFontFamilyName(fontFamilies[0]))+ }}}@@ -93,12 +100,25 @@ CollapsibleGroupProperty {width: parent.width;property int dIndex: index;FontResourceDropdown {- model: fontFamilyModel;+ id: fontCmb;+ sourceModel: fontFamilyModel;Layout.fillWidth: true;onActivated: {fontFamilies[fontListDelegate.dIndex] = currentText;}- Component.onCompleted: currentIndex = find(mainWindow.wwsFontFamilyName(fontFamilies[fontListDelegate.dIndex]));+ Component.onCompleted: {+ if (fontListDelegate.dIndex === 0) {+ modelWrapper = mainFamilyCmb.modelWrapper;+ }+ updateCurrentIndex();+ }+ Connections {+ target: fontCmb.modelWrapper;+ function onModelSortUpdated() { fontCmb.updateCurrentIndex() }+ }+ function updateCurrentIndex() {+ currentIndex = find(mainWindow.wwsFontFamilyName(fontFamilies[fontListDelegate.dIndex]))+ }}ToolButton {id: removeFont;diff --git a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml b/plugins/dockers/textproperties/qml/FontResourceDropdown.qmlindex 08f6278104..1acb6888d7 100644--- a/plugins/dockers/textproperties/qml/FontResourceDropdown.qml+++ b/plugins/dockers/textproperties/qml/FontResourceDropdown.qml@@ -10,6 +10,11 @@ import org.krita.flake.text 1.0ComboBox {id: familyCmb;+ property var sourceModel;+ property TagFilterProxyModelQmlWrapper modelWrapper : TagFilterProxyModelQmlWrapper{+ sourceModel: sourceModel;+ };+ model: modelWrapper.model;Component {id: fontDelegate@@ -135,9 +140,8 @@ ComboBox {model: fontResourceView.tagModel;textRole: "display";Layout.fillWidth: true;- onActivated: {- mainWindow.slotFontTagActivated(currentIndex);- }+ currentIndex: modelWrapper.currentTag;+ onActivated: modelWrapper.currentTag = currentIndex;}}@@ -161,12 +165,14 @@ ComboBox {id: search;placeholderText: i18nc("@info:placeholder", "Search...");Layout.fillWidth: true;- onTextEdited: mainWindow.slotFontSearchTextChanged(text);+ text: modelWrapper.searchText;+ onTextEdited: modelWrapper.searchText = text;}CheckBox {id: opticalSizeCbxtext: i18nc("@option:check", "Search in tag")- onCheckedChanged: mainWindow.slotFontSearchInTag(checked);+ onCheckedChanged: modelWrapper.searchInTag = checked;+ checked: modelWrapper.searchInTag;}}}