Skip to content

Commit 12741b9

Browse files
committed
gui: Add monospaced font settings
1 parent 76765d3 commit 12741b9

File tree

5 files changed

+134
-1
lines changed

5 files changed

+134
-1
lines changed

src/qt/forms/optionsdialog.ui

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,106 @@
692692
</item>
693693
</layout>
694694
</item>
695+
<item>
696+
<widget class="QGroupBox" name="font_groupBox">
697+
<property name="title">
698+
<string>Monospaced font in the Overview tab:</string>
699+
</property>
700+
<layout class="QVBoxLayout" name="font_verticalLayout">
701+
<item>
702+
<layout class="QHBoxLayout" name="embeddedFont_horizontalLayout">
703+
<item>
704+
<widget class="QRadioButton" name="embeddedFont_radioButton">
705+
<property name="text">
706+
<string>embedded &quot;%1&quot;</string>
707+
</property>
708+
</widget>
709+
</item>
710+
<item>
711+
<spacer name="embeddedFont_horizontalSpacer">
712+
<property name="orientation">
713+
<enum>Qt::Horizontal</enum>
714+
</property>
715+
<property name="sizeHint" stdset="0">
716+
<size>
717+
<width>40</width>
718+
<height>20</height>
719+
</size>
720+
</property>
721+
</spacer>
722+
</item>
723+
<item>
724+
<layout class="QVBoxLayout" name="embeddedFont_verticalLayout">
725+
<item>
726+
<widget class="QLabel" name="embeddedFont_label_1">
727+
<property name="text">
728+
<string>111.11111111 BTC</string>
729+
</property>
730+
</widget>
731+
</item>
732+
<item>
733+
<widget class="QLabel" name="embeddedFont_label_9">
734+
<property name="text">
735+
<string>909.09090909 BTC</string>
736+
</property>
737+
</widget>
738+
</item>
739+
</layout>
740+
</item>
741+
</layout>
742+
</item>
743+
<item>
744+
<widget class="Line" name="font_line">
745+
<property name="orientation">
746+
<enum>Qt::Horizontal</enum>
747+
</property>
748+
</widget>
749+
</item>
750+
<item>
751+
<layout class="QHBoxLayout" name="systemFont_horizontalLayout">
752+
<item>
753+
<widget class="QRadioButton" name="systemFont_radioButton">
754+
<property name="text">
755+
<string>closest matching &quot;%1&quot;</string>
756+
</property>
757+
</widget>
758+
</item>
759+
<item>
760+
<spacer name="systemFont_horizontalSpacer">
761+
<property name="orientation">
762+
<enum>Qt::Horizontal</enum>
763+
</property>
764+
<property name="sizeHint" stdset="0">
765+
<size>
766+
<width>40</width>
767+
<height>20</height>
768+
</size>
769+
</property>
770+
</spacer>
771+
</item>
772+
<item>
773+
<layout class="QVBoxLayout" name="systemFont_verticalLayout">
774+
<item>
775+
<widget class="QLabel" name="systemFont_label_1">
776+
<property name="text">
777+
<string>111.11111111 BTC</string>
778+
</property>
779+
</widget>
780+
</item>
781+
<item>
782+
<widget class="QLabel" name="systemFont_label_9">
783+
<property name="text">
784+
<string>909.09090909 BTC</string>
785+
</property>
786+
</widget>
787+
</item>
788+
</layout>
789+
</item>
790+
</layout>
791+
</item>
792+
</layout>
793+
</widget>
794+
</item>
695795
<item>
696796
<spacer name="verticalSpacer_Display">
697797
<property name="orientation">

src/qt/optionsdialog.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
136136
ui->minimizeToTray->setEnabled(false);
137137
}
138138

139+
QFont embedded_font{GUIUtil::fixedPitchFont(true)};
140+
ui->embeddedFont_radioButton->setText(ui->embeddedFont_radioButton->text().arg(QFontInfo(embedded_font).family()));
141+
embedded_font.setWeight(QFont::Bold);
142+
ui->embeddedFont_label_1->setFont(embedded_font);
143+
ui->embeddedFont_label_9->setFont(embedded_font);
144+
145+
QFont system_font{GUIUtil::fixedPitchFont(false)};
146+
ui->systemFont_radioButton->setText(ui->systemFont_radioButton->text().arg(QFontInfo(system_font).family()));
147+
system_font.setWeight(QFont::Bold);
148+
ui->systemFont_label_1->setFont(system_font);
149+
ui->systemFont_label_9->setFont(system_font);
150+
// Checking the embeddedFont_radioButton automatically unchecks the systemFont_radioButton.
151+
ui->systemFont_radioButton->setChecked(true);
152+
139153
GUIUtil::handleCloseWindowShortcut(this);
140154
}
141155

