mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-29 09:22:18 -07:00
[ThemeManager] Generate and apply immediately on change.
This commit is contained in:
parent
5427e419cc
commit
1951aca10f
6 changed files with 30 additions and 32 deletions
|
|
@ -138,8 +138,7 @@ void PaletteEditorDialog::setupUi()
|
||||||
|
|
||||||
buttonBox = new QDialogButtonBox;
|
buttonBox = new QDialogButtonBox;
|
||||||
resetBtn = buttonBox->addButton(tr("Reset"), QDialogButtonBox::ResetRole);
|
resetBtn = buttonBox->addButton(tr("Reset"), QDialogButtonBox::ResetRole);
|
||||||
applyBtn = buttonBox->addButton(tr("Apply"), QDialogButtonBox::ApplyRole);
|
saveBtn = buttonBox->addButton(tr("Save"), QDialogButtonBox::AcceptRole);
|
||||||
saveBtn = buttonBox->addButton(tr("Save && Apply"), QDialogButtonBox::AcceptRole);
|
|
||||||
closeBtn = buttonBox->addButton(QDialogButtonBox::Close);
|
closeBtn = buttonBox->addButton(QDialogButtonBox::Close);
|
||||||
|
|
||||||
footerLayout->addWidget(revertButton);
|
footerLayout->addWidget(revertButton);
|
||||||
|
|
@ -149,10 +148,14 @@ void PaletteEditorDialog::setupUi()
|
||||||
|
|
||||||
// Connections
|
// Connections
|
||||||
connect(schemeComboBox, &QComboBox::currentTextChanged, this, &PaletteEditorDialog::onSchemeChanged);
|
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(revertButton, &QPushButton::clicked, this, &PaletteEditorDialog::onRevertToDefault);
|
||||||
connect(resetBtn, &QPushButton::clicked, this, &PaletteEditorDialog::onReset);
|
connect(resetBtn, &QPushButton::clicked, this, &PaletteEditorDialog::onReset);
|
||||||
connect(applyBtn, &QPushButton::clicked, this, &PaletteEditorDialog::onApply);
|
|
||||||
connect(saveBtn, &QPushButton::clicked, this, &PaletteEditorDialog::onSave);
|
connect(saveBtn, &QPushButton::clicked, this, &PaletteEditorDialog::onSave);
|
||||||
connect(closeBtn, &QPushButton::clicked, this, &QDialog::reject);
|
connect(closeBtn, &QPushButton::clicked, this, &QDialog::reject);
|
||||||
|
|
||||||
|
|
@ -186,10 +189,8 @@ void PaletteEditorDialog::retranslateUi()
|
||||||
revertButton->setText(tr("↺ Revert to theme default"));
|
revertButton->setText(tr("↺ Revert to theme default"));
|
||||||
|
|
||||||
resetBtn->setText(tr("Reset"));
|
resetBtn->setText(tr("Reset"));
|
||||||
applyBtn->setText(tr("Apply"));
|
saveBtn->setText(tr("Save"));
|
||||||
saveBtn->setText(tr("Save && Apply"));
|
|
||||||
resetBtn->setToolTip(tr("Discard unsaved edits and restore the last saved palette"));
|
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()));
|
saveBtn->setToolTip(tr("Write palette-%1.toml and reload the theme").arg(loadedScheme.toLower()));
|
||||||
|
|
||||||
if (saveDir.isEmpty() || !QFileInfo(saveDir).isWritable()) {
|
if (saveDir.isEmpty() || !QFileInfo(saveDir).isWritable()) {
|
||||||
|
|
@ -242,7 +243,6 @@ void PaletteEditorDialog::onSchemeChanged(const QString &scheme)
|
||||||
loadedScheme = scheme;
|
loadedScheme = scheme;
|
||||||
paletteGrid->loadPalette(workingConfig.value(scheme));
|
paletteGrid->loadPalette(workingConfig.value(scheme));
|
||||||
seedAccentFromScheme(scheme);
|
seedAccentFromScheme(scheme);
|
||||||
onApply();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaletteEditorDialog::onGenerateFromAccent(const QColor &accent, int intensity)
|
void PaletteEditorDialog::onGenerateFromAccent(const QColor &accent, int intensity)
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
||||||
|
class QTimer;
|
||||||
|
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QComboBox;
|
class QComboBox;
|
||||||
class QDialogButtonBox;
|
class QDialogButtonBox;
|
||||||
|
|
@ -48,7 +50,6 @@ private:
|
||||||
QComboBox *schemeComboBox = nullptr;
|
QComboBox *schemeComboBox = nullptr;
|
||||||
QDialogButtonBox *buttonBox = nullptr;
|
QDialogButtonBox *buttonBox = nullptr;
|
||||||
QPushButton *resetBtn = nullptr;
|
QPushButton *resetBtn = nullptr;
|
||||||
QPushButton *applyBtn = nullptr;
|
|
||||||
QPushButton *saveBtn = nullptr;
|
QPushButton *saveBtn = nullptr;
|
||||||
QPushButton *closeBtn = nullptr;
|
QPushButton *closeBtn = nullptr;
|
||||||
QPushButton *revertButton = nullptr;
|
QPushButton *revertButton = nullptr;
|
||||||
|
|
@ -64,6 +65,8 @@ private:
|
||||||
QMap<QString, PaletteConfig> workingConfig;
|
QMap<QString, PaletteConfig> workingConfig;
|
||||||
QMap<QString, PaletteConfig> savedConfig;
|
QMap<QString, PaletteConfig> savedConfig;
|
||||||
|
|
||||||
|
QTimer *autoApplyTimer = nullptr;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void changeEvent(QEvent *e) override;
|
void changeEvent(QEvent *e) override;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,7 @@ void PaletteGridWidget::buildGrid(QWidget *host)
|
||||||
for (int col = 0; col < 3; ++col) {
|
for (int col = 0; col < 3; ++col) {
|
||||||
auto group = ALL_GROUPS[col];
|
auto group = ALL_GROUPS[col];
|
||||||
auto *btn = new ColorButton(host);
|
auto *btn = new ColorButton(host);
|
||||||
|
connect(btn, &ColorButton::colorChanged, this, [this] { emit paletteChanged(); });
|
||||||
colorButtons[group][role] = btn;
|
colorButtons[group][role] = btn;
|
||||||
grid->addWidget(btn, row + 1, col + 1, Qt::AlignHCenter | Qt::AlignVCenter);
|
grid->addWidget(btn, row + 1, col + 1, Qt::AlignHCenter | Qt::AlignVCenter);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,9 @@ public:
|
||||||
void loadPalette(const PaletteConfig &cfg);
|
void loadPalette(const PaletteConfig &cfg);
|
||||||
PaletteConfig currentPaletteConfig() const;
|
PaletteConfig currentPaletteConfig() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void paletteChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void buildGrid(QWidget *host);
|
void buildGrid(QWidget *host);
|
||||||
void changeEvent(QEvent *e);
|
void changeEvent(QEvent *e);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPushButton>
|
|
||||||
#include <QSlider>
|
#include <QSlider>
|
||||||
|
|
||||||
QuickSetupPanel::QuickSetupPanel(QWidget *parent) : QWidget(parent)
|
QuickSetupPanel::QuickSetupPanel(QWidget *parent) : QWidget(parent)
|
||||||
|
|
@ -41,8 +40,6 @@ QuickSetupPanel::QuickSetupPanel(QWidget *parent) : QWidget(parent)
|
||||||
intensityPercentageLabel->setFixedWidth(34);
|
intensityPercentageLabel->setFixedWidth(34);
|
||||||
intensityPercentageLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
intensityPercentageLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||||
|
|
||||||
generateButton = new QPushButton(this);
|
|
||||||
|
|
||||||
layout->addWidget(heading);
|
layout->addWidget(heading);
|
||||||
layout->addSpacing(6);
|
layout->addSpacing(6);
|
||||||
layout->addWidget(accentLabel);
|
layout->addWidget(accentLabel);
|
||||||
|
|
@ -54,12 +51,13 @@ QuickSetupPanel::QuickSetupPanel(QWidget *parent) : QWidget(parent)
|
||||||
layout->addWidget(labelHigh);
|
layout->addWidget(labelHigh);
|
||||||
layout->addWidget(intensityPercentageLabel);
|
layout->addWidget(intensityPercentageLabel);
|
||||||
layout->addStretch();
|
layout->addStretch();
|
||||||
layout->addWidget(generateButton);
|
|
||||||
|
|
||||||
connect(intensitySlider, &QSlider::valueChanged, this,
|
connect(intensitySlider, &QSlider::valueChanged, this, [this](int v) {
|
||||||
[this](int v) { intensityPercentageLabel->setText(tr("%1%").arg(v)); });
|
intensityPercentageLabel->setText(tr("%1%").arg(v));
|
||||||
connect(generateButton, &QPushButton::clicked, this,
|
emit valueChanged(accentButton->getColor(), v);
|
||||||
[this] { emit generateRequested(accentButton->getColor(), intensitySlider->value()); });
|
});
|
||||||
|
connect(accentButton, &ColorButton::colorChanged, this,
|
||||||
|
[this](const QColor &c) { emit valueChanged(c, intensitySlider->value()); });
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,10 +75,6 @@ void QuickSetupPanel::retranslateUi()
|
||||||
"30–70 Accented — buttons, tooltips, and borders join in\n"
|
"30–70 Accented — buttons, tooltips, and borders join in\n"
|
||||||
"70–100 Full colour — backgrounds, everything"));
|
"70–100 Full colour — backgrounds, everything"));
|
||||||
intensityPercentageLabel->setText(tr("70%"));
|
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
|
QColor QuickSetupPanel::accentColor() const
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
class QPushButton;
|
|
||||||
class QHBoxLayout;
|
class QHBoxLayout;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QSlider;
|
class QSlider;
|
||||||
|
|
@ -16,12 +15,11 @@ class QSlider;
|
||||||
*
|
*
|
||||||
* The panel contains:
|
* The panel contains:
|
||||||
* - an accent color picker,
|
* - an accent color picker,
|
||||||
* - an intensity slider,
|
* - an intensity slider.
|
||||||
* - and a generate button.
|
|
||||||
*
|
*
|
||||||
* When the user clicks the generate button, the panel emits
|
* Whenever either value changes the panel emits valueChanged() with
|
||||||
* generateRequested() with the currently selected accent color
|
* the current accent colour and intensity, which the parent dialog
|
||||||
* and intensity value.
|
* uses to auto-apply the generated palette.
|
||||||
*
|
*
|
||||||
* Typically used together with PaletteGenerator::fromAccent()
|
* Typically used together with PaletteGenerator::fromAccent()
|
||||||
* to quickly generate color schemes from a chosen accent color.
|
* to quickly generate color schemes from a chosen accent color.
|
||||||
|
|
@ -71,12 +69,12 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
/**
|
||||||
* @brief Emitted when the user requests palette generation.
|
* @brief Emitted whenever the accent colour or intensity changes.
|
||||||
*
|
*
|
||||||
* @param accent The selected accent color.
|
* The parent dialog consumes this to auto-apply the generated palette
|
||||||
* @param intensity The selected intensity value.
|
* without requiring an explicit Generate click.
|
||||||
*/
|
*/
|
||||||
void generateRequested(QColor accent, int intensity);
|
void valueChanged(QColor accent, int intensity);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHBoxLayout *layout;
|
QHBoxLayout *layout;
|
||||||
|
|
@ -88,7 +86,6 @@ private:
|
||||||
QLabel *labelHigh;
|
QLabel *labelHigh;
|
||||||
QSlider *intensitySlider;
|
QSlider *intensitySlider;
|
||||||
QLabel *intensityPercentageLabel;
|
QLabel *intensityPercentageLabel;
|
||||||
QPushButton *generateButton;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COCKATRICE_QUICK_SETUP_PANEL_H
|
#endif // COCKATRICE_QUICK_SETUP_PANEL_H
|
||||||
Loading…
Add table
Add a link
Reference in a new issue