Skip to content

Commit 7fca189

Browse files
committed
Merge bitcoin#79: Embed monospaced font
67f2631 gui: Add monospaced font settings (Hennadii Stepanov) 22e0114 qt: Choose monospaced font in C++ code rather in `*.ui` file (Hennadii Stepanov) 623de12 qt: Make GUIUtil::fixedPitchFont aware of embedded font (Hennadii Stepanov) 89e4219 gui: Add Roboto Mono font (Hennadii Stepanov) Pull request description: Qt does not guarantee that the actual applied font matches to the requested one. It was noted (bitcoin#16432 (comment)): > the monospace font looks a bit weird no macOS ... because it is _not_ monospaced. Also some discrepancies I've noted on Windows while testing Qt 5.15 ([bitcoin#19716](bitcoin#19716)). Of course, we could check the actual font with `QFontInfo`, and try to choose another font. But this PR suggests to just embed a monospaced font, and get the GUI look (partially) independent from a platform. [Roboto Mono](https://fonts.google.com/specimen/Roboto+Mono) was chosen after discussion with Bitcoin Design community, and due to its [Apache License, Version 2.0](https://fonts.google.com/specimen/Roboto+Mono#license). Changes are scoped to the Overview page only. --- Screenshots on macOS 10.15.6 (images are simulated by code patching): - master (ca30d34) ![Screenshot from 2020-09-03 14-10-03](https://user-images.githubusercontent.com/32963518/92107902-30357d80-edef-11ea-8a4f-b4c758eebf66.png) - this PR (3fdd5b6) ![Screenshot from 2020-09-03 15-41-36](https://user-images.githubusercontent.com/32963518/92116277-4b5aba00-edfc-11ea-8cb9-22fc44460bfb.png) --- More screenshots added after bitcoin-core/gui#79 (comment): - Linux Mint 20.1 + Cinnamon DE ![DeepinScreenshot_select-area_20210221205410](https://user-images.githubusercontent.com/32963518/108635739-b327be80-7489-11eb-8851-ac89f61199ee.png) - Windows 10 (with depends) ![DeepinScreenshot_select-area_20210221205056](https://user-images.githubusercontent.com/32963518/108635741-b6bb4580-7489-11eb-8b6b-66be5551eb8c.png) - macOS Big Sur (with depends) ![DeepinScreenshot_select-area_20210221202917](https://user-images.githubusercontent.com/32963518/108635746-bd49bd00-7489-11eb-8cd2-cf4bb2273a6d.png) ACKs for top commit: laanwj: Tested ACK 67f2631 Tree-SHA512: a59775570b8ce314669ede50a0b69f53e8a47a41e7eea428835013240f0ce9afcff6e4c258895455b56806417ed877e5b7a9522f1904e95a5f435db8ccf6078c
2 parents 84af293 + 67f2631 commit 7fca189

14 files changed

+180
-60
lines changed

contrib/debian/copyright

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ Files: src/qt/res/icons/proxy.png
8787
Copyright: Cristian Mircea Messel
8888
License: public-domain
8989

90+
Files: src/qt/fonts/RobotoMono-Bold.ttf
91+
License: Apache-2.0
92+
Comment: Site: https://fonts.google.com/specimen/Roboto+Mono
93+
9094

9195
License: Expat
9296
Permission is hereby granted, free of charge, to any person obtaining a
@@ -144,3 +148,14 @@ Comment:
144148

145149
License: public-domain
146150
This work is in the public domain.
151+
152+
License: Apache-2.0
153+
Licensed under the Apache License, Version 2.0 (the "License");
154+
you may not use this file except in compliance with the License.
155+
You may obtain a copy of the License at
156+
http://www.apache.org/licenses/LICENSE-2.0
157+
Unless required by applicable law or agreed to in writing, software
158+
distributed under the License is distributed on an "AS IS" BASIS,
159+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
160+
See the License for the specific language governing permissions and
161+
limitations under the License.

src/Makefile.qt.include

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ BITCOIN_QT_H = \
164164
qt/walletview.h \
165165
qt/winshutdownmonitor.h
166166

167+
RES_FONTS = \
168+
qt/res/fonts/RobotoMono-Bold.ttf
169+
167170
RES_ICONS = \
168171
qt/res/icons/add.png \
169172
qt/res/icons/address-book.png \
@@ -290,7 +293,7 @@ qt_libbitcoinqt_a_CXXFLAGS = $(AM_CXXFLAGS) $(QT_PIE_FLAGS)
290293
qt_libbitcoinqt_a_OBJCXXFLAGS = $(AM_OBJCXXFLAGS) $(QT_PIE_FLAGS)
291294

292295
qt_libbitcoinqt_a_SOURCES = $(BITCOIN_QT_CPP) $(BITCOIN_QT_H) $(QT_FORMS_UI) \
293-
$(QT_QRC) $(QT_QRC_LOCALE) $(QT_TS) $(RES_ICONS) $(RES_ANIMATION)
296+
$(QT_QRC) $(QT_QRC_LOCALE) $(QT_TS) $(RES_FONTS) $(RES_ICONS) $(RES_ANIMATION)
294297
if TARGET_DARWIN
295298
qt_libbitcoinqt_a_SOURCES += $(BITCOIN_MM)
296299
endif
@@ -361,7 +364,7 @@ $(QT_QRC_LOCALE_CPP): $(QT_QRC_LOCALE) $(QT_QM)
361364
$(SED) -e '/^\*\*.*Created:/d' -e '/^\*\*.*by:/d' > $@
362365
@rm $(@D)/temp_$(<F)
363366

364-
$(QT_QRC_CPP): $(QT_QRC) $(QT_FORMS_H) $(RES_ICONS) $(RES_ANIMATION)
367+
$(QT_QRC_CPP): $(QT_QRC) $(QT_FORMS_H) $(RES_FONTS) $(RES_ICONS) $(RES_ANIMATION)
365368
@test -f $(RCC)
366369
$(AM_V_GEN) QT_SELECT=$(QT_SELECT) $(RCC) -name bitcoin $< | \
367370
$(SED) -e '/^\*\*.*Created:/d' -e '/^\*\*.*by:/d' > $@

src/qt/bitcoin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
#include <QApplication>
4646
#include <QDebug>
47+
#include <QFontDatabase>
4748
#include <QLibraryInfo>
4849
#include <QLocale>
4950
#include <QMessageBox>
@@ -475,6 +476,7 @@ int GuiMain(int argc, char* argv[])
475476
#endif
476477

477478
BitcoinApplication app;
479+
QFontDatabase::addApplicationFont(":/fonts/monospace");
478480

479481
/// 2. Parse command-line options. We do this after qt in order to show an error if there are problems parsing these
480482
// Command-line options take precedence:

src/qt/bitcoin.qrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,7 @@
8383
<file alias="spinner-034">res/animation/spinner-034.png</file>
8484
<file alias="spinner-035">res/animation/spinner-035.png</file>
8585
</qresource>
86+
<qresource prefix="/fonts">
87+
<file alias="monospace">res/fonts/RobotoMono-Bold.ttf</file>
88+
</qresource>
8689
</RCC>

src/qt/forms/optionsdialog.ui

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

src/qt/forms/overviewpage.ui

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@
116116
</property>
117117
<item row="2" column="2">
118118
<widget class="QLabel" name="labelWatchPending">
119-
<property name="font">
120-
<font>
121-
<family>Monospace</family>
122-
<weight>75</weight>
123-
<bold>true</bold>
124-
</font>
125-
</property>
126119
<property name="cursor">
127120
<cursorShape>IBeamCursor</cursorShape>
128121
</property>
@@ -142,13 +135,6 @@
142135
</item>
143136
<item row="2" column="1">
144137
<widget class="QLabel" name="labelUnconfirmed">
145-
<property name="font">
146-
<font>
147-
<family>Monospace</family>
148-
<weight>75</weight>
149-
<bold>true</bold>
150-
</font>
151-
</property>
152138
<property name="cursor">
153139
<cursorShape>IBeamCursor</cursorShape>
154140
</property>
@@ -168,13 +154,6 @@
168154
</item>
169155
<item row="3" column="2">
170156
<widget class="QLabel" name="labelWatchImmature">
171-
<property name="font">
172-
<font>
173-
<family>Monospace</family>
174-
<weight>75</weight>
175-
<bold>true</bold>
176-
</font>
177-
</property>
178157
<property name="cursor">
179158
<cursorShape>IBeamCursor</cursorShape>
180159
</property>
@@ -227,13 +206,6 @@
227206
</item>
228207
<item row="3" column="1">
229208
<widget class="QLabel" name="labelImmature">
230-
<property name="font">
231-
<font>
232-
<family>Monospace</family>
233-
<weight>75</weight>
234-
<bold>true</bold>
235-
</font>
236-
</property>
237209
<property name="cursor">
238210
<cursorShape>IBeamCursor</cursorShape>
239211
</property>
@@ -273,13 +245,6 @@
273245
</item>
274246
<item row="5" column="1">
275247
<widget class="QLabel" name="labelTotal">
276-
<property name="font">
277-
<font>
278-
<family>Monospace</family>
279-
<weight>75</weight>
280-
<bold>true</bold>
281-
</font>
282-
</property>
283248
<property name="cursor">
284249
<cursorShape>IBeamCursor</cursorShape>
285250
</property>
@@ -299,13 +264,6 @@
299264
</item>
300265
<item row="5" column="2">
301266
<widget class="QLabel" name="labelWatchTotal">
302-
<property name="font">
303-
<font>
304-
<family>Monospace</family>
305-
<weight>75</weight>
306-
<bold>true</bold>
307-
</font>
308-
</property>
309267
<property name="cursor">
310268
<cursorShape>IBeamCursor</cursorShape>
311269
</property>
@@ -342,13 +300,6 @@
342300
</item>
343301
<item row="1" column="1">
344302
<widget class="QLabel" name="labelBalance">
345-
<property name="font">
346-
<font>
347-
<family>Monospace</family>
348-
<weight>75</weight>
349-
<bold>true</bold>
350-
</font>
351-
</property>
352303
<property name="cursor">
353304
<cursorShape>IBeamCursor</cursorShape>
354305
</property>
@@ -368,13 +319,6 @@
368319
</item>
369320
<item row="1" column="2">
370321
<widget class="QLabel" name="labelWatchAvailable">
371-
<property name="font">
372-
<font>
373-
<family>Monospace</family>
374-
<weight>75</weight>
375-
<bold>true</bold>
376-
</font>
377-
</property>
378322
<property name="cursor">
379323
<cursorShape>IBeamCursor</cursorShape>
380324
</property>

src/qt/guiutil.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ QString dateTimeStr(qint64 nTime)
7878
return dateTimeStr(QDateTime::fromTime_t((qint32)nTime));
7979
}
8080

81-
QFont fixedPitchFont()
81+
QFont fixedPitchFont(bool use_embedded_font)
8282
{
83+
if (use_embedded_font) {
84+
return {"Roboto Mono"};
85+
}
8386
return QFontDatabase::systemFont(QFontDatabase::FixedFont);
8487
}
8588

src/qt/guiutil.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace GUIUtil
5353
QString dateTimeStr(qint64 nTime);
5454

5555
// Return a monospace font
56-
QFont fixedPitchFont();
56+
QFont fixedPitchFont(bool use_embedded_font = false);
5757

5858
// Set up widget for address
5959
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent);

src/qt/optionsdialog.cpp

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

147+
QFont embedded_font{GUIUtil::fixedPitchFont(true)};
148+
ui->embeddedFont_radioButton->setText(ui->embeddedFont_radioButton->text().arg(QFontInfo(embedded_font).family()));
149+
embedded_font.setWeight(QFont::Bold);
150+
ui->embeddedFont_label_1->setFont(embedded_font);
151+
ui->embeddedFont_label_9->setFont(embedded_font);
152+
153+
QFont system_font{GUIUtil::fixedPitchFont(false)};
154+
ui->systemFont_radioButton->setText(ui->systemFont_radioButton->text().arg(QFontInfo(system_font).family()));
155+
system_font.setWeight(QFont::Bold);
156+
ui->systemFont_label_1->setFont(system_font);
157+
ui->systemFont_label_9->setFont(system_font);
158+
// Checking the embeddedFont_radioButton automatically unchecks the systemFont_radioButton.
159+
ui->systemFont_radioButton->setChecked(true);
160+
147161
GUIUtil::handleCloseWindowShortcut(this);
148162
}
149163

@@ -246,6 +260,7 @@ void OptionsDialog::setMapper()
246260
mapper->addMapping(ui->lang, OptionsModel::Language);
247261
mapper->addMapping(ui->unit, OptionsModel::DisplayUnit);
248262
mapper->addMapping(ui->thirdPartyTxUrls, OptionsModel::ThirdPartyTxUrls);
263+
mapper->addMapping(ui->embeddedFont_radioButton, OptionsModel::UseEmbeddedMonospacedFont);
249264
}
250265

251266
void OptionsDialog::setOkButtonState(bool fState)

src/qt/optionsmodel.cpp

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

165165
language = settings.value("language").toString();
166+
167+
if (!settings.contains("UseEmbeddedMonospacedFont")) {
168+
settings.setValue("UseEmbeddedMonospacedFont", "true");
169+
}
170+
m_use_embedded_monospaced_font = settings.value("UseEmbeddedMonospacedFont").toBool();
171+
Q_EMIT useEmbeddedMonospacedFontChanged(m_use_embedded_monospaced_font);
166172
}
167173

168174
/** Helper function to copy contents from one QSettings to another.
@@ -326,6 +332,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
326332
return strThirdPartyTxUrls;
327333
case Language:
328334
return settings.value("language");
335+
case UseEmbeddedMonospacedFont:
336+
return m_use_embedded_monospaced_font;
329337
case CoinControlFeatures:
330338
return fCoinControlFeatures;
331339
case Prune:
@@ -453,6 +461,11 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
453461
setRestartRequired(true);
454462
}
455463
break;
464+
case UseEmbeddedMonospacedFont:
465+
m_use_embedded_monospaced_font = value.toBool();
466+
settings.setValue("UseEmbeddedMonospacedFont", m_use_embedded_monospaced_font);
467+
Q_EMIT useEmbeddedMonospacedFontChanged(m_use_embedded_monospaced_font);
468+
break;
456469
case CoinControlFeatures:
457470
fCoinControlFeatures = value.toBool();
458471
settings.setValue("fCoinControlFeatures", fCoinControlFeatures);

0 commit comments

Comments
 (0)