mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-03 21:41:26 +12:00
Qt: allow to use native styles
This commit is contained in:
parent
8b6fa32d12
commit
2eae0a9d3a
3 changed files with 51 additions and 0 deletions
|
@ -36,6 +36,7 @@
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
|
#include <QStyleFactory>
|
||||||
|
|
||||||
#include <clocale>
|
#include <clocale>
|
||||||
|
|
||||||
|
@ -746,14 +747,55 @@ void gui_application::OnChangeStyleSheetRequest()
|
||||||
|
|
||||||
const QString stylesheet_name = m_gui_settings->GetValue(gui::m_currentStylesheet).toString();
|
const QString stylesheet_name = m_gui_settings->GetValue(gui::m_currentStylesheet).toString();
|
||||||
|
|
||||||
|
// Reset style to default before doing anything else, or we will get unexpected effects in custom stylesheets.
|
||||||
|
if (const QStringList styles = QStyleFactory::keys(); !styles.empty())
|
||||||
|
{
|
||||||
|
// The first style is the default style according to the Qt docs.
|
||||||
|
if (QStyle* style = QStyleFactory::create(styles.front()))
|
||||||
|
{
|
||||||
|
setStyle(style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto match_native_style = [&stylesheet_name]() -> QString
|
||||||
|
{
|
||||||
|
// Search for "native (<style>)"
|
||||||
|
static const QRegularExpression expr(gui::NativeStylesheet + " \\((?<style>.*)\\)");
|
||||||
|
const QRegularExpressionMatch match = expr.match(stylesheet_name);
|
||||||
|
|
||||||
|
if (match.hasMatch())
|
||||||
|
{
|
||||||
|
return match.captured("style");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
};
|
||||||
|
|
||||||
|
gui_log.notice("Changing stylesheet to '%s'", stylesheet_name);
|
||||||
|
|
||||||
if (stylesheet_name.isEmpty() || stylesheet_name == gui::DefaultStylesheet)
|
if (stylesheet_name.isEmpty() || stylesheet_name == gui::DefaultStylesheet)
|
||||||
{
|
{
|
||||||
|
gui_log.notice("Using default stylesheet");
|
||||||
setStyleSheet(gui::stylesheets::default_style_sheet);
|
setStyleSheet(gui::stylesheets::default_style_sheet);
|
||||||
}
|
}
|
||||||
else if (stylesheet_name == gui::NoStylesheet)
|
else if (stylesheet_name == gui::NoStylesheet)
|
||||||
{
|
{
|
||||||
|
gui_log.notice("Using empty style");
|
||||||
setStyleSheet("/* none */");
|
setStyleSheet("/* none */");
|
||||||
}
|
}
|
||||||
|
else if (const QString native_style = match_native_style(); !native_style.isEmpty())
|
||||||
|
{
|
||||||
|
if (QStyle* style = QStyleFactory::create(native_style))
|
||||||
|
{
|
||||||
|
gui_log.notice("Using native style '%s'", native_style);
|
||||||
|
setStyleSheet("/* none */");
|
||||||
|
setStyle(style);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gui_log.error("Failed to set stylesheet: Native style '%s' not available", native_style);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QString stylesheet_path;
|
QString stylesheet_path;
|
||||||
|
|
|
@ -89,6 +89,7 @@ namespace gui
|
||||||
const QString Settings = "CurrentSettings";
|
const QString Settings = "CurrentSettings";
|
||||||
const QString DefaultStylesheet = "default";
|
const QString DefaultStylesheet = "default";
|
||||||
const QString NoStylesheet = "none";
|
const QString NoStylesheet = "none";
|
||||||
|
const QString NativeStylesheet = "native";
|
||||||
|
|
||||||
const QString main_window = "main_window";
|
const QString main_window = "main_window";
|
||||||
const QString game_list = "GameList";
|
const QString game_list = "GameList";
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
#include <QStyleFactory>
|
||||||
|
|
||||||
#include "gui_settings.h"
|
#include "gui_settings.h"
|
||||||
#include "display_sleep_control.h"
|
#include "display_sleep_control.h"
|
||||||
|
@ -2412,6 +2413,13 @@ void settings_dialog::AddStylesheets()
|
||||||
ui->combo_stylesheets->clear();
|
ui->combo_stylesheets->clear();
|
||||||
|
|
||||||
ui->combo_stylesheets->addItem(tr("None", "Stylesheets"), gui::NoStylesheet);
|
ui->combo_stylesheets->addItem(tr("None", "Stylesheets"), gui::NoStylesheet);
|
||||||
|
|
||||||
|
for (const QString& key : QStyleFactory::keys())
|
||||||
|
{
|
||||||
|
// Variant value: "native (<style>)"
|
||||||
|
ui->combo_stylesheets->addItem(tr("Native (%0)", "Stylesheets").arg(key), QString("%0 (%1)").arg(gui::NativeStylesheet, key));
|
||||||
|
}
|
||||||
|
|
||||||
ui->combo_stylesheets->addItem(tr("Default (Bright)", "Stylesheets"), gui::DefaultStylesheet);
|
ui->combo_stylesheets->addItem(tr("Default (Bright)", "Stylesheets"), gui::DefaultStylesheet);
|
||||||
|
|
||||||
for (const QString& entry : m_gui_settings->GetStylesheetEntries())
|
for (const QString& entry : m_gui_settings->GetStylesheetEntries())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue