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++
Allow searching on all possible opentype features in the dropdown.
Wolthera van Hövell tot Westerflierfc9b0b14b76c
diff --git a/plugins/dockers/textproperties/OpenTypeFeatureModel.cpp b/plugins/dockers/textproperties/OpenTypeFeatureModel.cppindex 6f9785488f..76bb220e12 100644--- a/plugins/dockers/textproperties/OpenTypeFeatureModel.cpp+++ b/plugins/dockers/textproperties/OpenTypeFeatureModel.cpp@@ -3,17 +3,24 @@** SPDX-License-Identifier: GPL-2.0-or-later*/-#include "OpenTypeFeatureModel.h"+#include <QList>+#include <KoFontGlyphModel.h>#include <KoCSSFontInfo.h>#include <KoOpenTypeFeatureInfoFactory.h>#include <KoFontLibraryResourceUtils.h>#include <KoSvgTextProperties.h>#include <KoFontRegistry.h>+#include <lager/KoSvgTextPropertiesModel.h>+#include <KoSvgTextPropertyData.h>++#include "OpenTypeFeatureModel.h"struct OpenTypeFeatureModel::Private {Private(QObject *parent)- : glyphModel(new KoFontGlyphModel(parent)) {+ : glyphModel(new KoFontGlyphModel(parent))+ , allFeatures(new AllOpenTypeFeaturesModel(parent))+ {}QList<KoOpenTypeFeatureInfo> availableFeatures() const {@@ -32,6 +39,7 @@ struct OpenTypeFeatureModel::Private {}KoFontGlyphModel *glyphModel {nullptr};+ AllOpenTypeFeaturesModel *allFeatures {nullptr};KoOpenTypeFeatureInfoFactory factory;KoCSSFontInfo fontInfo;QVariantMap currentFeatures;@@ -173,7 +181,8 @@ void OpenTypeFeatureModel::setFromTextProperties(const KoSvgTextProperties &propif (!faces.empty()) {QString language = props.propertyOrDefault(KoSvgTextProperties::TextLanguage).toString();d->glyphModel->setFace(faces.front(), QLatin1String(language.toLatin1()));- emit availableFeaturesChanged();+ d->allFeatures->setAvailableFeatures(d->availableFeatures());+ d->fontInfo = props.cssFontInfo();}}@@ -199,21 +208,6 @@ void OpenTypeFeatureModel::setOpenTypeFeatures(const QVariantMap &newOpenTypeFeaemit openTypeFeaturesChanged();}-QVariantList OpenTypeFeatureModel::availableFeatures() const-{- QVariantList features;- Q_FOREACH(const KoOpenTypeFeatureInfo info, d->availableFeatures()) {- QVariantMap feat;-- feat.insert("tag", info.tag);- feat.insert("display", info.name);- feat.insert("toolTip", info.description);- feat.insert("sample", info.sample);- features.append(feat);- }- return features;-}-void OpenTypeFeatureModel::addFeature(const QString &tag){if (tag.isEmpty()) return;@@ -240,3 +234,124 @@ void OpenTypeFeatureModel::removeFeature(const QString &tag)endRemoveRows();emit openTypeFeaturesChanged();}++QAbstractItemModel *OpenTypeFeatureModel::featureFilterModel() const+{+ return d->allFeatures;+}+++void OpenTypeFeatureModel::setFromTextPropertiesModel(KoSvgTextPropertiesModel *textPropertiesModel)+{+ KoSvgTextProperties main;+ if (textPropertiesModel) {+ KoSvgTextPropertyData data = textPropertiesModel->textData.get();+ main = data.commonProperties;+ main.inheritFrom(data.inheritedProperties);+ }+ setFromTextProperties(main);+}++/********* AllOpenTypeFeaturesModel ************/+struct AllOpenTypeFeaturesModel::Private {++ KoOpenTypeFeatureInfoFactory factory;+ QList<KoOpenTypeFeatureInfo> availableFeatures; // Features in font.+ QStringList availableTags;+ QStringList allTags;++ bool featureAvailable(const QString &tag) const {+ return availableTags.contains(tag);+ }++ KoOpenTypeFeatureInfo featureByTag(QLatin1String tag) const {+ Q_FOREACH(KoOpenTypeFeatureInfo feature, availableFeatures) {+ if (feature.tag == tag) {+ return feature;+ break;+ }+ }++ return factory.infoByTag(tag);+ }++ // OpenType allows for "custom" opentype features, this forloop checks for those.+ void setAvailableTags() {+ QStringList tags;+ allTags = factory.tags();+ Q_FOREACH(KoOpenTypeFeatureInfo feature, availableFeatures) {+ const QString tag = QString::fromLatin1(feature.tag.data(), 4);+ if (!allTags.contains(tag)) {+ allTags.append(tag);+ }+ tags.append(tag);+ }+ availableTags = tags;+ }+};++AllOpenTypeFeaturesModel::AllOpenTypeFeaturesModel(QObject *parent)+ : QAbstractListModel(parent)+ , d(new Private)+{++}++AllOpenTypeFeaturesModel::~AllOpenTypeFeaturesModel()+{++}++void AllOpenTypeFeaturesModel::setAvailableFeatures(const QList<KoOpenTypeFeatureInfo> &features)+{+ beginResetModel();+ d->availableFeatures = features;+ d->setAvailableTags();+ endResetModel();+}++QVariant AllOpenTypeFeaturesModel::data(const QModelIndex &index, int role) const+{+ if (!index.isValid())+ return QVariant();++ const QString feature = d->allTags.at(index.row());+ KoOpenTypeFeatureInfo info = d->featureByTag(QLatin1String(feature.toLatin1(), 4));+ if (role == Qt::DisplayRole) {+ return info.name;+ } else if (role == Qt::ToolTipRole) {+ return info.description;+ } else if (role == Tag) {+ return feature;+ } else if (role == Sample) {+ return info.sample;+ } else if (role == Available) {+ return d->featureAvailable(feature);+ }+ return QVariant();+}++int AllOpenTypeFeaturesModel::rowCount(const QModelIndex &parent) const+{+ return d->allTags.size();+}++QVariant AllOpenTypeFeaturesModel::headerData(int section, Qt::Orientation orientation, int role) const+{+ if (role == Qt::DisplayRole) {+ if (orientation == Qt::Horizontal && section == 0) {+ return i18nc("@title:column", "OpenType Feature Tag");+ }+ }+ return QVariant();+}++QHash<int, QByteArray> AllOpenTypeFeaturesModel::roleNames() const+{+ QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();+ roles[Tag] = "tag";+ roles[Sample] = "sample";+ roles[Available] = "available";+ return roles;+}+diff --git a/plugins/dockers/textproperties/OpenTypeFeatureModel.h b/plugins/dockers/textproperties/OpenTypeFeatureModel.hindex 97b5d6e7f2..55843d80cf 100644--- a/plugins/dockers/textproperties/OpenTypeFeatureModel.h+++ b/plugins/dockers/textproperties/OpenTypeFeatureModel.h@@ -7,16 +7,25 @@#define OPENTYPEFEATUREMODEL_H#include <QAbstractItemModel>+#include <QSortFilterProxyModel>class KoSvgTextProperties;+class KoOpenTypeFeatureInfo;+class KoSvgTextPropertiesModel;+/**+ * @brief The OpenTypeFeatureModel class+ * This model keeps track of the currently set font-feature-settings property on a given piece of text,+ * and allows editing it. It also keeps track of the available features of a given font.+ *+ * Each feature is internally represented as a tag plus a number.+ */class OpenTypeFeatureModel : public QAbstractItemModel{Q_OBJECT+ // Current opentype features.Q_PROPERTY(QVariantMap openTypeFeatures READ openTypeFeatures WRITE setOpenTypeFeatures NOTIFY openTypeFeaturesChanged)- Q_PROPERTY(QVariantList availableFeatures READ availableFeatures NOTIFY availableFeaturesChanged)-public:OpenTypeFeatureModel(QObject *parent = nullptr);@@ -46,19 +55,37 @@ public:QHash<int, QByteArray> roleNames() const override;+ // Set the current model from a given set of text properties, if the font is different. Called by setFromTextPropertiesModel.void setFromTextProperties(const KoSvgTextProperties &props);+ // Current opentype features list. Map of tags with integer values.QVariantMap openTypeFeatures() const;void setOpenTypeFeatures(const QVariantMap &newOpenTypeFeatures);- QVariantList availableFeatures() const;-+ // Add a feature by tag and set its value to 1.Q_INVOKABLE void addFeature(const QString &tag);++ // Remove a feature by tag.Q_INVOKABLE void removeFeature(const QString &tag);+ /**+ * @brief featureFilterModel+ * @return return the OpenTypeFeatureFilterModel that allows+ * searching and sorting on all opentype features, whether available in the font+ * or part of the standard.+ */+ Q_INVOKABLE QAbstractItemModel *featureFilterModel() const;++ /**+ * @brief setFromTextPropertiesModel+ * Set the current glyph model font from the lager text properties model.+ * This allows us to use this class from qml, with little fuss.+ * @param newTextProperties -- the lager model to set from.+ */+ Q_INVOKABLE void setFromTextPropertiesModel(KoSvgTextPropertiesModel *textPropertiesModel);+Q_SIGNALS:void openTypeFeaturesChanged();- void availableFeaturesChanged();private:@@ -66,4 +93,30 @@ private:const QScopedPointer<Private> d;};+// Source model that keeps track of all available and possible opentype features.+class AllOpenTypeFeaturesModel: public QAbstractListModel {+public:+ AllOpenTypeFeaturesModel(QObject *parent = nullptr);++ /* @see OpenTypeFeatureModel::Roles */+ enum Roles {+ Tag = Qt::UserRole + 1,+ Sample,+ Available // bool, represents whether the current feature is also present in the font.+ };+ ~AllOpenTypeFeaturesModel();++ // Set the features for the currently available font.+ void setAvailableFeatures(const QList<KoOpenTypeFeatureInfo> &features);++ QVariant data(const QModelIndex &index, int role) const override;+ int rowCount(const QModelIndex &parent) const override;+ QVariant headerData(int section, Qt::Orientation orientation, int role) const;+ QHash<int, QByteArray> roleNames() const override;+private:++ struct Private;+ const QScopedPointer<Private> d;+};+#endif // OPENTYPEFEATUREMODEL_Hdiff --git a/plugins/dockers/textproperties/TextPropertiesDock.cpp b/plugins/dockers/textproperties/TextPropertiesDock.cppindex 06ee90468c..0e67528b5a 100644--- a/plugins/dockers/textproperties/TextPropertiesDock.cpp+++ b/plugins/dockers/textproperties/TextPropertiesDock.cpp@@ -105,7 +105,6 @@ struct TextPropertiesDock::PrivateFontAxesModel axesModel;KisResourceModel *fontModel{nullptr};KisCanvasResourceProvider *provider{nullptr};- OpenTypeFeatureModel featureModel;};TextPropertiesDock::TextPropertiesDock()@@ -144,12 +143,10 @@ TextPropertiesDock::TextPropertiesDock()d->stylesModel.setLocales(locales);connect(&d->axesModel, SIGNAL(axisValuesChanged()), this, SLOT(slotUpdateAxesValues()));- connect(&d->featureModel, SIGNAL(openTypeFeaturesChanged()), this, SLOT(slotUpdateFeatureSettings()));m_quickWidget->rootContext()->setContextProperty("textPropertiesModel", d->textModel);m_quickWidget->rootContext()->setContextProperty("fontStylesModel", QVariant::fromValue(&d->stylesModel));m_quickWidget->rootContext()->setContextProperty("fontAxesModel", QVariant::fromValue(&d->axesModel));- m_quickWidget->rootContext()->setContextProperty("fontFeatureModel", QVariant::fromValue(&d->featureModel));m_quickWidget->rootContext()->setContextProperty("locales", QVariant::fromValue(wellFormedBCPNames));connect(d->textModel, SIGNAL(textPropertyChanged()),this, SLOT(slotTextPropertiesChanged()));@@ -157,7 +154,6 @@ TextPropertiesDock::TextPropertiesDock()m_quickWidget->setSource(QUrl("qrc:/TextProperties.qml"));m_quickWidget->setPalette(this->palette());-}TextPropertiesDock::~TextPropertiesDock()@@ -215,10 +211,6 @@ void TextPropertiesDock::slotCanvasTextPropertiesChanged()if (d->textModel->textData.get() != data) {d->textModel->textData.set(data);- KoSvgTextProperties main = data.commonProperties;- main.inheritFrom(data.inheritedProperties);- d->featureModel.setFromTextProperties(main);-QMetaObject::invokeMethod(m_quickWidget->rootObject(), "setProperties");}}@@ -267,13 +259,6 @@ void TextPropertiesDock::slotUpdateAxesValues()d->textModel->setaxisValues(d->axesModel.axisValues());}-void TextPropertiesDock::slotUpdateFeatureSettings()-{- if (d->featureModel.openTypeFeatures() == d->textModel->fontFeatureSettings())- return;- d->textModel->setfontFeatureSettings(d->featureModel.openTypeFeatures());-}-#include <KoFontRegistry.h>QString TextPropertiesDock::wwsFontFamilyName(QString familyName){diff --git a/plugins/dockers/textproperties/TextPropertiesDock.h b/plugins/dockers/textproperties/TextPropertiesDock.hindex 112dca3102..c078beb4b1 100644--- a/plugins/dockers/textproperties/TextPropertiesDock.h+++ b/plugins/dockers/textproperties/TextPropertiesDock.h@@ -33,7 +33,6 @@ public Q_SLOTS:void slotTextPropertiesChanged();void slotUpdateStylesModel();void slotUpdateAxesValues();- void slotUpdateFeatureSettings();QString wwsFontFamilyName(QString familyName);void connectAutoEnabler(QObject *watched);diff --git a/plugins/dockers/textproperties/qml/OpenTypeFeatureDelegate.qml b/plugins/dockers/textproperties/qml/OpenTypeFeatureDelegate.qmlindex 52834f58c8..de6f878131 100644--- a/plugins/dockers/textproperties/qml/OpenTypeFeatureDelegate.qml+++ b/plugins/dockers/textproperties/qml/OpenTypeFeatureDelegate.qml@@ -11,12 +11,15 @@ import org.krita.flake.text 1.0Control {id: root;- height: childrenRect.height;+ height: visible? implicitHeight: 0;+ implicitHeight: layout.height + padding*2;property string display;property string tag;property string sample;property string toolTip;+ property bool enableMouseEvents: true;+property alias containsMouse: mouseArea.containsMouse;background: Rectangle {@@ -26,17 +29,20 @@ Control {signal featureClicked (QtObject mouse);RowLayout {- height: childrenRect.height;- width: parent.width;+ id: layout;+ width: parent.availableWidth;Label {- Layout.alignment: Qt.AlignCenter | Qt.AlignVCenter+ Layout.leftMargin: layout.spacing;+ Layout.alignment: Qt.AlignHCenter | Qt.AlignVCentertextFormat: Text.MarkdownText;// This is somehow the easiest way I've found it to require monospace...text: "`"+root.tag+"`";- Layout.fillHeight: true;+ Layout.preferredHeight: implicitHeight;Layout.maximumWidth: contentWidth;+ color: root.containsMouse? palette.highlightedText: palette.text;}+ToolSeparator {Layout.fillHeight: true;}@@ -44,31 +50,35 @@ Control {ColumnLayout {Layout.fillWidth: true;Layout.fillHeight: true;+ Layout.topMargin: layout.spacing;+ Layout.rightMargin: layout.spacing;+ Layout.bottomMargin: layout.spacing;Label {text: root.display;- Layout.alignment: Qt.AlignRight | Qt.AlignVCenterelide: Text.ElideRight;Layout.fillWidth: true;+ Layout.preferredHeight: implicitHeight+ color: root.containsMouse? palette.highlightedText: palette.text;}Label {text: root.sample;- Layout.alignment: Qt.AlignRight | Qt.AlignVCenterelide: Text.ElideRight;Layout.fillWidth: true;+ Layout.preferredHeight: implicitHeight+ color: root.containsMouse? palette.highlightedText: palette.text;}}}MouseArea {id: mouseArea;anchors.fill: parent;- hoverEnabled: true;- onClicked: (mouse)=>{- featureClicked(mouse);- }+ hoverEnabled: root.enableMouseEvents;+ enabled: root.enableMouseEvents;+ onClicked: (mouse)=>{ featureClicked(mouse); }ToolTip.text: root.toolTip;ToolTip.visible: containsMouse;- ToolTip.delay: 1000;+ ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval;}}diff --git a/plugins/dockers/textproperties/qml/OpenTypeFeatureSettings.qml b/plugins/dockers/textproperties/qml/OpenTypeFeatureSettings.qmlindex 7df013e1e8..46f56fa3eb 100644--- a/plugins/dockers/textproperties/qml/OpenTypeFeatureSettings.qml+++ b/plugins/dockers/textproperties/qml/OpenTypeFeatureSettings.qml@@ -17,8 +17,19 @@ TextPropertyBase {searchTerms: i18nc("comma separated search terms for the font-feature-settings property, matching is case-insensitive","font-feature-settings, OpenType");+ OpenTypeFeatureModel {+ id: fontFeatureModel;+ onOpenTypeFeaturesChanged: {+ if (!blockSignals) {+ properties.fontFeatureSettings = openTypeFeatures;+ }+ }+ }+onPropertiesUpdated: {blockSignals = true;+ // Setting text properties model will also set the opentype features.+ fontFeatureModel.setFromTextPropertiesModel(properties);visible = properties.fontFeatureSettingsState !== KoSvgTextPropertiesModel.PropertyUnset;blockSignals = false;}@@ -83,10 +94,22 @@ TextPropertyBase {currentIndex: activeFeatureDelegate.model.edit;+ contentItem: OpenTypeFeatureDelegate {+ display: activeFeatureControl.currentText;+ toolTip: activeFeatureDelegate.toolTip;+ sample: activeFeatureDelegate.sample;+ tag: activeFeatureDelegate.tag;+ enableMouseEvents: false;+ }++ ToolTip.text: activeFeatureDelegate.toolTip;+ ToolTip.visible: activeFeatureControl.hovered;+ ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval;+delegate: OpenTypeFeatureDelegate {display: modelData.display;width: activeFeatureControl.width;- toolTip: activeFeatureDelegate.display;+ toolTip: display;sample: activeFeatureDelegate.sample;tag: activeFeatureDelegate.tag;onFeatureClicked: {@@ -107,7 +130,7 @@ TextPropertyBase {icon.height: 22;icon.source: "qrc:///22_light_list-remove.svg"onClicked: fontFeatureModel.removeFeature(parent.tag);- ToolTip.text: i18n("Remove feature");+ ToolTip.text: i18n("Remove feature.");ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval;ToolTip.visible: hovered;}@@ -120,17 +143,28 @@ TextPropertyBase {}ComboBox {id: cmbAvailableFeatures;- model: fontFeatureModel.availableFeatures;+ model: fontFeatureModel.featureFilterModel();textRole: "display";valueRole: "tag";Layout.fillWidth: true;+ editable: true;+ selectTextByMouse: true;++ onAccepted: {+ fontFeatureModel.addFeature(currentValue);+ }++delegate: OpenTypeFeatureDelegate {- display: modelData.display;- toolTip: modelData.toolTip;- sample: modelData.sample;- tag: modelData.tag;+ required property var model;+ required property int index;+ display: model.display;+ toolTip: model.toolTip;+ sample: model.sample;+ tag: model.tag;width: cmbAvailableFeatures.width;+ visible: model.available;onFeatureClicked: (mouse) => {cmbAvailableFeatures.currentIndex = index;fontFeatureModel.addFeature(tag);