mirror of
https://github.com/YACReader/yacreader
synced 2026-04-12 15:49:53 -04:00
Improve theme editor usability so themes can be set from it
This commit is contained in:
@ -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();
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user