-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolorobject.cpp
More file actions
44 lines (37 loc) · 1.17 KB
/
colorobject.cpp
File metadata and controls
44 lines (37 loc) · 1.17 KB
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
#include "colorobject.h"
ColorObject::ColorObject(QColor valueAndDefault,
QString const& settingsKey,
QObject *parent)
: QObject{parent}
, m_value(valueAndDefault)
, m_default(valueAndDefault)
, m_settingsKey(settingsKey)
{ }
QColor ColorObject::value() const{
return m_value;
}
QString const& ColorObject::settingsKey() const {
return m_settingsKey;
}
QColor ColorObject::defaultValue() const {
return m_default;
}
void ColorObject::setValue(QColor value) {
if (m_value != value) {
m_value = value;
emit valueChanged(m_value);
}
}
void ColorObject::attachSettings(QSettings *settings) {
auto loadedSetting = settings->value(m_settingsKey, m_default).value<QColor>();
connect(this, &ColorObject::valueChanged,
[=](QColor newValue) {
qDebug() << "Updating " << m_settingsKey << ": " << newValue;
settings->setValue(m_settingsKey, newValue);
settings->sync();
});
// Updating local values
setValue(loadedSetting);
// Always write the setting back.
settings->setValue(m_settingsKey, m_value);
}