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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
// SPDX-License-Identifier: GPL-2.0
#include "core/subsurface-string.h"
#include "qPrefDisplay.h"
#include "qPrefPrivate.h"
#include <QApplication>
#include <QFont>
static const QString group = QStringLiteral("Display");
QPointF qPrefDisplay::st_tooltip_position;
static const QPointF st_tooltip_position_default = QPointF(0,0);
QString qPrefDisplay::st_lastDir;
static const QString st_lastDir_default = "";
QString qPrefDisplay::st_theme;
static const QString st_theme_default = "Blue";
QString qPrefDisplay::st_UserSurvey;
static const QString st_UserSurvey_default = "";
QByteArray qPrefDisplay::st_mainSplitter;
static const QByteArray st_mainSplitter_default = "";
QByteArray qPrefDisplay::st_topSplitter;
static const QByteArray st_topSplitter_default = "";
QByteArray qPrefDisplay::st_bottomSplitter;
static const QByteArray st_bottomSplitter_default = "";
bool qPrefDisplay::st_maximized;
static bool st_maximized_default = false;
QByteArray qPrefDisplay::st_geometry;
static const QByteArray st_geometry_default = 0;
QByteArray qPrefDisplay::st_windowState;
static const QByteArray st_windowState_default = 0;
int qPrefDisplay::st_lastState;
static int st_lastState_default = false;
qPrefDisplay::qPrefDisplay(QObject *parent) : QObject(parent)
{
}
qPrefDisplay *qPrefDisplay::instance()
{
static qPrefDisplay *self = new qPrefDisplay;
return self;
}
void qPrefDisplay::loadSync(bool doSync)
{
disk_animation_speed(doSync);
disk_divelist_font(doSync);
disk_font_size(doSync);
disk_display_invalid_dives(doSync);
disk_show_developer(doSync);
if (!doSync) {
load_tooltip_position();
load_theme();
load_UserSurvey();
}
}
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))) {
qPrefPrivate::copy_txt(&prefs.divelist_font, value);
disk_divelist_font(true);
qApp->setFont(QFont(newValue));
emit instance()->divelist_font_changed(value);
}
}
void qPrefDisplay::disk_divelist_font(bool doSync)
{
if (doSync)
qPrefPrivate::propSetValue(group + "/divelist_font", prefs.divelist_font);
else
setCorrectFont();
}
void qPrefDisplay::set_font_size(double value)
{
if (value != prefs.font_size) {
prefs.font_size = value;
disk_font_size(true);
QFont defaultFont = qApp->font();
defaultFont.setPointSizeF(prefs.font_size);
qApp->setFont(defaultFont);
emit instance()->font_size_changed(value);
}
}
void qPrefDisplay::disk_font_size(bool doSync)
{
if (doSync)
qPrefPrivate::propSetValue(group + "/font_size", prefs.font_size);
else
setCorrectFont();
}
//JAN static const QString group = QStringLiteral("Animations");
HANDLE_PREFERENCE_INT(Display, "/animation_speed", animation_speed);
HANDLE_PREFERENCE_BOOL(Display, "/displayinvalid", display_invalid_dives);
HANDLE_PREFERENCE_BOOL(Display, "/show_developer", show_developer);
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 = qPrefPrivate::propValue(group + "/divelist_font", prefs.divelist_font).value<QFont>();
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
}
prefs.font_size = qPrefPrivate::propValue(group + "/font_size", prefs.font_size).toFloat();
// 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 {
free((void *)prefs.divelist_font);
prefs.divelist_font = copy_qstring(fontName);
}
defaultFont.setPointSizeF(prefs.font_size);
qApp->setFont(defaultFont);
prefs.display_invalid_dives = qPrefPrivate::propValue(group + "/displayinvalid", default_prefs.display_invalid_dives).toBool();
}
HANDLE_PROP_QSTRING(Display, "FileDialog/LastDir", lastDir);
HANDLE_PROP_QSTRING(Display, "Theme/currentTheme", theme);
HANDLE_PROP_QPOINTF(Display, "ProfileMap/tooltip_position", tooltip_position);
HANDLE_PROP_QSTRING(Display, "UserSurvey/SurveyDone", UserSurvey);
HANDLE_PROP_QBYTEARRAY(Display, "MainWindow/mainSplitter", mainSplitter);
HANDLE_PROP_QBYTEARRAY(Display, "MainWindow/topSplitter", topSplitter);
HANDLE_PROP_QBYTEARRAY(Display, "MainWindow/bottomSplitter", bottomSplitter);
HANDLE_PROP_BOOL(Display, "MainWindow/maximized", maximized);
HANDLE_PROP_QBYTEARRAY(Display, "MainWindow/geometry", geometry);
HANDLE_PROP_QBYTEARRAY(Display, "MainWindow/windowState", windowState);
HANDLE_PROP_INT(Display, "MainWindow/lastState", lastState);
|