@@ -237,6 +251,7 @@ void OptionsDialog::setMapper()
237251
mapper->addMapping(ui->lang, OptionsModel::Language);
238252
mapper->addMapping(ui->unit, OptionsModel::DisplayUnit);
239253
mapper->addMapping(ui->thirdPartyTxUrls, OptionsModel::ThirdPartyTxUrls);
254+
mapper->addMapping(ui->embeddedFont_radioButton, OptionsModel::UseEmbeddedMonospacedFont);
240255
}
241256

242257
void OptionsDialog::setOkButtonState(bool fState)

src/qt/optionsmodel.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ void OptionsModel::Init(bool resetSettings)
154154
addOverriddenOption("-lang");
155155

156156
language = settings.value("language").toString();
157+
158+
if (!settings.contains("UseEmbeddedMonospacedFont")) {
159+
settings.setValue("UseEmbeddedMonospacedFont", "true");
160+
}
161+
m_use_embedded_monospaced_font = settings.value("UseEmbeddedMonospacedFont").toBool();
162+
Q_EMIT useEmbeddedMonospacedFontChanged(m_use_embedded_monospaced_font);
157163
}
158164

159165
/** Helper function to copy contents from one QSettings to another.
@@ -311,6 +317,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
311317
return strThirdPartyTxUrls;
312318
case Language:
313319
return settings.value("language");
320+
case UseEmbeddedMonospacedFont:
321+
return m_use_embedded_monospaced_font;
314322
case CoinControlFeatures:
315323
return fCoinControlFeatures;
316324
case Prune:
@@ -436,6 +444,11 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
436444
setRestartRequired(true);
437445
}
438446
break;
447+
case UseEmbeddedMonospacedFont:
448+
m_use_embedded_monospaced_font = value.toBool();
449+
settings.setValue("UseEmbeddedMonospacedFont", m_use_embedded_monospaced_font);
450+
Q_EMIT useEmbeddedMonospacedFontChanged(m_use_embedded_monospaced_font);
451+
break;
439452
case CoinControlFeatures:
440453
fCoinControlFeatures = value.toBool();
441454
settings.setValue("fCoinControlFeatures", fCoinControlFeatures);

src/qt/optionsmodel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class OptionsModel : public QAbstractListModel
5858
DisplayUnit, // BitcoinUnits::Unit
5959
ThirdPartyTxUrls, // QString
6060
Language, // QString
61+
UseEmbeddedMonospacedFont, // bool
6162
CoinControlFeatures, // bool
6263
ThreadsScriptVerif, // int
6364
Prune, // bool
@@ -83,6 +84,7 @@ class OptionsModel : public QAbstractListModel
8384
bool getMinimizeOnClose() const { return fMinimizeOnClose; }
8485
int getDisplayUnit() const { return nDisplayUnit; }
8586
QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; }
87+
bool getUseEmbeddedMonospacedFont() const { return m_use_embedded_monospaced_font; }
8688
bool getCoinControlFeatures() const { return fCoinControlFeatures; }
8789
const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; }
8890

@@ -106,6 +108,7 @@ class OptionsModel : public QAbstractListModel
106108
QString language;
107109
int nDisplayUnit;
108110
QString strThirdPartyTxUrls;
111+
bool m_use_embedded_monospaced_font;
109112
bool fCoinControlFeatures;
110113
/* settings that were overridden by command-line */
111114
QString strOverriddenByCommandLine;
@@ -119,6 +122,7 @@ class OptionsModel : public QAbstractListModel
119122
void displayUnitChanged(int unit);
120123
void coinControlFeaturesChanged(bool);
121124
void hideTrayIconChanged(bool);
125+
void useEmbeddedMonospacedFontChanged(bool);
122126
};
123127

124128
#endif // BITCOIN_QT_OPTIONSMODEL_H

src/qt/overviewpage.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ void OverviewPage::setClientModel(ClientModel *model)
233233
connect(model, &ClientModel::alertsChanged, this, &OverviewPage::updateAlerts);
234234
updateAlerts(model->getStatusBarWarnings());
235235

236-
setMonospacedFont(false);
236+
connect(model->getOptionsModel(), &OptionsModel::useEmbeddedMonospacedFontChanged, this, &OverviewPage::setMonospacedFont);
237+
setMonospacedFont(model->getOptionsModel()->getUseEmbeddedMonospacedFont());
237238
}
238239
}
239240

0 commit comments

Comments
 (0)