Remove namespace, fold I/O into structs.

Took 33 seconds
This commit is contained in:
Lukas Brübach 2026-05-17 09:27:24 +02:00
parent a39e133351
commit 64a5b36e88
4 changed files with 16 additions and 38 deletions

View file

@ -257,9 +257,8 @@ void PaletteEditorDialog::onSave()
PaletteConfig cfg = paletteGrid->currentPaletteConfig(); PaletteConfig cfg = paletteGrid->currentPaletteConfig();
if (!ThemeManager::savePaletteConfig(themeDirPath, loadedScheme, cfg)) { if (!ThemeManager::savePaletteConfig(themeDirPath, loadedScheme, cfg)) {
QMessageBox::warning( QMessageBox::warning(this, tr("Save failed"),
this, tr("Save failed"), tr("Could not write %1 to:\n%2").arg(PaletteConfig::fileName(loadedScheme), themeDirPath));
tr("Could not write %1 to:\n%2").arg(PaletteConfig::fileName(loadedScheme), themeDirPath));
return; return;
} }

View file

@ -127,9 +127,7 @@ QString PaletteConfig::toToml() const
continue; continue;
} }
out += QString("%1 = %2\n") out += QString("%1 = %2\n").arg(QString(roleName), -20).arg(it.value().name(QColor::HexArgb));
.arg(QString(roleName), -20)
.arg(it.value().name(QColor::HexArgb));
} }
out += "\n"; out += "\n";
@ -140,9 +138,7 @@ QString PaletteConfig::toToml() const
QString PaletteConfig::fileName(const QString &colorScheme) QString PaletteConfig::fileName(const QString &colorScheme)
{ {
return colorScheme.compare("Dark", Qt::CaseInsensitive) == 0 return colorScheme.compare("Dark", Qt::CaseInsensitive) == 0 ? "palette-dark.toml" : "palette-light.toml";
? "palette-dark.toml"
: "palette-light.toml";
} }
PaletteConfig PaletteConfig::fromFile(const QString &filePath) PaletteConfig PaletteConfig::fromFile(const QString &filePath)
@ -175,9 +171,7 @@ PaletteConfig PaletteConfig::fromFile(const QString &filePath)
if (currentSection.startsWith("Palette", Qt::CaseInsensitive)) { if (currentSection.startsWith("Palette", Qt::CaseInsensitive)) {
int dot = currentSection.indexOf('.'); int dot = currentSection.indexOf('.');
QString groupStr = (dot >= 0) QString groupStr = (dot >= 0) ? currentSection.mid(dot + 1) : "Active";
? currentSection.mid(dot + 1)
: "Active";
if (groupStr.compare("Disabled", Qt::CaseInsensitive) == 0) { if (groupStr.compare("Disabled", Qt::CaseInsensitive) == 0) {
currentGroup = QPalette::Disabled; currentGroup = QPalette::Disabled;
@ -232,19 +226,16 @@ PaletteConfig PaletteConfig::fromFile(const QString &filePath)
return cfg; return cfg;
} }
PaletteConfig PaletteConfig::fromScheme(const QString &themeDirPath, PaletteConfig PaletteConfig::fromScheme(const QString &themeDirPath, const QString &colorScheme)
const QString &colorScheme)
{ {
if (themeDirPath.isEmpty()) { if (themeDirPath.isEmpty()) {
return {}; return {};
} }
return fromFile( return fromFile(QDir(themeDirPath).absoluteFilePath(fileName(colorScheme)));
QDir(themeDirPath).absoluteFilePath(fileName(colorScheme)));
} }
PaletteConfig PaletteConfig::fromDefault(const QString &themeDirPath, PaletteConfig PaletteConfig::fromDefault(const QString &themeDirPath, const QString &colorScheme)
const QString &colorScheme)
{ {
if (themeDirPath.isEmpty()) { if (themeDirPath.isEmpty()) {
return {}; return {};
@ -252,21 +243,13 @@ PaletteConfig PaletteConfig::fromDefault(const QString &themeDirPath,
QDir dir(themeDirPath); QDir dir(themeDirPath);
bool wantDark = bool wantDark = colorScheme.compare("Dark", Qt::CaseInsensitive) == 0;
colorScheme.compare("Dark", Qt::CaseInsensitive) == 0;
PaletteConfig cfg = fromFile( PaletteConfig cfg =
dir.absoluteFilePath( fromFile(dir.absoluteFilePath(wantDark ? "palette-default-dark.toml" : "palette-default-light.toml"));
wantDark
? "palette-default-dark.toml"
: "palette-default-light.toml"));
if (!cfg.hasPalette()) { if (!cfg.hasPalette()) {
cfg = fromFile( cfg = fromFile(dir.absoluteFilePath(wantDark ? "palette-default-light.toml" : "palette-default-dark.toml"));
dir.absoluteFilePath(
wantDark
? "palette-default-light.toml"
: "palette-default-dark.toml"));
} }
return cfg; return cfg;
@ -275,9 +258,7 @@ PaletteConfig PaletteConfig::fromDefault(const QString &themeDirPath,
QPalette PaletteConfig::apply(QPalette base) const QPalette PaletteConfig::apply(QPalette base) const
{ {
for (auto git = colors.cbegin(); git != colors.cend(); ++git) { for (auto git = colors.cbegin(); git != colors.cend(); ++git) {
for (auto rit = git.value().cbegin(); for (auto rit = git.value().cbegin(); rit != git.value().cend(); ++rit) {
rit != git.value().cend();
++rit) {
base.setColor(git.key(), rit.key(), rit.value()); base.setColor(git.key(), rit.key(), rit.value());
} }
} }

View file

@ -28,10 +28,8 @@ struct PaletteConfig
static QString fileName(const QString &colorScheme); static QString fileName(const QString &colorScheme);
static PaletteConfig fromFile(const QString &filePath); static PaletteConfig fromFile(const QString &filePath);
static PaletteConfig fromScheme(const QString &themeDirPath, static PaletteConfig fromScheme(const QString &themeDirPath, const QString &colorScheme);
const QString &colorScheme); static PaletteConfig fromDefault(const QString &themeDirPath, const QString &colorScheme);
static PaletteConfig fromDefault(const QString &themeDirPath,
const QString &colorScheme);
QPalette apply(QPalette base) const; QPalette apply(QPalette base) const;
}; };

View file

@ -288,7 +288,7 @@ void ThemeManager::applyStyleAndPalette(const QString &themeName,
// Overlay custom palette colours // Overlay custom palette colours
if (palCfg.hasPalette()) { if (palCfg.hasPalette()) {
base = palCfg.apply( base); base = palCfg.apply(base);
} }
// Palette BEFORE style — setStyle() triggers a synchronous repolish of all // Palette BEFORE style — setStyle() triggers a synchronous repolish of all