stylesheets: make UI Colors optional

This commit is contained in:
Megamouse 2017-08-16 23:38:18 +02:00 committed by Ivan
parent e6a07e80d7
commit fff62df6a2
8 changed files with 99 additions and 27 deletions

View File

@ -49,7 +49,8 @@
"gui": { "gui": {
"configs": "Only useful to developers.\nIf unsure, don't use this option.", "configs": "Only useful to developers.\nIf unsure, don't use this option.",
"stylesheets": "Only useful to developers.\nIf unsure, don't use this option.", "stylesheets": "Only useful to developers.\nIf unsure, don't use this option.",
"show_welcome": "Shows the initial welcome screen upon starting RPCS3." "show_welcome": "Shows the initial welcome screen upon starting RPCS3.",
"custom_colors": "Prioritize custom user interface colors over properties set in stylesheet."
}, },
"misc": { "misc": {
"exitOnStop": "Automatically close RPCS3 when closing a game, or when a game closes itself.", "exitOnStop": "Automatically close RPCS3 when closing a game, or when a game closes itself.",

View File

@ -299,6 +299,7 @@ void rpcs3_app::OnChangeStyleSheetRequest(const QString& sheetFilePath)
setStyleSheet(file.readAll()); setStyleSheet(file.readAll());
file.close(); file.close();
} }
GUI::stylesheet = styleSheet();
} }
/** /**

View File

@ -849,7 +849,16 @@ void game_list_frame::SetSearchText(const QString& text)
void game_list_frame::RepaintToolBarIcons() void game_list_frame::RepaintToolBarIcons()
{ {
QColor newColor = xgui_settings->GetValue(GUI::gl_toolIconColor).value<QColor>(); QColor newColor;
if (xgui_settings->GetValue(GUI::m_enableUIColors).toBool())
{
newColor = GUI::get_Label_Color("gamelist_toolbar_icon_color");
}
else
{
newColor = xgui_settings->GetValue(GUI::gl_toolIconColor).value<QColor>();
}
m_catActHDD.colored = gui_settings::colorizedIcon(QIcon(":/Icons/hdd_blue.png"), GUI::gl_tool_icon_color, newColor, true); m_catActHDD.colored = gui_settings::colorizedIcon(QIcon(":/Icons/hdd_blue.png"), GUI::gl_tool_icon_color, newColor, true);
m_catActDisc.colored = gui_settings::colorizedIcon(QIcon(":/Icons/disc_blue.png"), GUI::gl_tool_icon_color, newColor, true); m_catActDisc.colored = gui_settings::colorizedIcon(QIcon(":/Icons/disc_blue.png"), GUI::gl_tool_icon_color, newColor, true);

View File

@ -299,7 +299,7 @@ QString gui_settings::GetCurrentStylesheetPath()
{ {
QString stylesheet = GetValue(GUI::m_currentStylesheet).toString(); QString stylesheet = GetValue(GUI::m_currentStylesheet).toString();
if (stylesheet == "default") if (stylesheet == GUI::Default)
{ {
return ""; return "";
} }

View File

@ -8,6 +8,7 @@
#include <QSize> #include <QSize>
#include <QColor> #include <QColor>
#include <QBitmap> #include <QBitmap>
#include <QLabel>
struct GUI_SAVE struct GUI_SAVE
{ {
@ -35,6 +36,8 @@ typedef QList<q_size_pair> q_size_list;
namespace GUI namespace GUI
{ {
static QString stylesheet;
const QSize gl_icon_size_min = QSize(40, 22); const QSize gl_icon_size_min = QSize(40, 22);
const QSize gl_icon_size_small = QSize(80, 44); const QSize gl_icon_size_small = QSize(80, 44);
const QSize gl_icon_size_medium = QSize(160, 88); const QSize gl_icon_size_medium = QSize(160, 88);
@ -42,12 +45,22 @@ namespace GUI
const int gl_max_slider_pos = 100; const int gl_max_slider_pos = 100;
inline int get_Index(const QSize& current) { inline int get_Index(const QSize& current)
{
int size_delta = gl_icon_size_max.width() - gl_icon_size_min.width(); int size_delta = gl_icon_size_max.width() - gl_icon_size_min.width();
int current_delta = current.width() - gl_icon_size_min.width(); int current_delta = current.width() - gl_icon_size_min.width();
return gl_max_slider_pos * current_delta / size_delta; return gl_max_slider_pos * current_delta / size_delta;
}; };
inline QColor get_Label_Color(const QString& objectName, QPalette::ColorRole colorRole = QPalette::Foreground)
{
QLabel dummy_color;
dummy_color.setObjectName(objectName);
dummy_color.ensurePolished();
return dummy_color.palette().color(colorRole);
};
const QString Default = QObject::tr("default");
const QString main_window = "main_window"; const QString main_window = "main_window";
const QString game_list = "GameList"; const QString game_list = "GameList";
const QString logger = "Logger"; const QString logger = "Logger";
@ -117,9 +130,10 @@ namespace GUI
const GUI_SAVE d_splitterState = GUI_SAVE( debugger, "splitterState", QByteArray()); const GUI_SAVE d_splitterState = GUI_SAVE( debugger, "splitterState", QByteArray());
const GUI_SAVE m_currentConfig = GUI_SAVE(meta, "currentConfig", QObject::tr("CurrentSettings")); const GUI_SAVE m_currentConfig = GUI_SAVE(meta, "currentConfig", QObject::tr("CurrentSettings"));
const GUI_SAVE m_currentStylesheet = GUI_SAVE(meta, "currentStylesheet", QObject::tr("default")); const GUI_SAVE m_currentStylesheet = GUI_SAVE(meta, "currentStylesheet", Default);
const GUI_SAVE m_saveNotes = GUI_SAVE(meta, "saveNotes", QVariantMap()); const GUI_SAVE m_saveNotes = GUI_SAVE(meta, "saveNotes", QVariantMap());
const GUI_SAVE m_showDebugTab = GUI_SAVE(meta, "showDebugTab", false); const GUI_SAVE m_showDebugTab = GUI_SAVE(meta, "showDebugTab", false);
const GUI_SAVE m_enableUIColors = GUI_SAVE(meta, "enableUIColors", false);
const GUI_SAVE gs_disableMouse = GUI_SAVE(gs_frame, "disableMouse", false); const GUI_SAVE gs_disableMouse = GUI_SAVE(gs_frame, "disableMouse", false);
const GUI_SAVE gs_resize = GUI_SAVE(gs_frame, "resize", false); const GUI_SAVE gs_resize = GUI_SAVE(gs_frame, "resize", false);

View File

@ -70,8 +70,6 @@ void main_window::Init()
{ {
ui->setupUi(this); ui->setupUi(this);
// Load Icons: This needs to happen before any actions or buttons are created
RepaintToolBarIcons();
appIcon = QIcon(":/rpcs3.ico"); appIcon = QIcon(":/rpcs3.ico");
// add toolbar widgets (crappy Qt designer is not able to) // add toolbar widgets (crappy Qt designer is not able to)
@ -100,6 +98,8 @@ void main_window::Init()
Q_EMIT RequestGlobalStylesheetChange(guiSettings->GetCurrentStylesheetPath()); Q_EMIT RequestGlobalStylesheetChange(guiSettings->GetCurrentStylesheetPath());
ConfigureGuiFromSettings(true); ConfigureGuiFromSettings(true);
RepaintToolBarIcons();
gameListFrame->RepaintToolBarIcons();
if (!utils::has_ssse3()) if (!utils::has_ssse3())
{ {
@ -694,7 +694,16 @@ void main_window::SaveWindowState()
void main_window::RepaintToolBarIcons() void main_window::RepaintToolBarIcons()
{ {
QColor newColor = guiSettings->GetValue(GUI::mw_toolIconColor).value<QColor>(); QColor newColor;
if (guiSettings->GetValue(GUI::m_enableUIColors).toBool())
{
newColor = GUI::get_Label_Color("toolbar_icon_color");
}
else
{
newColor = guiSettings->GetValue(GUI::mw_toolIconColor).value<QColor>();
}
icon_play = gui_settings::colorizedIcon(QIcon(":/Icons/play.png"), GUI::mw_tool_icon_color, newColor); icon_play = gui_settings::colorizedIcon(QIcon(":/Icons/play.png"), GUI::mw_tool_icon_color, newColor);
icon_pause = gui_settings::colorizedIcon(QIcon(":/Icons/pause.png"), GUI::mw_tool_icon_color, newColor); icon_pause = gui_settings::colorizedIcon(QIcon(":/Icons/pause.png"), GUI::mw_tool_icon_color, newColor);
@ -1026,14 +1035,23 @@ void main_window::AddRecentAction(const q_string_pair& entry)
void main_window::RepaintToolbar() void main_window::RepaintToolbar()
{ {
QColor tbc = guiSettings->GetValue(GUI::mw_toolBarColor).value<QColor>(); if (guiSettings->GetValue(GUI::m_enableUIColors).toBool())
ui->toolBar->setStyleSheet(styleSheet().append( {
"QToolBar { background-color: rgba(%1, %2, %3, %4); }" ui->toolBar->setStyleSheet(GUI::stylesheet);
"QToolBar::separator {background-color: rgba(%5, %6, %7, %8); width: 1px; margin-top: 2px; margin-bottom: 2px;}" }
"QSlider { background-color: rgba(%1, %2, %3, %4); }" else
"QLineEdit { background-color: rgba(%1, %2, %3, %4); }") {
.arg(tbc.red()).arg(tbc.green()).arg(tbc.blue()).arg(tbc.alpha()) QColor tbc = guiSettings->GetValue(GUI::mw_toolBarColor).value<QColor>();
.arg(tbc.red() - 20).arg(tbc.green() - 20).arg(tbc.blue() - 20).arg(tbc.alpha() - 20));
ui->toolBar->setStyleSheet(GUI::stylesheet + QString(
"QToolBar { background-color: rgba(%1, %2, %3, %4); }"
"QToolBar::separator {background-color: rgba(%5, %6, %7, %8); width: 1px; margin-top: 2px; margin-bottom: 2px;}"
"QSlider { background-color: rgba(%1, %2, %3, %4); }"
"QLineEdit { background-color: rgba(%1, %2, %3, %4); }")
.arg(tbc.red()).arg(tbc.green()).arg(tbc.blue()).arg(tbc.alpha())
.arg(tbc.red() - 20).arg(tbc.green() - 20).arg(tbc.blue() - 20).arg(tbc.alpha() - 20)
);
}
} }
void main_window::CreateActions() void main_window::CreateActions()
@ -1116,7 +1134,14 @@ void main_window::CreateConnects()
connect(&dlg, &settings_dialog::ToolBarRepaintRequest, this, &main_window::RepaintToolBarIcons); connect(&dlg, &settings_dialog::ToolBarRepaintRequest, this, &main_window::RepaintToolBarIcons);
connect(&dlg, &settings_dialog::ToolBarRepaintRequest, gameListFrame, &game_list_frame::RepaintToolBarIcons); connect(&dlg, &settings_dialog::ToolBarRepaintRequest, gameListFrame, &game_list_frame::RepaintToolBarIcons);
connect(&dlg, &settings_dialog::accepted, [this](){ connect(&dlg, &settings_dialog::accepted, [this](){
gameListFrame->RepaintIcons(guiSettings->GetValue(GUI::gl_iconColor).value<QColor>()); if (guiSettings->GetValue(GUI::m_enableUIColors).toBool())
{
gameListFrame->RepaintIcons(GUI::get_Label_Color("gamelist_icon_background_color"));
}
else
{
gameListFrame->RepaintIcons(guiSettings->GetValue(GUI::gl_iconColor).value<QColor>());
}
RepaintToolbar(); RepaintToolbar();
}); });
dlg.exec(); dlg.exec();

View File

@ -669,6 +669,8 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> xSettings, const
ui->cb_show_welcome->setToolTip(json_emu_gui["show_welcome"].toString()); ui->cb_show_welcome->setToolTip(json_emu_gui["show_welcome"].toString());
ui->cb_custom_colors->setToolTip(json_emu_gui["custom_colors"].toString());
xemu_settings->EnhanceCheckBox(ui->exitOnStop, emu_settings::ExitRPCS3OnFinish); xemu_settings->EnhanceCheckBox(ui->exitOnStop, emu_settings::ExitRPCS3OnFinish);
ui->exitOnStop->setToolTip(json_emu_misc["exitOnStop"].toString()); ui->exitOnStop->setToolTip(json_emu_misc["exitOnStop"].toString());
@ -691,6 +693,13 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> xSettings, const
{ {
ui->cb_show_welcome->setChecked(xgui_settings->GetValue(GUI::ib_show_welcome).toBool()); ui->cb_show_welcome->setChecked(xgui_settings->GetValue(GUI::ib_show_welcome).toBool());
bool enableUIColors = xgui_settings->GetValue(GUI::m_enableUIColors).toBool();
ui->cb_custom_colors->setChecked(enableUIColors);
ui->pb_gl_icon_color->setEnabled(enableUIColors);
ui->pb_gl_tool_icon_color->setEnabled(enableUIColors);
ui->pb_tool_bar_color->setEnabled(enableUIColors);
ui->pb_tool_icon_color->setEnabled(enableUIColors);
connect(ui->okButton, &QAbstractButton::clicked, [this]() { connect(ui->okButton, &QAbstractButton::clicked, [this]() {
// Only attempt to load a config if changes occurred. // Only attempt to load a config if changes occurred.
if (m_startingConfig != xgui_settings->GetValue(GUI::m_currentConfig).toString()) if (m_startingConfig != xgui_settings->GetValue(GUI::m_currentConfig).toString())
@ -707,8 +716,8 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> xSettings, const
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes) QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)
{ {
xgui_settings->Reset(true); xgui_settings->Reset(true);
xgui_settings->ChangeToConfig(tr("default")); xgui_settings->ChangeToConfig(GUI::Default);
Q_EMIT GuiStylesheetRequest(tr("default")); Q_EMIT GuiStylesheetRequest(GUI::Default);
Q_EMIT GuiSettingsSyncRequest(); Q_EMIT GuiSettingsSyncRequest();
AddConfigs(); AddConfigs();
AddStylesheets(); AddStylesheets();
@ -719,6 +728,13 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> xSettings, const
connect(ui->pb_apply_stylesheet, &QAbstractButton::clicked, this, &settings_dialog::OnApplyStylesheet); connect(ui->pb_apply_stylesheet, &QAbstractButton::clicked, this, &settings_dialog::OnApplyStylesheet);
connect(ui->pb_open_folder, &QAbstractButton::clicked, [=]() {QDesktopServices::openUrl(xgui_settings->GetSettingsDir()); }); connect(ui->pb_open_folder, &QAbstractButton::clicked, [=]() {QDesktopServices::openUrl(xgui_settings->GetSettingsDir()); });
connect(ui->cb_show_welcome, &QCheckBox::clicked, [=](bool val) {xgui_settings->SetValue(GUI::ib_show_welcome, val); }); connect(ui->cb_show_welcome, &QCheckBox::clicked, [=](bool val) {xgui_settings->SetValue(GUI::ib_show_welcome, val); });
connect(ui->cb_custom_colors, &QCheckBox::clicked, [=](bool val) {
xgui_settings->SetValue(GUI::m_enableUIColors, val);
ui->pb_gl_icon_color->setEnabled(val);
ui->pb_gl_tool_icon_color->setEnabled(val);
ui->pb_tool_bar_color->setEnabled(val);
ui->pb_tool_icon_color->setEnabled(val);
});
auto colorDialog = [&](const GUI_SAVE& color, const QString& title, QPushButton *button){ auto colorDialog = [&](const GUI_SAVE& color, const QString& title, QPushButton *button){
QColor oldColor = xgui_settings->GetValue(color).value<QColor>(); QColor oldColor = xgui_settings->GetValue(color).value<QColor>();
QColorDialog dlg(oldColor, this); QColorDialog dlg(oldColor, this);
@ -858,11 +874,11 @@ void settings_dialog::AddConfigs()
{ {
ui->combo_configs->clear(); ui->combo_configs->clear();
ui->combo_configs->addItem(tr("default")); ui->combo_configs->addItem(GUI::Default);
for (QString entry : xgui_settings->GetConfigEntries()) for (QString entry : xgui_settings->GetConfigEntries())
{ {
if (entry != tr("default")) if (entry != GUI::Default)
{ {
ui->combo_configs->addItem(entry); ui->combo_configs->addItem(entry);
} }
@ -886,20 +902,19 @@ void settings_dialog::AddStylesheets()
{ {
ui->combo_stylesheets->clear(); ui->combo_stylesheets->clear();
ui->combo_stylesheets->addItem(tr("default")); ui->combo_stylesheets->addItem(GUI::Default);
for (QString entry : xgui_settings->GetStylesheetEntries()) for (QString entry : xgui_settings->GetStylesheetEntries())
{ {
if (entry != tr("default")) if (entry != GUI::Default)
{ {
ui->combo_stylesheets->addItem(entry); ui->combo_stylesheets->addItem(entry);
} }
} }
QString currentSelection = xgui_settings->GetValue(GUI::m_currentStylesheet).toString(); m_startingStylesheet = xgui_settings->GetValue(GUI::m_currentStylesheet).toString();
m_startingStylesheet = currentSelection;
int index = ui->combo_stylesheets->findText(currentSelection); int index = ui->combo_stylesheets->findText(m_startingStylesheet);
if (index != -1) if (index != -1)
{ {
ui->combo_stylesheets->setCurrentIndex(index); ui->combo_stylesheets->setCurrentIndex(index);

View File

@ -1200,9 +1200,16 @@
<item> <item>
<widget class="QGroupBox" name="groupBox_2"> <widget class="QGroupBox" name="groupBox_2">
<property name="title"> <property name="title">
<string>UI Colors (difficult in stylesheets)</string> <string>UI Colors</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_13"> <layout class="QVBoxLayout" name="verticalLayout_13">
<item>
<widget class="QCheckBox" name="cb_custom_colors">
<property name="text">
<string>Use custom UI Colors</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="pb_tool_bar_color"> <widget class="QPushButton" name="pb_tool_bar_color">
<property name="text"> <property name="text">