~ubuntu-branches/ubuntu/utopic/picmi/utopic

« back to all changes in this revision

Viewing changes to src/settings.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-12-03 17:39:47 UTC
  • Revision ID: package-import@ubuntu.com-20121203173947-tt1kk5wp92zk1f2z
Tags: upstream-4.9.90
ImportĀ upstreamĀ versionĀ 4.9.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* *************************************************************************
 
2
 *  Copyright 2012 Jakob Gruber <jakob.gruber@gmail.com>                   *
 
3
 *                                                                         *
 
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.                                    *
 
8
 *                                                                         *
 
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.                           *
 
13
 *                                                                         *
 
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
 ************************************************************************* */
 
17
 
 
18
 
 
19
#include "settings.h"
 
20
 
 
21
Settings::Settings() {
 
22
 
 
23
    m_keys << "game/width"
 
24
           << "game/height"
 
25
           << "game/box_ratio"
 
26
           << "game/prevent_mistakes"
 
27
           << "game/level"
 
28
           << "game/custom_bg_enabled"
 
29
           << "game/custom_bg_path"
 
30
           << "game/font_color_solved"
 
31
           << "game/font_color_unsolved";
 
32
 
 
33
    m_qsettings = QSharedPointer<QSettings>(new QSettings);
 
34
    restore();
 
35
}
 
36
 
 
37
int Settings::height() const {
 
38
    return m_height;
 
39
}
 
40
 
 
41
int Settings::width() const {
 
42
    return m_width;
 
43
}
 
44
 
 
45
double Settings::boxDensity() const {
 
46
    return m_box_density;
 
47
}
 
48
 
 
49
bool Settings::preventMistakes() const {
 
50
    return m_prevent_mistakes;
 
51
}
 
52
 
 
53
KgDifficultyLevel::StandardLevel Settings::level() const {
 
54
    return m_level;
 
55
}
 
56
 
 
57
bool Settings::customBgEnabled() const
 
58
{
 
59
    return m_custom_bg_enabled;
 
60
}
 
61
 
 
62
QString Settings::customBgPath() const
 
63
{
 
64
    return m_custom_bg_path;
 
65
}
 
66
 
 
67
QString Settings::fontColorSolved() const
 
68
{
 
69
    return m_font_color_solved;
 
70
}
 
71
 
 
72
QString Settings::fontColorUnsolved() const
 
73
{
 
74
    return m_font_color_unsolved;
 
75
}
 
76
 
 
77
void Settings::setWidth(int width) {
 
78
    m_width = width;
 
79
    setValue(Width, width);
 
80
}
 
81
 
 
82
void Settings::setHeight(int height) {
 
83
    m_height = height;
 
84
    setValue(Height, height);
 
85
}
 
86
 
 
87
void Settings::setBoxDensity(double box_density) {
 
88
    m_box_density = box_density;
 
89
    setValue(BoxDensity, box_density);
 
90
}
 
91
 
 
92
void Settings::setPreventMistakes(bool prevent_mistakes) {
 
93
    m_prevent_mistakes = prevent_mistakes;
 
94
    setValue(PreventMistakes, prevent_mistakes);
 
95
}
 
96
 
 
97
void Settings::setLevel(KgDifficultyLevel::StandardLevel level) {
 
98
    m_level = level;
 
99
    setValue(Level, level);
 
100
}
 
101
 
 
102
void Settings::setCustomBgEnabled(bool enabled)
 
103
{
 
104
    m_custom_bg_enabled = enabled;
 
105
    setValue(CustomBgEnabled, enabled);
 
106
}
 
107
 
 
108
void Settings::setCustomBgPath(const QString &path)
 
109
{
 
110
    m_custom_bg_path = path;
 
111
    setValue(CustomBgPath, path);
 
112
}
 
113
 
 
114
void Settings::setFontColorSolved(const QString &color)
 
115
{
 
116
    m_font_color_solved = color;
 
117
    setValue(FontColorSolved, color);
 
118
}
 
119
 
 
120
void Settings::setFontColorUnsolved(const QString &color)
 
121
{
 
122
    m_font_color_unsolved = color;
 
123
    setValue(FontColorUnsolved, color);
 
124
}
 
125
 
 
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();
 
137
}
 
138
 
 
139
void Settings::setValue(SettingsType type, const QVariant &value)
 
140
{
 
141
    m_qsettings->setValue(m_keys[type], value);
 
142
    emit settingChanged(type);
 
143
}
 
144
 
 
145
void Settings::sync()
 
146
{
 
147
    m_qsettings->sync();
 
148
}
 
149
 
 
150
Settings *Settings::instance()
 
151
{
 
152
    static Settings settings;
 
153
    return &settings;
 
154
}