Skip to content

Commit c67f527

Browse files
hebastoPastaPastaPasta
authored andcommitted
Merge bitcoin-core/gui#448: Add helper to load font
d54ec27 qt: Add helper to load font (João Barbosa) Pull request description: Originally submitted as bitcoin-core/gui-qml#49. ACKs for top commit: hebasto: re-ACK d54ec27 stratospher: Tested ACK d54ec27. Refactoring the code and defining `loadFont()` in `src/qt/guiutil.cpp` reduces redundant imports of the `QFontDatabase` and is a better design. shaavan: ACK d54ec27 Tree-SHA512: b156bb6ffb08dd57476f383a29bbb0a1108b62794d430debb77252f7d09df1409a7532b09d17d8836d1c2ab7c126a6618231164b9d0def1b8f361a81ef22d107
1 parent 8e0abeb commit c67f527

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/qt/bitcoin.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747

4848
#include <QApplication>
4949
#include <QDebug>
50-
#include <QFontDatabase>
5150
#include <QLatin1String>
5251
#include <QLibraryInfo>
5352
#include <QLocale>
@@ -577,7 +576,7 @@ int GuiMain(int argc, char* argv[])
577576
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
578577

579578
BitcoinApplication app;
580-
QFontDatabase::addApplicationFont(":/fonts/monospace");
579+
GUIUtil::LoadFont(QStringLiteral(":/fonts/monospace"));
581580

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

src/qt/guiutil.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,12 @@ bool hasEntryData(const QAbstractItemView *view, int column, int role)
493493
return !selection.at(0).data(role).toString().isEmpty();
494494
}
495495

496+
void LoadFont(const QString& file_name)
497+
{
498+
const int id = QFontDatabase::addApplicationFont(file_name);
499+
assert(id != -1);
500+
}
501+
496502
QString getDefaultDataDirectory()
497503
{
498504
return PathToQString(GetDefaultDataDir());

src/qt/guiutil.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ namespace GUIUtil
172172

173173
void setClipboard(const QString& str);
174174

175+
/**
176+
* Loads the font from the file specified by file_name, aborts if it fails.
177+
*/
178+
void LoadFont(const QString& file_name);
179+
175180
/**
176181
* Determine default data directory for operating system.
177182
*/

0 commit comments

Comments
 (0)