diff options
Diffstat (limited to 'src/qt')
-rw-r--r-- | src/qt/forms/optionsdialog.ui | 121 | ||||
-rw-r--r-- | src/qt/optionsdialog.cpp | 84 | ||||
-rw-r--r-- | src/qt/optionsmodel.cpp | 13 | ||||
-rw-r--r-- | 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 6be47e94fe..99fb238772 100644 --- a/src/qt/forms/optionsdialog.ui +++ b/src/qt/forms/optionsdialog.ui @@ -772,104 +772,29 @@ </layout> </item> <item> - <widget class="QGroupBox" name="font_groupBox"> - <property name="title"> - <string>Monospaced font in the Overview tab:</string> - </property> - <layout class="QVBoxLayout" name="font_verticalLayout"> - <item> - <layout class="QHBoxLayout" name="embeddedFont_horizontalLayout"> - <item> - <widget class="QRadioButton" name="embeddedFont_radioButton"> - <property name="text"> - <string>embedded "%1"</string> - </property> - </widget> - </item> - <item> - <spacer name="embeddedFont_horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <layout class="QVBoxLayout" name="embeddedFont_verticalLayout"> - <item> - <widget class="QLabel" name="embeddedFont_label_1"> - <property name="text"> - <string notr="true">111.11111111 BTC</string> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="embeddedFont_label_9"> - <property name="text"> - <string notr="true">909.09090909 BTC</string> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </item> - <item> - <widget class="Line" name="font_line"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - </widget> - </item> - <item> - <layout class="QHBoxLayout" name="systemFont_horizontalLayout"> - <item> - <widget class="QRadioButton" name="systemFont_radioButton"> - <property name="text"> - <string>closest matching "%1"</string> - </property> - </widget> - </item> - <item> - <spacer name="systemFont_horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <layout class="QVBoxLayout" name="systemFont_verticalLayout"> - <item> - <widget class="QLabel" name="systemFont_label_1"> - <property name="text"> - <string notr="true">111.11111111 BTC</string> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="systemFont_label_9"> - <property name="text"> - <string notr="true">909.09090909 BTC</string> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </item> - </layout> - </widget> + <layout class="QHBoxLayout" name="horizontalLayout_4_Display"> + <item> + <widget class="QLabel" name="moneyFontLabel"> + <property name="text"> + <string>Font in the Overview tab: </string> + </property> + <property name="buddy"> + <cstring>moneyFont</cstring> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="moneyFont"/> + </item> + <item> + <widget class="QLabel" name="moneyFont_preview"> + <property name="text"> + <string notr="true">111.11111111 BTC +909.09090909 BTC</string> + </property> + </widget> + </item> + </layout> </item> <item> <spacer name="verticalSpacer_Display"> diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index fcc9aced09..b10c074083 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -23,14 +23,70 @@ #include <chrono> +#include <QApplication> #include <QDataWidgetMapper> #include <QDir> +#include <QFontDialog> #include <QIntValidator> #include <QLocale> #include <QMessageBox> #include <QSystemTrayIcon> #include <QTimer> +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<OptionsModel::FontChoice>()) continue; + if (item_data.value<OptionsModel::FontChoice>() == 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<OptionsModel::FontChoice>()) { + f = OptionsModel::getFontForChoice(item_data.value<OptionsModel::FontChoice>()); + } 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<int>::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<OptionsModel::FontChoice>(); - if (std::holds_alternative<OptionsModel::FontChoiceAbstract>(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 ef32a11523..2937b80019 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<FontChoiceAbstract>(m_font_money)) { - f = GUIUtil::fixedPitchFont(m_font_money != UseBestSystemFont); + if (std::holds_alternative<FontChoiceAbstract>(fc)) { + f = GUIUtil::fixedPitchFont(fc != UseBestSystemFont); f.setWeight(QFont::Bold); } else { - f = std::get<QFont>(m_font_money); + 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); }; diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 1984002028..b5ea6c783e 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -84,6 +84,7 @@ public: }; typedef std::variant<FontChoiceAbstract, QFont> FontChoice; static inline const FontChoice UseBestSystemFont{FontChoiceAbstract::BestSystemFont}; + static QFont getFontForChoice(const FontChoice& fc); bool Init(bilingual_str& error); void Reset(); |