mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-29 17:32:17 -07:00
[ThemeManager] Simply delete custom palette instead of reverting to default
This commit is contained in:
parent
143c466165
commit
5427e419cc
1 changed files with 27 additions and 12 deletions
|
|
@ -10,6 +10,7 @@
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
|
|
@ -175,15 +176,8 @@ void PaletteEditorDialog::retranslateUi()
|
||||||
setWindowTitle(tr("Palette Editor — %1").arg(themeName));
|
setWindowTitle(tr("Palette Editor — %1").arg(themeName));
|
||||||
titleLabel->setText(tr("<b>Palette Editor</b> · %1").arg(themeName));
|
titleLabel->setText(tr("<b>Palette Editor</b> · %1").arg(themeName));
|
||||||
|
|
||||||
// Revert button only makes sense when the theme ships default palette files
|
revertButton->setToolTip(
|
||||||
const bool hasDefault = ThemeManager::loadDefaultPaletteConfig(themeDirPath, themeName, "Light").hasPalette() ||
|
tr("Delete this scheme's custom palette and revert to the theme default (or the application palette)"));
|
||||||
ThemeManager::loadDefaultPaletteConfig(themeDirPath, themeName, "Dark").hasPalette();
|
|
||||||
revertButton->setEnabled(hasDefault);
|
|
||||||
if (!hasDefault) {
|
|
||||||
revertButton->setToolTip(tr("This theme ships no default palette files"));
|
|
||||||
} else {
|
|
||||||
revertButton->setToolTip(tr("Replace current colours with the theme author's defaults"));
|
|
||||||
}
|
|
||||||
|
|
||||||
schemeComboBox->setToolTip(tr("Switch between the light and dark palette files"));
|
schemeComboBox->setToolTip(tr("Switch between the light and dark palette files"));
|
||||||
editingLabel->setText(tr("Editing:"));
|
editingLabel->setText(tr("Editing:"));
|
||||||
|
|
@ -309,12 +303,33 @@ void PaletteEditorDialog::onReset()
|
||||||
|
|
||||||
void PaletteEditorDialog::onRevertToDefault()
|
void PaletteEditorDialog::onRevertToDefault()
|
||||||
{
|
{
|
||||||
|
// Delete this scheme's custom palette file so the theme falls back to its
|
||||||
|
// default (or, when it ships none, the application palette).
|
||||||
|
const QString fileName = PaletteConfig::fileName(loadedScheme);
|
||||||
|
QFile::remove(QDir(saveDir).absoluteFilePath(fileName));
|
||||||
|
if (!themeDirPath.isEmpty() && themeDirPath != saveDir) {
|
||||||
|
QFile::remove(QDir(themeDirPath).absoluteFilePath(fileName));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reload the live theme so the revert takes effect immediately.
|
||||||
|
themeManager->reloadCurrentTheme();
|
||||||
|
|
||||||
|
// Reflect the resolved palette (theme default, else current app palette) in
|
||||||
|
// the editor so it no longer shows the deleted custom colours.
|
||||||
PaletteConfig def = ThemeManager::loadDefaultPaletteConfig(themeDirPath, themeName, loadedScheme);
|
PaletteConfig def = ThemeManager::loadDefaultPaletteConfig(themeDirPath, themeName, loadedScheme);
|
||||||
if (!def.hasPalette()) {
|
if (!def.hasPalette()) {
|
||||||
QMessageBox::information(this, tr("No default found"),
|
const QPalette appPal = qApp->palette();
|
||||||
tr("No default palette file found for the \"%1\" scheme.").arg(loadedScheme));
|
for (auto group : {QPalette::Active, QPalette::Disabled, QPalette::Inactive}) {
|
||||||
return;
|
for (int i = 0; i < QPalette::NColorRoles; ++i) {
|
||||||
|
auto role = static_cast<QPalette::ColorRole>(i);
|
||||||
|
if (role != QPalette::NoRole) {
|
||||||
|
def.colors[group][role] = appPal.color(group, role);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
savedConfig[loadedScheme] = def;
|
||||||
workingConfig[loadedScheme] = def;
|
workingConfig[loadedScheme] = def;
|
||||||
paletteGrid->loadPalette(def);
|
paletteGrid->loadPalette(def);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue