1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
// SPDX-License-Identifier: GPL-2.0
#include "qPref.h"
#include "qPref_private.h"
#include "core/subsurface-string.h"
#include <QApplication>
#include <QFont>
qPrefDisplay::qPrefDisplay(QObject *parent) : QObject(parent)
{
}
qPrefDisplay *qPrefDisplay::instance()
{
static qPrefDisplay *self = new qPrefDisplay;
return self;
}
void qPrefDisplay::loadSync(bool doSync)
{
disk_divelist_font(doSync);
disk_font_size(doSync);
disk_display_invalid_dives(doSync);
disk_show_developer(doSync);
disk_theme(doSync);
}
GET_PREFERENCE_TXT(Display, divelist_font);
void qPrefDisplay::set_divelist_font(const QString& value)
{
QString newValue = value;
if (value.contains(","))
newValue = value.left(value.indexOf(","));
if (newValue != prefs.divelist_font &&
!subsurface_ignore_font(qPrintable(newValue))) {
COPY_TXT(divelist_font, value);
qApp->setFont(QFont(newValue));
disk_divelist_font(true);
emit divelist_font_changed(value);
}
}
void qPrefDisplay::disk_divelist_font(bool doSync)
{
LOADSYNC_TXT("/divelist_font", divelist_font);
if (!doSync)
setCorrectFont();
}
GET_PREFERENCE_DOUBLE(Display, font_size);
void qPrefDisplay::set_font_size(double value)
{
if (value != prefs.font_size) {
prefs.font_size = value;
QFont defaultFont = qApp->font();
defaultFont.setPointSizeF(prefs.font_size);
qApp->setFont(defaultFont);
disk_font_size(true);
emit font_size_changed(value);
}
}
void qPrefDisplay::disk_font_size(bool doSync)
{
LOADSYNC_DOUBLE("/font_size", font_size);
if (!doSync)
setCorrectFont();
}
HANDLE_PREFERENCE_BOOL(Display, "/displayinvalid", display_invalid_dives);
HANDLE_PREFERENCE_BOOL(Display, "/show_developer", show_developer);
HANDLE_PREFERENCE_TXT(Display, "/theme", theme);
void qPrefDisplay::setCorrectFont()
{
// get the font from the settings or our defaults
// respect the system default font size if none is explicitly set
QFont defaultFont(prefs.divelist_font);
if (IS_FP_SAME(system_divelist_default_font_size, -1.0)) {
prefs.font_size = qApp->font().pointSizeF();
system_divelist_default_font_size = prefs.font_size; // this way we don't save it on exit
}
// painful effort to ignore previous default fonts on Windows - ridiculous
QString fontName = defaultFont.toString();
if (fontName.contains(","))
fontName = fontName.left(fontName.indexOf(","));
if (subsurface_ignore_font(qPrintable(fontName)))
defaultFont = QFont(prefs.divelist_font);
else
COPY_TXT(divelist_font, fontName);
defaultFont.setPointSizeF(prefs.font_size);
qApp->setFont(defaultFont);
}
|