From 64a5b36e886f22c0e2696cd37a70e7729b1df94f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Sun, 17 May 2026 09:27:24 +0200 Subject: [PATCH] Remove namespace, fold I/O into structs. Took 33 seconds --- .../palette_editor/palette_editor_dialog.cpp | 5 +-- cockatrice/src/interface/theme_config.cpp | 41 +++++-------------- cockatrice/src/interface/theme_config.h | 6 +-- cockatrice/src/interface/theme_manager.cpp | 2 +- 4 files changed, 16 insertions(+), 38 deletions(-) diff --git a/cockatrice/src/interface/palette_editor/palette_editor_dialog.cpp b/cockatrice/src/interface/palette_editor/palette_editor_dialog.cpp index 195e73dad..826935f44 100644 --- a/cockatrice/src/interface/palette_editor/palette_editor_dialog.cpp +++ b/cockatrice/src/interface/palette_editor/palette_editor_dialog.cpp @@ -257,9 +257,8 @@ void PaletteEditorDialog::onSave() PaletteConfig cfg = paletteGrid->currentPaletteConfig(); if (!ThemeManager::savePaletteConfig(themeDirPath, loadedScheme, cfg)) { - QMessageBox::warning( - this, tr("Save failed"), - tr("Could not write %1 to:\n%2").arg(PaletteConfig::fileName(loadedScheme), themeDirPath)); + QMessageBox::warning(this, tr("Save failed"), + tr("Could not write %1 to:\n%2").arg(PaletteConfig::fileName(loadedScheme), themeDirPath)); return; } diff --git a/cockatrice/src/interface/theme_config.cpp b/cockatrice/src/interface/theme_config.cpp index fd63a5b24..b79c91265 100644 --- a/cockatrice/src/interface/theme_config.cpp +++ b/cockatrice/src/interface/theme_config.cpp @@ -127,9 +127,7 @@ QString PaletteConfig::toToml() const continue; } - out += QString("%1 = %2\n") - .arg(QString(roleName), -20) - .arg(it.value().name(QColor::HexArgb)); + out += QString("%1 = %2\n").arg(QString(roleName), -20).arg(it.value().name(QColor::HexArgb)); } out += "\n"; @@ -140,9 +138,7 @@ QString PaletteConfig::toToml() const QString PaletteConfig::fileName(const QString &colorScheme) { - return colorScheme.compare("Dark", Qt::CaseInsensitive) == 0 - ? "palette-dark.toml" - : "palette-light.toml"; + return colorScheme.compare("Dark", Qt::CaseInsensitive) == 0 ? "palette-dark.toml" : "palette-light.toml"; } PaletteConfig PaletteConfig::fromFile(const QString &filePath) @@ -175,9 +171,7 @@ PaletteConfig PaletteConfig::fromFile(const QString &filePath) if (currentSection.startsWith("Palette", Qt::CaseInsensitive)) { int dot = currentSection.indexOf('.'); - QString groupStr = (dot >= 0) - ? currentSection.mid(dot + 1) - : "Active"; + QString groupStr = (dot >= 0) ? currentSection.mid(dot + 1) : "Active"; if (groupStr.compare("Disabled", Qt::CaseInsensitive) == 0) { currentGroup = QPalette::Disabled; @@ -232,19 +226,16 @@ PaletteConfig PaletteConfig::fromFile(const QString &filePath) return cfg; } -PaletteConfig PaletteConfig::fromScheme(const QString &themeDirPath, - const QString &colorScheme) +PaletteConfig PaletteConfig::fromScheme(const QString &themeDirPath, const QString &colorScheme) { if (themeDirPath.isEmpty()) { return {}; } - return fromFile( - QDir(themeDirPath).absoluteFilePath(fileName(colorScheme))); + return fromFile(QDir(themeDirPath).absoluteFilePath(fileName(colorScheme))); } -PaletteConfig PaletteConfig::fromDefault(const QString &themeDirPath, - const QString &colorScheme) +PaletteConfig PaletteConfig::fromDefault(const QString &themeDirPath, const QString &colorScheme) { if (themeDirPath.isEmpty()) { return {}; @@ -252,21 +243,13 @@ PaletteConfig PaletteConfig::fromDefault(const QString &themeDirPath, QDir dir(themeDirPath); - bool wantDark = - colorScheme.compare("Dark", Qt::CaseInsensitive) == 0; + bool wantDark = colorScheme.compare("Dark", Qt::CaseInsensitive) == 0; - PaletteConfig cfg = fromFile( - dir.absoluteFilePath( - wantDark - ? "palette-default-dark.toml" - : "palette-default-light.toml")); + PaletteConfig cfg = + fromFile(dir.absoluteFilePath(wantDark ? "palette-default-dark.toml" : "palette-default-light.toml")); if (!cfg.hasPalette()) { - cfg = fromFile( - dir.absoluteFilePath( - wantDark - ? "palette-default-light.toml" - : "palette-default-dark.toml")); + cfg = fromFile(dir.absoluteFilePath(wantDark ? "palette-default-light.toml" : "palette-default-dark.toml")); } return cfg; @@ -275,9 +258,7 @@ PaletteConfig PaletteConfig::fromDefault(const QString &themeDirPath, QPalette PaletteConfig::apply(QPalette base) const { for (auto git = colors.cbegin(); git != colors.cend(); ++git) { - for (auto rit = git.value().cbegin(); - rit != git.value().cend(); - ++rit) { + for (auto rit = git.value().cbegin(); rit != git.value().cend(); ++rit) { base.setColor(git.key(), rit.key(), rit.value()); } } diff --git a/cockatrice/src/interface/theme_config.h b/cockatrice/src/interface/theme_config.h index 804cef6fb..07bf55b7a 100644 --- a/cockatrice/src/interface/theme_config.h +++ b/cockatrice/src/interface/theme_config.h @@ -28,10 +28,8 @@ struct PaletteConfig static QString fileName(const QString &colorScheme); static PaletteConfig fromFile(const QString &filePath); - static PaletteConfig fromScheme(const QString &themeDirPath, - const QString &colorScheme); - static PaletteConfig fromDefault(const QString &themeDirPath, - const QString &colorScheme); + static PaletteConfig fromScheme(const QString &themeDirPath, const QString &colorScheme); + static PaletteConfig fromDefault(const QString &themeDirPath, const QString &colorScheme); QPalette apply(QPalette base) const; }; diff --git a/cockatrice/src/interface/theme_manager.cpp b/cockatrice/src/interface/theme_manager.cpp index 4c06f6b5a..eeaa4e834 100644 --- a/cockatrice/src/interface/theme_manager.cpp +++ b/cockatrice/src/interface/theme_manager.cpp @@ -288,7 +288,7 @@ void ThemeManager::applyStyleAndPalette(const QString &themeName, // Overlay custom palette colours if (palCfg.hasPalette()) { - base = palCfg.apply( base); + base = palCfg.apply(base); } // Palette BEFORE style — setStyle() triggers a synchronous repolish of all