diff options
author | Luke Dashjr <luke-jr+git@utopios.org> | 2021-12-02 01:45:08 +0000 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2023-07-21 17:45:36 +0000 |
commit | 49eb97eff96c2ec9e5a55d599f18b1866f83b115 (patch) | |
tree | 905f0f17665d9b027583972010d531469b08c691 /src/qt | |
parent | f2dfde80b85b202bece0b5b4c8f1c8777c1a660d (diff) | |
download | bitcoin-49eb97eff96c2ec9e5a55d599f18b1866f83b115.tar.xz |
GUI: Add possibility for an explicit QFont for FontForMoney in OptionsModel
Diffstat (limited to 'src/qt')
-rw-r--r-- | src/qt/optionsmodel.cpp | 32 | ||||
-rw-r--r-- | src/qt/optionsmodel.h | 11 |
2 files changed, 36 insertions, 7 deletions
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<FontChoiceAbstract>(m_font_money)) { + f = GUIUtil::fixedPitchFont(m_font_money != UseBestSystemFont); + f.setWeight(QFont::Bold); + } else { + f = std::get<QFont>(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 <qt/guiconstants.h> #include <QAbstractListModel> +#include <QFont> #include <assert.h> +#include <variant> struct bilingual_str; namespace interfaces { @@ -76,6 +78,13 @@ public: OptionIDRowCount, }; + enum class FontChoiceAbstract { + EmbeddedFont, + BestSystemFont, + }; + typedef std::variant<FontChoiceAbstract, QFont> 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; |