forked from kn0w0n3/Super_Mario
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.cpp
152 lines (117 loc) · 4.25 KB
/
settings.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* Author: equati0n
* Date: December 2016
*/
#include "settings.h"
#include <iostream>
Settings::Settings(QWidget *parent) : QDialog(parent){
label = new QLabel(tr("Developer Login: "));
lineEdit = new QLineEdit;
lineEdit->setObjectName(QString("lineEdit"));
label->setBuddy(lineEdit);
bgmLabel = new QLabel(tr("Music"));
bgmSlider = new QSlider(Qt::Horizontal);
bgmSpinBox = new QSpinBox;
bgmSlider->setRange(0,100);
bgmSpinBox->setRange(0,100);
sfxLabel = new QLabel(tr("Sound Effects"));
sfxSlider = new QSlider(Qt::Horizontal);
sfxSpinBox = new QSpinBox;
sfxSlider->setRange(0,100);
sfxSpinBox->setRange(0,100);
screenSize = new QLabel(tr("Full Screen"));
fullScreenView = new QRadioButton("On");
windowedView = new QRadioButton("Off");
windowedView->setChecked(true);
confirmButton = new QPushButton(tr("Confirm"));
cancelButton = new QPushButton(tr("Cancel"));
connect(bgmSpinBox, SIGNAL(valueChanged(int)), bgmSlider, SLOT(setValue(int)));
connect(bgmSlider, SIGNAL(valueChanged(int)), bgmSpinBox, SLOT(setValue(int)));
connect(bgmSlider, SIGNAL(valueChanged(int)), this, SLOT(bgmChanged()));
connect(sfxSpinBox, SIGNAL(valueChanged(int)), sfxSlider, SLOT(setValue(int)));
connect(sfxSlider, SIGNAL(valueChanged(int)), sfxSpinBox, SLOT(setValue(int)));
connect(sfxSlider, SIGNAL(valueChanged(int)), this, SLOT(sfxChanged()));
connect(confirmButton, SIGNAL(clicked(bool)), this, SLOT(confirm()));
connect(cancelButton, SIGNAL(clicked(bool)), this, SLOT(reject()));
QHBoxLayout *firstLayout = new QHBoxLayout;
firstLayout->addWidget(label);
firstLayout->addWidget(lineEdit);
QHBoxLayout *secondLayout = new QHBoxLayout;
secondLayout->addWidget(screenSize);
secondLayout->addStretch();
secondLayout->addWidget(fullScreenView);
secondLayout->addWidget(windowedView);
secondLayout->addStretch();
QHBoxLayout *thirdLayout = new QHBoxLayout;
thirdLayout->addWidget(bgmLabel);
thirdLayout->addStretch();
thirdLayout->addWidget((bgmSlider));
thirdLayout->addWidget(bgmSpinBox);
QHBoxLayout *fourthLayout = new QHBoxLayout;
fourthLayout->addWidget(sfxLabel);
fourthLayout->addWidget((sfxSlider));
fourthLayout->addWidget(sfxSpinBox);
QHBoxLayout *fifthLayout = new QHBoxLayout;
fifthLayout->addWidget(confirmButton);
fifthLayout->addWidget(cancelButton);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(firstLayout);
mainLayout->addLayout(secondLayout);
mainLayout->addLayout(thirdLayout);
mainLayout->addLayout(fourthLayout);
mainLayout->addLayout(fifthLayout);
setLayout(mainLayout);
setWindowModality(Qt::WindowModal);
setWindowTitle("Settings");
}
void Settings::reject() {
this->revertState();
QDialog::reject();
}
void Settings::setState() {
full = fullScreenView->isChecked();
window = windowedView->isChecked();
bgm = bgmSlider->value();
sfx = sfxSlider->value();
}
void Settings::revertState() {
fullScreenView->setChecked(full);
windowedView->setChecked(window);
bgmSlider->setValue(bgm);
sfxSlider->setValue(sfx);
}
void Settings::alterState() {
if(full){
windowedView->setChecked(true);
} else {
fullScreenView->setChecked(true);
}
this->show();
this->confirm();
}
void Settings::readSettings() {
QSettings settings("CSC-17B Mario Group", "Mario Game");
fullScreenView->setChecked(settings.value("fullscreen", false).toBool());
bgmSlider->setValue(settings.value("bgm", 50).toInt());
sfxSlider->setValue(settings.value("sfx", 50).toInt());
confirm();
}
void Settings::writeSettings() {
QSettings settings("CSC-17B Mario Group", "Mario Game");
settings.setValue("fullscreen", fullScreenView->isChecked());
settings.setValue("bgm", bgmSlider->value());
settings.setValue("sfx", sfxSlider->value());
}
void Settings::bgmChanged() {
emit bgmAdjust(bgmSlider->value());
}
void Settings::sfxChanged() {
emit sfxAdjust(sfxSlider->value());
}
void Settings::confirm() {
emit fullScreen(fullScreenView->isChecked());
emit bgmAdjust(bgmSlider->value());
emit sfxAdjust(sfxSlider->value());
this->setState();
this->close();
}