MauiKit Controls

fontpickermodel.h
1#pragma once
2
3#include <QObject>
4#include <QQmlEngine>
5
6#include <QFont>
7#include <QStringList>
8#include <QFontDatabase>
9
10/**
11 * @brief A model of fonts and its properties.
12 * @note This class is exposed as the type `FontPickerModel` to the QML engine. *
13 */
15{
17 QML_ELEMENT
18 /**
19 * The current picked font for exposing its properties, such as FontPickerModel::styles, FontPickerModel::sizes, etc.
20 */
21 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
22
23 /**
24 * The available styles for the current picked font.
25 */
26 Q_PROPERTY(QStringList styles READ styles NOTIFY stylesChanged FINAL)
27
28 /**
29 * The available optimal font sizes for the picked font.
30 */
31 Q_PROPERTY(QStringList sizes READ sizes NOTIFY sizesChanged FINAL)
32
33 /**
34 * All of the fonts available in the system.
35 */
36 Q_PROPERTY(QStringList fontsModel READ fontsModel NOTIFY fontsModelChanged FINAL)
37
38 /**
39 * The desired writing system to filter out the fonts model.
40 */
41 Q_PROPERTY(QFontDatabase::WritingSystem writingSystem READ writingSystem WRITE setWritingSystem NOTIFY writingSystemChanged)
42
43 /**
44 * Whether to only list fonts in the fonts model that are mono mono-spaced.
45 */
46 Q_PROPERTY(bool onlyMonospaced READ onlyMonospaced WRITE setOnlyMonospaced NOTIFY onlyMonospacedChanged FINAL)
47
48public:
49 explicit FontPickerModel(QObject * parent = nullptr);
50
51 QFont font();
52 void setFont(const QFont &font);
53
56
58
59 QFontDatabase::WritingSystem writingSystem();
60 void setWritingSystem(QFontDatabase::WritingSystem value);
61
62 bool onlyMonospaced();
63 void setOnlyMonospaced(bool value);
64
65public Q_SLOTS:
66
67 /**
68 * @brief Forces the model to be updated.
69 */
70 void updateModel();
71
72 /**
73 * @brief Set the current picked font to extract its properties.
74 * @param desc the description of the font, and its properties.
75 * @note See the Qt QFont documentation to see how the font string decsription works.
76 */
77 void setFont(const QString &desc);
78
79 /**
80 * @brief Converts the current picked font to its string description.
81 * @return the converted QFont font and its all properties to a string text.
82 */
84
85private:
86 QFontDatabase m_fontDatabase;
87 QFont m_font;
88 QFontDatabase::WritingSystem m_writingSystem;
89 bool m_onlyMonospaced;
90
92 void fontChanged();
93 void stylesChanged();
94 void sizesChanged();
95 void fontsModelChanged();
96 void writingSystemChanged();
97 void onlyMonospacedChanged();
98};
A model of fonts and its properties.
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.
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 12:00:22 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.