-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreferences.cpp
241 lines (183 loc) · 6.46 KB
/
preferences.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
#include "preferences.h"
#include <QSettings>
#include <QDebug>
Preferences *Preferences::m_instance;
Preferences *Preferences::instance()
{
if (!m_instance)
m_instance = new Preferences;
return m_instance;
}
Preferences::Preferences():m_settings(new QSettings(this))
{
m_settings->beginGroup(QLatin1String("General"));
m_defaultUnit = intValue("DefaultUnit",0);
m_autoSave = boolValue("AutoSave",true);
m_hardwareAcceleration = boolValue("HardwareAcceleration",true);
m_language = stringValue("Language","en");
m_openLastFileOnStartup = boolValue("OpenLastFileOnStartup",true);
m_settings->endGroup();
m_settings->beginGroup(QLatin1String("Canvas"));
m_rulerVisible = boolValue("RulerVisible",true);
m_snapToGrid = boolValue("SnapToGrid",true);
m_gridVisible = m_snapToGrid?boolValue("GridVisible",true):false;
m_gridColor = colorValue("GridColor",Qt::darkGray);
m_girdSize = intValue("GridSize",4);
m_settings->endGroup();
m_settings->beginGroup(QLatin1String("Theme"));
m_style = intValue("style",THEME_DARKEN);
m_baseColor = colorValue("BaseColor",QColor(242,242,242,100));
m_selectionColor = colorValue("SelectionColor",QColor(48, 140, 198));
m_settings->endGroup();
m_settings->beginGroup(QLatin1String("System"));
m_defaultPageSize = sizeValue("DefaultPageSize",QSize(297,210));
m_settings->endGroup();
}
void Preferences::setGridVisible(bool gridVisible)
{
if (m_gridVisible == gridVisible)
return;
m_gridVisible = gridVisible;
m_settings->setValue(QLatin1String("Canvas/GridVisible"), gridVisible);
emit gridVisibleChanged(m_gridVisible);
}
void Preferences::setGridColor(QColor gridColor)
{
if (m_gridColor == gridColor)
return;
m_gridColor = gridColor;
m_settings->setValue(QLatin1String("Canvas/GridColor"), gridColor);
emit gridColorChanged(m_gridColor);
}
void Preferences::setGridFine(int gridFine)
{
if (m_gridFine == gridFine)
return;
m_gridFine = gridFine;
m_settings->setValue(QLatin1String("Canvas/GridFine"), gridFine);
emit gridFineChanged(m_gridFine);
}
void Preferences::setLanguage(QString language)
{
if (m_language == language)
return;
m_language = language;
m_settings->setValue(QLatin1String("General/Language"), language);
emit languageChanged(m_language);
}
void Preferences::setRulerVisible(bool rulerVisible)
{
if (m_rulerVisible == rulerVisible)
return;
m_rulerVisible = rulerVisible;
m_settings->setValue(QLatin1String("Canvas/RulerVisible"), rulerVisible);
emit rulerVisibleChanged(m_rulerVisible);
}
void Preferences::setSnapToGrid(bool snapToGrid)
{
{
if (m_snapToGrid == snapToGrid)
return;
m_snapToGrid = snapToGrid;
m_settings->setValue(QLatin1String("Canvas/SnapToGrid"), snapToGrid);
emit snapToGridChanged(m_snapToGrid);
}
}
void Preferences::setDefaultPageSize(QSize defaultPageSize)
{
if (m_defaultPageSize==defaultPageSize)
return;
m_defaultPageSize = defaultPageSize;
}
void Preferences::setGridSize(int girdSize)
{
if (m_girdSize == girdSize)
return;
m_girdSize = girdSize;
m_settings->setValue(QLatin1String("Canvas/GridSize"), girdSize);
emit gridSizeChanged(m_girdSize);
}
void Preferences::setBaseColor(QColor baseColor)
{
if (m_baseColor == baseColor)
return;
m_baseColor = baseColor;
m_settings->setValue(QLatin1String("Theme/BaseColor"), baseColor);
emit baseColorChanged(m_baseColor);
}
void Preferences::setSelectionColor(QColor selectionColor)
{
if (m_selectionColor == selectionColor)
return;
m_selectionColor = selectionColor;
m_settings->setValue(QLatin1String("Theme/SelectionColor"), selectionColor);
emit selectionColorChanged(m_selectionColor);
}
void Preferences::setStyle(int style)
{
if (m_style == style)
return;
m_style = style;
m_settings->setValue(QLatin1String("Theme/Style"), style);
emit styleChanged(m_style);
}
void Preferences::setDefaultUnit(int defaultUnit)
{
if (m_defaultUnit == defaultUnit)
return;
m_defaultUnit = defaultUnit;
m_settings->setValue(QLatin1String("General/DefaultUnit"), defaultUnit);
emit defaultUnitChanged(m_defaultUnit);
}
void Preferences::setAutoSave(bool autoSave)
{
if (m_autoSave == autoSave)
return;
m_autoSave = autoSave;
m_settings->setValue(QLatin1String("General/AutoSave"), autoSave);
emit autoSaveChanged(m_autoSave);
}
void Preferences::setHardwareAcceleration(bool hardwareAcceleration)
{
if (m_hardwareAcceleration == hardwareAcceleration)
return;
m_hardwareAcceleration = hardwareAcceleration;
m_settings->setValue(QLatin1String("General/HardwareAcceleration"), hardwareAcceleration);
emit hardwareAccelerationChanged(m_hardwareAcceleration);
}
void Preferences::setOpenLastFileOnStartup(bool openLastFileOnStartup)
{
if (m_openLastFileOnStartup == openLastFileOnStartup)
return;
m_openLastFileOnStartup = openLastFileOnStartup;
m_settings->setValue(QLatin1String("General/OpenLastFileOnStartup"), openLastFileOnStartup);
emit openLastFileOnStartupChanged(m_openLastFileOnStartup);
}
bool Preferences::boolValue(const char *key, bool defaultValue) const
{
return m_settings->value(QLatin1String(key), defaultValue).toBool();
}
QColor Preferences::colorValue(const char *key, const QColor &def) const
{
const QString name = m_settings->value(QLatin1String(key),
def.name()).toString();
if (!QColor::isValidColor(name))
return QColor();
return QColor(name);
}
QString Preferences::stringValue(const char *key, const QString &def) const
{
return m_settings->value(QLatin1String(key), def).toString();
}
int Preferences::intValue(const char *key, int defaultValue) const
{
return m_settings->value(QLatin1String(key), defaultValue).toInt();
}
qreal Preferences::realValue(const char *key, qreal defaultValue) const
{
return m_settings->value(QLatin1String(key), defaultValue).toReal();
}
QSize Preferences::sizeValue(const char *key, QSize defaultValue) const
{
return m_settings->value(QLatin1String(key), defaultValue).toSize();
}