Krita Source Code Documentation
Loading...
Searching...
No Matches
FontAxesModel Class Reference

The FontAxesModel class. More...

#include <FontAxesModel.h>

+ Inheritance diagram for FontAxesModel:

Classes

struct  Private
 

Public Types

enum  Roles { Min = Qt::UserRole + 1 , Max , Hidden }
 

Public Slots

void setAxisValues (const QVariantMap &newAxisValues)
 

Signals

void axisValuesChanged ()
 

Public Member Functions

bool axesValueSignalBlocked () const
 
QVariantMap axisValues () const
 
int columnCount (const QModelIndex &parent) const override
 
QVariant data (const QModelIndex &index, int role) const override
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 
 FontAxesModel (QObject *parent=nullptr)
 
QModelIndex index (int row, int column, const QModelIndex &parent) const override
 
QModelIndex parent (const QModelIndex &child) const override
 
QHash< int, QByteArray > roleNames () const override
 
int rowCount (const QModelIndex &parent) const override
 
void setAxesData (QList< KoSvgText::FontFamilyAxis > axes)
 
void setBlockAxesValuesSignal (bool block)
 
bool setData (const QModelIndex &index, const QVariant &value, int role) override
 
Q_INVOKABLE void setFromTextPropertiesModel (KoSvgTextPropertiesModel *textPropertiesModel)
 
void setOpticalSizeDisabled (bool disable)
 If optical size link is enabled, then the slider should be disabled.
 
 ~FontAxesModel ()
 

Properties

QVariantMap axisValues
 

Private Attributes

const QScopedPointer< Privated
 

Detailed Description

The FontAxesModel class.

This models the KoSvgText::FontFamilyAxis inside the KoFontFamily resource, with the exception of the width, weight, slant and italic axes, as these are already handled by the existing sliders.

Definition at line 23 of file FontAxesModel.h.

Member Enumeration Documentation

◆ Roles

Enumerator
Min 

double, represents lower end

Max 

double, represents upper end

Hidden 

bool

Definition at line 28 of file FontAxesModel.h.

28 {
29 Min = Qt::UserRole + 1,
30 Max,
31 Hidden
32 };
@ Min
double, represents lower end
@ Max
double, represents upper end

Constructor & Destructor Documentation

◆ FontAxesModel()

FontAxesModel::FontAxesModel ( QObject * parent = nullptr)

Definition at line 30 of file FontAxesModel.cpp.

31 : QAbstractItemModel(parent)
32 , d(new Private)
33{
35 QList<QLocale> locales;
36 Q_FOREACH (const QString langCode, KLocalizedString::languages()) {
37 locales.append(QLocale(langCode));
38 }
39 d->locales = locales;
40}
QModelIndex parent(const QModelIndex &child) const override
const QScopedPointer< Private > d
The KisResourceModel class provides the main access to resources. It is possible to filter the resour...
const QString FontFamilies

References d, and ResourceType::FontFamilies.

◆ ~FontAxesModel()

FontAxesModel::~FontAxesModel ( )

Definition at line 42 of file FontAxesModel.cpp.

43{
44}

Member Function Documentation

◆ axesValueSignalBlocked()

bool FontAxesModel::axesValueSignalBlocked ( ) const

Definition at line 78 of file FontAxesModel.cpp.

79{
80 return d->blockAxesValuesUpdate;
81}

References d.

◆ axisValues()

QVariantMap FontAxesModel::axisValues ( ) const

Definition at line 180 of file FontAxesModel.cpp.

181{
182 return d->axisValues;
183}

References d.

◆ axisValuesChanged

void FontAxesModel::axisValuesChanged ( )
signal

◆ columnCount()

int FontAxesModel::columnCount ( const QModelIndex & parent) const
override

Definition at line 103 of file FontAxesModel.cpp.

104{
105 Q_UNUSED(parent);
106 return 1;
107}

References parent().

◆ data()

QVariant FontAxesModel::data ( const QModelIndex & index,
int role ) const
override

Definition at line 109 of file FontAxesModel.cpp.

