diff options
author | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2024-02-07 19:24:50 +0000 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2024-02-07 19:28:37 +0000 |
commit | 60ac503800bb38db97f1cee786d1be38996e614f (patch) | |
tree | e6cd328850b05c7042965b9ef8e9b1f2585560ef /src/qt/optionsmodel.cpp | |
parent | 7b397025133cbc4c37be6cabc9e55b4c9a38f8ee (diff) | |
parent | a17fd33edd1374145fd6986fbe352295355fde4f (diff) |
Merge bitcoin-core/gui#497: Enable users to configure their monospace font specifically
a17fd33edd1374145fd6986fbe352295355fde4f GUI: OptionsDialog: Replace verbose two-option font selector with simple combobox with Custom... choice (Luke Dashjr)
98e9ac51992b2332587d87f25351988bf4863238 GUI: Use FontChoice type in OptionsModel settings abstraction (Luke Dashjr)
3a6757eed9a24e91e7d800d8026cc3a5c4840141 GUI: Load custom FontForMoney from QSettings (Luke Dashjr)
49eb97eff96c2ec9e5a55d599f18b1866f83b115 GUI: Add possibility for an explicit QFont for FontForMoney in OptionsModel (Luke Dashjr)
f2dfde80b85b202bece0b5b4c8f1c8777c1a660d GUI: Move "embedded font or not" decision into new OptionsModel::getFontForMoney method (Luke Dashjr)
Pull request description:
This replaces the overly-verbose radio-button font setting (which only allows embedded or autodetected from system) with a simple combobox providing both existing options as well as a custom option to allow the user to select any font of their choice/style.
ACKs for top commit:
pablomartin4btc:
tested ACK a17fd33edd1374145fd6986fbe352295355fde4f
hebasto:
ACK a17fd33edd1374145fd6986fbe352295355fde4f, I have reviewed the code and tested it on Ubuntu 22.04. This is a UX improvement. https://github.com/bitcoin-core/gui/pull/497#issuecomment-1341222673 might be addressed in a follow-up.
Tree-SHA512: 2f0a8bc1242a374c4b7dc6e34014400428b6d36063fa0b01c9f62a8bd6078adfbbca93d95c87e4ccb580d982fe10173e1d9a28bcec586591dd3f966c7b90fc5d
Diffstat (limited to 'src/qt/optionsmodel.cpp')
-rw-r--r-- | src/qt/optionsmodel.cpp | 77 |
1 files changed, 67 insertions, 10 deletions
diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 43564dad16..d816a72ca3 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -119,6 +119,37 @@ struct ProxySetting { static ProxySetting ParseProxyString(const std::string& proxy); static std::string ProxyString(bool is_set, QString ip, QString port); +static const QLatin1String fontchoice_str_embedded{"embedded"}; +static const QLatin1String fontchoice_str_best_system{"best_system"}; +static const QString fontchoice_str_custom_prefix{QStringLiteral("custom, ")}; + +QString OptionsModel::FontChoiceToString(const OptionsModel::FontChoice& f) +{ + if (std::holds_alternative<FontChoiceAbstract>(f)) { + if (f == UseBestSystemFont) { + return fontchoice_str_best_system; + } else { + return fontchoice_str_embedded; + } + } + return fontchoice_str_custom_prefix + std::get<QFont>(f).toString(); +} + +OptionsModel::FontChoice OptionsModel::FontChoiceFromString(const QString& s) +{ + if (s == fontchoice_str_best_system) { + return FontChoiceAbstract::BestSystemFont; + } else if (s == fontchoice_str_embedded) { + return FontChoiceAbstract::EmbeddedFont; + } else if (s.startsWith(fontchoice_str_custom_prefix)) { + QFont f; + f.fromString(s.mid(fontchoice_str_custom_prefix.size())); + return f; + } else { + return FontChoiceAbstract::EmbeddedFont; // default + } +} + OptionsModel::OptionsModel(interfaces::Node& node, QObject *parent) : QAbstractListModel(parent), m_node{node} { @@ -216,11 +247,16 @@ bool OptionsModel::Init(bilingual_str& error) #endif // Display - if (!settings.contains("UseEmbeddedMonospacedFont")) { - settings.setValue("UseEmbeddedMonospacedFont", "true"); + if (settings.contains("FontForMoney")) { + m_font_money = FontChoiceFromString(settings.value("FontForMoney").toString()); + } else if (settings.contains("UseEmbeddedMonospacedFont")) { + if (settings.value("UseEmbeddedMonospacedFont").toBool()) { + m_font_money = FontChoiceAbstract::EmbeddedFont; + } else { + m_font_money = FontChoiceAbstract::BestSystemFont; + } } - m_use_embedded_monospaced_font = settings.value("UseEmbeddedMonospacedFont").toBool(); - Q_EMIT useEmbeddedMonospacedFontChanged(m_use_embedded_monospaced_font); + Q_EMIT fontForMoneyChanged(getFontForMoney()); m_mask_values = settings.value("mask_values", false).toBool(); @@ -428,8 +464,8 @@ QVariant OptionsModel::getOption(OptionID option, const std::string& suffix) con return strThirdPartyTxUrls; case Language: return QString::fromStdString(SettingToString(setting(), "")); - case UseEmbeddedMonospacedFont: - return m_use_embedded_monospaced_font; + case FontForMoney: + return QVariant::fromValue(m_font_money); case CoinControlFeatures: return fCoinControlFeatures; case EnablePSBTControls: @@ -455,6 +491,23 @@ QVariant OptionsModel::getOption(OptionID option, const std::string& suffix) con } } +QFont OptionsModel::getFontForChoice(const FontChoice& fc) +{ + QFont f; + if (std::holds_alternative<FontChoiceAbstract>(fc)) { + f = GUIUtil::fixedPitchFont(fc != UseBestSystemFont); + f.setWeight(QFont::Bold); + } else { + f = std::get<QFont>(fc); + } + return f; +} + +QFont OptionsModel::getFontForMoney() const +{ + return getFontForChoice(m_font_money); +} + bool OptionsModel::setOption(OptionID option, const QVariant& value, const std::string& suffix) { auto changed = [&] { return value.isValid() && value != getOption(option, suffix); }; @@ -587,11 +640,15 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value, const std:: setRestartRequired(true); } break; - case UseEmbeddedMonospacedFont: - m_use_embedded_monospaced_font = value.toBool(); - settings.setValue("UseEmbeddedMonospacedFont", m_use_embedded_monospaced_font); - Q_EMIT useEmbeddedMonospacedFontChanged(m_use_embedded_monospaced_font); + case FontForMoney: + { + const auto& new_font = value.value<FontChoice>(); + if (m_font_money == new_font) break; + settings.setValue("FontForMoney", FontChoiceToString(new_font)); + m_font_money = new_font; + Q_EMIT fontForMoneyChanged(getFontForMoney()); break; + } case CoinControlFeatures: fCoinControlFeatures = value.toBool(); settings.setValue("fCoinControlFeatures", fCoinControlFeatures); |