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.h
Go to the documentation of this file.
1 #ifndef KBMODE_H
2 #define KBMODE_H
3 
4 #include <QObject>
5 #include "kblight.h"
6 #include "kbbind.h"
7 #include "kbperf.h"
8 
9 // ID structure for modes/profiles. Stores a GUID indentifying the item as well as a 32-bit number representing its last modification.
10 
11 struct UsbId {
12  QUuid guid;
13  quint32 modified;
14  quint32 hwModified; // Last modification value saved to hardware
15 
16  inline UsbId(const QString& _guid, quint32 _modified) : guid(_guid), modified(_modified), hwModified(_modified) {}
17  inline UsbId(const QString& _guid, const QString& _modified) : guid(_guid), modified(_modified.toUInt(0, 16)), hwModified(modified) {}
18  inline UsbId() : guid(QUuid::createUuid()),modified(0) {}
19 
20  QString guidString() const { return guid.toString().toUpper(); }
21  void guidString(const QString& newGuid) { guid = newGuid; }
22  QString modifiedString() const { return QString::number(modified, 16); }
23  void modifiedString(const QString& newModified) { modified = newModified.toUInt(0, 16); }
24  QString hwModifiedString() const { return QString::number(hwModified, 16); }
25  void hwModifiedString(const QString& newModified){ hwModified = newModified.toUInt(0, 16); }
26 
27  // Generate a new random ID
28  void newGuid() { guid = QUuid::createUuid(); }
29  void newModified() { quint32 newMod; do { newMod = qrand(); } while(newMod == modified); modified = newMod; }
30 };
31 
32 class Kb;
33 
34 // Profile mode
35 
36 class KbMode : public QObject
37 {
38  Q_OBJECT
39 public:
40  // New mode with key map, and optionally ID
41  KbMode(Kb* parent, const KeyMap& keyMap, const QString& guid = "", const QString& modified = "");
42  // Mode from settings
43  KbMode(Kb* parent, const KeyMap& keyMap, CkbSettings& settings);
44  // Mode by copy
45  KbMode(Kb* parent, const KeyMap& keyMap, const KbMode& other);
46 
47  ~KbMode();
48 
49  // Mode properties
50  inline const QString& name() const { return _name; }
51  inline void name(const QString& newName) { _needsSave = true; _name = newName.trimmed(); if(_name == "") _name = "Unnamed"; }
52  inline UsbId& id() { return _id; }
53  inline void id(const UsbId& newId) { _needsSave = true; _id = newId; }
54  void newId();
55 
56  // Device key map
57  void keyMap(const KeyMap& keyMap);
58 
59  // Lighting and binding setup
60  inline KbLight* light() { return _light; }
61  inline KbBind* bind() { return _bind; }
62  inline KbPerf* perf() { return _perf; }
63 
64  // Save settings
65  void save(CkbSettings& settings);
66  bool needsSave() const;
67  inline void setNeedsSave() { _needsSave = true; }
69 
70 signals:
71  void updated();
72 
73 private:
74  QString _name;
76 
80 
81  bool _needsSave;
82 
83 private slots:
84  void doUpdate();
85 };
86 
87 #endif // KBMODE_H
UsbId(const QString &_guid, quint32 _modified)
Definition: kbmode.h:16
UsbId & id()
Definition: kbmode.h:52
QUuid guid
Definition: kbmode.h:12
void setNeedsUpdate()
Definition: kbmode.h:68
KbBind * _bind
Definition: kbmode.h:78
bool _needsSave
Definition: kbmode.h:81
KbBind * bind()
Definition: kbmode.h:61
QString modifiedString() const
Definition: kbmode.h:22
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
UsbId(const QString &_guid, const QString &_modified)
Definition: kbmode.h:17
void doUpdate()
Definition: kbmode.cpp:82
KbMode(Kb *parent, const KeyMap &keyMap, const QString &guid="", const QString &modified="")
Definition: kbmode.cpp:4
KbLight * light()
Definition: kbmode.h:60
Definition: kbmode.h:11
QString guidString() const
Definition: kbmode.h:20
void setNeedsUpdate()
Definition: kbperf.h:116
quint32 modified
Definition: kbmode.h:13
void keyMap(const KeyMap &keyMap)
Definition: kbmode.cpp:60
void name(const QString &newName)
Definition: kbmode.h:51
bool needsSave() const
Definition: kbmode.cpp:78
KbLight * _light
Definition: kbmode.h:77
QString _name
Definition: kbmode.h:74
void id(const UsbId &newId)
Definition: kbmode.h:53
Definition: kbmode.h:36
void guidString(const QString &newGuid)
Definition: kbmode.h:21
Definition: kbperf.h:15
Definition: kb.h:11
Definition: kbbind.h:20
void setNeedsSave()
Definition: kbmode.h:67
void updated()
Definition: moc_kbmode.cpp:131
void newModified()
Definition: kbmode.h:29
quint32 hwModified
Definition: kbmode.h:14
void modifiedString(const QString &newModified)
Definition: kbmode.h:23
void setNeedsUpdate()
Definition: kbbind.h:85
const QString & name() const
Definition: kbmode.h:50
Definition: keymap.h:49
UsbId()
Definition: kbmode.h:18
void newGuid()
Definition: kbmode.h:28
void hwModifiedString(const QString &newModified)
Definition: kbmode.h:25
KbPerf * perf()
Definition: kbmode.h:62
void save(CkbSettings &settings)
Definition: kbmode.cpp:66
KbPerf * _perf
Definition: kbmode.h:79
void newId()
Definition: kbmode.cpp:52
QString hwModifiedString() const
Definition: kbmode.h:24