Skip to content

Commit 636e7a6

Browse files
UdjinM6kwvg
authored andcommitted
refactor: remove redundant preview and simplify font handling
- Remove moneyFont_preview label from appearance dialog since Overview page now shows live preview - Remove updateMoneyPreview() slot and related signal connections - Simplify setupFontOptions() to remove preview parameter - Remove moneyFont_preview from vecIgnoreObjects in guiutil_font.cpp - Simplify getFontForChoice() by removing unused weight/size settings since callers only use the font family (weight and size are overridden by setMonospacedFont()) - Use g_font_registry.GetFont() directly for ApplicationFont case - Set consistent width (282px) for moneyFont combobox to match other comboboxes in the dialog
1 parent b59b0f7 commit 636e7a6

File tree

5 files changed

+22
-41
lines changed

5 files changed

+22
-41
lines changed

src/qt/appearancewidget.cpp

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int setFontChoice(QComboBox* cb, const OptionsModel::FontChoice& fc)
4242
return i;
4343
}
4444

45-
void setupFontOptions(QComboBox* cb, QLabel* preview)
45+
void setupFontOptions(QComboBox* cb)
4646
{
4747
QFont embedded_font{GUIUtil::fixedPitchFont(true)};
4848
QFont system_font{GUIUtil::fixedPitchFont(false)};
@@ -51,24 +51,21 @@ void setupFontOptions(QComboBox* cb, QLabel* preview)
5151
cb->addItem(QObject::tr("Use existing font"), QVariant::fromValue(OptionsModel::FontChoice{OptionsModel::FontChoiceAbstract::ApplicationFont}));
5252
cb->addItem(QObject::tr("Custom…"));
5353

54-
const auto& on_font_choice_changed = [cb, preview](int index) {
54+
const auto& on_font_choice_changed = [cb](int index) {
5555
static int previous_index = -1;
5656
QVariant item_data = cb->itemData(index);
57-
QFont f;
5857
if (item_data.canConvert<OptionsModel::FontChoice>()) {
59-
f = OptionsModel::getFontForChoice(item_data.value<OptionsModel::FontChoice>());
58+
// Valid predefined choice, nothing to do
6059
} else {
60+
// "Custom..." was selected, show font dialog
6161
bool ok;
62-
f = QFontDialog::getFont(&ok, GUIUtil::fixedPitchFont(false), cb->parentWidget());
62+
QFont f = QFontDialog::getFont(&ok, GUIUtil::fixedPitchFont(false), cb->parentWidget());
6363
if (!ok) {
6464
cb->setCurrentIndex(previous_index);
6565
return;
6666
}
6767
index = setFontChoice(cb, OptionsModel::FontChoice{f});
6868
}
69-
if (preview) {
70-
preview->setFont(f);
71-
}
7269
previous_index = index;
7370
};
7471
QObject::connect(cb, QOverload<int>::of(&QComboBox::currentIndexChanged), on_font_choice_changed);
@@ -101,18 +98,16 @@ AppearanceWidget::AppearanceWidget(QWidget* parent) :
10198
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
10299
mapper->setOrientation(Qt::Vertical);
103100

104-
setupFontOptions(ui->moneyFont, ui->moneyFont_preview);
101+
setupFontOptions(ui->moneyFont);
105102

106103
connect(ui->fontFamily, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &AppearanceWidget::updateFontFamily);
107104
connect(ui->fontFamily, QOverload<int>::of(&QComboBox::currentIndexChanged), [this]() { Q_EMIT appearanceChanged(); });
108-
connect(ui->fontFamily, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &AppearanceWidget::updateMoneyPreview);
109105

110106
connect(ui->fontScaleSlider, &QSlider::sliderReleased, [this]() { Q_EMIT appearanceChanged(); });
111107
connect(ui->fontScaleSlider, &QSlider::valueChanged, this, &AppearanceWidget::updateFontScale);
112108

113109
connect(ui->fontWeightBoldSlider, &QSlider::sliderReleased, [this]() { Q_EMIT appearanceChanged(); });
114110
connect(ui->fontWeightBoldSlider, &QSlider::valueChanged, [this](auto nValue) { updateFontWeightBold(nValue); });
115-
connect(ui->fontWeightBoldSlider, &QSlider::valueChanged, this, &AppearanceWidget::updateMoneyPreview);
116111

117112
connect(ui->fontWeightNormalSlider, &QSlider::sliderReleased, [this]() { Q_EMIT appearanceChanged(); });
118113
connect(ui->fontWeightNormalSlider, &QSlider::valueChanged, [this](auto nValue) { updateFontWeightNormal(nValue); });
@@ -273,22 +268,6 @@ void AppearanceWidget::updateFontWeightBold(int nValue, bool fForce)
273268
GUIUtil::updateFonts();
274269
}
275270

276-
void AppearanceWidget::updateMoneyPreview()
277-
{
278-
QVariant item_data = ui->moneyFont->currentData();
279-
if (!item_data.canConvert<OptionsModel::FontChoice>()) {
280-
return;
281-
}
282-
const auto fc = item_data.value<OptionsModel::FontChoice>();
283-
if (!std::holds_alternative<OptionsModel::FontChoiceAbstract>(fc)) {
284-
return;
285-
}
286-
if (std::get<OptionsModel::FontChoiceAbstract>(fc) != OptionsModel::FontChoiceAbstract::ApplicationFont) {
287-
return;
288-
}
289-
ui->moneyFont_preview->setFont(GUIUtil::getFontBold());
290-
}
291-
292271
void AppearanceWidget::updateMoneyFont(int index)
293272
{
294273
if (!model) {

src/qt/appearancewidget.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ private Q_SLOTS:
4141
void updateFontScale(int nScale);
4242
void updateFontWeightNormal(int nValue, bool fForce = false);
4343
void updateFontWeightBold(int nValue, bool fForce = false);
44-
void updateMoneyPreview();
4544
void updateMoneyFont(int index);
4645

4746
private:

src/qt/forms/appearancewidget.ui

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,18 @@
505505
</spacer>
506506
</item>
507507
<item>
508-
<widget class="QComboBox" name="moneyFont"/>
509-
</item>
510-
<item>
511-
<widget class="QLabel" name="moneyFont_preview">
512-
<property name="text">
513-
<string notr="true">111.11111111 DASH
514-
909.09090909 DASH</string>
508+
<widget class="QComboBox" name="moneyFont">
509+
<property name="minimumSize">
510+
<size>
511+
<width>282</width>
512+
<height>0</height>
513+
</size>
514+
</property>
515+
<property name="maximumSize">
516+
<size>
517+
<width>282</width>
518+
<height>16777215</height>
519+
</size>
515520
</property>
516521
</widget>
517522
</item>

src/qt/guiutil_font.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ constexpr std::array<std::string_view, 18> vecIgnoreClasses{
9494
};
9595

9696
//! List of Qt objects to ignore when applying fonts
97-
constexpr std::array<std::string_view, 2> vecIgnoreObjects{
97+
constexpr std::array<std::string_view, 1> vecIgnoreObjects{
9898
"messagesWidget",
99-
"moneyFont_preview",
10099
};
101100

102101
//! Weights considered when testing for weights supported by a font

src/qt/optionsmodel.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,21 +527,20 @@ QFont OptionsModel::getFontForChoice(const FontChoice& fc)
527527
if (std::holds_alternative<FontChoiceAbstract>(fc)) {
528528
switch (std::get<FontChoiceAbstract>(fc)) {
529529
case FontChoiceAbstract::ApplicationFont:
530-
f = GUIUtil::getFontBold();
530+
f.setFamily(GUIUtil::g_font_registry.GetFont());
531531
break;
532532
case FontChoiceAbstract::EmbeddedFont:
533533
f = GUIUtil::fixedPitchFont(true);
534-
f.setWeight(QFont::Bold);
535534
break;
536535
case FontChoiceAbstract::BestSystemFont:
537536
f = GUIUtil::fixedPitchFont(false);
538-
f.setWeight(QFont::Bold);
539537
break;
540538
}
541539
} else {
542540
f = std::get<QFont>(fc);
543541
}
544-
f.setPointSize(10);
542+
// Note: Only the font family is actually used by callers.
543+
// Weight and size are overridden in setMonospacedFont().
545544
return f;
546545
}
547546

0 commit comments

Comments
 (0)