Krita Source Code Documentation
Loading...
Searching...
No Matches
OpenTypeFeatureModel.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#ifndef OPENTYPEFEATUREMODEL_H
7#define OPENTYPEFEATUREMODEL_H
8
9#include <QAbstractItemModel>
10#include <QSortFilterProxyModel>
11
15
16// Filter SortProxy that filters by both name and tag.
17class OpenTypeFeatureFilterModel : public QSortFilterProxyModel
18{
19 Q_OBJECT
21 Q_PROPERTY (QString searchText READ searchText WRITE setSearchText NOTIFY searchTextChanged)
22public:
23 OpenTypeFeatureFilterModel(QObject *parent = nullptr);
24
25 Q_INVOKABLE QString firstValidTag() const;
26 // QSortFilterProxyModel interface
27 bool filterAvailable() const;
28 void setFilterAvailable(bool newFilterAvailable);
29
30 QString searchText() const;
31 void setSearchText(const QString &newSearchText);
32
33Q_SIGNALS:
35
37
38protected:
39 bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
40private:
42};
43
51class OpenTypeFeatureModel : public QAbstractItemModel
52{
53 Q_OBJECT
54
55 // Current opentype features.
56 Q_PROPERTY(QVariantMap openTypeFeatures READ openTypeFeatures WRITE setOpenTypeFeatures NOTIFY openTypeFeaturesChanged)
57public:
58 OpenTypeFeatureModel(QObject *parent = nullptr);
59
61
62 enum Roles {
63 Tag = Qt::UserRole + 1,
66 Max
67 };
68 // Basic functionality:
69 QModelIndex index(int row, int column,
70 const QModelIndex &parent = QModelIndex()) const override;
71 QModelIndex parent(const QModelIndex &index) const override;
72
73 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
74 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
75
76 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
77
78 // Editable:
79 bool setData(const QModelIndex &index, const QVariant &value,
80 int role = Qt::EditRole) override;
81
82 Qt::ItemFlags flags(const QModelIndex& index) const override;
83
84 QHash<int, QByteArray> roleNames() const override;
85
86 // Set the current model from a given set of text properties, if the font is different. Called by setFromTextPropertiesModel.
87 void setFromTextProperties(const KoSvgTextProperties &props);
88
89 // Current opentype features list. Map of tags with integer values.
90 QVariantMap openTypeFeatures() const;
91 void setOpenTypeFeatures(const QVariantMap &newOpenTypeFeatures);
92
93 // Add a feature by tag and set its value to 1.
94 Q_INVOKABLE void addFeature(const QString &tag);
95
96 // Remove a feature by tag.
97 Q_INVOKABLE void removeFeature(const QString &tag);
98
105 Q_INVOKABLE QAbstractItemModel *allFeatureModel() const;
106
113 Q_INVOKABLE void setFromTextPropertiesModel(KoSvgTextPropertiesModel *textPropertiesModel);
114
115Q_SIGNALS:
117
118private:
119
120 struct Private;
121 const QScopedPointer<Private> d;
122};
123
124// Source model that keeps track of all available and possible opentype features.
125class AllOpenTypeFeaturesModel: public QAbstractListModel {
126public:
127 AllOpenTypeFeaturesModel(QObject *parent = nullptr);
128
129 /* @see OpenTypeFeatureModel::Roles */
130 enum Roles {
131 Tag = Qt::UserRole + 1,
133 Available
134 };
136
137 // Set the features for the currently available font.
138 void setAvailableFeatures(const QList<KoOpenTypeFeatureInfo> &features);
139
140 QVariant data(const QModelIndex &index, int role) const override;
141 int rowCount(const QModelIndex &parent) const override;
142 QVariant headerData(int section, Qt::Orientation orientation, int role) const;
143 QHash<int, QByteArray> roleNames() const override;
144private:
145
146 struct Private;
147 const QScopedPointer<Private> d;
148};
149
150#endif // OPENTYPEFEATUREMODEL_H
float value(const T *src, size_t ch)
const QScopedPointer< Private > d
The KoSvgTextPropertiesModel class.
void setFilterAvailable(bool newFilterAvailable)
void setSearchText(const QString &newSearchText)
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
Q_INVOKABLE QString firstValidTag() const
The OpenTypeFeatureModel class This model keeps track of the currently set font-feature-settings prop...
@ Sample
QString, the sample for this feature, may be empty.
@ Parameters
QVariantList, indices with names of the feature count.
const QScopedPointer< Private > d
void openTypeFeaturesChanged()