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
kblight.h
Go to the documentation of this file.
1 #ifndef KBLIGHT_H
2 #define KBLIGHT_H
3 
4 #include <QFile>
5 #include <QObject>
6 #include <QSet>
7 #include <QSettings>
8 #include "animscript.h"
9 #include "kbanim.h"
10 #include "keymap.h"
11 #include "colormap.h"
12 
13 class KbMode;
14 
15 // Keyboard lighting setup
16 
17 class KbLight : public QObject
18 {
19  Q_OBJECT
20 public:
21  // New lighting setup
22  KbLight(KbMode* parent, const KeyMap& keyMap);
23  // Copy a lighting setup
24  KbLight(KbMode *parent, const KeyMap& keyMap, const KbLight& other);
25  ~KbLight();
26 
27  // Key map
28  inline const KeyMap& map() { return _map; }
29  void map(const KeyMap& map);
30  // Key -> color map
31  inline const QColorMap& colorMap() { return _qColorMap; }
32  // Color a key
33  void color(const QString& key, const QColor& newColor);
34  // Color all keys in the current map
35  void color(const QColor& newColor);
36 
37  // Overall dimming. 0 = max brightness, 3 = off
38  static const int MAX_DIM = 3;
39  inline int dimming() { return _dimming; }
40  void dimming(int newDimming);
41  // Shared brightness between all modes (-1 for sharing disabled)
42  static int shareDimming();
43  static void shareDimming(int newShareDimming);
44 
45  // Lighting animations
46  typedef QList<KbAnim*> AnimList;
47  KbAnim* addAnim(const AnimScript* base, const QStringList& keys, const QString& name, const QMap<QString, QVariant>& preset);
48  KbAnim* duplicateAnim(KbAnim* oldAnim);
49  const AnimList& animList() { return _animList; }
50  void animList(const AnimList& newAnimList) { _needsSave = true; _animList = newAnimList; }
51  KbAnim* findAnim(const QUuid& guid) const { foreach(KbAnim* anim, _animList) { if(anim->guid() == guid) return anim; } return 0; }
52  int findAnimIdx(const QUuid& guid) const { return _animList.indexOf(findAnim(guid)); }
53  // Preview animation - temporary animation displayed at the top of the animation list
54  void previewAnim(const AnimScript* base, const QStringList& keys, const QMap<QString, QVariant>& preset);
55  void stopPreview();
56  // Stops and restarts all animations
57  void restartAnimation();
58  // Sends a keypress event to active animations
59  void animKeypress(const QString& key, bool down);
60 
61  // Start the mode
62  void open();
63  // Whether or not all animations have started
64  bool isStarted();
65  // Make the lighting idle, stopping any animations.
66  void close();
67 
68  // Reset indicator state
69  void resetIndicators();
70  // Set an indicator to a given ARGB value
71  void setIndicator(const char* name, QRgb argb);
72 
73  // Write a new frame to the keyboard. Write "mode %d" first. Optionally provide a list of keys to use as indicators and overwrite the lighting
74  void frameUpdate(QFile& cmd, bool monochrome = false);
75  // Write the mode's base colors without any animation
76  void base(QFile& cmd, bool ignoreDim = false, bool monochrome = false);
77 
78  // Load and save from stored settings
79  void load(CkbSettings& settings);
80  void save(CkbSettings& settings);
81  bool needsSave() const;
82 
83 signals:
84  void didLoad();
85  void updated();
86  void frameDisplayed(const ColorMap& animatedColors, const QSet<QString>& indicatorList);
87 
88 private:
94  QSet<QString> _indicatorList;
95  quint64 lastFrameSignal;
97  bool _start;
99 
100  // Rebuild base ColorMap (if needed)
101  void rebuildBaseMap();
102  // Print RGB values to cmd node
103  void printRGB(QFile& cmd, const ColorMap& animMap);
104 };
105 
106 #endif // KBLIGHT_H
QSet< QString > _indicatorList
Definition: kblight.h:94
void frameDisplayed(const ColorMap &animatedColors, const QSet< QString > &indicatorList)
void stopPreview()
Definition: kblight.cpp:143
KbAnim * duplicateAnim(KbAnim *oldAnim)
Definition: kblight.cpp:148
quint64 lastFrameSignal
Definition: kblight.h:95
KeyMap _map
Definition: kblight.h:91
KbLight(KbMode *parent, const KeyMap &keyMap)
Definition: kblight.cpp:10
const AnimList & animList()
Definition: kblight.h:49
void frameUpdate(QFile &cmd, bool monochrome=false)
Definition: kblight.cpp:296
KbAnim * addAnim(const AnimScript *base, const QStringList &keys, const QString &name, const QMap< QString, QVariant > &preset)
Definition: kblight.cpp:100
void save(CkbSettings &settings)
Definition: kblight.cpp:447
cmd
Definition: command.h:7
bool isStarted()
Definition: kblight.cpp:169
bool needsSave() const
Definition: kblight.cpp:474
void didLoad()
AnimList _animList
Definition: kblight.h:89
void rebuildBaseMap()
Definition: kblight.cpp:238
ColorMap _indicatorMap
Definition: kblight.h:93
const QColorMap & colorMap()
Definition: kblight.h:31
~KbLight()
Definition: kblight.cpp:45
Definition: keymap.h:49
static const int MAX_DIM
Definition: kblight.h:38
void updated()
ColorMap _animMap
Definition: kblight.h:93
void previewAnim(const AnimScript *base, const QStringList &keys, const QMap< QString, QVariant > &preset)
Definition: kblight.cpp:124
void load(CkbSettings &settings)
Definition: kblight.cpp:408
const KeyMap & map()
Definition: kblight.h:28
static int shareDimming()
Definition: kblight.cpp:78
void animKeypress(const QString &key, bool down)
Definition: kblight.cpp:189
QColorMap _qColorMap
Definition: kblight.h:92
Definition: kbmode.h:36
void resetIndicators()
Definition: kblight.cpp:254
void close()
Definition: kblight.cpp:215
Definition: kbanim.h:11
ColorMap _lastFrameIndicatorMap
Definition: kblight.h:93
const QUuid & guid() const
Definition: kbanim.h:71
void color(const QString &key, const QColor &newColor)
Definition: kblight.cpp:49
QList< KbAnim * > AnimList
Definition: kblight.h:46
ColorMap _colorMap
Definition: kblight.h:93
ColorMap _lastFrameAnimMap
Definition: kblight.h:93
QHash< QString, QRgb > QColorMap
Definition: colormap.h:9
bool _needsSave
Definition: kblight.h:98
void open()
Definition: kblight.cpp:200
bool _start
Definition: kblight.h:97
void setIndicator(const char *name, QRgb argb)
Definition: kblight.cpp:259
bool _needsMapRefresh
Definition: kblight.h:98
Definition: keymap.h:49
void printRGB(QFile &cmd, const ColorMap &animMap)
Definition: kblight.cpp:223
void restartAnimation()
Definition: kblight.cpp:179
int _lastFrameDimming
Definition: kblight.h:96
int dimming()
Definition: kblight.h:39
KbAnim * _previewAnim
Definition: kblight.h:90
void base(QFile &cmd, bool ignoreDim=false, bool monochrome=false)
Definition: kblight.cpp:378
void animList(const AnimList &newAnimList)
Definition: kblight.h:50
KbAnim * findAnim(const QUuid &guid) const
Definition: kblight.h:51
int _dimming
Definition: kblight.h:96
struct keyAnim * anim
Definition: main.c:55
int findAnimIdx(const QUuid &guid) const
Definition: kblight.h:52