Merge pull request #6768 from spycrab/qt_stylesheet
Qt: Allow custom stylesheets
This commit is contained in:
commit
a9987588eb
|
@ -57,6 +57,7 @@
|
||||||
#define WII_WC24CONF_DIR "shared2" DIR_SEP "wc24"
|
#define WII_WC24CONF_DIR "shared2" DIR_SEP "wc24"
|
||||||
#define RESOURCES_DIR "Resources"
|
#define RESOURCES_DIR "Resources"
|
||||||
#define THEMES_DIR "Themes"
|
#define THEMES_DIR "Themes"
|
||||||
|
#define STYLES_DIR "Styles"
|
||||||
#define ANAGLYPH_DIR "Anaglyph"
|
#define ANAGLYPH_DIR "Anaglyph"
|
||||||
#define PIPES_DIR "Pipes"
|
#define PIPES_DIR "Pipes"
|
||||||
#define MEMORYWATCHER_DIR "MemoryWatcher"
|
#define MEMORYWATCHER_DIR "MemoryWatcher"
|
||||||
|
|
|
@ -774,6 +774,7 @@ static void RebuildUserDirectories(unsigned int dir_index)
|
||||||
s_user_paths[D_LOGS_IDX] = s_user_paths[D_USER_IDX] + LOGS_DIR DIR_SEP;
|
s_user_paths[D_LOGS_IDX] = s_user_paths[D_USER_IDX] + LOGS_DIR DIR_SEP;
|
||||||
s_user_paths[D_MAILLOGS_IDX] = s_user_paths[D_LOGS_IDX] + MAIL_LOGS_DIR DIR_SEP;
|
s_user_paths[D_MAILLOGS_IDX] = s_user_paths[D_LOGS_IDX] + MAIL_LOGS_DIR DIR_SEP;
|
||||||
s_user_paths[D_THEMES_IDX] = s_user_paths[D_USER_IDX] + THEMES_DIR DIR_SEP;
|
s_user_paths[D_THEMES_IDX] = s_user_paths[D_USER_IDX] + THEMES_DIR DIR_SEP;
|
||||||
|
s_user_paths[D_STYLES_IDX] = s_user_paths[D_USER_IDX] + STYLES_DIR DIR_SEP;
|
||||||
s_user_paths[D_PIPES_IDX] = s_user_paths[D_USER_IDX] + PIPES_DIR DIR_SEP;
|
s_user_paths[D_PIPES_IDX] = s_user_paths[D_USER_IDX] + PIPES_DIR DIR_SEP;
|
||||||
s_user_paths[D_WFSROOT_IDX] = s_user_paths[D_USER_IDX] + WFSROOT_DIR DIR_SEP;
|
s_user_paths[D_WFSROOT_IDX] = s_user_paths[D_USER_IDX] + WFSROOT_DIR DIR_SEP;
|
||||||
s_user_paths[D_BACKUP_IDX] = s_user_paths[D_USER_IDX] + BACKUP_DIR DIR_SEP;
|
s_user_paths[D_BACKUP_IDX] = s_user_paths[D_USER_IDX] + BACKUP_DIR DIR_SEP;
|
||||||
|
|
|
@ -44,6 +44,7 @@ enum
|
||||||
D_LOGS_IDX,
|
D_LOGS_IDX,
|
||||||
D_MAILLOGS_IDX,
|
D_MAILLOGS_IDX,
|
||||||
D_THEMES_IDX,
|
D_THEMES_IDX,
|
||||||
|
D_STYLES_IDX,
|
||||||
D_PIPES_IDX,
|
D_PIPES_IDX,
|
||||||
D_MEMORYWATCHER_IDX,
|
D_MEMORYWATCHER_IDX,
|
||||||
D_WFSROOT_IDX,
|
D_WFSROOT_IDX,
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
// Licensed under GPLv2+
|
// Licensed under GPLv2+
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QFile>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
|
|
||||||
|
@ -26,6 +28,8 @@ Settings::Settings()
|
||||||
|
|
||||||
Config::AddConfigChangedCallback(
|
Config::AddConfigChangedCallback(
|
||||||
[this] { QueueOnObject(this, [this] { emit ConfigChanged(); }); });
|
[this] { QueueOnObject(this, [this] { emit ConfigChanged(); }); });
|
||||||
|
|
||||||
|
SetCurrentUserStyle(GetCurrentUserStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings& Settings::Instance()
|
Settings& Settings::Instance()
|
||||||
|
@ -48,6 +52,39 @@ void Settings::SetThemeName(const QString& theme_name)
|
||||||
emit ThemeChanged();
|
emit ThemeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Settings::GetCurrentUserStyle() const
|
||||||
|
{
|
||||||
|
return GetQSettings().value(QStringLiteral("userstyle/path"), false).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::SetCurrentUserStyle(const QString& stylesheet_path)
|
||||||
|
{
|
||||||
|
QString stylesheet_contents;
|
||||||
|
|
||||||
|
if (!stylesheet_path.isEmpty() && AreUserStylesEnabled())
|
||||||
|
{
|
||||||
|
// Load custom user stylesheet
|
||||||
|
QFile stylesheet(stylesheet_path);
|
||||||
|
|
||||||
|
if (stylesheet.open(QFile::ReadOnly))
|
||||||
|
stylesheet_contents = QString::fromUtf8(stylesheet.readAll().data());
|
||||||
|
}
|
||||||
|
|
||||||
|
qApp->setStyleSheet(stylesheet_contents);
|
||||||
|
|
||||||
|
GetQSettings().setValue(QStringLiteral("userstyle/path"), stylesheet_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Settings::AreUserStylesEnabled() const
|
||||||
|
{
|
||||||
|
return GetQSettings().value(QStringLiteral("userstyle/enabled"), false).toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::SetUserStylesEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
GetQSettings().setValue(QStringLiteral("userstyle/enabled"), enabled);
|
||||||
|
}
|
||||||
|
|
||||||
QStringList Settings::GetPaths() const
|
QStringList Settings::GetPaths() const
|
||||||
{
|
{
|
||||||
QStringList list;
|
QStringList list;
|
||||||
|
|
|
@ -44,6 +44,11 @@ public:
|
||||||
|
|
||||||
// UI
|
// UI
|
||||||
void SetThemeName(const QString& theme_name);
|
void SetThemeName(const QString& theme_name);
|
||||||
|
void SetCurrentUserStyle(const QString& stylesheet_path);
|
||||||
|
QString GetCurrentUserStyle() const;
|
||||||
|
|
||||||
|
void SetUserStylesEnabled(bool enabled);
|
||||||
|
bool AreUserStylesEnabled() const;
|
||||||
|
|
||||||
bool IsInDevelopmentWarningEnabled() const;
|
bool IsInDevelopmentWarningEnabled() const;
|
||||||
bool IsLogVisible() const;
|
bool IsLogVisible() const;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
|
#include <QLabel>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
@ -73,8 +74,8 @@ static QComboBox* MakeLanguageComboBox()
|
||||||
InterfacePane::InterfacePane(QWidget* parent) : QWidget(parent)
|
InterfacePane::InterfacePane(QWidget* parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
CreateLayout();
|
CreateLayout();
|
||||||
ConnectLayout();
|
|
||||||
LoadConfig();
|
LoadConfig();
|
||||||
|
ConnectLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterfacePane::CreateLayout()
|
void InterfacePane::CreateLayout()
|
||||||
|
@ -106,9 +107,9 @@ void InterfacePane::CreateUI()
|
||||||
combobox_layout->addRow(tr("&Theme:"), m_combobox_theme);
|
combobox_layout->addRow(tr("&Theme:"), m_combobox_theme);
|
||||||
|
|
||||||
// List avalable themes
|
// List avalable themes
|
||||||
auto file_search_results =
|
auto theme_search_results =
|
||||||
Common::DoFileSearch({File::GetUserPath(D_THEMES_IDX), File::GetSysDirectory() + THEMES_DIR});
|
Common::DoFileSearch({File::GetUserPath(D_THEMES_IDX), File::GetSysDirectory() + THEMES_DIR});
|
||||||
for (const std::string& filename : file_search_results)
|
for (const std::string& filename : theme_search_results)
|
||||||
{
|
{
|
||||||
std::string name, ext;
|
std::string name, ext;
|
||||||
SplitPath(filename, nullptr, &name, &ext);
|
SplitPath(filename, nullptr, &name, &ext);
|
||||||
|
@ -117,13 +118,32 @@ void InterfacePane::CreateUI()
|
||||||
m_combobox_theme->addItem(qt_name);
|
m_combobox_theme->addItem(qt_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// User Style Combobox
|
||||||
|
m_combobox_userstyle = new QComboBox;
|
||||||
|
m_label_userstyle = new QLabel(tr("User Style:"));
|
||||||
|
combobox_layout->addRow(m_label_userstyle, m_combobox_userstyle);
|
||||||
|
|
||||||
|
auto userstyle_search_results = Common::DoFileSearch({File::GetUserPath(D_STYLES_IDX)});
|
||||||
|
|
||||||
|
m_combobox_userstyle->addItem(tr("(None)"), QStringLiteral(""));
|
||||||
|
|
||||||
|
for (const std::string& filename : userstyle_search_results)
|
||||||
|
{
|
||||||
|
std::string name, ext;
|
||||||
|
SplitPath(filename, nullptr, &name, &ext);
|
||||||
|
QString qt_name = QString::fromStdString(name);
|
||||||
|
m_combobox_userstyle->addItem(qt_name, QString::fromStdString(filename));
|
||||||
|
}
|
||||||
|
|
||||||
// Checkboxes
|
// Checkboxes
|
||||||
m_checkbox_top_window = new QCheckBox(tr("Keep Window on Top"));
|
m_checkbox_top_window = new QCheckBox(tr("Keep Window on Top"));
|
||||||
m_checkbox_use_builtin_title_database = new QCheckBox(tr("Use Built-In Database of Game Names"));
|
m_checkbox_use_builtin_title_database = new QCheckBox(tr("Use Built-In Database of Game Names"));
|
||||||
|
m_checkbox_use_userstyle = new QCheckBox(tr("Use Custom User Style"));
|
||||||
m_checkbox_show_debugging_ui = new QCheckBox(tr("Show Debugging UI"));
|
m_checkbox_show_debugging_ui = new QCheckBox(tr("Show Debugging UI"));
|
||||||
|
|
||||||
groupbox_layout->addWidget(m_checkbox_top_window);
|
groupbox_layout->addWidget(m_checkbox_top_window);
|
||||||
groupbox_layout->addWidget(m_checkbox_use_builtin_title_database);
|
groupbox_layout->addWidget(m_checkbox_use_builtin_title_database);
|
||||||
|
groupbox_layout->addWidget(m_checkbox_use_userstyle);
|
||||||
groupbox_layout->addWidget(m_checkbox_show_debugging_ui);
|
groupbox_layout->addWidget(m_checkbox_show_debugging_ui);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,6 +177,9 @@ void InterfacePane::ConnectLayout()
|
||||||
connect(m_checkbox_show_debugging_ui, &QCheckBox::clicked, this, &InterfacePane::OnSaveConfig);
|
connect(m_checkbox_show_debugging_ui, &QCheckBox::clicked, this, &InterfacePane::OnSaveConfig);
|
||||||
connect(m_combobox_theme, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::activated),
|
connect(m_combobox_theme, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::activated),
|
||||||
&Settings::Instance(), &Settings::SetThemeName);
|
&Settings::Instance(), &Settings::SetThemeName);
|
||||||
|
connect(m_combobox_userstyle,
|
||||||
|
static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged), this,
|
||||||
|
&InterfacePane::OnSaveConfig);
|
||||||
connect(m_combobox_language, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this,
|
connect(m_combobox_language, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this,
|
||||||
&InterfacePane::OnSaveConfig);
|
&InterfacePane::OnSaveConfig);
|
||||||
connect(m_checkbox_confirm_on_stop, &QCheckBox::clicked, this, &InterfacePane::OnSaveConfig);
|
connect(m_checkbox_confirm_on_stop, &QCheckBox::clicked, this, &InterfacePane::OnSaveConfig);
|
||||||
|
@ -165,6 +188,7 @@ void InterfacePane::ConnectLayout()
|
||||||
connect(m_checkbox_pause_on_focus_lost, &QCheckBox::clicked, this, &InterfacePane::OnSaveConfig);
|
connect(m_checkbox_pause_on_focus_lost, &QCheckBox::clicked, this, &InterfacePane::OnSaveConfig);
|
||||||
connect(m_checkbox_hide_mouse, &QCheckBox::clicked, &Settings::Instance(),
|
connect(m_checkbox_hide_mouse, &QCheckBox::clicked, &Settings::Instance(),
|
||||||
&Settings::SetHideCursor);
|
&Settings::SetHideCursor);
|
||||||
|
connect(m_checkbox_use_userstyle, &QCheckBox::toggled, this, &InterfacePane::OnSaveConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterfacePane::LoadConfig()
|
void InterfacePane::LoadConfig()
|
||||||
|
@ -178,6 +202,20 @@ void InterfacePane::LoadConfig()
|
||||||
m_combobox_theme->setCurrentIndex(
|
m_combobox_theme->setCurrentIndex(
|
||||||
m_combobox_theme->findText(QString::fromStdString(SConfig::GetInstance().theme_name)));
|
m_combobox_theme->findText(QString::fromStdString(SConfig::GetInstance().theme_name)));
|
||||||
|
|
||||||
|
const QString userstyle = Settings::Instance().GetCurrentUserStyle();
|
||||||
|
|
||||||
|
if (userstyle.isEmpty())
|
||||||
|
m_combobox_userstyle->setCurrentIndex(0);
|
||||||
|
else
|
||||||
|
m_combobox_userstyle->setCurrentText(userstyle);
|
||||||
|
|
||||||
|
m_checkbox_use_userstyle->setChecked(Settings::Instance().AreUserStylesEnabled());
|
||||||
|
|
||||||
|
const bool visible = m_checkbox_use_userstyle->isChecked();
|
||||||
|
|
||||||
|
m_combobox_userstyle->setVisible(visible);
|
||||||
|
m_label_userstyle->setVisible(visible);
|
||||||
|
|
||||||
// In Game Options
|
// In Game Options
|
||||||
m_checkbox_confirm_on_stop->setChecked(startup_params.bConfirmStop);
|
m_checkbox_confirm_on_stop->setChecked(startup_params.bConfirmStop);
|
||||||
m_checkbox_use_panic_handlers->setChecked(startup_params.bUsePanicHandlers);
|
m_checkbox_use_panic_handlers->setChecked(startup_params.bUsePanicHandlers);
|
||||||
|
@ -193,6 +231,13 @@ void InterfacePane::OnSaveConfig()
|
||||||
Settings::Instance().SetKeepWindowOnTop(m_checkbox_top_window->isChecked());
|
Settings::Instance().SetKeepWindowOnTop(m_checkbox_top_window->isChecked());
|
||||||
settings.m_use_builtin_title_database = m_checkbox_use_builtin_title_database->isChecked();
|
settings.m_use_builtin_title_database = m_checkbox_use_builtin_title_database->isChecked();
|
||||||
Settings::Instance().SetDebugModeEnabled(m_checkbox_show_debugging_ui->isChecked());
|
Settings::Instance().SetDebugModeEnabled(m_checkbox_show_debugging_ui->isChecked());
|
||||||
|
Settings::Instance().SetCurrentUserStyle(m_combobox_userstyle->currentData().toString());
|
||||||
|
Settings::Instance().SetUserStylesEnabled(m_checkbox_use_userstyle->isChecked());
|
||||||
|
|
||||||
|
const bool visible = m_checkbox_use_userstyle->isChecked();
|
||||||
|
|
||||||
|
m_combobox_userstyle->setVisible(visible);
|
||||||
|
m_label_userstyle->setVisible(visible);
|
||||||
|
|
||||||
// In Game Options
|
// In Game Options
|
||||||
settings.bConfirmStop = m_checkbox_confirm_on_stop->isChecked();
|
settings.bConfirmStop = m_checkbox_confirm_on_stop->isChecked();
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
class QCheckBox;
|
class QCheckBox;
|
||||||
class QComboBox;
|
class QComboBox;
|
||||||
|
class QLabel;
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
|
|
||||||
class InterfacePane final : public QWidget
|
class InterfacePane final : public QWidget
|
||||||
|
@ -28,8 +29,11 @@ private:
|
||||||
QComboBox* m_combobox_language;
|
QComboBox* m_combobox_language;
|
||||||
|
|
||||||
QComboBox* m_combobox_theme;
|
QComboBox* m_combobox_theme;
|
||||||
|
QComboBox* m_combobox_userstyle;
|
||||||
|
QLabel* m_label_userstyle;
|
||||||
QCheckBox* m_checkbox_top_window;
|
QCheckBox* m_checkbox_top_window;
|
||||||
QCheckBox* m_checkbox_use_builtin_title_database;
|
QCheckBox* m_checkbox_use_builtin_title_database;
|
||||||
|
QCheckBox* m_checkbox_use_userstyle;
|
||||||
QCheckBox* m_checkbox_show_debugging_ui;
|
QCheckBox* m_checkbox_show_debugging_ui;
|
||||||
|
|
||||||
QCheckBox* m_checkbox_confirm_on_stop;
|
QCheckBox* m_checkbox_confirm_on_stop;
|
||||||
|
|
|
@ -153,6 +153,7 @@ void CreateDirectories()
|
||||||
File::CreateFullPath(File::GetUserPath(D_STATESAVES_IDX));
|
File::CreateFullPath(File::GetUserPath(D_STATESAVES_IDX));
|
||||||
#ifndef ANDROID
|
#ifndef ANDROID
|
||||||
File::CreateFullPath(File::GetUserPath(D_THEMES_IDX));
|
File::CreateFullPath(File::GetUserPath(D_THEMES_IDX));
|
||||||
|
File::CreateFullPath(File::GetUserPath(D_STYLES_IDX));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue