From 0ceba0ea74f9040dd3071d66d3c842aefe7ce58e Mon Sep 17 00:00:00 2001 From: luisangelsm Date: Fri, 6 Mar 2026 15:06:20 +0100 Subject: [PATCH] Improve theme editor usability so themes can be set from it --- common/themes/appearance_tab_widget.cpp | 16 ++++++++++++++++ common/themes/theme_editor_dialog.cpp | 19 ++++++++++++++++--- common/themes/theme_editor_dialog.h | 3 +++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/common/themes/appearance_tab_widget.cpp b/common/themes/appearance_tab_widget.cpp index bcf1f218..387ac094 100644 --- a/common/themes/appearance_tab_widget.cpp +++ b/common/themes/appearance_tab_widget.cpp @@ -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(); diff --git a/common/themes/theme_editor_dialog.cpp b/common/themes/theme_editor_dialog.cpp index 72d03327..459f9b5b 100644 --- a/common/themes/theme_editor_dialog.cpp +++ b/common/themes/theme_editor_dialog.cpp @@ -150,14 +150,19 @@ ThemeEditorDialog::ThemeEditorDialog(const QJsonObject ¶ms, 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 diff --git a/common/themes/theme_editor_dialog.h b/common/themes/theme_editor_dialog.h index a2f5a5e2..e889d95a 100644 --- a/common/themes/theme_editor_dialog.h +++ b/common/themes/theme_editor_dialog.h @@ -21,8 +21,11 @@ public: QJsonObject currentParams() const { return params; } + void updateSavedId(const QString &id); + signals: void themeJsonChanged(const QJsonObject ¶ms); + void saveToLibraryRequested(const QJsonObject &json); private: void populate(QTreeWidgetItem *parent, const QJsonObject &obj, const QStringList &path);