67 lines
1.3 KiB
C++
67 lines
1.3 KiB
C++
#include "settingsdialog.h"
|
|
#include "ui_settingsdialog.h"
|
|
|
|
using namespace Xybrid;
|
|
|
|
#include <QDialogButtonBox>
|
|
#include <QPushButton>
|
|
|
|
#include "fileops.h"
|
|
#include "config/uiconfig.h"
|
|
using namespace Xybrid::Config;
|
|
|
|
SettingsDialog* SettingsDialog::instance = nullptr;
|
|
|
|
namespace {
|
|
std::vector<std::function<void()>>* bnd;
|
|
|
|
void bind(QCheckBox* o, bool& v) {
|
|
o->setChecked(v);
|
|
bnd->push_back([o, &v] {
|
|
v = o->isChecked();
|
|
});
|
|
}
|
|
}
|
|
|
|
SettingsDialog::SettingsDialog(QWidget *parent) :
|
|
QDialog(parent),
|
|
ui(new Ui::SettingsDialog) {
|
|
ui->setupUi(this);
|
|
|
|
connect(ui->buttonBox->button(QDialogButtonBox::Apply), &QPushButton::clicked, this, &SettingsDialog::apply);
|
|
|
|
instance = this;
|
|
bnd = &this->binds;
|
|
|
|
bind(ui->checkVerticalKnobs, UIConfig::verticalKnobs);
|
|
}
|
|
|
|
SettingsDialog::~SettingsDialog() {
|
|
if (instance == this) instance = nullptr;
|
|
delete ui;
|
|
}
|
|
|
|
void SettingsDialog::apply() {
|
|
for (auto& f : binds) f();
|
|
FileOps::saveConfig();
|
|
}
|
|
|
|
void SettingsDialog::reject() {
|
|
QDialog::reject();
|
|
if (instance == this) instance = nullptr;
|
|
deleteLater();
|
|
}
|
|
|
|
void SettingsDialog::tryOpen() {
|
|
if (!instance) {
|
|
(new SettingsDialog(nullptr))->show();
|
|
} else {
|
|
instance->show();
|
|
instance->raise();
|
|
instance->activateWindow();
|
|
}
|
|
}
|
|
|
|
|
|
|