Merge bitcoin-core/gui#448: Add helper to load font

d54ec27bac388d7b84cf7b6cb4506bb0c25f2f88 qt: Add helper to load font (João Barbosa)

Pull request description:

  Originally submitted as https://github.com/bitcoin-core/gui-qml/pull/49.

ACKs for top commit:
  hebasto:
    re-ACK d54ec27bac388d7b84cf7b6cb4506bb0c25f2f88
  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 d54ec27bac388d7b84cf7b6cb4506bb0c25f2f88

Tree-SHA512: b156bb6ffb08dd57476f383a29bbb0a1108b62794d430debb77252f7d09df1409a7532b09d17d8836d1c2ab7c126a6618231164b9d0def1b8f361a81ef22d107
This commit is contained in:
Hennadii Stepanov 2021-10-09 13:36:59 +03:00 committed by pasta
parent 8e0abeb1c1
commit c67f527b0b
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
3 changed files with 12 additions and 2 deletions

View File

@ -47,7 +47,6 @@
#include <QApplication>
#include <QDebug>
#include <QFontDatabase>
#include <QLatin1String>
#include <QLibraryInfo>
#include <QLocale>
@ -577,7 +576,7 @@ int GuiMain(int argc, char* argv[])
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
BitcoinApplication app;
QFontDatabase::addApplicationFont(":/fonts/monospace");
GUIUtil::LoadFont(QStringLiteral(":/fonts/monospace"));
/// 2. Parse command-line options. We do this after qt in order to show an error if there are problems parsing these
// Command-line options take precedence:

View File

@ -493,6 +493,12 @@ bool hasEntryData(const QAbstractItemView *view, int column, int role)
return !selection.at(0).data(role).toString().isEmpty();
}
void LoadFont(const QString& file_name)
{
const int id = QFontDatabase::addApplicationFont(file_name);
assert(id != -1);
}
QString getDefaultDataDirectory()
{
return PathToQString(GetDefaultDataDir());

View File

@ -172,6 +172,11 @@ namespace GUIUtil
void setClipboard(const QString& str);
/**
* Loads the font from the file specified by file_name, aborts if it fails.
*/
void LoadFont(const QString& file_name);
/**
* Determine default data directory for operating system.
*/