From fcfca6efda24839fe2cb9b49f148e7d6c664a80f Mon Sep 17 00:00:00 2001 From: Megamouse Date: Thu, 1 Jun 2023 01:06:30 +0200 Subject: [PATCH] Qt: add ability to style richtext href links --- bin/GuiConfigs/Darker Style by TheMitoSan.qss | 3 +++ bin/GuiConfigs/Envy.qss | 3 +++ bin/GuiConfigs/Kuroi (Dark) by Ani.qss | 3 +++ .../ModernBlue Theme by TheMitoSan.qss | 3 +++ bin/GuiConfigs/Nekotekina by GooseWing.qss | 3 +++ bin/GuiConfigs/Skyline (Nightfall).qss | 3 +++ rpcs3/rpcs3qt/about_dialog.cpp | 11 ++++++++++ rpcs3/rpcs3qt/about_dialog.ui | 3 --- rpcs3/rpcs3qt/gui_application.cpp | 6 ++--- rpcs3/rpcs3qt/gui_settings.cpp | 2 ++ rpcs3/rpcs3qt/gui_settings.h | 2 +- rpcs3/rpcs3qt/main_window.cpp | 4 ++-- rpcs3/rpcs3qt/qt_utils.cpp | 21 ++++++++++++++++++ rpcs3/rpcs3qt/qt_utils.h | 9 ++++++++ rpcs3/rpcs3qt/tooltips.h | 11 +++++----- rpcs3/rpcs3qt/welcome_dialog.cpp | 22 +++++++++++++++++++ rpcs3/rpcs3qt/welcome_dialog.ui | 6 ----- 17 files changed, 95 insertions(+), 20 deletions(-) diff --git a/bin/GuiConfigs/Darker Style by TheMitoSan.qss b/bin/GuiConfigs/Darker Style by TheMitoSan.qss index c4d867cd1b..15be0a5fd3 100644 --- a/bin/GuiConfigs/Darker Style by TheMitoSan.qss +++ b/bin/GuiConfigs/Darker Style by TheMitoSan.qss @@ -384,3 +384,6 @@ QTreeView::branch:open:has-children:has-siblings:hover { #game_list_grid_item[focus="true"] #game_list_grid_item_title_label { background-color: #0078D7; } + +/* Richtext link color */ +QLabel#richtext_link_color { color: #87cefa; } diff --git a/bin/GuiConfigs/Envy.qss b/bin/GuiConfigs/Envy.qss index 8bc80166c1..fbdda99643 100644 --- a/bin/GuiConfigs/Envy.qss +++ b/bin/GuiConfigs/Envy.qss @@ -680,3 +680,6 @@ QTreeView::branch:open:has-children:has-siblings:hover { background-color: #2d3038; color: #8cf944; } + +/* Richtext link color */ +QLabel#richtext_link_color { color: #8cf944; } diff --git a/bin/GuiConfigs/Kuroi (Dark) by Ani.qss b/bin/GuiConfigs/Kuroi (Dark) by Ani.qss index ba46bb5831..7e7f5d4b84 100644 --- a/bin/GuiConfigs/Kuroi (Dark) by Ani.qss +++ b/bin/GuiConfigs/Kuroi (Dark) by Ani.qss @@ -384,3 +384,6 @@ QTreeView::branch:open:has-children:has-siblings:hover { color: #e6e6e6; background-color: #4c4b4b; } + +/* Richtext link color */ +QLabel#richtext_link_color { color: #87cefa; } diff --git a/bin/GuiConfigs/ModernBlue Theme by TheMitoSan.qss b/bin/GuiConfigs/ModernBlue Theme by TheMitoSan.qss index 44f7902353..f8d41c3af0 100644 --- a/bin/GuiConfigs/ModernBlue Theme by TheMitoSan.qss +++ b/bin/GuiConfigs/ModernBlue Theme by TheMitoSan.qss @@ -381,3 +381,6 @@ QTreeView::branch:open:has-children:has-siblings:hover { #game_list_grid_item[focus="true"] #game_list_grid_item_title_label { background-color: #0078D7; } + +/* Richtext link color */ +QLabel#richtext_link_color { color: #87cefa; } diff --git a/bin/GuiConfigs/Nekotekina by GooseWing.qss b/bin/GuiConfigs/Nekotekina by GooseWing.qss index eba076ff55..435d550755 100755 --- a/bin/GuiConfigs/Nekotekina by GooseWing.qss +++ b/bin/GuiConfigs/Nekotekina by GooseWing.qss @@ -504,3 +504,6 @@ QWidget#trophy_notification_frame { background-color: #4d4940; color: #ffd785; } + +/* Richtext link color */ +QLabel#richtext_link_color { color: #87cefa; } diff --git a/bin/GuiConfigs/Skyline (Nightfall).qss b/bin/GuiConfigs/Skyline (Nightfall).qss index 5271643ac3..fbd6b25194 100644 --- a/bin/GuiConfigs/Skyline (Nightfall).qss +++ b/bin/GuiConfigs/Skyline (Nightfall).qss @@ -720,3 +720,6 @@ QTreeView::branch:open:has-children:has-siblings:hover { background-color: #0f1d36; color: #2397ff; } + +/* Richtext link color */ +QLabel#richtext_link_color { color: #0074e7; } diff --git a/rpcs3/rpcs3qt/about_dialog.cpp b/rpcs3/rpcs3qt/about_dialog.cpp index c6422afeb1..34f20e9316 100644 --- a/rpcs3/rpcs3qt/about_dialog.cpp +++ b/rpcs3/rpcs3qt/about_dialog.cpp @@ -2,6 +2,7 @@ #include "ui_about_dialog.h" #include "rpcs3_version.h" +#include "qt_utils.h" #include #include @@ -14,6 +15,16 @@ about_dialog::about_dialog(QWidget* parent) : QDialog(parent), ui(new Ui::about_ ui->close->setDefault(true); ui->icon->load(QStringLiteral(":/rpcs3.svg")); ui->version->setText(tr("RPCS3 Version: %1").arg(QString::fromStdString(rpcs3::get_verbose_version()))); + ui->description->setText(tr( + R"( +

+ RPCS3 is an open-source Sony PlayStation 3 emulator and debugger.
+ It is written in C++ for Windows, Linux, FreeBSD and MacOS funded with Patreon.
+ Our developers and contributors are always working hard to ensure this project is the best that it can be.
+ There are still plenty of implementations to make and optimizations to do. +

+ )" + ).arg(gui::utils::get_link_style())); // Events connect(ui->gitHub, &QPushButton::clicked, [] { QDesktopServices::openUrl(QUrl("https://www.github.com/RPCS3")); }); diff --git a/rpcs3/rpcs3qt/about_dialog.ui b/rpcs3/rpcs3qt/about_dialog.ui index 00e1256647..f50f953d0d 100644 --- a/rpcs3/rpcs3qt/about_dialog.ui +++ b/rpcs3/rpcs3qt/about_dialog.ui @@ -123,9 +123,6 @@ true - - <html><head/><body><p>RPCS3 is an open-source Sony PlayStation 3 emulator and debugger.<br/>It is written in C++ for Windows, Linux, FreeBSD and MacOS funded with <a href="https://www.patreon.com/Nekotekina"><span style=" text-decoration: underline; color:#0000ff;">Patreon</span></a>.<br/>Our developers and contributors are always working hard to ensure this project is the best that it can be.<br/>There are still plenty of implementations to make and optimizations to do.</p></body></html> - Qt::RichText diff --git a/rpcs3/rpcs3qt/gui_application.cpp b/rpcs3/rpcs3qt/gui_application.cpp index 9b92cfdab3..32924a291a 100644 --- a/rpcs3/rpcs3qt/gui_application.cpp +++ b/rpcs3/rpcs3qt/gui_application.cpp @@ -77,17 +77,17 @@ bool gui_application::Init() msg.setTextFormat(Qt::RichText); msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msg.setDefaultButton(QMessageBox::No); - msg.setText(QString(tr( + msg.setText(tr( R"(

