forked from lsk-china/my-live2d-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigDialog.cpp
80 lines (74 loc) · 3.36 KB
/
configDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// Created by lsk on 10/25/22.
//
#include "configDialog.h"
#include <utility>
ConfigDialog::ConfigDialog(configuration currentConfiguration, QWidget *parent) : QDialog(parent) {
this->ui = new Ui::Dialog();
this->ui->setupUi(this);
this->currentConfiguration = currentConfiguration;
this->ui->mouseSensibility->setValue(currentConfiguration.getMouseSensibility() * 10);
this->reloadMouseSensibilityValue();
vector<string> models = this->listModels();
for (const string& model : models) {
this->ui->comboBox->addItem(STQ(model));
}
this->ui->comboBox->setCurrentText(this->currentConfiguration.getModelName());
this->ui->label_3->setText(this->currentConfiguration.getResourceDir());
this->ui->widgetHeight->setValue(this->currentConfiguration.getWidgetSize().height());
this->ui->widgetWidth->setValue(this->currentConfiguration.getWidgetSize().width());
connect(this->ui->pushButton_2, &QPushButton::clicked, this, [this](bool clicked) {
int height = this->ui->widgetHeight->value();
int width = this->ui->widgetWidth->value();
this->currentConfiguration.setWidgetSize(QSize(height, width));
emit okPressed(this->currentConfiguration);
this->currentConfiguration.save();
this->hide();
});
connect(this->ui->comboBox, &QComboBox::currentTextChanged, this, [this](QString model) {
this->currentConfiguration.setModelName(model);
});
connect(this->ui->pushButton_3, &QPushButton::clicked, this, [this]() {
this->hide();
});
connect(this->ui->pushButton, &QPushButton::clicked, this, [this]() {
QString selectedDir = QFileDialog::getExistingDirectory(this, "Choose resource directory", this->currentConfiguration.getResourceDir());
if (selectedDir.isEmpty()) {
return;
}
// complete the missing slash if selectDir is not endsWith slash
// otherwise, a SEGV will be thrown when the widget loads the model
selectedDir = !selectedDir.endsWith("/") ? selectedDir.append("/") : selectedDir;
this->currentConfiguration.setResourceDir(selectedDir);
this->ui->label_3->setText(this->currentConfiguration.getResourceDir());
vector<string> models = this->listModels();
for (const string& model : models) {
this->ui->comboBox->addItem(QString::fromStdString(model));
}
});
connect(this->ui->mouseSensibility, &QSlider::valueChanged, this, [this](int num) {
this->currentConfiguration.setMouseSensibility(num / 10.0);
this->reloadMouseSensibilityValue();
});
resize(680, 253);
setWindowModality(Qt::WindowModality::ApplicationModal);
setAttribute(Qt::WA_DeleteOnClose, false);
}
vector<string> ConfigDialog::listModels() {
vector<string> result;
for (const auto & entry : std::filesystem::directory_iterator(this->currentConfiguration.getResourceDir().toStdString())) {
if (entry.is_directory()) {
result.push_back(entry.path().filename());
}
}
return result;
}
ConfigDialog::~ConfigDialog() noexcept {
delete ui;
ui = nullptr;
this->currentConfiguration.save();
}
void ConfigDialog::reloadMouseSensibilityValue() {
double sensibility = this->currentConfiguration.getMouseSensibility();
this->ui->mouseSensibilityValue->setText(QString::fromStdString(to_string(sensibility)));
}