Skip to content

Commit 3a6757e

Browse files
committed
GUI: Load custom FontForMoney from QSettings
1 parent 49eb97e commit 3a6757e

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
@@ -118,6 +118,25 @@ struct ProxySetting {
118118
static ProxySetting ParseProxyString(const std::string& proxy);
119119
static std::string ProxyString(bool is_set, QString ip, QString port);
120120

121+
static const QLatin1String fontchoice_str_embedded{"embedded"};
122+
static const QLatin1String fontchoice_str_best_system{"best_system"};
123+
static const QString fontchoice_str_custom_prefix{QStringLiteral("custom, ")};
124+
125+
OptionsModel::FontChoice OptionsModel::FontChoiceFromString(const QString& s)
126+
{
127+
if (s == fontchoice_str_best_system) {
128+
return FontChoiceAbstract::BestSystemFont;
129+
} else if (s == fontchoice_str_embedded) {
130+
return FontChoiceAbstract::EmbeddedFont;
131+
} else if (s.startsWith(fontchoice_str_custom_prefix)) {
132+
QFont f;
133+
f.fromString(s.mid(fontchoice_str_custom_prefix.size()));
134+
return f;
135+
} else {
136+
return FontChoiceAbstract::EmbeddedFont; // default
137+
}
138+
}
139+
121140
OptionsModel::OptionsModel(interfaces::Node& node, QObject *parent) :
122141
QAbstractListModel(parent), m_node{node}
123142
{
@@ -215,13 +234,14 @@ bool OptionsModel::Init(bilingual_str& error)
215234
#endif
216235

217236
// Display
218-
if (!settings.contains("UseEmbeddedMonospacedFont")) {
219-
settings.setValue("UseEmbeddedMonospacedFont", "true");
220-
}
221-
if (settings.value("UseEmbeddedMonospacedFont").toBool()) {
222-
m_font_money = FontChoiceAbstract::EmbeddedFont;
223-
} else {
224-
m_font_money = FontChoiceAbstract::BestSystemFont;
237+
if (settings.contains("FontForMoney")) {
238+
m_font_money = FontChoiceFromString(settings.value("FontForMoney").toString());
239+
} else if (settings.contains("UseEmbeddedMonospacedFont")) {
240+
if (settings.value("UseEmbeddedMonospacedFont").toBool()) {
241+
m_font_money = FontChoiceAbstract::EmbeddedFont;
242+
} else {
243+
m_font_money = FontChoiceAbstract::BestSystemFont;
244+
}
225245
}
226246
Q_EMIT fontForMoneyChanged(getFontForMoney());
227247

@@ -615,6 +635,7 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value, const std::
615635
m_font_money = FontChoiceAbstract::BestSystemFont;
616636
}
617637
settings.setValue("UseEmbeddedMonospacedFont", use_embedded_monospaced_font);
638+
settings.remove("FontForMoney");
618639
Q_EMIT fontForMoneyChanged(getFontForMoney());
619640
break;
620641
}

src/qt/optionsmodel.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class OptionsModel : public QAbstractListModel
129129
QString language;
130130
BitcoinUnit m_display_bitcoin_unit;
131131
QString strThirdPartyTxUrls;
132-
FontChoice m_font_money;
132+
FontChoice m_font_money{FontChoiceAbstract::EmbeddedFont};
133133
bool fCoinControlFeatures;
134134
bool m_sub_fee_from_amount;
135135
bool m_enable_psbt_controls;
@@ -138,6 +138,8 @@ class OptionsModel : public QAbstractListModel
138138
/* settings that were overridden by command-line */
139139
QString strOverriddenByCommandLine;
140140

141+
static FontChoice FontChoiceFromString(const QString&);
142+
141143
// Add option to list of GUI options overridden through command line/config file
142144
void addOverriddenOption(const std::string &option);
143145

0 commit comments

Comments
 (0)