[ThemeManager] Generate and apply immediately on change.

This commit is contained in:
Lukas Brübach 2026-07-21 09:35:13 +02:00
parent 5427e419cc
commit 1951aca10f
6 changed files with 30 additions and 32 deletions

View file

@ -138,8 +138,7 @@ void PaletteEditorDialog::setupUi()
buttonBox = new QDialogButtonBox;
resetBtn = buttonBox->addButton(tr("Reset"), QDialogButtonBox::ResetRole);
applyBtn = buttonBox->addButton(tr("Apply"), QDialogButtonBox::ApplyRole);
saveBtn = buttonBox->addButton(tr("Save && Apply"), QDialogButtonBox::AcceptRole);
saveBtn = buttonBox->addButton(tr("Save"), QDialogButtonBox::AcceptRole);
closeBtn = buttonBox->addButton(QDialogButtonBox::Close);
footerLayout->addWidget(revertButton);
@ -149,10 +148,14 @@ void PaletteEditorDialog::setupUi()
// Connections
connect(schemeComboBox, &QComboBox::currentTextChanged, this, &PaletteEditorDialog::onSchemeChanged);
connect(quickSetupPanel, &QuickSetupPanel::generateRequested, this, &PaletteEditorDialog::onGenerateFromAccent);
autoApplyTimer = new QTimer(this);
autoApplyTimer->setSingleShot(true);
autoApplyTimer->setInterval(150);
connect(autoApplyTimer, &QTimer::timeout, this, &PaletteEditorDialog::onApply);
connect(quickSetupPanel, &QuickSetupPanel::valueChanged, this, &PaletteEditorDialog::onGenerateFromAccent);
connect(paletteGrid, &PaletteGridWidget::paletteChanged, this, [this] { autoApplyTimer->start(); });
connect(revertButton, &QPushButton::clicked, this, &PaletteEditorDialog::onRevertToDefault);
connect(resetBtn, &QPushButton::clicked, this, &PaletteEditorDialog::onReset);
connect(applyBtn, &QPushButton::clicked, this, &PaletteEditorDialog::onApply);
connect(saveBtn, &QPushButton::clicked, this, &PaletteEditorDialog::onSave);
connect(closeBtn, &QPushButton::clicked, this, &QDialog::reject);
@ -186,10 +189,8 @@ void PaletteEditorDialog::retranslateUi()
revertButton->setText(tr("↺ Revert to theme default"));
resetBtn->setText(tr("Reset"));
applyBtn->setText(tr("Apply"));
saveBtn->setText(tr("Save && Apply"));
saveBtn->setText(tr("Save"));
resetBtn->setToolTip(tr("Discard unsaved edits and restore the last saved palette"));
applyBtn->setToolTip(tr("Preview this palette without saving to disk"));
saveBtn->setToolTip(tr("Write palette-%1.toml and reload the theme").arg(loadedScheme.toLower()));
if (saveDir.isEmpty() || !QFileInfo(saveDir).isWritable()) {
@ -242,7 +243,6 @@ void PaletteEditorDialog::onSchemeChanged(const QString &scheme)
loadedScheme = scheme;
paletteGrid->loadPalette(workingConfig.value(scheme));
seedAccentFromScheme(scheme);
onApply();
}
void PaletteEditorDialog::onGenerateFromAccent(const QColor &accent, int intensity)

View file

@ -7,6 +7,8 @@
#include <QFrame>
#include <QMap>
class QTimer;
class QLabel;
class QComboBox;
class QDialogButtonBox;
@ -48,7 +50,6 @@ private:
QComboBox *schemeComboBox = nullptr;
QDialogButtonBox *buttonBox = nullptr;
QPushButton *resetBtn = nullptr;
QPushButton *applyBtn = nullptr;
QPushButton *saveBtn = nullptr;
QPushButton *closeBtn = nullptr;
QPushButton *revertButton = nullptr;
@ -64,6 +65,8 @@ private:
QMap<QString, PaletteConfig> workingConfig;
QMap<QString, PaletteConfig> savedConfig;
QTimer *autoApplyTimer = nullptr;
protected:
void changeEvent(QEvent *e) override;
};

View file

