Skip to content

Commit bada5f3

Browse files
committed
GUI: Load custom FontForMoney from QSettings
1 parent a74661c commit bada5f3

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

src/qt/optionsmodel.cpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ const char *DEFAULT_GUI_PROXY_HOST = "127.0.0.1";
2929

3030
static const QString GetDefaultProxyAddress();
3131

32+
static const QLatin1String fontchoice_str_embedded{"embedded"};
33+
static const QLatin1String fontchoice_str_best_system{"best_system"};
34+
static const QString fontchoice_str_custom_prefix{QStringLiteral("custom, ")};
35+
36+
OptionsModel::FontChoice OptionsModel::FontChoiceFromString(const QString& s)
37+
{
38+
if (s == fontchoice_str_best_system) {
39+
return FontChoiceAbstract::BestSystemFont;
40+
} else if (s == fontchoice_str_embedded) {
41+
return FontChoiceAbstract::EmbeddedFont;
42+
} else if (s.startsWith(fontchoice_str_custom_prefix)) {
43+
QFont f;
44+
f.fromString(s.mid(fontchoice_str_custom_prefix.size()));
45+
return f;
46+
} else {
47+
return FontChoiceAbstract::EmbeddedFont; // default
48+
}
49+
}
50+
3251
OptionsModel::OptionsModel(QObject *parent, bool resetSettings) :
3352
QAbstractListModel(parent)
3453
{
@@ -184,13 +203,14 @@ void OptionsModel::Init(bool resetSettings)
184203

185204
language = settings.value("language").toString();
186205

187-
if (!settings.contains("UseEmbeddedMonospacedFont")) {
188-
settings.setValue("UseEmbeddedMonospacedFont", "true");
189-
}
190-
if (settings.value("UseEmbeddedMonospacedFont").toBool()) {
191-
m_font_money = FontChoiceAbstract::EmbeddedFont;
192-
} else {
193-
m_font_money = FontChoiceAbstract::BestSystemFont;
206+
if (settings.contains("FontForMoney")) {
207+
m_font_money = FontChoiceFromString(settings.value("FontForMoney").toString());
208+
} else if (settings.contains("UseEmbeddedMonospacedFont")) {
209+
if (settings.value("UseEmbeddedMonospacedFont").toBool()) {
210+
m_font_money = FontChoiceAbstract::EmbeddedFont;
211+
} else {
212+
m_font_money = FontChoiceAbstract::BestSystemFont;
213+
}
194214
}
195215
Q_EMIT fontForMoneyChanged(getFontForMoney());
196216
}
@@ -514,6 +534,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
514534
m_font_money = FontChoiceAbstract::BestSystemFont;
515535
}
516536
settings.setValue("UseEmbeddedMonospacedFont", use_embedded_monospaced_font);
537+
settings.remove("FontForMoney");
517538
Q_EMIT fontForMoneyChanged(getFontForMoney());
518539
break;
519540
}

src/qt/optionsmodel.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,14 @@ class OptionsModel : public QAbstractListModel
121121
QString language;
122122
int nDisplayUnit;
123123
QString strThirdPartyTxUrls;
124-
FontChoice m_font_money;
124+
FontChoice m_font_money{FontChoiceAbstract::EmbeddedFont};
125125
bool fCoinControlFeatures;
126126
bool m_sub_fee_from_amount;
127127
/* settings that were overridden by command-line */
128128
QString strOverriddenByCommandLine;
129129

130+
static FontChoice FontChoiceFromString(const QString&);
131+
130132
// Add option to list of GUI options overridden through command line/config file
131133
void addOverriddenOption(const std::string &option);
132134

0 commit comments

Comments
 (0)