mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-05 21:13:55 -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;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
themeChangedSlot();
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ public:
|
|||
// Load/save per-scheme palette colors
|
||||
static PaletteConfig loadPaletteConfig(const QString &themeDirPath, const QString &colorScheme);
|
||||
static bool savePaletteConfig(const QString &themeDirPath, const QString &colorScheme, const PaletteConfig &cfg);
|
||||
void setColorScheme(const QString &scheme);
|
||||
|
||||
void reloadCurrentTheme();
|
||||
void previewPalette(const PaletteConfig &cfg, const QString &scheme);
|
||||
|
|
|
|||
|
|
@ -433,6 +433,34 @@ AppearanceSettingsPage::AppearanceSettingsPage()
|
|||
|
||||
connect(&themeBox, qOverload<int>(&QComboBox::currentIndexChanged), this, &AppearanceSettingsPage::themeBoxChanged);
|
||||
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);
|
||||
|
||||
for (const auto &entry : BackgroundSources::all()) {
|
||||
|
|
@ -468,13 +496,15 @@ AppearanceSettingsPage::AppearanceSettingsPage()
|
|||
themeGrid->addWidget(&themeLabel, 0, 0);
|
||||
themeGrid->addWidget(&themeBox, 0, 1);
|
||||
themeGrid->addWidget(&openThemeButton, 1, 1);
|
||||
themeGrid->addWidget(&editPaletteButton, 2, 1);
|
||||
themeGrid->addWidget(&homeTabBackgroundSourceLabel, 3, 0);
|
||||
themeGrid->addWidget(&homeTabBackgroundSourceBox, 3, 1);
|
||||
themeGrid->addWidget(&homeTabBackgroundShuffleFrequencyLabel, 4, 0);
|
||||
themeGrid->addWidget(&homeTabBackgroundShuffleFrequencySpinBox, 4, 1);
|
||||
themeGrid->addWidget(&homeTabDisplayCardNameLabel, 5, 0);
|
||||
themeGrid->addWidget(&homeTabDisplayCardNameCheckBox, 5, 1);
|
||||
themeGrid->addWidget(&schemeComboLabel, 2, 0);
|
||||
themeGrid->addWidget(&schemeCombo, 2, 1);
|
||||
themeGrid->addWidget(&editPaletteButton, 3, 1);
|
||||
themeGrid->addWidget(&homeTabBackgroundSourceLabel, 4, 0);
|
||||
themeGrid->addWidget(&homeTabBackgroundSourceBox, 4, 1);
|
||||
themeGrid->addWidget(&homeTabBackgroundShuffleFrequencyLabel, 5, 0);
|
||||
themeGrid->addWidget(&homeTabBackgroundShuffleFrequencySpinBox, 5, 1);
|
||||
themeGrid->addWidget(&homeTabDisplayCardNameLabel, 6, 0);
|
||||
themeGrid->addWidget(&homeTabDisplayCardNameCheckBox, 6, 1);
|
||||
|
||||
themeGroupBox = new QGroupBox;
|
||||
themeGroupBox->setLayout(themeGrid);
|
||||
|
|
@ -743,6 +773,7 @@ void AppearanceSettingsPage::retranslateUi()
|
|||
themeGroupBox->setTitle(tr("Theme settings"));
|
||||
themeLabel.setText(tr("Current theme:"));
|
||||
openThemeButton.setText(tr("Open themes folder"));
|
||||
schemeComboLabel.setText(tr("Active theme palette"));
|
||||
editPaletteButton.setText(tr("Edit theme palette"));
|
||||
homeTabBackgroundSourceLabel.setText(tr("Home tab background source:"));
|
||||
homeTabBackgroundShuffleFrequencyLabel.setText(tr("Home tab background shuffle frequency:"));
|
||||
|
|
|
|||
|
|
@ -115,6 +115,8 @@ private:
|
|||
QLabel themeLabel;
|
||||
QComboBox themeBox;
|
||||
QPushButton openThemeButton;
|
||||
QLabel schemeComboLabel;
|
||||
QComboBox schemeCombo;
|
||||
QPushButton editPaletteButton;
|
||||
QLabel homeTabBackgroundSourceLabel;
|
||||
QComboBox homeTabBackgroundSourceBox;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue