Improve theme editor usability so themes can be set from it

This commit is contained in:
luisangelsm
2026-03-06 15:06:20 +01:00
parent 86b5003f07
commit 0ceba0ea74
3 changed files with 35 additions and 3 deletions

View File

@ -189,6 +189,22 @@ AppearanceTabWidget::AppearanceTabWidget(
themeEditor->setAttribute(Qt::WA_DeleteOnClose);
connect(themeEditor, &ThemeEditorDialog::themeJsonChanged, this,
[this](const QJsonObject &json) { this->applyTheme(json); });
connect(themeEditor, &ThemeEditorDialog::saveToLibraryRequested, this,
[this](const QJsonObject &json) {
if (!this->repository)
return;
const QString id = this->repository->saveUserTheme(json);
this->repopulateCombos();
const bool isLight = (json["meta"].toObject()["variant"].toString() == "light");
if (isLight)
selectInCombo(this->lightCombo, id);
else
selectInCombo(this->darkCombo, id);
if (this->config && this->config->selection().mode == ThemeMode::ForcedTheme)
selectInCombo(this->customCombo, id);
if (this->themeEditor)
this->themeEditor->updateSavedId(id);
});
}
themeEditor->show();
themeEditor->raise();

View File

@ -150,14 +150,19 @@ ThemeEditorDialog::ThemeEditorDialog(const QJsonObject &params, QWidget *parent)
});
// --- bottom buttons ---
auto *saveBtn = new QPushButton(tr("Save to file..."), this);
auto *saveLibBtn = new QPushButton(tr("Save and apply"), this);
auto *exportBtn = new QPushButton(tr("Export to file..."), this);
auto *loadBtn = new QPushButton(tr("Load from file..."), this);
auto *closeBtn = new QPushButton(tr("Close"), this);
connect(saveBtn, &QPushButton::clicked, this, &ThemeEditorDialog::saveToFile);
connect(saveLibBtn, &QPushButton::clicked, this, [this]() {
emit saveToLibraryRequested(this->params);
});
connect(exportBtn, &QPushButton::clicked, this, &ThemeEditorDialog::saveToFile);
connect(loadBtn, &QPushButton::clicked, this, &ThemeEditorDialog::loadFromFile);
connect(closeBtn, &QPushButton::clicked, this, &QDialog::close);
auto *buttons = new QHBoxLayout();
buttons->addWidget(saveBtn);
buttons->addWidget(saveLibBtn);
buttons->addWidget(exportBtn);
buttons->addWidget(loadBtn);
buttons->addStretch();
buttons->addWidget(closeBtn);
@ -373,6 +378,14 @@ void ThemeEditorDialog::syncMetaFromParams()
variantCombo->setCurrentIndex(variant == "light" ? 0 : 1);
}
void ThemeEditorDialog::updateSavedId(const QString &id)
{
auto meta = params["meta"].toObject();
meta["id"] = id;
params["meta"] = meta;
idLabel->setText(id);
}
void ThemeEditorDialog::saveToFile()
{
// Assign a user-scoped UUID if the current id is builtin or empty

View File

@ -21,8 +21,11 @@ public:
QJsonObject currentParams() const { return params; }
void updateSavedId(const QString &id);
signals:
void themeJsonChanged(const QJsonObject &params);
void saveToLibraryRequested(const QJsonObject &json);
private:
void populate(QTreeWidgetItem *parent, const QJsonObject &obj, const QStringList &path);