mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-29 17:32:17 -07:00
[ThemeManager] Expose styling again
Took 3 minutes
This commit is contained in:
parent
d70349da4a
commit
6a889d301a
4 changed files with 45 additions and 4 deletions
|
|
@ -92,9 +92,12 @@ struct PaletteColorInfo
|
||||||
ThemeManager::ThemeManager(QObject *parent) : QObject(parent)
|
ThemeManager::ThemeManager(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
defaultStyleName = qApp->style()->objectName();
|
defaultStyleName = qApp->style()->objectName();
|
||||||
//! \todo Workaround for windows11 style being broken.
|
// On Windows, Qt may report the legacy "windowsvista" style as the default.
|
||||||
if (defaultStyleName == "windows11") {
|
// Prefer the modern "windows11" style when it is available; "windowsvista"
|
||||||
defaultStyleName = "windowsvista";
|
// remains selectable through the per-theme style setting.
|
||||||
|
if (defaultStyleName.compare("windowsvista", Qt::CaseInsensitive) == 0 &&
|
||||||
|
QStyleFactory::keys().contains("windows11", Qt::CaseInsensitive)) {
|
||||||
|
defaultStyleName = "windows11";
|
||||||
}
|
}
|
||||||
ensureThemeDirectoryExists();
|
ensureThemeDirectoryExists();
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
|
||||||
|
|
@ -273,6 +276,17 @@ void ThemeManager::setColorScheme(const QString &scheme)
|
||||||
reloadCurrentTheme();
|
reloadCurrentTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ThemeManager::setStyleName(const QString &styleName)
|
||||||
|
{
|
||||||
|
const QString dirPath = getAvailableThemes().value(SettingsCache::instance().getThemeName());
|
||||||
|
ThemeConfig cfg = ThemeConfig::fromThemeDir(dirPath);
|
||||||
|
|
||||||
|
cfg.styleName = styleName;
|
||||||
|
|
||||||
|
cfg.save(dirPath);
|
||||||
|
reloadCurrentTheme();
|
||||||
|
}
|
||||||
|
|
||||||
void ThemeManager::reloadCurrentTheme()
|
void ThemeManager::reloadCurrentTheme()
|
||||||
{
|
{
|
||||||
themeChangedSlot();
|
themeChangedSlot();
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ public:
|
||||||
static PaletteConfig
|
static PaletteConfig
|
||||||
loadDefaultPaletteConfig(const QString &themeDirPath, const QString &themeName, const QString &colorScheme);
|
loadDefaultPaletteConfig(const QString &themeDirPath, const QString &themeName, const QString &colorScheme);
|
||||||
void setColorScheme(const QString &scheme);
|
void setColorScheme(const QString &scheme);
|
||||||
|
void setStyleName(const QString &styleName);
|
||||||
|
|
||||||
void reloadCurrentTheme();
|
void reloadCurrentTheme();
|
||||||
void previewPalette(const PaletteConfig &cfg, const QString &scheme);
|
void previewPalette(const PaletteConfig &cfg, const QString &scheme);
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QStyleFactory>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
AppearanceSettingsPage::AppearanceSettingsPage()
|
AppearanceSettingsPage::AppearanceSettingsPage()
|
||||||
|
|
@ -47,6 +48,19 @@ AppearanceSettingsPage::AppearanceSettingsPage()
|
||||||
connect(&schemeCombo, &QComboBox::currentIndexChanged, this,
|
connect(&schemeCombo, &QComboBox::currentIndexChanged, this,
|
||||||
[this] { themeManager->setColorScheme(schemeCombo.currentData().toString()); });
|
[this] { themeManager->setColorScheme(schemeCombo.currentData().toString()); });
|
||||||
|
|
||||||
|
// Qt widget style; "Default" lets the application decide
|
||||||
|
styleCombo.addItem(tr("Default"), QStringLiteral("Default"));
|
||||||
|
for (const QString &key : QStyleFactory::keys()) {
|
||||||
|
styleCombo.addItem(key, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString currentStyle = cfg.styleName;
|
||||||
|
const int styleSeedIdx = currentStyle.isEmpty() ? 0 : styleCombo.findData(currentStyle);
|
||||||
|
styleCombo.setCurrentIndex(styleSeedIdx >= 0 ? styleSeedIdx : 0);
|
||||||
|
|
||||||
|
connect(&styleCombo, &QComboBox::currentIndexChanged, this,
|
||||||
|
[this] { themeManager->setStyleName(styleCombo.currentData().toString()); });
|
||||||
|
|
||||||
connect(themeManager, &ThemeManager::themeChanged, this, [this, dirPath] {
|
connect(themeManager, &ThemeManager::themeChanged, this, [this, dirPath] {
|
||||||
const QString newDir = themeManager->getAvailableThemes().value(SettingsCache::instance().getThemeName());
|
const QString newDir = themeManager->getAvailableThemes().value(SettingsCache::instance().getThemeName());
|
||||||
const ThemeConfig cfg = ThemeConfig::fromThemeDir(newDir);
|
const ThemeConfig cfg = ThemeConfig::fromThemeDir(newDir);
|
||||||
|
|
@ -56,6 +70,12 @@ AppearanceSettingsPage::AppearanceSettingsPage()
|
||||||
const int idx = schemeCombo.findData(current);
|
const int idx = schemeCombo.findData(current);
|
||||||
schemeCombo.setCurrentIndex(idx >= 0 ? idx : 0);
|
schemeCombo.setCurrentIndex(idx >= 0 ? idx : 0);
|
||||||
schemeCombo.blockSignals(false);
|
schemeCombo.blockSignals(false);
|
||||||
|
|
||||||
|
styleCombo.blockSignals(true);
|
||||||
|
const QString currentStyle = cfg.styleName;
|
||||||
|
const int styleIdx = currentStyle.isEmpty() ? 0 : styleCombo.findData(currentStyle);
|
||||||
|
styleCombo.setCurrentIndex(styleIdx >= 0 ? styleIdx : 0);
|
||||||
|
styleCombo.blockSignals(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(&editPaletteButton, &QPushButton::clicked, this, &AppearanceSettingsPage::editPalette);
|
connect(&editPaletteButton, &QPushButton::clicked, this, &AppearanceSettingsPage::editPalette);
|
||||||
|
|
@ -66,7 +86,9 @@ AppearanceSettingsPage::AppearanceSettingsPage()
|
||||||
themeGrid->addWidget(&openThemeButton, 1, 1);
|
themeGrid->addWidget(&openThemeButton, 1, 1);
|
||||||
themeGrid->addWidget(&schemeComboLabel, 2, 0);
|
themeGrid->addWidget(&schemeComboLabel, 2, 0);
|
||||||
themeGrid->addWidget(&schemeCombo, 2, 1);
|
themeGrid->addWidget(&schemeCombo, 2, 1);
|
||||||
themeGrid->addWidget(&editPaletteButton, 3, 1);
|
themeGrid->addWidget(&styleComboLabel, 3, 0);
|
||||||
|
themeGrid->addWidget(&styleCombo, 3, 1);
|
||||||
|
themeGrid->addWidget(&editPaletteButton, 4, 1);
|
||||||
|
|
||||||
themeGroupBox = new QGroupBox;
|
themeGroupBox = new QGroupBox;
|
||||||
themeGroupBox->setLayout(themeGrid);
|
themeGroupBox->setLayout(themeGrid);
|
||||||
|
|
@ -400,6 +422,8 @@ void AppearanceSettingsPage::retranslateUi()
|
||||||
themeLabel.setText(tr("Current theme:"));
|
themeLabel.setText(tr("Current theme:"));
|
||||||
openThemeButton.setText(tr("Open themes folder"));
|
openThemeButton.setText(tr("Open themes folder"));
|
||||||
schemeComboLabel.setText(tr("Active theme palette:"));
|
schemeComboLabel.setText(tr("Active theme palette:"));
|
||||||
|
styleComboLabel.setText(tr("Active theme style:"));
|
||||||
|
styleCombo.setToolTip(tr("Qt widget style saved to this theme (\"Default\" lets the application decide)"));
|
||||||
editPaletteButton.setText(tr("Edit theme palette"));
|
editPaletteButton.setText(tr("Edit theme palette"));
|
||||||
|
|
||||||
homeTabGroupBox->setTitle(tr("Home tab settings"));
|
homeTabGroupBox->setTitle(tr("Home tab settings"));
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@ private:
|
||||||
QPushButton openThemeButton;
|
QPushButton openThemeButton;
|
||||||
QLabel schemeComboLabel;
|
QLabel schemeComboLabel;
|
||||||
QComboBox schemeCombo;
|
QComboBox schemeCombo;
|
||||||
|
QLabel styleComboLabel;
|
||||||
|
QComboBox styleCombo;
|
||||||
QPushButton editPaletteButton;
|
QPushButton editPaletteButton;
|
||||||
QLabel homeTabBackgroundSourceLabel;
|
QLabel homeTabBackgroundSourceLabel;
|
||||||
QComboBox homeTabBackgroundSourceBox;
|
QComboBox homeTabBackgroundSourceBox;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue