1
/* *************************************************************************
2
* Copyright 2012 Jakob Gruber <jakob.gruber@gmail.com> *
4
* This program is free software: you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation, either version 2 of the License, or *
7
* (at your option) any later version. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
16
************************************************************************* */
21
Settings::Settings() {
23
m_keys << "game/width"
26
<< "game/prevent_mistakes"
28
<< "game/custom_bg_enabled"
29
<< "game/custom_bg_path"
30
<< "game/font_color_solved"
31
<< "game/font_color_unsolved";
33
m_qsettings = QSharedPointer<QSettings>(new QSettings);
37
int Settings::height() const {
41
int Settings::width() const {
45
double Settings::boxDensity() const {
49
bool Settings::preventMistakes() const {
50
return m_prevent_mistakes;
53
KgDifficultyLevel::StandardLevel Settings::level() const {
57
bool Settings::customBgEnabled() const
59
return m_custom_bg_enabled;
62
QString Settings::customBgPath() const
64
return m_custom_bg_path;
67
QString Settings::fontColorSolved() const
69
return m_font_color_solved;
72
QString Settings::fontColorUnsolved() const
74
return m_font_color_unsolved;
77
void Settings::setWidth(int width) {
79
setValue(Width, width);
82
void Settings::setHeight(int height) {
84
setValue(Height, height);
87
void Settings::setBoxDensity(double box_density) {
88
m_box_density = box_density;
89
setValue(BoxDensity, box_density);
92
void Settings::setPreventMistakes(bool prevent_mistakes) {
93
m_prevent_mistakes = prevent_mistakes;
94
setValue(PreventMistakes, prevent_mistakes);
97
void Settings::setLevel(KgDifficultyLevel::StandardLevel level) {
99
setValue(Level, level);
102
void Settings::setCustomBgEnabled(bool enabled)
104
m_custom_bg_enabled = enabled;
105
setValue(CustomBgEnabled, enabled);
108
void Settings::setCustomBgPath(const QString &path)
110
m_custom_bg_path = path;
111
setValue(CustomBgPath, path);
114
void Settings::setFontColorSolved(const QString &color)
116
m_font_color_solved = color;
117
setValue(FontColorSolved, color);
120
void Settings::setFontColorUnsolved(const QString &color)
122
m_font_color_unsolved = color;
123
setValue(FontColorUnsolved, color);
126
void Settings::restore() {
127
m_width = m_qsettings->value(m_keys[Width], 15).toInt();
128
m_height = m_qsettings->value(m_keys[Height], 10).toInt();
129
m_box_density = m_qsettings->value(m_keys[BoxDensity], 0.55).toDouble();
130
m_prevent_mistakes = m_qsettings->value(m_keys[PreventMistakes], false).toBool();
131
m_level = (KgDifficultyLevel::StandardLevel)m_qsettings->value(m_keys[Level],
132
KgDifficultyLevel::Medium).toInt();
133
m_custom_bg_enabled = m_qsettings->value(m_keys[CustomBgEnabled], false).toBool();
134
m_custom_bg_path = m_qsettings->value(m_keys[CustomBgPath], "").toString();
135
m_font_color_solved = m_qsettings->value(m_keys[FontColorSolved], "#555555").toString();
136
m_font_color_unsolved = m_qsettings->value(m_keys[FontColorUnsolved], "#000000").toString();
139
void Settings::setValue(SettingsType type, const QVariant &value)
141
m_qsettings->setValue(m_keys[type], value);
142
emit settingChanged(type);
145
void Settings::sync()
150
Settings *Settings::instance()
152
static Settings settings;