mirror of
https://github.com/huderlem/porymap.git
synced 2026-09-15 12:25:40 -05:00
Move themes to PreferenceEditor
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
#include "preferenceeditor.h"
|
||||
#include "ui_preferenceeditor.h"
|
||||
#include "config.h"
|
||||
#include "noscrollcombobox.h"
|
||||
|
||||
#include <QAbstractButton>
|
||||
#include <QRegularExpression>
|
||||
#include <QDirIterator>
|
||||
#include <QFormLayout>
|
||||
|
||||
|
||||
PreferenceEditor::PreferenceEditor(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::PreferenceEditor)
|
||||
ui(new Ui::PreferenceEditor),
|
||||
themeSelector(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
auto *formLayout = new QFormLayout(ui->groupBox_Themes);
|
||||
themeSelector = new NoScrollComboBox(ui->groupBox_Themes);
|
||||
formLayout->addRow("Themes", themeSelector);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
connect(ui->buttonBox, &QDialogButtonBox::clicked,
|
||||
this, &PreferenceEditor::dialogButtonClicked);
|
||||
@@ -23,10 +31,28 @@ PreferenceEditor::~PreferenceEditor()
|
||||
|
||||
void PreferenceEditor::populateFields() {
|
||||
ui->lineEdit_TextEditor->setText(porymapConfig.getTextEditorCommand());
|
||||
|
||||
QStringList themes = { "default" };
|
||||
QRegularExpression re(":/themes/([A-z0-9_-]+).qss");
|
||||
QDirIterator it(":/themes", QDirIterator::Subdirectories);
|
||||
while (it.hasNext()) {
|
||||
QString themeName = re.match(it.next()).captured(1);
|
||||
themes.append(themeName);
|
||||
}
|
||||
themeSelector->addItems(themes);
|
||||
themeSelector->setCurrentText(porymapConfig.getTheme());
|
||||
}
|
||||
|
||||
void PreferenceEditor::saveFields() {
|
||||
porymapConfig.setTextEditorCommand(ui->lineEdit_TextEditor->text());
|
||||
|
||||
if (themeSelector->currentText() != porymapConfig.getTheme()) {
|
||||
const auto theme = themeSelector->currentText();
|
||||
porymapConfig.setTheme(theme);
|
||||
emit themeChanged(theme);
|
||||
}
|
||||
|
||||
emit preferencesSaved();
|
||||
}
|
||||
|
||||
void PreferenceEditor::dialogButtonClicked(QAbstractButton *button) {
|
||||
|
||||
Reference in New Issue
Block a user