diff --git a/src/qt/forms/optionsdialog.ui b/src/qt/forms/optionsdialog.ui
index 6be47e94feb..99fb2387723 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 fcc9aced09a..b10c0740831 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 ef32a115230..2937b800196 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 19840020289..b5ea6c783e4 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();