0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-03 09:56:38 -05:00

GUI: Use FontChoice type in OptionsModel settings abstraction

This commit is contained in:
Luke Dashjr 2021-12-02 16:59:46 +00:00
parent 3a6757eed9
commit 98e9ac5199
3 changed files with 38 additions and 17 deletions

View file

@ -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<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);
}
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();

View file

@ -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<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) {
@ -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<FontChoice>();
if (m_font_money == new_font) break;
settings.setValue("FontForMoney", FontChoiceToString(new_font));
m_font_money = new_font;
Q_EMIT fontForMoneyChanged(getFontForMoney());
break;
}

View file

@ -62,7 +62,7 @@ public:
DisplayUnit, // BitcoinUnit
ThirdPartyTxUrls, // QString
Language, // QString
UseEmbeddedMonospacedFont, // bool
FontForMoney, // FontChoice
CoinControlFeatures, // bool
SubFeeFromAmount, // bool
ThreadsScriptVerif, // int
@ -138,6 +138,7 @@ private:
/* 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 @@ Q_SIGNALS:
void fontForMoneyChanged(const QFont&);
};
Q_DECLARE_METATYPE(OptionsModel::FontChoice)
#endif // BITCOIN_QT_OPTIONSMODEL_H