Please understand that this build is not an official RPCS3 release.
This build contains changes that may break games, or even damage your data.
- We recommend to download and use the official build from the RPCS3 website.

+ We recommend to download and use the official build from the RPCS3 website.

Build origin: %1
Do you wish to use this build anyway?

)" - )).arg(Qt::convertFromPlainText(branch_name.data()))); + ).arg(gui::utils::get_link_style()).arg(Qt::convertFromPlainText(branch_name.data()))); msg.layout()->setSizeConstraint(QLayout::SetFixedSize); if (msg.exec() == QMessageBox::No) diff --git a/rpcs3/rpcs3qt/gui_settings.cpp b/rpcs3/rpcs3qt/gui_settings.cpp index 0447c5ab05..74ab101544 100644 --- a/rpcs3/rpcs3qt/gui_settings.cpp +++ b/rpcs3/rpcs3qt/gui_settings.cpp @@ -13,6 +13,8 @@ LOG_CHANNEL(cfg_log, "CFG"); namespace gui { + QString stylesheet; + QString get_game_list_column_name(game_list_columns col) { switch (col) diff --git a/rpcs3/rpcs3qt/gui_settings.h b/rpcs3/rpcs3qt/gui_settings.h index dd8f44ae8b..c1898d3fa7 100644 --- a/rpcs3/rpcs3qt/gui_settings.h +++ b/rpcs3/rpcs3qt/gui_settings.h @@ -10,7 +10,7 @@ namespace gui { - static QString stylesheet; + extern QString stylesheet; enum custom_roles { diff --git a/rpcs3/rpcs3qt/main_window.cpp b/rpcs3/rpcs3qt/main_window.cpp index 73b1054168..b2bc6091a0 100644 --- a/rpcs3/rpcs3qt/main_window.cpp +++ b/rpcs3/rpcs3qt/main_window.cpp @@ -274,7 +274,7 @@ bool main_window::OnMissingFw() { const QString title = tr("Missing Firmware Detected!"); const QString message = tr("Commercial games require the firmware (PS3UPDAT.PUP file) to be installed." - "\n
For information about how to obtain the required firmware read the quickstart guide."); + "\n
For information about how to obtain the required firmware read the quickstart guide.").arg(gui::utils::get_link_style()); QMessageBox mb(QMessageBox::Question, title, message, QMessageBox::Ok | QMessageBox::Cancel, this, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint); mb.setTextFormat(Qt::RichText); @@ -445,7 +445,7 @@ void main_window::show_boot_error(game_boot_result status) message = tr("Unknown error."); break; } - const QString link = tr("

