From 71379aac66f002e8bc87bc3bc936fbfc4b688b27 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Wed, 16 Dec 2020 18:15:54 -0800 Subject: [PATCH] Qt: Unify monospace font usage --- CHANGES | 1 + src/platform/qt/AssetInfo.cpp | 7 ++++--- src/platform/qt/AssetTile.cpp | 3 +-- src/platform/qt/CheatsModel.cpp | 4 ++-- src/platform/qt/GBAApp.cpp | 4 ++++ src/platform/qt/GBAApp.h | 5 +++++ src/platform/qt/IOViewer.cpp | 4 ++-- src/platform/qt/MapView.cpp | 1 - src/platform/qt/MemoryModel.cpp | 3 +-- src/platform/qt/MessagePainter.cpp | 7 +++---- src/platform/qt/ObjView.cpp | 3 +-- src/platform/qt/PaletteView.cpp | 3 +-- src/platform/qt/RegisterView.cpp | 4 ++-- src/platform/qt/TileView.cpp | 1 - 14 files changed, 27 insertions(+), 23 deletions(-) diff --git a/CHANGES b/CHANGES index 730cc6804..ab7ff318b 100644 --- a/CHANGES +++ b/CHANGES @@ -113,6 +113,7 @@ Misc: - Qt: Window title updates can be disabled (closes mgba.io/i/1912) - Qt: Redo OpenGL context thread handling (fixes mgba.io/i/1724) - Qt: Discard additional frame draws if waiting fails + - Qt: Unify monospace font usage - SDL: Fall back to sw blit if OpenGL init fails - Util: Reset vector size on deinit - VFS: Change semantics of VFile.sync on mapped files (fixes mgba.io/i/1730) diff --git a/src/platform/qt/AssetInfo.cpp b/src/platform/qt/AssetInfo.cpp index f70d8ea0d..aaab59a42 100644 --- a/src/platform/qt/AssetInfo.cpp +++ b/src/platform/qt/AssetInfo.cpp @@ -5,7 +5,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "AssetInfo.h" -#include +#include "GBAApp.h" + #include using namespace QGBA; @@ -19,7 +20,7 @@ void AssetInfo::addCustomProperty(const QString& id, const QString& visibleName) QHBoxLayout* newLayout = new QHBoxLayout; newLayout->addWidget(new QLabel(visibleName)); QLabel* value = new QLabel; - value->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); + value->setFont(GBAApp::monospaceFont()); value->setAlignment(Qt::AlignRight); newLayout->addWidget(value); m_customProperties[id] = value; @@ -37,4 +38,4 @@ void AssetInfo::setCustomProperty(const QString& id, const QVariant& value) { int AssetInfo::customLocation(const QString&) { return layout()->count(); -} \ No newline at end of file +} diff --git a/src/platform/qt/AssetTile.cpp b/src/platform/qt/AssetTile.cpp index 437ece086..bad2a5d51 100644 --- a/src/platform/qt/AssetTile.cpp +++ b/src/platform/qt/AssetTile.cpp @@ -8,7 +8,6 @@ #include "CoreController.h" #include "GBAApp.h" -#include #include #include @@ -32,7 +31,7 @@ AssetTile::AssetTile(QWidget* parent) connect(m_ui.preview, &Swatch::indexPressed, this, &AssetTile::selectColor); - const QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont); + const QFont font = GBAApp::monospaceFont(); m_ui.tileId->setFont(font); m_ui.paletteId->setFont(font); diff --git a/src/platform/qt/CheatsModel.cpp b/src/platform/qt/CheatsModel.cpp index a04b30b1f..419e3cc26 100644 --- a/src/platform/qt/CheatsModel.cpp +++ b/src/platform/qt/CheatsModel.cpp @@ -5,6 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "CheatsModel.h" +#include "GBAApp.h" #include "LogController.h" #include "VFileDevice.h" @@ -19,8 +20,7 @@ CheatsModel::CheatsModel(mCheatDevice* device, QObject* parent) : QAbstractItemModel(parent) , m_device(device) { - m_font.setFamily("Source Code Pro"); - m_font.setStyleHint(QFont::Monospace); + m_font = GBAApp::monospaceFont(); } QVariant CheatsModel::data(const QModelIndex& index, int role) const { diff --git a/src/platform/qt/GBAApp.cpp b/src/platform/qt/GBAApp.cpp index c16f89535..f6a0f96e8 100644 --- a/src/platform/qt/GBAApp.cpp +++ b/src/platform/qt/GBAApp.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -35,11 +36,14 @@ static GBAApp* g_app = nullptr; mLOG_DEFINE_CATEGORY(QT, "Qt", "platform.qt"); +QFont GBAApp::s_monospace; + GBAApp::GBAApp(int& argc, char* argv[], ConfigController* config) : QApplication(argc, argv) , m_configController(config) { g_app = this; + s_monospace = QFontDatabase::systemFont(QFontDatabase::FixedFont); #ifdef BUILD_SDL SDL_Init(SDL_INIT_NOPARACHUTE); diff --git a/src/platform/qt/GBAApp.h b/src/platform/qt/GBAApp.h index e5cbb99a9..8f2f1dd6f 100644 --- a/src/platform/qt/GBAApp.h +++ b/src/platform/qt/GBAApp.h @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -56,6 +57,8 @@ public: static QString dataDir(); + static QFont monospaceFont() { return s_monospace; } + QList windows() { return m_windows; } Window* newWindow(); @@ -111,6 +114,8 @@ private: QThreadPool m_workerThreads; qint64 m_nextJob = 1; + static QFont s_monospace; + NoIntroDB* m_db = nullptr; }; diff --git a/src/platform/qt/IOViewer.cpp b/src/platform/qt/IOViewer.cpp index 92dfd1814..53be36db1 100644 --- a/src/platform/qt/IOViewer.cpp +++ b/src/platform/qt/IOViewer.cpp @@ -6,9 +6,9 @@ #include "IOViewer.h" #include "CoreController.h" +#include "GBAApp.h" #include -#include #include #include @@ -1037,7 +1037,7 @@ IOViewer::IOViewer(std::shared_ptr controller, QWidget* parent) m_ui.regSelect->addItem("0x0400" + QString("%1: %2").arg(i << 1, 4, 16, QChar('0')).toUpper().arg(reg), i << 1); } - const QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont); + const QFont font = GBAApp::monospaceFont(); m_ui.regValue->setFont(font); connect(m_ui.buttonBox, &QDialogButtonBox::clicked, this, &IOViewer::buttonPressed); diff --git a/src/platform/qt/MapView.cpp b/src/platform/qt/MapView.cpp index 72936257a..c8f2ac68c 100644 --- a/src/platform/qt/MapView.cpp +++ b/src/platform/qt/MapView.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include diff --git a/src/platform/qt/MemoryModel.cpp b/src/platform/qt/MemoryModel.cpp index 723844b9c..ab21408d0 100644 --- a/src/platform/qt/MemoryModel.cpp +++ b/src/platform/qt/MemoryModel.cpp @@ -27,8 +27,7 @@ using namespace QGBA; MemoryModel::MemoryModel(QWidget* parent) : QAbstractScrollArea(parent) { - m_font.setFamily("Source Code Pro"); - m_font.setStyleHint(QFont::Monospace); + m_font = GBAApp::monospaceFont(); #ifdef Q_OS_MAC m_font.setPointSize(12); #else diff --git a/src/platform/qt/MessagePainter.cpp b/src/platform/qt/MessagePainter.cpp index 379fc7bdf..fecff4917 100644 --- a/src/platform/qt/MessagePainter.cpp +++ b/src/platform/qt/MessagePainter.cpp @@ -5,9 +5,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "MessagePainter.h" -#include +#include "GBAApp.h" -#include +#include #include @@ -16,8 +16,7 @@ using namespace QGBA; MessagePainter::MessagePainter(QObject* parent) : QObject(parent) { - m_messageFont.setFamily("Source Code Pro"); - m_messageFont.setStyleHint(QFont::Monospace); + m_messageFont = GBAApp::monospaceFont(); m_messageFont.setPixelSize(13); connect(&m_messageTimer, &QTimer::timeout, this, &MessagePainter::clearMessage); m_messageTimer.setSingleShot(true); diff --git a/src/platform/qt/ObjView.cpp b/src/platform/qt/ObjView.cpp index 3044f9259..1dfc70935 100644 --- a/src/platform/qt/ObjView.cpp +++ b/src/platform/qt/ObjView.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include @@ -34,7 +33,7 @@ ObjView::ObjView(std::shared_ptr controller, QWidget* parent) m_ui.setupUi(this); m_ui.tile->setController(controller); - const QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont); + const QFont font = GBAApp::monospaceFont(); m_ui.x->setFont(font); m_ui.y->setFont(font); diff --git a/src/platform/qt/PaletteView.cpp b/src/platform/qt/PaletteView.cpp index 9a7a1206b..9c72976dc 100644 --- a/src/platform/qt/PaletteView.cpp +++ b/src/platform/qt/PaletteView.cpp @@ -11,7 +11,6 @@ #include "VFileDevice.h" #include -#include #include #ifdef M_CORE_GBA @@ -48,7 +47,7 @@ PaletteView::PaletteView(std::shared_ptr controller, QWidget* pa m_ui.selected->setDimensions(QSize(1, 1)); updatePalette(); - const QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont); + const QFont font = GBAApp::monospaceFont(); m_ui.hexcode->setFont(font); m_ui.value->setFont(font); diff --git a/src/platform/qt/RegisterView.cpp b/src/platform/qt/RegisterView.cpp index c098ad2c0..130f44f96 100644 --- a/src/platform/qt/RegisterView.cpp +++ b/src/platform/qt/RegisterView.cpp @@ -6,6 +6,7 @@ #include "RegisterView.h" #include "CoreController.h" +#include "GBAApp.h" #ifdef M_CORE_GBA #include @@ -14,7 +15,6 @@ #include #endif -#include #include #include @@ -74,7 +74,7 @@ RegisterView::RegisterView(std::shared_ptr controller, QWidget* void RegisterView::addRegisters(const QStringList& names) { QFormLayout* form = static_cast(layout()); - const QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont); + const QFont font = GBAApp::monospaceFont(); for (const auto& reg : names) { QLabel* value = new QLabel; value->setTextInteractionFlags(Qt::TextSelectableByMouse); diff --git a/src/platform/qt/TileView.cpp b/src/platform/qt/TileView.cpp index 166114a1d..7fa0f09a7 100644 --- a/src/platform/qt/TileView.cpp +++ b/src/platform/qt/TileView.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #ifdef M_CORE_GB