Skip to content

Commit 49eb97e

Browse files
committed
GUI: Add possibility for an explicit QFont for FontForMoney in OptionsModel
1 parent f2dfde8 commit 49eb97e

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

src/qt/optionsmodel.cpp

+26-6
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,11 @@ bool OptionsModel::Init(bilingual_str& error)
218218
if (!settings.contains("UseEmbeddedMonospacedFont")) {
219219
settings.setValue("UseEmbeddedMonospacedFont", "true");
220220
}
221-
m_use_embedded_monospaced_font = settings.value("UseEmbeddedMonospacedFont").toBool();
221+
if (settings.value("UseEmbeddedMonospacedFont").toBool()) {
222+
m_font_money = FontChoiceAbstract::EmbeddedFont;
223+
} else {
224+
m_font_money = FontChoiceAbstract::BestSystemFont;
225+
}
222226
Q_EMIT fontForMoneyChanged(getFontForMoney());
223227

224228
m_mask_values = settings.value("mask_values", false).toBool();
@@ -428,7 +432,7 @@ QVariant OptionsModel::getOption(OptionID option, const std::string& suffix) con
428432
case Language:
429433
return QString::fromStdString(SettingToString(setting(), ""));
430434
case UseEmbeddedMonospacedFont:
431-
return m_use_embedded_monospaced_font;
435+
return (m_font_money != UseBestSystemFont);
432436
case CoinControlFeatures:
433437
return fCoinControlFeatures;
434438
case EnablePSBTControls:
@@ -456,8 +460,13 @@ QVariant OptionsModel::getOption(OptionID option, const std::string& suffix) con
456460

457461
QFont OptionsModel::getFontForMoney() const
458462
{
459-
QFont f = GUIUtil::fixedPitchFont(m_use_embedded_monospaced_font);
460-
f.setWeight(QFont::Bold);
463+
QFont f;
464+
if (std::holds_alternative<FontChoiceAbstract>(m_font_money)) {
465+
f = GUIUtil::fixedPitchFont(m_font_money != UseBestSystemFont);
466+
f.setWeight(QFont::Bold);
467+
} else {
468+
f = std::get<QFont>(m_font_money);
469+
}
461470
return f;
462471
}
463472

@@ -594,10 +603,21 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value, const std::
594603
}
595604
break;
596605
case UseEmbeddedMonospacedFont:
597-
m_use_embedded_monospaced_font = value.toBool();
598-
settings.setValue("UseEmbeddedMonospacedFont", m_use_embedded_monospaced_font);
606+
{
607+
const bool use_embedded_monospaced_font = value.toBool();
608+
if (use_embedded_monospaced_font) {
609+
if (m_font_money != UseBestSystemFont) {
610+
// Leave it as-is
611+
break;
612+
}
613+
m_font_money = FontChoiceAbstract::EmbeddedFont;
614+
} else {
615+
m_font_money = FontChoiceAbstract::BestSystemFont;
616+
}
617+
settings.setValue("UseEmbeddedMonospacedFont", use_embedded_monospaced_font);
599618
Q_EMIT fontForMoneyChanged(getFontForMoney());
600619
break;
620+
}
601621
case CoinControlFeatures:
602622
fCoinControlFeatures = value.toBool();
603623
settings.setValue("fCoinControlFeatures", fCoinControlFeatures);

src/qt/optionsmodel.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
#include <qt/guiconstants.h>
1111

1212
#include <QAbstractListModel>
13+
#include <QFont>
1314

1415
#include <assert.h>
16+
#include <variant>
1517

1618
struct bilingual_str;
1719
namespace interfaces {
@@ -76,6 +78,13 @@ class OptionsModel : public QAbstractListModel
7678
OptionIDRowCount,
7779
};
7880

81+
enum class FontChoiceAbstract {
82+
EmbeddedFont,
83+
BestSystemFont,
84+
};
85+
typedef std::variant<FontChoiceAbstract, QFont> FontChoice;
86+
static inline const FontChoice UseBestSystemFont{FontChoiceAbstract::BestSystemFont};
87+
7988
bool Init(bilingual_str& error);
8089
void Reset();
8190

@@ -120,7 +129,7 @@ class OptionsModel : public QAbstractListModel
120129
QString language;
121130
BitcoinUnit m_display_bitcoin_unit;
122131
QString strThirdPartyTxUrls;
123-
bool m_use_embedded_monospaced_font;
132+
FontChoice m_font_money;
124133
bool fCoinControlFeatures;
125134
bool m_sub_fee_from_amount;
126135
bool m_enable_psbt_controls;

0 commit comments

Comments
 (0)