ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
kbmode.cpp
Go to the documentation of this file.
1 #include "kbmode.h"
2 #include "kb.h"
3 
4 KbMode::KbMode(Kb* parent, const KeyMap& keyMap, const QString &guid, const QString& modified) :
5  QObject(parent),
6  _name("Unnamed"), _id(guid, modified),
7  _light(new KbLight(this, keyMap)), _bind(new KbBind(this, parent, keyMap)), _perf(new KbPerf(this)),
8  _needsSave(true)
9 {
10  connect(_light, SIGNAL(updated()), this, SLOT(doUpdate()));
11  if(_id.guid.isNull())
12  _id.guid = QUuid::createUuid();
13 }
14 
21 KbMode::KbMode(Kb* parent, const KeyMap& keyMap, const KbMode& other) :
22  QObject(parent),
23  _name(other._name), _id(other._id),
24  _light(new KbLight(this, keyMap, *other._light)), _bind(new KbBind(this, parent, keyMap, *other._bind)), _perf(new KbPerf(this, *other._perf)),
25  _needsSave(true)
26 {
27  connect(_light, SIGNAL(updated()), this, SLOT(doUpdate()));
28 }
29 
30 KbMode::KbMode(Kb* parent, const KeyMap& keyMap, CkbSettings& settings) :
31  QObject(parent),
32  _name(settings.value("Name").toString().trimmed()),
33  _id(settings.value("GUID").toString().trimmed(), settings.value("Modified").toString().trimmed()),
34  _light(new KbLight(this, keyMap)), _bind(new KbBind(this, parent, keyMap)), _perf(new KbPerf(this)),
35  _needsSave(false)
36 {
37  if(settings.contains("HwModified"))
38  _id.hwModifiedString(settings.value("HwModified").toString());
39  else
41 
42  connect(_light, SIGNAL(updated()), this, SLOT(doUpdate()));
43  if(_id.guid.isNull())
44  _id.guid = QUuid::createUuid();
45  if(_name == "")
46  _name = "Unnamed";
47  _light->load(settings);
48  _bind->load(settings);
49  _perf->load(settings);
50 }
51 
53  _needsSave = true;
54  _id = UsbId();
55  // Create new IDs for animations
56  foreach(KbAnim* anim, _light->animList())
57  anim->newId();
58 }
59 
60 void KbMode::keyMap(const KeyMap &keyMap){
61  _needsSave = true;
62  _light->map(keyMap);
63  _bind->map(keyMap);
64 }
65 
66 void KbMode::save(CkbSettings& settings){
67  _needsSave = false;
68  _id.newModified();
69  settings.setValue("GUID", _id.guidString());
70  settings.setValue("Modified", _id.modifiedString());
71  settings.setValue("HwModified", _id.hwModifiedString());
72  settings.setValue("Name", _name);
73  _light->save(settings);
74  _bind->save(settings);
75  _perf->save(settings);
76 }
77 
78 bool KbMode::needsSave() const {
79  return _needsSave || _light->needsSave() || _bind->needsSave() || _perf->needsSave();
80 }
81 
83  emit updated();
84 }
85 
90 }
void load(CkbSettings &settings)
Definition: kbbind.cpp:58
void setValue(const QString &key, const QVariant &value)
QUuid guid
Definition: kbmode.h:12
KbBind * _bind
Definition: kbmode.h:78
bool _needsSave
Definition: kbmode.h:81
QString modifiedString() const
Definition: kbmode.h:22
bool needsSave() const
Definition: kbbind.h:38
UsbId _id
Definition: kbmode.h:75
~KbMode()
KbMode::~KbMode Destructor may be used for Debugging (issue #38 with SIGSEGV). Insert qDebug-statemen...
Definition: kbmode.cpp:89
const AnimList & animList()
Definition: kblight.h:49
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
void save(CkbSettings &settings)
Definition: kblight.cpp:447
void doUpdate()
Definition: kbmode.cpp:82
bool needsSave() const
Definition: kblight.cpp:474
const KeyMap & map()
Definition: kbbind.h:41
bool contains(const QString &key) const
KbMode(Kb *parent, const KeyMap &keyMap, const QString &guid="", const QString &modified="")
Definition: kbmode.cpp:4
Definition: kbmode.h:11
QString guidString() const
Definition: kbmode.h:20
quint32 modified
Definition: kbmode.h:13
void keyMap(const KeyMap &keyMap)
Definition: kbmode.cpp:60
void newId()
Definition: kbanim.h:72
bool needsSave() const
Definition: kbmode.cpp:78
KbLight * _light
Definition: kbmode.h:77
void load(CkbSettings &settings)
Definition: kblight.cpp:408
const KeyMap & map()
Definition: kblight.h:28
QString _name
Definition: kbmode.h:74
Definition: kbmode.h:36
void save(CkbSettings &settings)
Definition: kbbind.cpp:81
Definition: kbperf.h:15
Definition: kb.h:11
Definition: kbanim.h:11
Definition: kbbind.h:20
void updated()
Definition: moc_kbmode.cpp:131
void newModified()
Definition: kbmode.h:29
quint32 hwModified
Definition: kbmode.h:14
Definition: keymap.h:49
bool needsSave() const
Definition: kbperf.h:28
void save(CkbSettings &settings)
Definition: kbperf.cpp:211
void load(CkbSettings &settings)
Definition: kbperf.cpp:106
void save(CkbSettings &settings)
Definition: kbmode.cpp:66
struct keyAnim * anim
Definition: main.c:55
KbPerf * _perf
Definition: kbmode.h:79
void newId()
Definition: kbmode.cpp:52
QString hwModifiedString() const
Definition: kbmode.h:24