2020-11-16 12:39:42 +00:00
|
|
|
#include "preferenceeditor.h"
|
|
|
|
#include "ui_preferenceeditor.h"
|
|
|
|
#include "config.h"
|
2020-11-16 14:35:55 +00:00
|
|
|
#include "noscrollcombobox.h"
|
2020-11-16 12:39:42 +00:00
|
|
|
|
|
|
|
#include <QAbstractButton>
|
2020-11-16 14:35:55 +00:00
|
|
|
#include <QRegularExpression>
|
|
|
|
#include <QDirIterator>
|
|
|
|
#include <QFormLayout>
|
2020-11-16 12:39:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
PreferenceEditor::PreferenceEditor(QWidget *parent) :
|
|
|
|
QMainWindow(parent),
|
2020-11-16 14:35:55 +00:00
|
|
|
ui(new Ui::PreferenceEditor),
|
|
|
|
themeSelector(nullptr)
|
2020-11-16 12:39:42 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2020-11-16 14:35:55 +00:00
|
|
|
auto *formLayout = new QFormLayout(ui->groupBox_Themes);
|
|
|
|
themeSelector = new NoScrollComboBox(ui->groupBox_Themes);
|
|
|
|
formLayout->addRow("Themes", themeSelector);
|
2020-11-16 12:39:42 +00:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
connect(ui->buttonBox, &QDialogButtonBox::clicked,
|
|
|
|
this, &PreferenceEditor::dialogButtonClicked);
|
|
|
|
populateFields();
|
|
|
|
}
|
|
|
|
|
|
|
|
PreferenceEditor::~PreferenceEditor()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreferenceEditor::populateFields() {
|
2020-11-16 14:35:55 +00:00
|
|
|
QStringList themes = { "default" };
|
2022-11-23 03:57:26 +00:00
|
|
|
static const QRegularExpression re(":/themes/([A-z0-9_-]+).qss");
|
2020-11-16 14:35:55 +00:00
|
|
|
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());
|
2020-12-01 12:12:32 +00:00
|
|
|
|
|
|
|
ui->lineEdit_TextEditorOpenFolder->setText(porymapConfig.getTextEditorOpenFolder());
|
|
|
|
|
|
|
|
ui->lineEdit_TextEditorGotoLine->setText(porymapConfig.getTextEditorGotoLine());
|
2020-11-16 12:39:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreferenceEditor::saveFields() {
|
2020-11-16 14:35:55 +00:00
|
|
|
if (themeSelector->currentText() != porymapConfig.getTheme()) {
|
|
|
|
const auto theme = themeSelector->currentText();
|
|
|
|
porymapConfig.setTheme(theme);
|
|
|
|
emit themeChanged(theme);
|
|
|
|
}
|
|
|
|
|
2020-12-01 12:12:32 +00:00
|
|
|
porymapConfig.setTextEditorOpenFolder(ui->lineEdit_TextEditorOpenFolder->text());
|
|
|
|
|
|
|
|
porymapConfig.setTextEditorGotoLine(ui->lineEdit_TextEditorGotoLine->text());
|
|
|
|
|
2020-11-16 14:35:55 +00:00
|
|
|
emit preferencesSaved();
|
2020-11-16 12:39:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreferenceEditor::dialogButtonClicked(QAbstractButton *button) {
|
|
|
|
auto buttonRole = ui->buttonBox->buttonRole(button);
|
|
|
|
if (buttonRole == QDialogButtonBox::AcceptRole) {
|
|
|
|
saveFields();
|
|
|
|
close();
|
|
|
|
} else if (buttonRole == QDialogButtonBox::ApplyRole) {
|
|
|
|
saveFields();
|
|
|
|
} else if (buttonRole == QDialogButtonBox::RejectRole) {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
}
|