For information on setting up the emulator and dumping your PS3 games, read the quickstart guide."); + const QString link = tr("

For information on setting up the emulator and dumping your PS3 games, read the quickstart guide.").arg(gui::utils::get_link_style()); QMessageBox msg; msg.setWindowTitle(tr("Boot Failed")); diff --git a/rpcs3/rpcs3qt/qt_utils.cpp b/rpcs3/rpcs3qt/qt_utils.cpp index a179b28cb0..5dd0f8b456 100644 --- a/rpcs3/rpcs3qt/qt_utils.cpp +++ b/rpcs3/rpcs3qt/qt_utils.cpp @@ -1,5 +1,6 @@ #include "stdafx.h" #include "qt_utils.h" +#include "gui_settings.h" #include #include #include @@ -198,6 +199,26 @@ namespace gui return l.sizeHint().width(); } + QColor get_link_color(const QString& name) + { + return gui::utils::get_label_color(name); + } + + QString get_link_color_string(const QString& name) + { + return get_link_color(name).name(); + } + + QString get_link_style(const QString& name) + { + if (!gui::stylesheet.contains(name)) + { + return {}; + } + + return QString("style=\"color: %0;\"").arg(get_link_color_string(name)); + } + QPixmap get_centered_pixmap(QPixmap pixmap, const QSize& icon_size, int offset_x, int offset_y, qreal device_pixel_ratio, Qt::TransformationMode mode) { // Create empty canvas for expanded image diff --git a/rpcs3/rpcs3qt/qt_utils.h b/rpcs3/rpcs3qt/qt_utils.h index 32312b34ae..6aa6032242 100644 --- a/rpcs3/rpcs3qt/qt_utils.h +++ b/rpcs3/rpcs3qt/qt_utils.h @@ -74,6 +74,15 @@ namespace gui // Returns the width of the text int get_label_width(const QString& text, const QFont* font = nullptr); + // Returns the color for richtext links. + QColor get_link_color(const QString& name = "richtext_link_color"); + + // Returns the color string for richtext links. + QString get_link_color_string(const QString& name = "richtext_link_color"); + + // Returns the style for richtext links. e.g. style="color: #123456;" + QString get_link_style(const QString& name = "richtext_link_color"); + template void set_font_size(T& qobj, int size) { diff --git a/rpcs3/rpcs3qt/tooltips.h b/rpcs3/rpcs3qt/tooltips.h index 13b99cd41c..f7a31cdd34 100644 --- a/rpcs3/rpcs3qt/tooltips.h +++ b/rpcs3/rpcs3qt/tooltips.h @@ -1,5 +1,6 @@ #pragma once +#include "qt_utils.h" #include #include @@ -251,17 +252,17 @@ public: const QString null = tr("This controller is disabled and will appear as disconnected to software. Choose another handler to enable it."); const QString ldd_pad = tr("This port is currently assigned to a custom controller by the application and can't be changed."); const QString keyboard = tr("While it is possible to use a keyboard as a pad in RPCS3, the use of an actual controller is strongly recommended.
To bind mouse movement to a button or joystick, click on the desired button to activate it, then click and hold while dragging the mouse to a direction."); - const QString ds3_windows = tr("In order to use the DualShock 3 handler, you need to install the official DualShock 3 driver first.
See the
RPCS3 Wiki for instructions."); - const QString ds3_linux = tr("In order to use the DualShock 3 handler, you might need to add udev rules to let RPCS3 access the controller.
See the RPCS3 Wiki for instructions."); + const QString ds3_windows = tr("In order to use the DualShock 3 handler, you need to install the official DualShock 3 driver first.
See the RPCS3 Wiki for instructions.").arg(gui::utils::get_link_style()); + const QString ds3_linux = tr("In order to use the DualShock 3 handler, you might need to add udev rules to let RPCS3 access the controller.
See the RPCS3 Wiki for instructions.").arg(gui::utils::get_link_style()); const QString ds3_other = tr("The DualShock 3 handler is recommended for official DualShock 3 controllers."); const QString ds4_windows = tr("If you have any issues with the DualShock 4 handler, it might be caused by third-party tools such as DS4Windows. It's recommended that you disable them while using this handler."); - const QString ds4_linux = tr("In order to use the DualShock 4 handler, you might need to add udev rules to let RPCS3 access the controller.
See the RPCS3 Wiki for instructions."); + const QString ds4_linux = tr("In order to use the DualShock 4 handler, you might need to add udev rules to let RPCS3 access the controller.
See the RPCS3 Wiki for instructions.").arg(gui::utils::get_link_style()); const QString ds4_other = tr("The DualShock 4 handler is recommended for official DualShock 4 controllers."); const QString dualsense_windows = tr("The DualSense handler is recommended for official DualSense controllers."); const QString dualsense_linux = tr("The DualSense handler is recommended for official DualSense controllers."); const QString dualsense_other = tr("The DualSense handler is recommended for official DualSense controllers."); - const QString xinput = tr("The XInput handler will work with Xbox controllers and many third-party PC-compatible controllers. Pressure sensitive buttons from SCP are supported when SCP's XInput1_3.dll is placed in the main RPCS3 directory. For more details, see the RPCS3 Wiki."); - const QString evdev = tr("The evdev handler should work with any controller that has linux support.
If your joystick is not being centered properly, read the RPCS3 Wiki for instructions."); + const QString xinput = tr("The XInput handler will work with Xbox controllers and many third-party PC-compatible controllers. Pressure sensitive buttons from SCP are supported when SCP's XInput1_3.dll is placed in the main RPCS3 directory. For more details, see the RPCS3 Wiki.").arg(gui::utils::get_link_style()); + const QString evdev = tr("The evdev handler should work with any controller that has linux support.
If your joystick is not being centered properly, read the RPCS3 Wiki for instructions.").arg(gui::utils::get_link_style()); const QString mmjoy = tr("The MMJoystick handler should work with almost any controller recognized by Windows. However, it is recommended that you use the more specific handlers if you have a controller that supports them."); const QString sdl = tr("The SDL handler supports a variety of controllers across different platforms."); diff --git a/rpcs3/rpcs3qt/welcome_dialog.cpp b/rpcs3/rpcs3qt/welcome_dialog.cpp index b732381bc2..1e7d389011 100644 --- a/rpcs3/rpcs3qt/welcome_dialog.cpp +++ b/rpcs3/rpcs3qt/welcome_dialog.cpp @@ -2,6 +2,7 @@ #include "ui_welcome_dialog.h" #include "gui_settings.h" +#include "qt_utils.h" #include #include @@ -18,6 +19,27 @@ welcome_dialog::welcome_dialog(std::shared_ptr gui_settings, QWidg ui->okay->setEnabled(false); ui->icon_label->load(QStringLiteral(":/rpcs3.svg")); + ui->label_3->setText(tr( + R"( +

+ RPCS3 is an open-source Sony PlayStation 3 emulator and debugger.
+ It is written in C++ for Windows, Linux, FreeBSD and MacOS funded with Patreon.
+ Our developers and contributors are always working hard to ensure this project is the best that it can be.
+ There are still plenty of implementations to make and optimizations to do. +

+ )" + ).arg(gui::utils::get_link_style())); + + ui->label_info->setText(tr( + R"( +

+ To get started, you must first install the PlayStation 3 firmware.
+ Please refer to the Quickstart guide found on the official website for further information.
+ If you have any further questions, please refer to the FAQ.
+ Otherwise, further discussion and support can be found on the Forums or on our Discord server. +

+ )" + ).arg(gui::utils::get_link_style())); connect(ui->i_have_read, &QCheckBox::clicked, [this](bool checked) { diff --git a/rpcs3/rpcs3qt/welcome_dialog.ui b/rpcs3/rpcs3qt/welcome_dialog.ui index ecfc52646c..e4102e4806 100644 --- a/rpcs3/rpcs3qt/welcome_dialog.ui +++ b/rpcs3/rpcs3qt/welcome_dialog.ui @@ -110,9 +110,6 @@ true - - <html><head/><body><p>RPCS3 is an open-source Sony PlayStation 3 emulator and debugger.<br/>It is written in C++ for Windows, Linux, FreeBSD and MacOS funded with <a href="https://www.patreon.com/Nekotekina"><span style=" text-decoration: underline; color:#0000ff;">Patreon</span></a>.<br/>Our developers and contributors are always working hard to ensure this project is the best that it can be.<br/>There are still plenty of implementations to make and optimizations to do.</p></body></html> - Qt::RichText @@ -155,9 +152,6 @@ true - - <html><head/><body><p>To get started, you must first install the <span style=" font-weight:600;">PlayStation 3 firmware</span>.<br/>Please refer to the <a href="https://rpcs3.net/quickstart"><span style=" text-decoration: underline; color:#0000ff;">Quickstart</span></a> guide found on the official website for further information.<br/>If you have any further questions, please refer to the <a href="https://rpcs3.net/faq"><span style=" text-decoration: underline; color:#0000ff;">FAQ</span></a>.<br/>Otherwise, further discussion and support can be found on the <a href="https://forums.rpcs3.net"><span style=" text-decoration: underline; color:#0000ff;">Forums</span></a> or on our <a href="https://discord.me/RPCS3"><span style=" text-decoration: underline; color:#0000ff;">Discord</span></a> server.</p></body></html> - Qt::RichText