mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-30 18:43:55 -07:00
Add style comboBox
Took 12 minutes Took 3 seconds Took 2 minutes
This commit is contained in:
parent
3ea298bfef
commit
79bb8a9572
4 changed files with 75 additions and 17 deletions
|
|
@ -188,6 +188,41 @@ QStringMap &ThemeManager::getAvailableThemes()
|
||||||
return availableThemes;
|
return availableThemes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ThemeConfig ThemeManager::effectiveThemeConfig(const QString &themeName)
|
||||||
|
{
|
||||||
|
const QString dirPath = ThemeManager().getAvailableThemes().value(themeName);
|
||||||
|
const QString userDirPath = userThemeDirFor(themeName);
|
||||||
|
|
||||||
|
ThemeConfig userCfg = ThemeConfig::fromThemeDir(userDirPath);
|
||||||
|
ThemeConfig systemCfg = ThemeConfig::fromThemeDir(dirPath);
|
||||||
|
|
||||||
|
ThemeConfig result = systemCfg;
|
||||||
|
|
||||||
|
// User values override system values on a per-field basis
|
||||||
|
if (!userCfg.colorScheme.isEmpty()) {
|
||||||
|
result.colorScheme = userCfg.colorScheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!userCfg.styleName.isEmpty()) {
|
||||||
|
result.styleName = userCfg.styleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThemeManager::setStyleName(const QString &styleName)
|
||||||
|
{
|
||||||
|
const QString themeName = SettingsCache::instance().getThemeName();
|
||||||
|
const QString dirPath = getAvailableThemes().value(themeName);
|
||||||
|
const QString userDirPath = userThemeDirFor(themeName);
|
||||||
|
|
||||||
|
ThemeConfig cfg = ThemeConfig::fromThemeDir(dirPath);
|
||||||
|
cfg.styleName = styleName;
|
||||||
|
cfg.save(userDirPath);
|
||||||
|
|
||||||
|
reloadCurrentTheme();
|
||||||
|
}
|
||||||
|
|
||||||
QBrush ThemeManager::loadBrush(QString fileName, QColor fallbackColor)
|
QBrush ThemeManager::loadBrush(QString fileName, QColor fallbackColor)
|
||||||
{
|
{
|
||||||
QBrush brush;
|
QBrush brush;
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,8 @@ public:
|
||||||
static bool isDarkMode(const QString &themeDirPath, const QString &userDirPath = {});
|
static bool isDarkMode(const QString &themeDirPath, const QString &userDirPath = {});
|
||||||
static QString userThemeDirFor(const QString &themeName);
|
static QString userThemeDirFor(const QString &themeName);
|
||||||
QStringMap &getAvailableThemes();
|
QStringMap &getAvailableThemes();
|
||||||
|
ThemeConfig effectiveThemeConfig(const QString &themeName);
|
||||||
|
void setStyleName(const QString &styleName);
|
||||||
// Returns the path to the currently active theme directory (empty = default)
|
// Returns the path to the currently active theme directory (empty = default)
|
||||||
QString getCurrentThemePath() const
|
QString getCurrentThemePath() const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
|
|
@ -31,32 +32,33 @@ AppearanceSettingsPage::AppearanceSettingsPage()
|
||||||
connect(&themeBox, qOverload<int>(&QComboBox::currentIndexChanged), this, &AppearanceSettingsPage::themeBoxChanged);
|
connect(&themeBox, qOverload<int>(&QComboBox::currentIndexChanged), this, &AppearanceSettingsPage::themeBoxChanged);
|
||||||
connect(&openThemeButton, &QPushButton::clicked, this, &AppearanceSettingsPage::openThemeLocation);
|
connect(&openThemeButton, &QPushButton::clicked, this, &AppearanceSettingsPage::openThemeLocation);
|
||||||
|
|
||||||
|
// Populate Scheme
|
||||||
|
|
||||||
schemeCombo.addItem(tr("Light"), QStringLiteral("Light"));
|
schemeCombo.addItem(tr("Light"), QStringLiteral("Light"));
|
||||||
schemeCombo.addItem(tr("Dark"), QStringLiteral("Dark"));
|
schemeCombo.addItem(tr("Dark"), QStringLiteral("Dark"));
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
|
||||||
schemeCombo.addItem(tr("System"), QStringLiteral("System"));
|
schemeCombo.addItem(tr("System"), QStringLiteral("System"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Seed from whatever the current theme already has saved
|
|
||||||
const QString dirPath = themeManager->getAvailableThemes().value(SettingsCache::instance().getThemeName());
|
|
||||||
const ThemeConfig cfg = ThemeConfig::fromThemeDir(dirPath);
|
|
||||||
const QString current = cfg.colorScheme;
|
|
||||||
const int seedIdx = schemeCombo.findData(current);
|
|
||||||
schemeCombo.setCurrentIndex(seedIdx >= 0 ? seedIdx : 0);
|
|
||||||
|
|
||||||
connect(&schemeCombo, &QComboBox::currentIndexChanged, this,
|
connect(&schemeCombo, &QComboBox::currentIndexChanged, this,
|
||||||
[this] { themeManager->setColorScheme(schemeCombo.currentData().toString()); });
|
[this] { themeManager->setColorScheme(schemeCombo.currentData().toString()); });
|
||||||
|
|
||||||
connect(themeManager, &ThemeManager::themeChanged, this, [this, dirPath] {
|
// Populate Style
|
||||||
const QString newDir = themeManager->getAvailableThemes().value(SettingsCache::instance().getThemeName());
|
|
||||||
const ThemeConfig cfg = ThemeConfig::fromThemeDir(newDir);
|
|
||||||
const QString current = cfg.colorScheme;
|
|
||||||
|
|
||||||
schemeCombo.blockSignals(true);
|
styleComboBox.addItem(tr("Default"), QString());
|
||||||
const int idx = schemeCombo.findData(current);
|
|
||||||
schemeCombo.setCurrentIndex(idx >= 0 ? idx : 0);
|
for (const QString &style : QStyleFactory::keys()) {
|
||||||
schemeCombo.blockSignals(false);
|
styleComboBox.addItem(style, style);
|
||||||
});
|
}
|
||||||
|
|
||||||
|
connect(&styleComboBox, &QComboBox::currentIndexChanged, this,
|
||||||
|
[this] { themeManager->setStyleName(styleComboBox.currentData().toString()); });
|
||||||
|
|
||||||
|
// Refresh theme and style
|
||||||
|
|
||||||
|
reloadThemeSettings();
|
||||||
|
|
||||||
|
connect(themeManager, &ThemeManager::themeChanged, this, &AppearanceSettingsPage::reloadThemeSettings);
|
||||||
|
|
||||||
connect(&editPaletteButton, &QPushButton::clicked, this, &AppearanceSettingsPage::editPalette);
|
connect(&editPaletteButton, &QPushButton::clicked, this, &AppearanceSettingsPage::editPalette);
|
||||||
|
|
||||||
|
|
@ -66,7 +68,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(&styleLabel, 3, 0);
|
||||||
|
themeGrid->addWidget(&styleComboBox, 3, 1);
|
||||||
|
themeGrid->addWidget(&editPaletteButton, 4, 1);
|
||||||
|
|
||||||
themeGroupBox = new QGroupBox;
|
themeGroupBox = new QGroupBox;
|
||||||
themeGroupBox->setLayout(themeGrid);
|
themeGroupBox->setLayout(themeGrid);
|
||||||
|
|
@ -320,6 +324,19 @@ void AppearanceSettingsPage::openThemeLocation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AppearanceSettingsPage::reloadThemeSettings()
|
||||||
|
{
|
||||||
|
const ThemeConfig cfg = themeManager->effectiveThemeConfig(SettingsCache::instance().getThemeName());
|
||||||
|
|
||||||
|
schemeCombo.blockSignals(true);
|
||||||
|
schemeCombo.setCurrentIndex(std::max(0, schemeCombo.findData(cfg.colorScheme)));
|
||||||
|
schemeCombo.blockSignals(false);
|
||||||
|
|
||||||
|
styleComboBox.blockSignals(true);
|
||||||
|
styleComboBox.setCurrentIndex(qMax(0, styleComboBox.findData(cfg.styleName)));
|
||||||
|
styleComboBox.blockSignals(false);
|
||||||
|
}
|
||||||
|
|
||||||
void AppearanceSettingsPage::editPalette()
|
void AppearanceSettingsPage::editPalette()
|
||||||
{
|
{
|
||||||
PaletteEditorDialog dlg(themeManager->getCurrentThemePath(), SettingsCache::instance().getThemeName(), this);
|
PaletteEditorDialog dlg(themeManager->getCurrentThemePath(), SettingsCache::instance().getThemeName(), this);
|
||||||
|
|
@ -390,6 +407,7 @@ 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:"));
|
||||||
|
styleLabel.setText(tr("Active theme style:"));
|
||||||
editPaletteButton.setText(tr("Edit theme palette"));
|
editPaletteButton.setText(tr("Edit theme palette"));
|
||||||
|
|
||||||
homeTabGroupBox->setTitle(tr("Home tab settings"));
|
homeTabGroupBox->setTitle(tr("Home tab settings"));
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ class AppearanceSettingsPage : public AbstractSettingsPage
|
||||||
private slots:
|
private slots:
|
||||||
void themeBoxChanged(int index);
|
void themeBoxChanged(int index);
|
||||||
void openThemeLocation();
|
void openThemeLocation();
|
||||||
|
void reloadThemeSettings();
|
||||||
void editPalette();
|
void editPalette();
|
||||||
void updateHomeTabSettingsVisibility();
|
void updateHomeTabSettingsVisibility();
|
||||||
void showShortcutsChanged(QT_STATE_CHANGED_T enabled);
|
void showShortcutsChanged(QT_STATE_CHANGED_T enabled);
|
||||||
|
|
@ -31,6 +32,8 @@ private:
|
||||||
QPushButton openThemeButton;
|
QPushButton openThemeButton;
|
||||||
QLabel schemeComboLabel;
|
QLabel schemeComboLabel;
|
||||||
QComboBox schemeCombo;
|
QComboBox schemeCombo;
|
||||||
|
QLabel styleLabel;
|
||||||
|
QComboBox styleComboBox;
|
||||||
QPushButton editPaletteButton;
|
QPushButton editPaletteButton;
|
||||||
QLabel homeTabBackgroundSourceLabel;
|
QLabel homeTabBackgroundSourceLabel;
|
||||||
QComboBox homeTabBackgroundSourceBox;
|
QComboBox homeTabBackgroundSourceBox;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue