Skip to content

Commit b59b0f7

Browse files
UdjinM6kwvg
authored andcommitted
feat(qt): add live preview for monospace font in appearance settings
- Add updateMoneyFont() slot to update font immediately on selection - Save original font choice to restore on Cancel - Include full optionsmodel.h header for FontChoice type usage - Matches behavior of other appearance settings (theme, font family, etc.)
1 parent 83af951 commit b59b0f7

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/qt/appearancewidget.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ AppearanceWidget::AppearanceWidget(QWidget* parent) :
118118
connect(ui->fontWeightNormalSlider, &QSlider::valueChanged, [this](auto nValue) { updateFontWeightNormal(nValue); });
119119

120120
connect(ui->moneyFont, &QComboBox::currentTextChanged, [this]() { Q_EMIT appearanceChanged(); });
121+
connect(ui->moneyFont, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &AppearanceWidget::updateMoneyFont);
121122

122123
connect(ui->theme, &QComboBox::currentTextChanged, this, &AppearanceWidget::updateTheme);
123124
connect(ui->theme, &QComboBox::currentTextChanged, [this]() { Q_EMIT appearanceChanged(); });
@@ -145,6 +146,13 @@ AppearanceWidget::~AppearanceWidget()
145146
if (prevWeightBold != GUIUtil::g_font_registry.GetWeightBold()) {
146147
GUIUtil::g_font_registry.SetWeightBold(prevWeightBold);
147148
}
149+
// Restore monospace font if cancelled
150+
if (model) {
151+
const auto& current_money_font = model->data(model->index(OptionsModel::FontForMoney, 0), Qt::EditRole).value<OptionsModel::FontChoice>();
152+
if (current_money_font != prevMoneyFont) {
153+
model->setData(model->index(OptionsModel::FontForMoney, 0), QVariant::fromValue(prevMoneyFont));
154+
}
155+
}
148156
GUIUtil::setApplicationFont();
149157
GUIUtil::updateFonts();
150158
}
@@ -171,6 +179,7 @@ void AppearanceWidget::setModel(OptionsModel* _model)
171179
mapper->toFirst();
172180

173181
const auto& font_for_money = _model->data(_model->index(OptionsModel::FontForMoney, 0), Qt::EditRole).value<OptionsModel::FontChoice>();
182+
prevMoneyFont = font_for_money; // Save original value for cancel
174183
setFontChoice(ui->moneyFont, font_for_money);
175184

176185
const bool override_family{_model->isOptionOverridden("-font-family")};
@@ -208,9 +217,7 @@ void AppearanceWidget::setModel(OptionsModel* _model)
208217
void AppearanceWidget::accept()
209218
{
210219
fAcceptChanges = true;
211-
if (model) {
212-
model->setData(model->index(OptionsModel::FontForMoney, 0), ui->moneyFont->itemData(ui->moneyFont->currentIndex()));
213-
}
220+
// Note: FontForMoney is now updated immediately via updateMoneyFont()
214221
}
215222

216223
void AppearanceWidget::updateTheme(const QString& theme)
@@ -282,6 +289,19 @@ void AppearanceWidget::updateMoneyPreview()
282289
ui->moneyFont_preview->setFont(GUIUtil::getFontBold());
283290
}
284291

292+
void AppearanceWidget::updateMoneyFont(int index)
293+
{
294+
if (!model) {
295+
return;
296+
}
297+
QVariant item_data = ui->moneyFont->itemData(index);
298+
if (!item_data.canConvert<OptionsModel::FontChoice>()) {
299+
return;
300+
}
301+
// Update the model immediately to trigger live preview in Overview page
302+
model->setData(model->index(OptionsModel::FontForMoney, 0), item_data);
303+
}
304+
285305
void AppearanceWidget::updateWeightSlider(const bool fForce)
286306
{
287307
int nMaximum = GUIUtil::g_font_registry.GetSupportedWeights().size() - 1;

src/qt/appearancewidget.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99

1010
#include <qt/guiutil.h>
1111
#include <qt/guiutil_font.h>
12+
#include <qt/optionsmodel.h>
1213

1314
namespace Ui {
1415
class AppearanceWidget;
1516
}
1617

17-
class OptionsModel;
18-
1918
class QDataWidgetMapper;
2019
class QSlider;
2120
class QComboBox;
@@ -43,6 +42,7 @@ private Q_SLOTS:
4342
void updateFontWeightNormal(int nValue, bool fForce = false);
4443
void updateFontWeightBold(int nValue, bool fForce = false);
4544
void updateMoneyPreview();
45+
void updateMoneyFont(int index);
4646

4747
private:
4848
Ui::AppearanceWidget* ui;
@@ -54,6 +54,7 @@ private Q_SLOTS:
5454
QString prevFontFamily;
5555
QFont::Weight prevWeightNormal;
5656
QFont::Weight prevWeightBold;
57+
OptionsModel::FontChoice prevMoneyFont{OptionsModel::FontChoiceAbstract::ApplicationFont};
5758

5859
void updateWeightSlider(bool fForce = false);
5960
};

0 commit comments

Comments
 (0)