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++

Improve OpenTypeFeature widget by handling the Available and searching all via QSortFilterModels.

Wolthera van Hövell tot Westerflier4173dec9ce0b
diff --git a/plugins/dockers/textproperties/OpenTypeFeatureModel.cpp b/plugins/dockers/textproperties/OpenTypeFeatureModel.cpp
index 4ede09e952..74ce2c83a7 100644
--- a/plugins/dockers/textproperties/OpenTypeFeatureModel.cpp
+++ b/plugins/dockers/textproperties/OpenTypeFeatureModel.cpp
@@ -236,12 +236,11 @@ void OpenTypeFeatureModel::removeFeature(const QString &tag)
emit openTypeFeaturesChanged();
}
-QAbstractItemModel *OpenTypeFeatureModel::featureFilterModel() const
+QAbstractItemModel *OpenTypeFeatureModel::allFeatureModel() const
{
return d->allFeatures;
}
-
void OpenTypeFeatureModel::setFromTextPropertiesModel(KoSvgTextPropertiesModel *textPropertiesModel)
{
KoSvgTextProperties main;
@@ -334,6 +333,7 @@ QVariant AllOpenTypeFeaturesModel::data(const QModelIndex &index, int role) cons
int AllOpenTypeFeaturesModel::rowCount(const QModelIndex &parent) const
{
+ Q_UNUSED(parent)
return d->allTags.size();
}
@@ -356,3 +356,55 @@ QHash<int, QByteArray> AllOpenTypeFeaturesModel::roleNames() const
return roles;
}
+OpenTypeFeatureFilterModel::OpenTypeFeatureFilterModel(QObject *parent)
+ : QSortFilterProxyModel(parent)
+{
+
+}
+
+QString OpenTypeFeatureFilterModel::firstValidTag() const
+{
+ const QModelIndex idx = index(0, 0, QModelIndex());
+ if (!idx.isValid()) return QString();
+ return data(idx, AllOpenTypeFeaturesModel::Tag).toString();
+}
+
+#include <QDebug>
+bool OpenTypeFeatureFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
+{
+ const QModelIndex idx = sourceModel()->index(source_row, 0, source_parent);
+ if (!idx.isValid()) return false;
+ const bool available = sourceModel()->data(idx, AllOpenTypeFeaturesModel::Available).toBool();
+ if (m_filterAvailable && !available) return false;
+ if (filterRegularExpression().pattern().isEmpty()) return true;
+ const QString tag = sourceModel()->data(idx, AllOpenTypeFeaturesModel::Tag).toString();
+ const QString name = sourceModel()->data(idx, Qt::DisplayRole).toString();
+ return (tag.contains(filterRegularExpression()) || name.contains(filterRegularExpression()));
+}
+
+bool OpenTypeFeatureFilterModel::filterAvailable() const
+{
+ return m_filterAvailable;
+}
+
+void OpenTypeFeatureFilterModel::setFilterAvailable(bool newFilterAvailable)
+{
+ if (m_filterAvailable == newFilterAvailable)
+ return;
+ m_filterAvailable = newFilterAvailable;
+ invalidateFilter();
+ emit filterAvailableChanged();
+}
+
+QString OpenTypeFeatureFilterModel::searchText() const
+{
+ return filterRegularExpression().pattern();
+}
+
+void OpenTypeFeatureFilterModel::setSearchText(const QString &newSearchText)
+{
+ if (filterRegularExpression().pattern() == newSearchText)
+ return;
+ setFilterRegularExpression(newSearchText);
+ emit searchTextChanged();
+}
diff --git a/plugins/dockers/textproperties/OpenTypeFeatureModel.h b/plugins/dockers/textproperties/OpenTypeFeatureModel.h
index 55843d80cf..a04859c524 100644
--- a/plugins/dockers/textproperties/OpenTypeFeatureModel.h
+++ b/plugins/dockers/textproperties/OpenTypeFeatureModel.h
@@ -13,6 +13,34 @@ class KoSvgTextProperties;
class KoOpenTypeFeatureInfo;
class KoSvgTextPropertiesModel;
+// Filter SortProxy that filters by both name and tag.
+class OpenTypeFeatureFilterModel : public QSortFilterProxyModel
+{
+ Q_OBJECT
+ Q_PROPERTY (bool filterAvailable READ filterAvailable WRITE setFilterAvailable NOTIFY filterAvailableChanged)
+ Q_PROPERTY (QString searchText READ searchText WRITE setSearchText NOTIFY searchTextChanged)
+public:
+ OpenTypeFeatureFilterModel(QObject *parent = nullptr);
+
+ Q_INVOKABLE QString firstValidTag() const;
+ // QSortFilterProxyModel interface
+ bool filterAvailable() const;
+ void setFilterAvailable(bool newFilterAvailable);
+
+ QString searchText() const;
+ void setSearchText(const QString &newSearchText);
+
+Q_SIGNALS:
+ void filterAvailableChanged();
+
+ void searchTextChanged();
+
+protected:
+ bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
+private:
+ bool m_filterAvailable;
+};
+
/**
* @brief The OpenTypeFeatureModel class
* This model keeps track of the currently set font-feature-settings property on a given piece of text,
@@ -74,7 +102,7 @@ public:
* searching and sorting on all opentype features, whether available in the font
* or part of the standard.
*/
- Q_INVOKABLE QAbstractItemModel *featureFilterModel() const;
+ Q_INVOKABLE QAbstractItemModel *allFeatureModel() const;
/**
* @brief setFromTextPropertiesModel
@@ -102,7 +130,7 @@ public:
enum Roles {
Tag = Qt::UserRole + 1,
Sample,
- Available // bool, represents whether the current feature is also present in the font.
+ Available
};
~AllOpenTypeFeaturesModel();
diff --git a/plugins/dockers/textproperties/TextPropertiesDock.cpp b/plugins/dockers/textproperties/TextPropertiesDock.cpp
index 627fbe29a3..356d39352a 100644
--- a/plugins/dockers/textproperties/TextPropertiesDock.cpp
+++ b/plugins/dockers/textproperties/TextPropertiesDock.cpp
@@ -69,6 +69,7 @@ KIS_DECLARE_STATIC_INITIALIZER {
qmlRegisterType<FontStyleModel>("org.krita.flake.text", 1, 0, "FontStyleModel");
qmlRegisterType<FontAxesModel>("org.krita.flake.text", 1, 0, "FontAxesModel");
+ qmlRegisterType<OpenTypeFeatureFilterModel>("org.krita.flake.text", 1, 0, "OpenTypeFeatureFilterModel");
qmlRegisterType<OpenTypeFeatureModel>("org.krita.flake.text", 1, 0, "OpenTypeFeatureModel");
qmlRegisterType<KoShapeQtQuickLabel>("org.krita.flake.text", 1, 0, "KoShapeQtQuickLabel");
qmlRegisterType<CssQmlUnitConverter>("org.krita.flake.text", 1, 0, "CssQmlUnitConverter");
diff --git a/plugins/dockers/textproperties/qml/OpenTypeFeatureSettings.qml b/plugins/dockers/textproperties/qml/OpenTypeFeatureSettings.qml
index 1648fe3762..b605a63811 100644
--- a/plugins/dockers/textproperties/qml/OpenTypeFeatureSettings.qml
+++ b/plugins/dockers/textproperties/qml/OpenTypeFeatureSettings.qml
@@ -160,18 +160,16 @@ TextPropertyBase {
}
ComboBox {
id: cmbAvailableFeatures;
- model: fontFeatureModel.featureFilterModel();
- textRole: "display";
- valueRole: "tag";
- Layout.fillWidth: true;
-
- editable: true;
- selectTextByMouse: true;
- onAccepted: {
- fontFeatureModel.addFeature(currentValue);
+ property OpenTypeFeatureFilterModel availableFilter: OpenTypeFeatureFilterModel {
+ sourceModel: fontFeatureModel.allFeatureModel();
+ filterAvailable: true;
}
+ model: availableFilter;
+ textRole: "display";
+ valueRole: "tag";
+ Layout.fillWidth: true;
delegate: OpenTypeFeatureDelegate {
required property var model;
@@ -181,7 +179,6 @@ TextPropertyBase {
sample: model.sample;
tag: model.tag;
width: cmbAvailableFeatures.width;
- visible: model.available;
fontFamilies: properties.fontFamilies;
fontWeight: properties.fontWeight;
fontStyle: properties.fontStyle.style;
@@ -195,6 +192,87 @@ TextPropertyBase {
cmbAvailableFeatures.popup.close();
}
}
+
+ contentItem: TextField {
+ id: featureTxtEdit;
+ verticalAlignment: Text.AlignVCenter
+ font: cmbAvailableFeatures.font
+ color: cmbAvailableFeatures.palette.text
+ selectionColor: cmbAvailableFeatures.palette.highlight
+ selectedTextColor: cmbAvailableFeatures.palette.highlightedText;
+
+ property bool blockSignals: false;
+
+ property OpenTypeFeatureFilterModel filterModel: OpenTypeFeatureFilterModel {
+ sourceModel: fontFeatureModel.allFeatureModel();
+ }
+
+ selectByMouse: true;
+
+ onTextChanged: {
+ if (text !== "") {
+ filterModel.setFilterRegularExpression(text);
+ completerPopup.open();
+ } else {
+ completerPopup.close();
+ filterModel.setFilterRegularExpression(text);
+ }
+ }
+
+ onAccepted: {
+ blockSignals = true;
+ let name = filterModel.firstValidTag();
+ if (typeof name != 'undefined') {
+ fontFeatureModel.addFeature(name);
+ }
+ finalize();
+ blockSignals = false;
+ }
+
+ function finalize() {
+ text = "";
+ }
+
+ Popup {
+ id: completerPopup;
+ y: -height;
+ x: 0;
+ padding: 0;
+ width: featureTxtEdit.width;
+ height: Math.min(contentItem.implicitHeight, 300);
+ property string highlightedTag;
+ contentItem: ListView {
+ model: featureTxtEdit.filterModel;
+ implicitHeight: contentHeight;
+ clip: true;
+
+ ScrollBar.vertical: ScrollBar {
+ }
+
+ delegate: OpenTypeFeatureDelegate {
+ required property var model;
+ required property int index;
+ display: model.display;
+ toolTip: model.toolTip;
+ sample: model.sample;
+ tag: model.tag;
+ height: implicitHeight;
+ width: featureTxtEdit.width;
+ fontFamilies: properties.fontFamilies;
+ fontWeight: properties.fontWeight;
+ fontStyle: properties.fontStyle.style;
+ fontSlant: properties.fontStyle.value;
+ fontWidth: properties.fontWidth;
+ fontAxesValues: properties.axisValues;
+ featureValue: 0;
+ onFeatureClicked: (mouse) => {
+ fontFeatureModel.addFeature(tag);
+ featureTxtEdit.finalize();
+ }
+ }
+ }
+ }
+ }
}
}
}