mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-06 05:23:56 -07:00
Add a combo box to quick switch settings.
Took 19 minutes
This commit is contained in:
parent
4b05e8f8b8
commit
7ed0dadaf8
4 changed files with 52 additions and 7 deletions
|
|
@ -242,6 +242,17 @@ bool ThemeManager::savePaletteConfig(const QString &themeDirPath, const QString
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ThemeManager::setColorScheme(const QString &scheme)
|
||||||
|
{
|
||||||
|
const QString dirPath = getAvailableThemes().value(SettingsCache::instance().getThemeName());
|
||||||
|
ThemeConfig cfg = ThemeConfig::fromThemeDir(dirPath);
|
||||||
|
|
||||||
|
cfg.colorScheme = scheme;
|
||||||
|
|
||||||
|
cfg.save(dirPath);
|
||||||
|
reloadCurrentTheme();
|
||||||
|
}
|
||||||
|
|
||||||
void ThemeManager::reloadCurrentTheme()
|
void ThemeManager::reloadCurrentTheme()
|
||||||
{
|
{
|
||||||
themeChangedSlot();
|
themeChangedSlot();
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ public:
|
||||||
// Load/save per-scheme palette colors
|
// Load/save per-scheme palette colors
|
||||||
static PaletteConfig loadPaletteConfig(const QString &themeDirPath, const QString &colorScheme);
|
static PaletteConfig loadPaletteConfig(const QString &themeDirPath, const QString &colorScheme);
|
||||||
static bool savePaletteConfig(const QString &themeDirPath, const QString &colorScheme, const PaletteConfig &cfg);
|
static bool savePaletteConfig(const QString &themeDirPath, const QString &colorScheme, const PaletteConfig &cfg);
|
||||||
|
void setColorScheme(const QString &scheme);
|
||||||
|
|
||||||
void reloadCurrentTheme();
|
void reloadCurrentTheme();
|
||||||
void previewPalette(const PaletteConfig &cfg, const QString &scheme);
|
void previewPalette(const PaletteConfig &cfg, const QString &scheme);
|
||||||
|
|
|
||||||
|
|
@ -433,6 +433,34 @@ 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);
|
||||||
|
|
||||||
|
schemeCombo.addItem(tr("Light"), QStringLiteral("Light"));
|
||||||
|
schemeCombo.addItem(tr("Dark"), QStringLiteral("Dark"));
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
|
||||||
|
schemeCombo.addItem(tr("System"), QStringLiteral("System"));
|
||||||
|
#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,
|
||||||
|
[this] { themeManager->setColorScheme(schemeCombo.currentData().toString()); });
|
||||||
|
|
||||||
|
connect(themeManager, &ThemeManager::themeChanged, this, [this, dirPath] {
|
||||||
|
const QString newDir = themeManager->getAvailableThemes().value(SettingsCache::instance().getThemeName());
|
||||||
|
const ThemeConfig cfg = ThemeConfig::fromThemeDir(newDir);
|
||||||
|
const QString current = cfg.colorScheme;
|
||||||
|
|
||||||
|
schemeCombo.blockSignals(true);
|
||||||
|
const int idx = schemeCombo.findData(current);
|
||||||
|
schemeCombo.setCurrentIndex(idx >= 0 ? idx : 0);
|
||||||
|
schemeCombo.blockSignals(false);
|
||||||
|
});
|
||||||
|
|
||||||
connect(&editPaletteButton, &QPushButton::clicked, this, &AppearanceSettingsPage::editPalette);
|
connect(&editPaletteButton, &QPushButton::clicked, this, &AppearanceSettingsPage::editPalette);
|
||||||
|
|
||||||
for (const auto &entry : BackgroundSources::all()) {
|
for (const auto &entry : BackgroundSources::all()) {
|
||||||
|
|
@ -468,13 +496,15 @@ AppearanceSettingsPage::AppearanceSettingsPage()
|
||||||
themeGrid->addWidget(&themeLabel, 0, 0);
|
themeGrid->addWidget(&themeLabel, 0, 0);
|
||||||
themeGrid->addWidget(&themeBox, 0, 1);
|
themeGrid->addWidget(&themeBox, 0, 1);
|
||||||
themeGrid->addWidget(&openThemeButton, 1, 1);
|
themeGrid->addWidget(&openThemeButton, 1, 1);
|
||||||
themeGrid->addWidget(&editPaletteButton, 2, 1);
|
themeGrid->addWidget(&schemeComboLabel, 2, 0);
|
||||||
themeGrid->addWidget(&homeTabBackgroundSourceLabel, 3, 0);
|
themeGrid->addWidget(&schemeCombo, 2, 1);
|
||||||
themeGrid->addWidget(&homeTabBackgroundSourceBox, 3, 1);
|
themeGrid->addWidget(&editPaletteButton, 3, 1);
|
||||||
themeGrid->addWidget(&homeTabBackgroundShuffleFrequencyLabel, 4, 0);
|
themeGrid->addWidget(&homeTabBackgroundSourceLabel, 4, 0);
|
||||||
themeGrid->addWidget(&homeTabBackgroundShuffleFrequencySpinBox, 4, 1);
|
themeGrid->addWidget(&homeTabBackgroundSourceBox, 4, 1);
|
||||||
themeGrid->addWidget(&homeTabDisplayCardNameLabel, 5, 0);
|
themeGrid->addWidget(&homeTabBackgroundShuffleFrequencyLabel, 5, 0);
|
||||||
themeGrid->addWidget(&homeTabDisplayCardNameCheckBox, 5, 1);
|
themeGrid->addWidget(&homeTabBackgroundShuffleFrequencySpinBox, 5, 1);
|
||||||
|
themeGrid->addWidget(&homeTabDisplayCardNameLabel, 6, 0);
|
||||||
|
themeGrid->addWidget(&homeTabDisplayCardNameCheckBox, 6, 1);
|
||||||
|
|
||||||
themeGroupBox = new QGroupBox;
|
themeGroupBox = new QGroupBox;
|
||||||
themeGroupBox->setLayout(themeGrid);
|
themeGroupBox->setLayout(themeGrid);
|
||||||
|
|
@ -743,6 +773,7 @@ void AppearanceSettingsPage::retranslateUi()
|
||||||
themeGroupBox->setTitle(tr("Theme settings"));
|
themeGroupBox->setTitle(tr("Theme settings"));
|
||||||
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"));
|
||||||
editPaletteButton.setText(tr("Edit theme palette"));
|
editPaletteButton.setText(tr("Edit theme palette"));
|
||||||
homeTabBackgroundSourceLabel.setText(tr("Home tab background source:"));
|
homeTabBackgroundSourceLabel.setText(tr("Home tab background source:"));
|
||||||
homeTabBackgroundShuffleFrequencyLabel.setText(tr("Home tab background shuffle frequency:"));
|
homeTabBackgroundShuffleFrequencyLabel.setText(tr("Home tab background shuffle frequency:"));
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,8 @@ private:
|
||||||
QLabel themeLabel;
|
QLabel themeLabel;
|
||||||
QComboBox themeBox;
|
QComboBox themeBox;
|
||||||
QPushButton openThemeButton;
|
QPushButton openThemeButton;
|
||||||
|
QLabel schemeComboLabel;
|
||||||
|
QComboBox schemeCombo;
|
||||||
QPushButton editPaletteButton;
|
QPushButton editPaletteButton;
|
||||||
QLabel homeTabBackgroundSourceLabel;
|
QLabel homeTabBackgroundSourceLabel;
|
||||||
QComboBox homeTabBackgroundSourceBox;
|
QComboBox homeTabBackgroundSourceBox;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue