-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.cpp
261 lines (217 loc) · 7.1 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#include <QDebug>
#include <QDir>
#include <QCoreApplication>
#include <QStandardPaths>
#include "settings.h"
const QString Settings::RUN_ON_STARTUP_LNK_FILENAME = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/Startup/PowerPAD.lnk";
const QString Settings::PLAY_SOUNDS_ON_DISABLE_KEY = "General/PlaySoundsOnDisable";
const bool Settings::PLAY_SOUNDS_ON_DISABLE_DEFAULT = true;
const QString Settings::LANGUAGE_KEY = "General/Language";
const QString Settings::LANGUAGE_STRING_SYSTEM = "SYSTEM";
const QString Settings::LANGUAGE_STRING_DEFAULT = LANGUAGE_STRING_SYSTEM;
const QString Settings::MOUSE_SPEED_KEY = "Mouse/Speed";
const double Settings::MOUSE_SPEED_MIN = 0.0;
const double Settings::MOUSE_SPEED_DEFAULT = 5.0;
const double Settings::MOUSE_SPEED_MAX = 10.0;
const QString Settings::MOUSE_ACCELERATION_KEY = "Mouse/Acceleration";
const double Settings::MOUSE_ACCELERATION_MIN = 0.0;
const double Settings::MOUSE_ACCELERATION_DEFAULT = 5.0;
const double Settings::MOUSE_ACCELERATION_MAX = 10.0;
const QString Settings::MOUSE_SCROLL_SPEED_KEY = "Mouse/ScrollSpeed";
const double Settings::MOUSE_SCROLL_SPEED_MIN = 0.0;
const double Settings::MOUSE_SCROLL_SPEED_DEFAULT = 5.0;
const double Settings::MOUSE_SCROLL_SPEED_MAX = 10.0;
const QString Settings::LEFT_JOYSTICK_DEADZONE_KEY = "Controller/LeftJoystickDeadZone";
const QString Settings::RIGHT_JOYSTICK_DEADZONE_KEY = "Controller/RightJoystickDeadZone";
const quint32 Settings::JOYSTICK_DEADZONE_MIN = 2000;
const quint32 Settings::JOYSTICK_DEADZONE_DEFAULT = 7000;
const quint32 Settings::JOYSTICK_DEADZONE_MAX = 20000;
double Settings::mouseSpeedNormalize(double mouseSpeed)
{
return qMin(MOUSE_SPEED_MAX, qMax(MOUSE_SPEED_MIN, mouseSpeed));
}
double Settings::mouseScrollSpeedNormalize(double mouseScrollSpeed)
{
return qMin(MOUSE_SCROLL_SPEED_MAX, qMax(MOUSE_SCROLL_SPEED_MIN, mouseScrollSpeed));
}
double Settings::mouseAccelerationNormalize(double mouseAcceleration)
{
return qMin(MOUSE_ACCELERATION_MAX, qMax(MOUSE_ACCELERATION_MIN, mouseAcceleration));
}
quint32 Settings::joystickNormalize(quint32 joystickSpeed)
{
return qMin(JOYSTICK_DEADZONE_MAX, qMax(JOYSTICK_DEADZONE_MIN, joystickSpeed));
}
Settings::Settings(QObject *parent) : QObject(parent),
m_settings("Tekit", "PowerPAD")
{
revert();
}
Settings* Settings::instance()
{
static Settings *s = new Settings();
return s;
}
void Settings::setMouseSpeed(double mouseSpeed)
{
if (m_mouseSpeed == mouseSpeed)
return;
m_mouseSpeed = mouseSpeedNormalize(mouseSpeed);
emit mouseSpeedChanged();
}
double Settings::mouseSpeed()
{
return m_mouseSpeed;
}
double Settings::mouseSpeedDefault()
{
return MOUSE_SPEED_DEFAULT;
}
double Settings::mouseSpeedMin()
{
return MOUSE_SPEED_MIN;
}
double Settings::mouseSpeedMax()
{
return MOUSE_SPEED_MAX;
}
void Settings::setMouseAcceleration(double mouseAcceleration)
{
if (m_mouseAcceleration == mouseAcceleration)
return;
m_mouseAcceleration = mouseAccelerationNormalize(mouseAcceleration);
emit mouseAccelerationChanged();
}
double Settings::mouseAcceleration()
{
return m_mouseAcceleration;
}
double Settings::mouseAccelerationDefault()
{
return MOUSE_ACCELERATION_DEFAULT;
}
double Settings::mouseAccelerationMin()
{
return MOUSE_ACCELERATION_MIN;
}
double Settings::mouseAccelerationMax()
{
return MOUSE_ACCELERATION_MAX;
}
void Settings::setMouseScrollSpeed(double mouseScrollSpeed)
{
if (m_mouseScrollSpeed == mouseScrollSpeed)
return;
m_mouseScrollSpeed = mouseScrollSpeedNormalize(mouseScrollSpeed);
emit mouseScrollSpeedChanged();
}
double Settings::mouseScrollSpeed()
{
return m_mouseScrollSpeed;
}
double Settings::mouseScrollSpeedDefault()
{
return MOUSE_SCROLL_SPEED_DEFAULT;
}
double Settings::mouseScrollSpeedMin()
{
return MOUSE_SCROLL_SPEED_MIN;
}
double Settings::mouseScrollSpeedMax()
{
return MOUSE_SCROLL_SPEED_MAX;
}
void Settings::setRunOnStartup(bool runOnStartup)
{
if (m_runOnStartup != runOnStartup) {
m_runOnStartup = runOnStartup;
emit runOnStartupChanged();
}
}
bool Settings::runOnStartup()
{
return m_runOnStartup;
}
void Settings::setPlaySoundsOnDisable(bool playSoundsOnDisable)
{
if (m_playSoundsOnDisable != playSoundsOnDisable) {
m_playSoundsOnDisable = playSoundsOnDisable;
emit playSoundsOnDisableChanged();
}
}
bool Settings::playSoundsOnDisable()
{
return m_playSoundsOnDisable;
}
void Settings::setLanguage(const QString &language)
{
if (m_language != language) {
m_language = language;
emit languageChanged();
}
}
QString Settings::language()
{
return m_language;
}
void Settings::setLeftJoystickDeadZone(quint32 leftJoystickDeadZone)
{
if (m_leftJoystickDeadZone != leftJoystickDeadZone)
{
m_leftJoystickDeadZone = leftJoystickDeadZone;
emit leftJoystickDeadZoneChanged();
}
}
quint32 Settings::leftJoystickDeadZone()
{
return m_leftJoystickDeadZone;
}
void Settings::setRightJoystickDeadZone(quint32 rightJoystickDeadZone)
{
if (m_rightJoystickDeadZone != rightJoystickDeadZone)
{
m_rightJoystickDeadZone = rightJoystickDeadZone;
emit rightJoystickDeadZoneChanged();
}
}
quint32 Settings::rightJoystickDeadZone()
{
return m_rightJoystickDeadZone;
}
quint32 Settings::joystickDeadZoneDefault()
{
return JOYSTICK_DEADZONE_DEFAULT;
}
quint32 Settings::joystickDeadZoneMin()
{
return JOYSTICK_DEADZONE_MIN;
}
quint32 Settings::joystickDeadZoneMax()
{
return JOYSTICK_DEADZONE_MAX;
}
void Settings::commit()
{
if (m_runOnStartup)
QFile::link(QCoreApplication::applicationFilePath(), RUN_ON_STARTUP_LNK_FILENAME);
else
QFile::remove(RUN_ON_STARTUP_LNK_FILENAME);
m_settings.setValue(PLAY_SOUNDS_ON_DISABLE_KEY, m_playSoundsOnDisable);
m_settings.setValue(LANGUAGE_KEY, m_language);
m_settings.setValue(MOUSE_SPEED_KEY, m_mouseSpeed);
m_settings.setValue(MOUSE_ACCELERATION_KEY, m_mouseAcceleration);
m_settings.setValue(MOUSE_SCROLL_SPEED_KEY, m_mouseScrollSpeed);
m_settings.setValue(LEFT_JOYSTICK_DEADZONE_KEY, m_leftJoystickDeadZone);
m_settings.setValue(RIGHT_JOYSTICK_DEADZONE_KEY, m_rightJoystickDeadZone);
}
void Settings::revert()
{
setRunOnStartup(QFile::exists(RUN_ON_STARTUP_LNK_FILENAME));
setPlaySoundsOnDisable(m_settings.value(PLAY_SOUNDS_ON_DISABLE_KEY, PLAY_SOUNDS_ON_DISABLE_DEFAULT).toBool());
setLanguage(m_settings.value(LANGUAGE_KEY, LANGUAGE_STRING_DEFAULT).toString());
setMouseSpeed(mouseSpeedNormalize(m_settings.value(MOUSE_SPEED_KEY, MOUSE_SPEED_DEFAULT).toDouble()));
setMouseScrollSpeed(mouseScrollSpeedNormalize(m_settings.value(MOUSE_SCROLL_SPEED_KEY, MOUSE_SCROLL_SPEED_DEFAULT).toDouble()));
setMouseAcceleration(mouseAccelerationNormalize(m_settings.value(MOUSE_ACCELERATION_KEY, MOUSE_ACCELERATION_DEFAULT).toDouble()));
setLeftJoystickDeadZone(joystickNormalize(m_settings.value(LEFT_JOYSTICK_DEADZONE_KEY, JOYSTICK_DEADZONE_DEFAULT).toUInt()));
setRightJoystickDeadZone(joystickNormalize(m_settings.value(RIGHT_JOYSTICK_DEADZONE_KEY, JOYSTICK_DEADZONE_DEFAULT).toUInt()));
}