From 49eb97eff96c2ec9e5a55d599f18b1866f83b115 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 2 Dec 2021 01:45:08 +0000 Subject: GUI: Add possibility for an explicit QFont for FontForMoney in OptionsModel --- src/qt/optionsmodel.cpp | 32 ++++++++++++++++++++++++++------ src/qt/optionsmodel.h | 11 ++++++++++- 2 files changed, 36 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 8bf1dfd9be..a8f20fec23 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -218,7 +218,11 @@ bool OptionsModel::Init(bilingual_str& error) if (!settings.contains("UseEmbeddedMonospacedFont")) { settings.setValue("UseEmbeddedMonospacedFont", "true"); } - m_use_embedded_monospaced_font = settings.value("UseEmbeddedMonospacedFont").toBool(); + if (settings.value("UseEmbeddedMonospacedFont").toBool()) { + m_font_money = FontChoiceAbstract::EmbeddedFont; + } else { + m_font_money = FontChoiceAbstract::BestSystemFont; + } Q_EMIT fontForMoneyChanged(getFontForMoney()); m_mask_values = settings.value("mask_values", false).toBool(); @@ -428,7 +432,7 @@ QVariant OptionsModel::getOption(OptionID option, const std::string& suffix) con case Language: return QString::fromStdString(SettingToString(setting(), "")); case UseEmbeddedMonospacedFont: - return m_use_embedded_monospaced_font; + return (m_font_money != UseBestSystemFont); case CoinControlFeatures: return fCoinControlFeatures; case EnablePSBTControls: @@ -456,8 +460,13 @@ QVariant OptionsModel::getOption(OptionID option, const std::string& suffix) con QFont OptionsModel::getFontForMoney() const { - QFont f = GUIUtil::fixedPitchFont(m_use_embedded_monospaced_font); - f.setWeight(QFont::Bold); + QFont f; + if (std::holds_alternative(m_font_money)) { + f = GUIUtil::fixedPitchFont(m_font_money != UseBestSystemFont); + f.setWeight(QFont::Bold); + } else { + f = std::get(m_font_money); + } return f; } @@ -594,10 +603,21 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value, const std:: } break; case UseEmbeddedMonospacedFont: - m_use_embedded_monospaced_font = value.toBool(); - settings.setValue("UseEmbeddedMonospacedFont", m_use_embedded_monospaced_font); + { + const bool use_embedded_monospaced_font = value.toBool(); + if (use_embedded_monospaced_font) { + if (m_font_money != UseBestSystemFont) { + // Leave it as-is + break; + } + m_font_money = FontChoiceAbstract::EmbeddedFont; + } else { + m_font_money = FontChoiceAbstract::BestSystemFont; + } + settings.setValue("UseEmbeddedMonospacedFont", use_embedded_monospaced_font); Q_EMIT fontForMoneyChanged(getFontForMoney()); break; + } case CoinControlFeatures: fCoinControlFeatures = value.toBool(); settings.setValue("fCoinControlFeatures", fCoinControlFeatures); diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 63abfb11fe..f31907178b 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -10,8 +10,10 @@ #include #include +#include #include +#include struct bilingual_str; namespace interfaces { @@ -76,6 +78,13 @@ public: OptionIDRowCount, }; + enum class FontChoiceAbstract { + EmbeddedFont, + BestSystemFont, + }; + typedef std::variant FontChoice; + static inline const FontChoice UseBestSystemFont{FontChoiceAbstract::BestSystemFont}; + bool Init(bilingual_str& error); void Reset(); @@ -120,7 +129,7 @@ private: QString language; BitcoinUnit m_display_bitcoin_unit; QString strThirdPartyTxUrls; - bool m_use_embedded_monospaced_font; + FontChoice m_font_money; bool fCoinControlFeatures; bool m_sub_fee_from_amount; bool m_enable_psbt_controls; -- cgit v1.2.3