110{
111 if (!index.isValid()) return QVariant();
112
113 KoSvgText::FontFamilyAxis axis = d->axes.at(index.row());
114 if (role == Qt::DisplayRole) {
115 if (axis.tag == OPTICAL_TAG){
116 // Refers to https://learn.microsoft.com/en-us/typography/opentype/spec/dvaraxistag_opsz
117 return i18nc("@info:label", "Optical Size");
118 }
119 if (axis.localizedLabels.isEmpty()) {
120 return axis.tag;
121 }
122 QString label = axis.localizedLabels.value(QLocale(QLocale::English), axis.localizedLabels.values().first());
123 Q_FOREACH(const QLocale &locale, d->locales) {
124 if (axis.localizedLabels.keys().contains(locale)) {
125 label = axis.localizedLabels.value(locale, label);
126 break;
127 }
128 }
129 return label;
130 } else if (role == Qt::EditRole) {
131 return d->axisValues.value(axis.tag, axis.defaultValue).toDouble();
132 } else if (role == Min) {
133 return axis.min;
134 } else if (role == Max) {
135 return axis.max;
136 } else if (role == Hidden) {
137 return axis.axisHidden;
138 }
139 return QVariant();
140}
const QString OPTICAL_TAG
QModelIndex index(int row, int column, const QModelIndex &parent) const override
QHash< QLocale, QString > localizedLabels
Definition KoSvgText.h:777

References KoSvgText::FontFamilyAxis::axisHidden, d, KoSvgText::FontFamilyAxis::defaultValue, Hidden, index(), KoSvgText::FontFamilyAxis::localizedLabels, KoSvgText::FontFamilyAxis::max, Max, KoSvgText::FontFamilyAxis::min, Min, OPTICAL_TAG, and KoSvgText::FontFamilyAxis::tag.

◆ flags()

Qt::ItemFlags FontAxesModel::flags ( const QModelIndex & index) const
override

Definition at line 159 of file FontAxesModel.cpp.

160{
161 Qt::ItemFlags flags = QAbstractItemModel::flags(index) | Qt::ItemNeverHasChildren | Qt::ItemIsEditable;
162
163 /*KoSvgText::FontFamilyAxis axis = d->axes.value(index.row());
164 if (!(axis.tag == OPTICAL_TAG && d->opticalSizeDisabled)) {
165 flags |= Qt::ItemIsEnabled;
166 }*/
167
168 return flags;
169}
Qt::ItemFlags flags(const QModelIndex &index) const override

References flags(), and index().

◆ index()

QModelIndex FontAxesModel::index ( int row,
int column,
const QModelIndex & parent ) const
override

Definition at line 83 of file FontAxesModel.cpp.

84{
85 Q_UNUSED(parent);
86 if (column != 0) return QModelIndex();
87 if (row >= 0 && row < d->axes.size()) return createIndex(row, column, &row);
88 return QModelIndex();
89}

References parent().

◆ parent()

QModelIndex FontAxesModel::parent ( const QModelIndex & child) const
override

Definition at line 91 of file FontAxesModel.cpp.

92{
93 Q_UNUSED(child);
94 return QModelIndex();
95}

◆ roleNames()

QHash< int, QByteArray > FontAxesModel::roleNames ( ) const
override

Definition at line 171 of file FontAxesModel.cpp.

172{
173 QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
174 roles[Min] = "axismin";
175 roles[Max] = "axismax";
176 roles[Hidden] = "axishidden";
177 return roles;
178}

References Hidden, Max, and Min.

◆ rowCount()

int FontAxesModel::rowCount ( const QModelIndex & parent) const
override

Definition at line 97 of file FontAxesModel.cpp.

98{
99 Q_UNUSED(parent);
100 return d->axes.size();
101}

References d, and parent().

◆ setAxesData()

void FontAxesModel::setAxesData ( QList< KoSvgText::FontFamilyAxis > axes)

Definition at line 46 of file FontAxesModel.cpp.

47{
49 for (int i=0; i < axes.size(); i++) {
50 QString tag = axes.at(i).tag;
51 if (!(tag == WEIGHT_TAG
52 || tag == WIDTH_TAG
53 || tag == ITALIC_TAG
54 || tag == SLANT_TAG)
55 && !axes.at(i).axisHidden) {
56 newAxes.append(axes.at(i));
57 }
58 }
59 if (newAxes != d->axes) {
60 // TODO: Rework this whole thing so we don't update axes unless absolutely necessary.
61 // This wll probably require a filterproxy model where invisible axes are filtered out.
62 beginResetModel();
63 d->axes = newAxes;
64 endResetModel();
65 }
66}
const QString SLANT_TAG
const QString WEIGHT_TAG
const QString ITALIC_TAG
const QString WIDTH_TAG

