From f786c078c2004d0b0b05e9793828d069104b09b1 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Wed, 28 Feb 2018 01:21:58 +0100 Subject: [PATCH] Qt: enable custom fonts for stylesheets and add random object names --- rpcs3/rpcs3_app.cpp | 18 +++++++++++++++++- rpcs3/rpcs3_app.h | 2 ++ rpcs3/rpcs3qt/auto_pause_settings_dialog.cpp | 1 + rpcs3/rpcs3qt/cg_disasm_window.cpp | 1 + rpcs3/rpcs3qt/kernel_explorer.cpp | 1 - rpcs3/rpcs3qt/log_frame.cpp | 3 +++ rpcs3/rpcs3qt/memory_string_searcher.cpp | 1 + rpcs3/rpcs3qt/rsx_debugger.cpp | 1 + rpcs3/rpcs3qt/settings_dialog.cpp | 11 ++++++----- rpcs3/rpcs3qt/settings_dialog.ui | 4 ++-- rpcs3/rpcs3qt/trophy_manager_dialog.cpp | 1 + rpcs3/rpcs3qt/trophy_notification_frame.cpp | 12 +++++++----- rpcs3/rpcs3qt/vfs_dialog.cpp | 1 + 13 files changed, 43 insertions(+), 14 deletions(-) diff --git a/rpcs3/rpcs3_app.cpp b/rpcs3/rpcs3_app.cpp index 865875f128..b9b33e72cc 100644 --- a/rpcs3/rpcs3_app.cpp +++ b/rpcs3/rpcs3_app.cpp @@ -10,7 +10,6 @@ #include "rpcs3qt/trophy_notification_helper.h" #include "rpcs3qt/save_data_dialog.h" -#include "rpcs3qt/msg_dialog_frame.h" #include "Emu/Io/Null/NullKeyboardHandler.h" #include "basic_keyboard_handler.h" @@ -356,6 +355,23 @@ void rpcs3_app::OnChangeStyleSheetRequest(const QString& sheetFilePath) } else if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { + QString config_dir = qstr(fs::get_config_dir()); + + // HACK: dev_flash must be mounted for vfs to work for loading fonts. + vfs::mount("dev_flash", fmt::replace_all(g_cfg.vfs.dev_flash, "$(EmulatorDir)", Emu.GetEmuDir())); + + // Add PS3 fonts + QDirIterator ps3_font_it(qstr(vfs::get("/dev_flash/data/font/")), QStringList() << "*.ttf", QDir::Files, QDirIterator::Subdirectories); + while (ps3_font_it.hasNext()) + QFontDatabase::addApplicationFont(ps3_font_it.next()); + + // Add custom fonts + QDirIterator custom_font_it(config_dir + "fonts/", QStringList() << "*.ttf", QDir::Files, QDirIterator::Subdirectories); + while (custom_font_it.hasNext()) + QFontDatabase::addApplicationFont(custom_font_it.next()); + + // Set root for stylesheets + QDir::setCurrent(config_dir); setStyleSheet(file.readAll()); file.close(); } diff --git a/rpcs3/rpcs3_app.h b/rpcs3/rpcs3_app.h index 6bc7c97bcf..71951c7efd 100644 --- a/rpcs3/rpcs3_app.h +++ b/rpcs3/rpcs3_app.h @@ -7,6 +7,7 @@ #include "basic_mouse_handler.h" #include "Utilities/Config.h" +#include "Emu/VFS.h" #include "Emu/RSX/GSRender.h" #include "Emu/Io/KeyboardHandler.h" #include "Emu/Io/PadHandler.h" @@ -19,6 +20,7 @@ #include "rpcs3qt/emu_settings.h" #include +#include /** RPCS3 Application Class * The point of this class is to do application initialization and to hold onto the main window. The main thing I intend this class to do, for now, is to initialize callbacks and the main_window. diff --git a/rpcs3/rpcs3qt/auto_pause_settings_dialog.cpp b/rpcs3/rpcs3qt/auto_pause_settings_dialog.cpp index 7ce872ccfc..61643fb75a 100644 --- a/rpcs3/rpcs3qt/auto_pause_settings_dialog.cpp +++ b/rpcs3/rpcs3qt/auto_pause_settings_dialog.cpp @@ -37,6 +37,7 @@ auto_pause_settings_dialog::auto_pause_settings_dialog(QWidget *parent) : QDialo setMinimumSize(QSize(400, 360)); setWindowTitle(tr("Auto Pause Manager")); + setObjectName("auto_pause_manager"); //Events connect(pauseList, &QTableWidget::customContextMenuRequested, this, &auto_pause_settings_dialog::ShowContextMenu); diff --git a/rpcs3/rpcs3qt/cg_disasm_window.cpp b/rpcs3/rpcs3qt/cg_disasm_window.cpp index ab5097dbe4..1960e08b89 100644 --- a/rpcs3/rpcs3qt/cg_disasm_window.cpp +++ b/rpcs3/rpcs3qt/cg_disasm_window.cpp @@ -23,6 +23,7 @@ inline std::string sstr(const QString& _in) { return _in.toStdString(); } cg_disasm_window::cg_disasm_window(std::shared_ptr xSettings): xgui_settings(xSettings) { setWindowTitle(tr("Cg Disasm")); + setObjectName("cg_disasm"); setAttribute(Qt::WA_DeleteOnClose); setAcceptDrops(true); setMinimumSize(QSize(200, 150)); // seems fine on win 10 diff --git a/rpcs3/rpcs3qt/kernel_explorer.cpp b/rpcs3/rpcs3qt/kernel_explorer.cpp index 0c4a0d0408..a02eae4a09 100644 --- a/rpcs3/rpcs3qt/kernel_explorer.cpp +++ b/rpcs3/rpcs3qt/kernel_explorer.cpp @@ -54,7 +54,6 @@ kernel_explorer::kernel_explorer(QWidget* parent) : QDialog(parent) // Events connect(button_refresh, &QAbstractButton::clicked, this, &kernel_explorer::Update); - // Fill the wxTreeCtrl Update(); }; diff --git a/rpcs3/rpcs3qt/log_frame.cpp b/rpcs3/rpcs3qt/log_frame.cpp index e3d08b9ae5..95c04c5c04 100644 --- a/rpcs3/rpcs3qt/log_frame.cpp +++ b/rpcs3/rpcs3qt/log_frame.cpp @@ -7,6 +7,7 @@ #include #include #include +#include constexpr auto qstr = QString::fromStdString; @@ -103,6 +104,8 @@ static gui_listener s_gui_listener; log_frame::log_frame(std::shared_ptr guiSettings, QWidget *parent) : QDockWidget(tr("Log"), parent), xgui_settings(guiSettings) { m_tabWidget = new QTabWidget; + m_tabWidget->setObjectName("tab_widget_log"); + m_tabWidget->tabBar()->setObjectName("tab_bar_log"); m_log = new QTextEdit(m_tabWidget); m_log->setObjectName("log_frame"); diff --git a/rpcs3/rpcs3qt/memory_string_searcher.cpp b/rpcs3/rpcs3qt/memory_string_searcher.cpp index 378f2118f7..6063213107 100644 --- a/rpcs3/rpcs3qt/memory_string_searcher.cpp +++ b/rpcs3/rpcs3qt/memory_string_searcher.cpp @@ -7,6 +7,7 @@ memory_string_searcher::memory_string_searcher(QWidget* parent) : QDialog(parent) { setWindowTitle(tr("String Searcher")); + setObjectName("memory_string_searcher"); setAttribute(Qt::WA_DeleteOnClose); m_addr_line = new QLineEdit(this); diff --git a/rpcs3/rpcs3qt/rsx_debugger.cpp b/rpcs3/rpcs3qt/rsx_debugger.cpp index 866d2da17f..93f75dbea6 100644 --- a/rpcs3/rpcs3qt/rsx_debugger.cpp +++ b/rpcs3/rpcs3qt/rsx_debugger.cpp @@ -17,6 +17,7 @@ rsx_debugger::rsx_debugger(QWidget* parent) , exit(false) { setWindowTitle(tr("RSX Debugger")); + setObjectName("rsx_debugger"); setAttribute(Qt::WA_DeleteOnClose); //Fonts and Colors diff --git a/rpcs3/rpcs3qt/settings_dialog.cpp b/rpcs3/rpcs3qt/settings_dialog.cpp index 4253dd7cf9..386f7f7055 100644 --- a/rpcs3/rpcs3qt/settings_dialog.cpp +++ b/rpcs3/rpcs3qt/settings_dialog.cpp @@ -32,13 +32,14 @@ settings_dialog::settings_dialog(std::shared_ptr guiSettings, std: { ui->setupUi(this); ui->cancelButton->setFocus(); - ui->tabWidget->setUsesScrollButtons(false); + ui->tab_widget_settings->setUsesScrollButtons(false); + ui->tab_widget_settings->tabBar()->setObjectName("tab_bar_settings"); bool showDebugTab = xgui_settings->GetValue(gui::m_showDebugTab).toBool(); xgui_settings->SetValue(gui::m_showDebugTab, showDebugTab); if (!showDebugTab) { - ui->tabWidget->removeTab(7); + ui->tab_widget_settings->removeTab(7); } // Add description labels @@ -111,7 +112,7 @@ settings_dialog::settings_dialog(std::shared_ptr guiSettings, std: connect(ui->cancelButton, &QAbstractButton::clicked, this, &QWidget::close); - connect(ui->tabWidget, &QTabWidget::currentChanged, [=]() + connect(ui->tab_widget_settings, &QTabWidget::currentChanged, [=]() { ui->cancelButton->setFocus(); }); @@ -1081,7 +1082,7 @@ int settings_dialog::exec() // If we use setCurrentIndex now we will miraculously see a resize of the dialog as soon as we // switch to the cpu tab after conjuring the settings_dialog with another tab opened first. // Weirdly enough this won't happen if we change the tab order so that anything else is at index 0. - QTimer::singleShot(0, [=]{ ui->tabWidget->setCurrentIndex(m_tab_Index); }); + QTimer::singleShot(0, [=]{ ui->tab_widget_settings->setCurrentIndex(m_tab_Index); }); return QDialog::exec(); } @@ -1105,7 +1106,7 @@ bool settings_dialog::eventFilter(QObject* object, QEvent* event) return QDialog::eventFilter(object, event); } - int i = ui->tabWidget->currentIndex(); + int i = ui->tab_widget_settings->currentIndex(); QLabel* label = m_description_labels[i].first; if (event->type() == QEvent::Enter) diff --git a/rpcs3/rpcs3qt/settings_dialog.ui b/rpcs3/rpcs3qt/settings_dialog.ui index 693f5c8ca7..ba40328f98 100644 --- a/rpcs3/rpcs3qt/settings_dialog.ui +++ b/rpcs3/rpcs3qt/settings_dialog.ui @@ -25,7 +25,7 @@ - + true @@ -36,7 +36,7 @@ - 6 + 0 diff --git a/rpcs3/rpcs3qt/trophy_manager_dialog.cpp b/rpcs3/rpcs3qt/trophy_manager_dialog.cpp index 81715131ff..6b18290d8b 100644 --- a/rpcs3/rpcs3qt/trophy_manager_dialog.cpp +++ b/rpcs3/rpcs3qt/trophy_manager_dialog.cpp @@ -41,6 +41,7 @@ trophy_manager_dialog::trophy_manager_dialog(std::shared_ptr gui_s { // Nonspecific widget settings setWindowTitle(tr("Trophy Manager")); + setObjectName("trophy_manager"); m_icon_height = m_gui_settings->GetValue(gui::tr_icon_height).toInt(); m_show_locked_trophies = m_gui_settings->GetValue(gui::tr_show_locked).toBool(); diff --git a/rpcs3/rpcs3qt/trophy_notification_frame.cpp b/rpcs3/rpcs3qt/trophy_notification_frame.cpp index b3de736ea3..609c6684bc 100644 --- a/rpcs3/rpcs3qt/trophy_notification_frame.cpp +++ b/rpcs3/rpcs3qt/trophy_notification_frame.cpp @@ -10,6 +10,7 @@ constexpr auto qstr = QString::fromStdString; trophy_notification_frame::trophy_notification_frame(const std::vector& imgBuffer, const SceNpTrophyDetails& trophy, int height) : QWidget() { + setObjectName("trophy_notification_frame"); setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); setAttribute(Qt::WA_ShowWithoutActivating); @@ -42,14 +43,14 @@ trophy_notification_frame::trophy_notification_frame(const std::vector& i QString trophyType = ""; switch (trophy.trophyGrade) { - case SCE_NP_TROPHY_GRADE_BRONZE: trophyType = "bronze"; break; - case SCE_NP_TROPHY_GRADE_SILVER: trophyType = "silver"; break; - case SCE_NP_TROPHY_GRADE_GOLD: trophyType = "gold"; break; + case SCE_NP_TROPHY_GRADE_BRONZE: trophyType = "bronze"; break; + case SCE_NP_TROPHY_GRADE_SILVER: trophyType = "silver"; break; + case SCE_NP_TROPHY_GRADE_GOLD: trophyType = "gold"; break; case SCE_NP_TROPHY_GRADE_PLATINUM: trophyType = "platinum"; break; default: break; } - trophyName->setText("You have earned the " + trophyType + " trophy\n" + qstr(trophy.name)); + trophyName->setText(tr("You have earned the %1 trophy\n").arg(trophyType) + qstr(trophy.name)); trophyName->setAutoFillBackground(true); trophyName->setPalette(black_background); @@ -60,7 +61,8 @@ trophy_notification_frame::trophy_notification_frame(const std::vector& i setPalette(black_background); // I may consider moving this code later to be done at a better location. - QTimer::singleShot(TROPHY_TIMEOUT_MS, [this]() { + QTimer::singleShot(TROPHY_TIMEOUT_MS, [this]() + { deleteLater(); }); } diff --git a/rpcs3/rpcs3qt/vfs_dialog.cpp b/rpcs3/rpcs3qt/vfs_dialog.cpp index c52dccaa10..5ffdd4fb3e 100644 --- a/rpcs3/rpcs3qt/vfs_dialog.cpp +++ b/rpcs3/rpcs3qt/vfs_dialog.cpp @@ -83,4 +83,5 @@ vfs_dialog::vfs_dialog(std::shared_ptr guiSettings, std::shared_pt setLayout(vbox); setWindowTitle(tr("Virtual File System")); + setObjectName("vfs_dialog"); }