ckb-next  beta-v0.2.8 at branch testing
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
colormap.h
Go to the documentation of this file.
1 #ifndef COLORMAP_H
2 #define COLORMAP_H
3 
4 #include <QHash>
5 #include <QRgb>
6 #include "keymap.h"
7 
8 // Qt-based color map for use by classes outside KbLight
9 typedef QHash<QString, QRgb> QColorMap;
10 typedef QHashIterator<QString, QRgb> QColorMapIterator;
11 typedef QMutableHashIterator<QString, QRgb> QMutableColorMapIterator;
12 
13 // ColorMap provides a flat, fast-access array for storing color values on a keyboard. Keys are sorted by name.
14 
15 class ColorMap
16 {
17 public:
18  ColorMap();
19  ~ColorMap();
20  ColorMap(const ColorMap& rhs);
21  const ColorMap& operator=(const ColorMap& rhs);
22 
23  // Initialize the color map with the given keys. Color values are initialized to transparent black.
24  // This may be called more than once; the existing color set will be erased.
25  void init(const KeyMap& map);
26  // Erase current color values
27  void clear();
28 
29  // Flat key -> color map
30  int count() const { return _count; }
31  const char* const* keyNames() const { return _keyNames; }
32  QRgb* colors() { return _colors; }
33  const QRgb* colors() const { return _colors; }
34 
35  // Finds a color by key name. Returns null if the key isn't in the map.
36  QRgb* colorForName(const char* name);
37  const QRgb* colorForName(const char* name) const;
38 
39 private:
40  void alloc(int count);
41  void deAlloc();
42 
43  const char** _keyNames;
44  QRgb* _colors;
46 };
47 
48 #endif // COLORMAP_H
QRgb * colors()
Definition: colormap.h:32
const QRgb * colors() const
Definition: colormap.h:33
~ColorMap()
Definition: colormap.cpp:8
void init(const KeyMap &map)
Definition: colormap.cpp:53
int _count
Definition: colormap.h:45
QHashIterator< QString, QRgb > QColorMapIterator
Definition: colormap.h:10
QRgb * colorForName(const char *name)
Definition: colormap.cpp:72
void deAlloc()
Definition: colormap.cpp:39
QHash< QString, QRgb > QColorMap
Definition: colormap.h:9
ColorMap()
Definition: colormap.cpp:3
const char *const * keyNames() const
Definition: colormap.h:31
Definition: keymap.h:49
const ColorMap & operator=(const ColorMap &rhs)
Definition: colormap.cpp:18
const char ** _keyNames
Definition: colormap.h:43
QMutableHashIterator< QString, QRgb > QMutableColorMapIterator
Definition: colormap.h:11
int _mapCount
Definition: colormap.h:45
int count() const
Definition: colormap.h:30
QRgb * _colors
Definition: colormap.h:44
void clear()
Definition: colormap.cpp:45
void alloc(int count)
Definition: colormap.cpp:27