From f2dfde80b85b202bece0b5b4c8f1c8777c1a660d Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 2 Dec 2021 01:10:05 +0000 Subject: [PATCH 1/5] GUI: Move "embedded font or not" decision into new OptionsModel::getFontForMoney method --- src/qt/optionsmodel.cpp | 11 +++++++++-- src/qt/optionsmodel.h | 4 ++-- src/qt/overviewpage.cpp | 8 +++----- src/qt/overviewpage.h | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index bee8fafddc290..8bf1dfd9bef27 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -219,7 +219,7 @@ bool OptionsModel::Init(bilingual_str& error) settings.setValue("UseEmbeddedMonospacedFont", "true"); } 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(); @@ -454,6 +454,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); + return f; +} + bool OptionsModel::setOption(OptionID option, const QVariant& value, const std::string& suffix) { auto changed = [&] { return value.isValid() && value != getOption(option, suffix); }; @@ -589,7 +596,7 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value, const std:: 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); + Q_EMIT fontForMoneyChanged(getFontForMoney()); break; case CoinControlFeatures: fCoinControlFeatures = value.toBool(); diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index f28a1087ba50e..63abfb11fe063 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -93,7 +93,7 @@ class OptionsModel : public QAbstractListModel bool getMinimizeOnClose() const { return fMinimizeOnClose; } BitcoinUnit getDisplayUnit() const { return m_display_bitcoin_unit; } QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; } - bool getUseEmbeddedMonospacedFont() const { return m_use_embedded_monospaced_font; } + QFont getFontForMoney() const; bool getCoinControlFeatures() const { return fCoinControlFeatures; } bool getSubFeeFromAmount() const { return m_sub_fee_from_amount; } bool getEnablePSBTControls() const { return m_enable_psbt_controls; } @@ -139,7 +139,7 @@ class OptionsModel : public QAbstractListModel void displayUnitChanged(BitcoinUnit unit); void coinControlFeaturesChanged(bool); void showTrayIconChanged(bool); - void useEmbeddedMonospacedFontChanged(bool); + void fontForMoneyChanged(const QFont&); }; #endif // BITCOIN_QT_OPTIONSMODEL_H diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 0f00d167f76ae..7d584920822c8 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -250,8 +250,8 @@ void OverviewPage::setClientModel(ClientModel *model) connect(model, &ClientModel::alertsChanged, this, &OverviewPage::updateAlerts); updateAlerts(model->getStatusBarWarnings()); - connect(model->getOptionsModel(), &OptionsModel::useEmbeddedMonospacedFontChanged, this, &OverviewPage::setMonospacedFont); - setMonospacedFont(model->getOptionsModel()->getUseEmbeddedMonospacedFont()); + connect(model->getOptionsModel(), &OptionsModel::fontForMoneyChanged, this, &OverviewPage::setMonospacedFont); + setMonospacedFont(clientModel->getOptionsModel()->getFontForMoney()); } } @@ -340,10 +340,8 @@ void OverviewPage::showOutOfSyncWarning(bool fShow) ui->labelTransactionsStatus->setVisible(fShow); } -void OverviewPage::setMonospacedFont(bool use_embedded_font) +void OverviewPage::setMonospacedFont(const QFont& f) { - QFont f = GUIUtil::fixedPitchFont(use_embedded_font); - f.setWeight(QFont::Bold); ui->labelBalance->setFont(f); ui->labelUnconfirmed->setFont(f); ui->labelImmature->setFont(f); diff --git a/src/qt/overviewpage.h b/src/qt/overviewpage.h index 5c487ee11621f..fc7a99f319aa9 100644 --- a/src/qt/overviewpage.h +++ b/src/qt/overviewpage.h @@ -65,7 +65,7 @@ private Q_SLOTS: void handleTransactionClicked(const QModelIndex &index); void updateAlerts(const QString &warnings); void updateWatchOnlyLabels(bool showWatchOnly); - void setMonospacedFont(bool use_embedded_font); + void setMonospacedFont(const QFont&); }; #endif // BITCOIN_QT_OVERVIEWPAGE_H From 49eb97eff96c2ec9e5a55d599f18b1866f83b115 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 2 Dec 2021 01:45:08 +0000 Subject: [PATCH 2/5] 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(-) diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index 8bf1dfd9bef27..a8f20fec230cd 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 63abfb11fe063..f31907178b29d 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 @@ class OptionsModel : public QAbstractListModel 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 @@ class OptionsModel : public QAbstractListModel 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; From 3a6757eed9a24e91e7d800d8026cc3a5c4840141 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 2 Dec 2021 02:25:30 +0000 Subject: [PATCH 3/5] GUI: Load custom FontForMoney from QSettings --- src/qt/optionsmodel.cpp | 35 ++++++++++++++++++++++++++++------- src/qt/optionsmodel.h | 4 +++- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index a8f20fec230cd..a7aea3185885a 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -118,6 +118,25 @@ 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, ")}; + +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} { @@ -215,13 +234,14 @@ bool OptionsModel::Init(bilingual_str& error) #endif // Display - if (!settings.contains("UseEmbeddedMonospacedFont")) { - settings.setValue("UseEmbeddedMonospacedFont", "true"); - } - if (settings.value("UseEmbeddedMonospacedFont").toBool()) { - m_font_money = FontChoiceAbstract::EmbeddedFont; - } else { - m_font_money = FontChoiceAbstract::BestSystemFont; + 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; + } } Q_EMIT fontForMoneyChanged(getFontForMoney()); @@ -615,6 +635,7 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value, const std:: m_font_money = FontChoiceAbstract::BestSystemFont; } settings.setValue("UseEmbeddedMonospacedFont", use_embedded_monospaced_font); + settings.remove("FontForMoney"); Q_EMIT fontForMoneyChanged(getFontForMoney()); break; } diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index f31907178b29d..79928d2fa91d0 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -129,7 +129,7 @@ class OptionsModel : public QAbstractListModel QString language; BitcoinUnit m_display_bitcoin_unit; QString strThirdPartyTxUrls; - FontChoice m_font_money; + FontChoice m_font_money{FontChoiceAbstract::EmbeddedFont}; bool fCoinControlFeatures; bool m_sub_fee_from_amount; bool m_enable_psbt_controls; @@ -138,6 +138,8 @@ class OptionsModel : public QAbstractListModel /* settings that were overridden by command-line */ QString strOverriddenByCommandLine; + static FontChoice FontChoiceFromString(const QString&); + // Add option to list of GUI options overridden through command line/config file void addOverriddenOption(const std::string &option); From 98e9ac51992b2332587d87f25351988bf4863238 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 2 Dec 2021 16:59:46 +0000 Subject: [PATCH 4/5] GUI: Use FontChoice type in OptionsModel settings abstraction --- src/qt/optionsdialog.cpp | 16 +++++++++++++++- src/qt/optionsmodel.cpp | 34 +++++++++++++++++++--------------- src/qt/optionsmodel.h | 5 ++++- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 6dec4b2e42e54..fcc9aced09a77 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -198,6 +198,15 @@ void OptionsDialog::setModel(OptionsModel *_model) setMapper(); mapper->toFirst(); + const auto& font_for_money = _model->data(_model->index(OptionsModel::FontForMoney, 0), Qt::EditRole).value(); + if (std::holds_alternative(font_for_money)) { + ui->embeddedFont_radioButton->setChecked(font_for_money != OptionsModel::UseBestSystemFont); + ui->systemFont_radioButton->setChecked(font_for_money == OptionsModel::UseBestSystemFont); + } else { + ui->embeddedFont_radioButton->setChecked(false); + ui->systemFont_radioButton->setChecked(false); + } + updateDefaultProxyNets(); } @@ -275,7 +284,6 @@ void OptionsDialog::setMapper() mapper->addMapping(ui->lang, OptionsModel::Language); mapper->addMapping(ui->unit, OptionsModel::DisplayUnit); mapper->addMapping(ui->thirdPartyTxUrls, OptionsModel::ThirdPartyTxUrls); - mapper->addMapping(ui->embeddedFont_radioButton, OptionsModel::UseEmbeddedMonospacedFont); } void OptionsDialog::setOkButtonState(bool fState) @@ -337,6 +345,12 @@ void OptionsDialog::on_openBitcoinConfButton_clicked() void OptionsDialog::on_okButton_clicked() { + if (ui->embeddedFont_radioButton->isChecked()) { + model->setData(model->index(OptionsModel::FontForMoney, 0), QVariant::fromValue(OptionsModel::FontChoice{OptionsModel::FontChoiceAbstract::EmbeddedFont})); + } else if (ui->systemFont_radioButton->isChecked()) { + model->setData(model->index(OptionsModel::FontForMoney, 0), QVariant::fromValue(OptionsModel::FontChoice{OptionsModel::FontChoiceAbstract::BestSystemFont})); + } + mapper->submit(); accept(); updateDefaultProxyNets(); diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index a7aea3185885a..ef32a11523023 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -122,6 +122,18 @@ 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(f)) { + if (f == UseBestSystemFont) { + return fontchoice_str_best_system; + } else { + return fontchoice_str_embedded; + } + } + return fontchoice_str_custom_prefix + std::get(f).toString(); +} + OptionsModel::FontChoice OptionsModel::FontChoiceFromString(const QString& s) { if (s == fontchoice_str_best_system) { @@ -451,8 +463,8 @@ QVariant OptionsModel::getOption(OptionID option, const std::string& suffix) con return strThirdPartyTxUrls; case Language: return QString::fromStdString(SettingToString(setting(), "")); - case UseEmbeddedMonospacedFont: - return (m_font_money != UseBestSystemFont); + case FontForMoney: + return QVariant::fromValue(m_font_money); case CoinControlFeatures: return fCoinControlFeatures; case EnablePSBTControls: @@ -622,20 +634,12 @@ bool OptionsModel::setOption(OptionID option, const QVariant& value, const std:: setRestartRequired(true); } break; - case UseEmbeddedMonospacedFont: + case FontForMoney: { - 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); - settings.remove("FontForMoney"); + const auto& new_font = value.value(); + if (m_font_money == new_font) break; + settings.setValue("FontForMoney", FontChoiceToString(new_font)); + m_font_money = new_font; Q_EMIT fontForMoneyChanged(getFontForMoney()); break; } diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 79928d2fa91d0..1984002028967 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -62,7 +62,7 @@ class OptionsModel : public QAbstractListModel DisplayUnit, // BitcoinUnit ThirdPartyTxUrls, // QString Language, // QString - UseEmbeddedMonospacedFont, // bool + FontForMoney, // FontChoice CoinControlFeatures, // bool SubFeeFromAmount, // bool ThreadsScriptVerif, // int @@ -138,6 +138,7 @@ class OptionsModel : public QAbstractListModel /* settings that were overridden by command-line */ QString strOverriddenByCommandLine; + static QString FontChoiceToString(const OptionsModel::FontChoice&); static FontChoice FontChoiceFromString(const QString&); // Add option to list of GUI options overridden through command line/config file @@ -153,4 +154,6 @@ class OptionsModel : public QAbstractListModel void fontForMoneyChanged(const QFont&); }; +Q_DECLARE_METATYPE(OptionsModel::FontChoice) + #endif // BITCOIN_QT_OPTIONSMODEL_H From a17fd33edd1374145fd6986fbe352295355fde4f Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 2 Dec 2021 23:40:15 +0000 Subject: [PATCH 5/5] GUI: OptionsDialog: Replace verbose two-option font selector with simple combobox with Custom... choice --- src/qt/forms/optionsdialog.ui | 121 +++++++--------------------------- src/qt/optionsdialog.cpp | 84 ++++++++++++++++------- src/qt/optionsmodel.cpp | 13 ++-- src/qt/optionsmodel.h | 1 + 4 files changed, 92 insertions(+), 127 deletions(-) diff --git a/src/qt/forms/optionsdialog.ui b/src/qt/forms/optionsdialog.ui index 6be47e94feb88..99fb238772342 100644 --- a/src/qt/forms/optionsdialog.ui +++ b/src/qt/forms/optionsdialog.ui @@ -772,104 +772,29 @@ - - - Monospaced font in the Overview tab: - - - - - - - - embedded "%1" - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - 111.11111111 BTC - - - - - - - 909.09090909 BTC - - - - - - - - - - - Qt::Horizontal - - - - - - - - - closest matching "%1" - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - 111.11111111 BTC - - - - - - - 909.09090909 BTC - - - - - - - - - + + + + + Font in the Overview tab: + + + moneyFont + + + + + + + + + + 111.11111111 BTC +909.09090909 BTC + + + + diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index fcc9aced09a77..b10c07408310e 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -23,14 +23,70 @@ #include +#include #include #include +#include #include #include #include #include #include +int setFontChoice(QComboBox* cb, const OptionsModel::FontChoice& fc) +{ + int i; + for (i = cb->count(); --i >= 0; ) { + QVariant item_data = cb->itemData(i); + if (!item_data.canConvert()) continue; + if (item_data.value() == fc) { + break; + } + } + if (i == -1) { + // New item needed + QFont chosen_font = OptionsModel::getFontForChoice(fc); + QSignalBlocker block_currentindexchanged_signal(cb); // avoid triggering QFontDialog + cb->insertItem(0, QFontInfo(chosen_font).family(), QVariant::fromValue(fc)); + i = 0; + } + + cb->setCurrentIndex(i); + return i; +} + +void setupFontOptions(QComboBox* cb, QLabel* preview) +{ + QFont embedded_font{GUIUtil::fixedPitchFont(true)}; + QFont system_font{GUIUtil::fixedPitchFont(false)}; + cb->addItem(QObject::tr("Embedded \"%1\"").arg(QFontInfo(embedded_font).family()), QVariant::fromValue(OptionsModel::FontChoice{OptionsModel::FontChoiceAbstract::EmbeddedFont})); + cb->addItem(QObject::tr("Default system font \"%1\"").arg(QFontInfo(system_font).family()), QVariant::fromValue(OptionsModel::FontChoice{OptionsModel::FontChoiceAbstract::BestSystemFont})); + cb->addItem(QObject::tr("Custom…")); + + const auto& on_font_choice_changed = [cb, preview](int index) { + static int previous_index = -1; + QVariant item_data = cb->itemData(index); + QFont f; + if (item_data.canConvert()) { + f = OptionsModel::getFontForChoice(item_data.value()); + } else { + bool ok; + f = QFontDialog::getFont(&ok, GUIUtil::fixedPitchFont(false), cb->parentWidget()); + if (!ok) { + cb->setCurrentIndex(previous_index); + return; + } + index = setFontChoice(cb, OptionsModel::FontChoice{f}); + } + if (preview) { + preview->setFont(f); + } + previous_index = index; + }; + QObject::connect(cb, QOverload::of(&QComboBox::currentIndexChanged), on_font_choice_changed); + on_font_choice_changed(cb->currentIndex()); +} + OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet) : QDialog(parent, GUIUtil::dialog_flags), ui(new Ui::OptionsDialog) @@ -148,19 +204,7 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet) ui->minimizeToTray->setEnabled(false); } - QFont embedded_font{GUIUtil::fixedPitchFont(true)}; - ui->embeddedFont_radioButton->setText(ui->embeddedFont_radioButton->text().arg(QFontInfo(embedded_font).family())); - embedded_font.setWeight(QFont::Bold); - ui->embeddedFont_label_1->setFont(embedded_font); - ui->embeddedFont_label_9->setFont(embedded_font); - - QFont system_font{GUIUtil::fixedPitchFont(false)}; - ui->systemFont_radioButton->setText(ui->systemFont_radioButton->text().arg(QFontInfo(system_font).family())); - system_font.setWeight(QFont::Bold); - ui->systemFont_label_1->setFont(system_font); - ui->systemFont_label_9->setFont(system_font); - // Checking the embeddedFont_radioButton automatically unchecks the systemFont_radioButton. - ui->systemFont_radioButton->setChecked(true); + setupFontOptions(ui->moneyFont, ui->moneyFont_preview); GUIUtil::handleCloseWindowShortcut(this); } @@ -199,13 +243,7 @@ void OptionsDialog::setModel(OptionsModel *_model) mapper->toFirst(); const auto& font_for_money = _model->data(_model->index(OptionsModel::FontForMoney, 0), Qt::EditRole).value(); - if (std::holds_alternative(font_for_money)) { - ui->embeddedFont_radioButton->setChecked(font_for_money != OptionsModel::UseBestSystemFont); - ui->systemFont_radioButton->setChecked(font_for_money == OptionsModel::UseBestSystemFont); - } else { - ui->embeddedFont_radioButton->setChecked(false); - ui->systemFont_radioButton->setChecked(false); - } + setFontChoice(ui->moneyFont, font_for_money); updateDefaultProxyNets(); } @@ -345,11 +383,7 @@ void OptionsDialog::on_openBitcoinConfButton_clicked() void OptionsDialog::on_okButton_clicked() { - if (ui->embeddedFont_radioButton->isChecked()) { - model->setData(model->index(OptionsModel::FontForMoney, 0), QVariant::fromValue(OptionsModel::FontChoice{OptionsModel::FontChoiceAbstract::EmbeddedFont})); - } else if (ui->systemFont_radioButton->isChecked()) { - model->setData(model->index(OptionsModel::FontForMoney, 0), QVariant::fromValue(OptionsModel::FontChoice{OptionsModel::FontChoiceAbstract::BestSystemFont})); - } + model->setData(model->index(OptionsModel::FontForMoney, 0), ui->moneyFont->itemData(ui->moneyFont->currentIndex())); mapper->submit(); accept(); diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index ef32a11523023..2937b800196ef 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -490,18 +490,23 @@ QVariant OptionsModel::getOption(OptionID option, const std::string& suffix) con } } -QFont OptionsModel::getFontForMoney() const +QFont OptionsModel::getFontForChoice(const FontChoice& fc) { QFont f; - if (std::holds_alternative(m_font_money)) { - f = GUIUtil::fixedPitchFont(m_font_money != UseBestSystemFont); + if (std::holds_alternative(fc)) { + f = GUIUtil::fixedPitchFont(fc != UseBestSystemFont); f.setWeight(QFont::Bold); } else { - f = std::get(m_font_money); + f = std::get(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); }; diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 1984002028967..b5ea6c783e4d1 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -84,6 +84,7 @@ class OptionsModel : public QAbstractListModel }; typedef std::variant FontChoice; static inline const FontChoice UseBestSystemFont{FontChoiceAbstract::BestSystemFont}; + static QFont getFontForChoice(const FontChoice& fc); bool Init(bilingual_str& error); void Reset();