References d, ITALIC_TAG, SLANT_TAG, WEIGHT_TAG, and WIDTH_TAG.

◆ setAxisValues

void FontAxesModel::setAxisValues ( const QVariantMap & newAxisValues)
slot

Definition at line 210 of file FontAxesModel.cpp.

211{
212 if (d->axisValues == newAxisValues)
213 return;
214 d->axisValues = newAxisValues;
215
216 if (!d->blockAxesValuesUpdate) {
217 emit axisValuesChanged();
218 }
219
220 QModelIndex idx1 = index(0, 0, QModelIndex());
221 QModelIndex idx2 = index(rowCount(QModelIndex())-1, 0, QModelIndex());
222 if (idx1.isValid() && idx2.isValid()) {
223 emit dataChanged(idx1, idx2, {Qt::EditRole});
224 }
225}
void axisValuesChanged()
int rowCount(const QModelIndex &parent) const override

References axisValuesChanged(), d, index(), and rowCount().

◆ setBlockAxesValuesSignal()

void FontAxesModel::setBlockAxesValuesSignal ( bool block)

Definition at line 73 of file FontAxesModel.cpp.

74{
75 d->blockAxesValuesUpdate = block;
76}

References d.

◆ setData()

bool FontAxesModel::setData ( const QModelIndex & index,
const QVariant & value,
int role )
override

Definition at line 142 of file FontAxesModel.cpp.

143{
144 if (index.isValid() && role == Qt::EditRole) {
145
146 KoSvgText::FontFamilyAxis axis = d->axes.at(index.row());
147 if (!d->axisValues.keys().contains(axis.tag) || !qFuzzyCompare(d->axisValues.value(axis.tag).toDouble(), value.toDouble())) {
148 d->axisValues.insert(axis.tag, value);
149 if (!d->blockAxesValuesUpdate) {
150 emit axisValuesChanged();
151 }
152 emit dataChanged(index, index, { Qt::EditRole});
153 return true;
154 }
155 }
156 return false;
157}
float value(const T *src, size_t ch)

References axisValuesChanged(), d, index(), KoSvgText::FontFamilyAxis::tag, and value().

◆ setFromTextPropertiesModel()

void FontAxesModel::setFromTextPropertiesModel ( KoSvgTextPropertiesModel * textPropertiesModel)

Definition at line 185 of file FontAxesModel.cpp.

186{
187 QStringList families = textPropertiesModel->fontFamilies();
189
190
191 if (!families.isEmpty() && d->fontModel) {
192
193 std::optional<QString> name = KoFontRegistry::instance()->wwsNameByFamilyName(families.first());
194 QString familyName = !name? families.first(): name.value();
195
196 QVector<KoResourceSP> res = d->fontModel->resourcesForFilename(familyName);
197 if (!res.isEmpty()) {
198 KoFontFamilySP family = res.first().staticCast<KoFontFamily>();
199 if (family) {
200 axes = family->axes();
201 }
202 }
203 }
205 setAxesData(axes);
206 setAxisValues(textPropertiesModel->axisValues());
208}
void setAxisValues(const QVariantMap &newAxisValues)
void setAxesData(QList< KoSvgText::FontFamilyAxis > axes)
void setBlockAxesValuesSignal(bool block)
The KoFontFamily class Abstract representation of a Weight/Width/Slant font family,...
std::optional< QString > wwsNameByFamilyName(const QString familyName) const
static KoFontRegistry * instance()
const char * name(StandardAction id)

References d, KoFontRegistry::instance(), setAxesData(), setAxisValues(), setBlockAxesValuesSignal(), and KoFontRegistry::wwsNameByFamilyName().

◆ setOpticalSizeDisabled()

void FontAxesModel::setOpticalSizeDisabled ( bool disable)

If optical size link is enabled, then the slider should be disabled.

Definition at line 68 of file FontAxesModel.cpp.

69{
70 d->opticalSizeDisabled = disable;
71}

References d.

Member Data Documentation

◆ d

const QScopedPointer<Private> FontAxesModel::d
private

Definition at line 68 of file FontAxesModel.h.

Property Documentation

◆ axisValues

QVariantMap FontAxesModel::axisValues
readwrite

Definition at line 26 of file FontAxesModel.h.


The documentation for this class was generated from the following files: