MauiKit Controls

fontpickermodel.cpp
1#include "fontpickermodel.h"
2
3#include <QDebug>
4
5FontPickerModel::FontPickerModel(QObject* parent) : QObject(parent)
6,m_writingSystem(QFontDatabase::Any)
7,m_onlyMonospaced(false)
8{
9}
10
12{
13 auto fonts = m_fontDatabase.families(m_writingSystem);
14
15 if(m_onlyMonospaced)
16 {
17 QStringList res;
18 foreach (const QString &family, fonts)
19 {
20 if (m_fontDatabase.isFixedPitch(family))
21 {
22 res << family;
23 }
24 }
25
26 return res;
27 }
28
29 return fonts;
30}
31
33{
34 return m_font;
35}
36
38{
39 return m_onlyMonospaced;
40}
41
42void FontPickerModel::setFont(const QFont& font)
43{
44 if(m_font == font)
45 return;
46
47 m_font = font;
48 Q_EMIT fontChanged();
49 Q_EMIT sizesChanged();
50 Q_EMIT stylesChanged();
51}
52
53void FontPickerModel::setOnlyMonospaced(bool value)
54{
55 if(m_onlyMonospaced == value)
56 return;
57
58 m_onlyMonospaced = value;
59 Q_EMIT onlyMonospacedChanged();
60 Q_EMIT fontsModelChanged();
61}
62
63void FontPickerModel::setWritingSystem(QFontDatabase::WritingSystem value)
64{
65 if(m_writingSystem == value)
66 return;
67
68 m_writingSystem = value;
69 Q_EMIT writingSystemChanged();
70 Q_EMIT fontsModelChanged();
71}
72
74{
75 QStringList res;
76
77 for(auto value : m_fontDatabase.smoothSizes(m_font.family(), m_font.styleName()))
78 {
79 res << QString::number(value);
80 }
81
82 return res;
83}
84
86{
87 return m_fontDatabase.styles(m_font.family());
88}
89
91{
92 return m_writingSystem;
93}
94
96{
97 Q_EMIT sizesChanged();
98 Q_EMIT stylesChanged();
99}
100
102{
103 return m_font.toString();
104}
105
106void FontPickerModel::setFont(const QString& desc)
107{
108 QFont font;
109
110 if(!font.fromString(desc))
111 {
112 qWarning() << "Failed to set QFont from desc" << desc;
113 return;
114 }
115
116 setFont(font);
117}
118
119
120
121
122
123
124
125
QStringList styles
The available styles for the current picked font.
QFontDatabase::WritingSystem writingSystem
The desired writing system to filter out the fonts model.
QStringList sizes
The available optimal font sizes for the picked font.
QML_ELEMENTQFont font
The current picked font for exposing its properties, such as FontPickerModel::styles,...
QString fontToString()
Converts the current picked font to its string description.
QStringList fontsModel
All of the fonts available in the system.
void updateModel()
Forces the model to be updated.
bool onlyMonospaced
Whether to only list fonts in the fonts model that are mono mono-spaced.
QString family() const const
QString toString() const const
QStringList families(WritingSystem writingSystem)
bool isFixedPitch(const QString &family, const QString &style)
QStringList styles(const QString &family)
Q_EMITQ_EMIT
QString number(double n, char format, int precision)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:56:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.