-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettingdialog.cpp
More file actions
87 lines (76 loc) · 2.91 KB
/
settingdialog.cpp
File metadata and controls
87 lines (76 loc) · 2.91 KB
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
81
82
83
84
85
86
87
#include "settingdialog.h"
#include "widget.h"
#include "settings.h"
#include <QSettings>
#include <QPushButton>
SettingDialog::SettingDialog(QWidget *parent) :
QDialog(parent),
filePath(QApplication::applicationFilePath().replace('/', '\\'))
{
setupUi(this);
setting = new QSettings(St::OrgName, St::AppName, this);
reg = new QSettings(R"(HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run)",
QSettings::NativeFormat, this);
readSetting();
textLineEdit->setToolTip(tr("Use %0 to represent the number generated automatically").arg(St::Default_Symbol));
buttonBox->button(QDialogButtonBox::Save)->setText(tr("Save"));
buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));
buttonBox->button(QDialogButtonBox::RestoreDefaults)->setText(tr("Restore Defaults"));
}
void SettingDialog::readSetting()
{
calendar->setSelectedDate(setting->value(St::Date_ExamDate, St::Default_Date).toDate());
textLineEdit->setText(
setting->value(
St::Date_Text,
tr("%0 Days Before Entrance Exam").arg(St::Default_Symbol)
).toString());
opacityDoubleSpinBox->setValue(setting->value(St::Action_Opacity, St::Default_Opacity).toDouble());
// Read startup state
if (reg->value(St::AppName).toString() == filePath) {
autoRunCheckBox->setChecked(true);
} else {
autoRunCheckBox->setChecked(false);
}
}
/// Save new Settings
void SettingDialog::on_buttonBox_accepted()
{
// Set exam date
setting->setValue(St::Date_ExamDate, calendar->selectedDate());
setting->setValue(St::Date_Text, textLineEdit->text());
setting->setValue(St::Action_Opacity, opacityDoubleSpinBox->value());
// Change startup state
if (autoRunCheckBox->isChecked()) {
if (reg->value(St::AppName).toString() != filePath) {
reg->setValue(St::AppName, filePath);
}
} else {
reg->remove(St::AppName);
}
}
/// Restore Defaults Settings
void SettingDialog::on_buttonBox_clicked(QAbstractButton *button)
{
if (button == buttonBox->button(QDialogButtonBox::RestoreDefaults)) {
bool isFirstRun = setting->value(St::Action_FirstRun, true).toBool();
setting->remove(St::Date);
setting->remove(St::Action);
reg->remove(St::AppName);
setting->setValue(St::Action_FirstRun, isFirstRun);
readSetting(); // Read Default Settings
Widget *p = dynamic_cast<Widget*>(parentWidget());
if (p)
p->readSetting();
}
}
/// Sync opacitySlider to opacityDoubleSpinBox
void SettingDialog::on_opacitySlider_valueChanged(int value)
{
opacityDoubleSpinBox->setValue(value * 0.01);
}
/// Sync opacityDoubleSpinBox to opacitySlider
void SettingDialog::on_opacityDoubleSpinBox_valueChanged(double value)
{
opacitySlider->setValue(int(value * 100 + 0.5)); // int(n+0.5), get a round number
}