Krita Source Code Documentation
Loading...
Searching...
No Matches
KisUiFont Namespace Reference

Functions

QFont dockFont ()
 Gets a font with a smallish font size for dock widgets to use.
 
QFont normalFont ()
 Gets a font for normal UI widgets to use.
 
static QFont systemDefaultUiFont ()
 Gets the system default UI font.
 
static boost::optional< QFont > userCfgUiFont ()
 Returns the font the user has configured.
 

Variables

static const QString customFontSizeCfgName = QStringLiteral("custom_font_size")
 
static const QString customSystemFontCfgName = QStringLiteral("custom_system_font")
 
static const QString useCustomSystemFontCfgName = QStringLiteral("use_custom_system_font")
 

Function Documentation

◆ dockFont()

KRITAUI_EXPORT QFont KisUiFont::dockFont ( )

Gets a font with a smallish font size for dock widgets to use.

Returns
the small font.

Definition at line 98 of file KisUiFont.cpp.

99{
100 QFont font = normalFont();
101 // Font size may be in pixels (on Android) or points (everywhere else.)
102 qreal ratio = 0.9;
103 if (font.pixelSize() == -1) {
104 font.setPointSizeF(font.pointSizeF() * ratio);
105 } else {
106 font.setPixelSize(qRound(font.pixelSize() * ratio));
107 }
108 return font;
109}
QFont normalFont()
Gets a font for normal UI widgets to use.
Definition KisUiFont.cpp:81

References normalFont().

◆ normalFont()

KRITAUI_EXPORT QFont KisUiFont::normalFont ( )

Gets a font for normal UI widgets to use.

Returns
the UI font.

Definition at line 81 of file KisUiFont.cpp.

82{
83 QFont font;
84 if (boost::optional<QFont> userFont = userCfgUiFont()) {
85 font = *userFont;
86 } else {
87 font = systemDefaultUiFont();
88 }
89#ifdef Q_OS_WIN
90 // XXX: Forces Qt to use full hinting for UI text, otherwise the default
91 // will cause Qt to do vertical hinting only when High-DPI is active,
92 // which makes some UI text extremely blurry on CJK systems.
93 font.setHintingPreference(QFont::PreferFullHinting);
94#endif
95 return font;
96}
static boost::optional< QFont > userCfgUiFont()
Returns the font the user has configured.
Definition KisUiFont.cpp:58

References systemDefaultUiFont(), and userCfgUiFont().

◆ systemDefaultUiFont()

QFont KisUiFont::systemDefaultUiFont ( )
static

Gets the system default UI font.

Returns
the system default UI font.

Definition at line 49 of file KisUiFont.cpp.

50{
51#if defined(Q_OS_WIN) && QT_VERSION < 0x060000
52 return windowsSystemUiFont();
53#else
54 return QFontDatabase::systemFont(QFontDatabase::GeneralFont);
55#endif
56}

◆ userCfgUiFont()

boost::optional< QFont > KisUiFont::userCfgUiFont ( )
static

Returns the font the user has configured.

Returns
the user font if it has been set, otherwise boost::none.

Definition at line 58 of file KisUiFont.cpp.

59{
60 KisConfig cfg(true);
61 if (cfg.readEntry<bool>(useCustomSystemFontCfgName, false)) {
62 QString fontName = cfg.readEntry<QString>(customSystemFontCfgName, QString());
63 if (fontName.isEmpty()) {
64 return boost::none;
65 }
66 int fontSize = cfg.readEntry<int>(customFontSizeCfgName, -1);
67 if (fontSize <= 6) {
68 // Font size may be in pixels (on Android) or points (everywhere else.)
69 QFont systemFont = systemDefaultUiFont();
70 fontSize = systemFont.pointSize();
71 if (fontSize == -1) {
72 fontSize = systemFont.pixelSize();
73 }
74 }
75 return QFont(fontName, fontSize);
76 } else {
77 return boost::none;
78 }
79}
static const QString customSystemFontCfgName
Definition KisUiFont.cpp:30

References customFontSizeCfgName, customSystemFontCfgName, KisConfig::readEntry(), systemDefaultUiFont(), and useCustomSystemFontCfgName.

Variable Documentation

◆ customFontSizeCfgName

const QString KisUiFont::customFontSizeCfgName = QStringLiteral("custom_font_size")
static

Definition at line 31 of file KisUiFont.cpp.

◆ customSystemFontCfgName

const QString KisUiFont::customSystemFontCfgName = QStringLiteral("custom_system_font")
static

Definition at line 30 of file KisUiFont.cpp.

◆ useCustomSystemFontCfgName

const QString KisUiFont::useCustomSystemFontCfgName = QStringLiteral("use_custom_system_font")
static

Definition at line 29 of file KisUiFont.cpp.