@ -117,6 +117,7 @@ void PaletteGridWidget::buildGrid(QWidget *host)
for (int col = 0; col < 3; ++col) {
auto group = ALL_GROUPS[col];
auto *btn = new ColorButton(host);
connect(btn, &ColorButton::colorChanged, this, [this] { emit paletteChanged(); });
colorButtons[group][role] = btn;
grid->addWidget(btn, row + 1, col + 1, Qt::AlignHCenter | Qt::AlignVCenter);
}

View file

@ -22,6 +22,9 @@ public:
void loadPalette(const PaletteConfig &cfg);
PaletteConfig currentPaletteConfig() const;
signals:
void paletteChanged();
private:
void buildGrid(QWidget *host);
void changeEvent(QEvent *e);

View file

@ -3,7 +3,6 @@
#include <QApplication>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QSlider>
QuickSetupPanel::QuickSetupPanel(QWidget *parent) : QWidget(parent)
@ -41,8 +40,6 @@ QuickSetupPanel::QuickSetupPanel(QWidget *parent) : QWidget(parent)
intensityPercentageLabel->setFixedWidth(34);
intensityPercentageLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
generateButton = new QPushButton(this);
layout->addWidget(heading);
layout->addSpacing(6);
layout->addWidget(accentLabel);
@ -54,12 +51,13 @@ QuickSetupPanel::QuickSetupPanel(QWidget *parent) : QWidget(parent)
layout->addWidget(labelHigh);
layout->addWidget(intensityPercentageLabel);
layout->addStretch();
layout->addWidget(generateButton);
connect(intensitySlider, &QSlider::valueChanged, this,
[this](int v) { intensityPercentageLabel->setText(tr("%1%").arg(v)); });
connect(generateButton, &QPushButton::clicked, this,
[this] { emit generateRequested(accentButton->getColor(), intensitySlider->value()); });
connect(intensitySlider, &QSlider::valueChanged, this, [this](int v) {
intensityPercentageLabel->setText(tr("%1%").arg(v));
emit valueChanged(accentButton->getColor(), v);
});
connect(accentButton, &ColorButton::colorChanged, this,
[this](const QColor &c) { emit valueChanged(c, intensitySlider->value()); });
retranslateUi();
}
@ -77,10 +75,6 @@ void QuickSetupPanel::retranslateUi()
"30–70 Accented — buttons, tooltips, and borders join in\n"
"70–100 Full colour — backgrounds, everything"));
intensityPercentageLabel->setText(tr("70%"));
generateButton->setText(tr("Generate ↓"));
generateButton->setToolTip(tr("Derive all palette roles from the accent colour above.\n"
"Fine-tune individual colours in the grid afterwards."));
}
QColor QuickSetupPanel::accentColor() const

View file

@ -5,7 +5,6 @@
#include <QWidget>
class QPushButton;
class QHBoxLayout;
class QLabel;
class QSlider;
@ -16,12 +15,11 @@ class QSlider;
*
* The panel contains:
* - an accent color picker,
* - an intensity slider,
* - and a generate button.
* - an intensity slider.
*
* When the user clicks the generate button, the panel emits
* generateRequested() with the currently selected accent color
* and intensity value.
* Whenever either value changes the panel emits valueChanged() with
* the current accent colour and intensity, which the parent dialog
* uses to auto-apply the generated palette.
*
* Typically used together with PaletteGenerator::fromAccent()
* to quickly generate color schemes from a chosen accent color.
@ -71,12 +69,12 @@ public:
signals:
/**
* @brief Emitted when the user requests palette generation.
* @brief Emitted whenever the accent colour or intensity changes.
*
* @param accent The selected accent color.
* @param intensity The selected intensity value.
* The parent dialog consumes this to auto-apply the generated palette
* without requiring an explicit Generate click.
*/
void generateRequested(QColor accent, int intensity);
void valueChanged(QColor accent, int intensity);
private:
QHBoxLayout *layout;
@ -88,7 +86,6 @@ private:
QLabel *labelHigh;
QSlider *intensitySlider;
QLabel *intensityPercentageLabel;
QPushButton *generateButton;
};
#endif // COCKATRICE_QUICK_SETUP_PANEL_H