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
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  bool operator==(const ColorMap& rhs) const;
23 
24  // Initialize the color map with the given keys. Color values are initialized to transparent black.
25  // This may be called more than once; the existing color set will be erased.
26  void init(const KeyMap& map);
27  // Erase current color values
28  void clear();
29 
30  // Flat key -> color map
31  int count() const { return _count; }
32  const char* const* keyNames() const { return _keyNames; }
33  QRgb* colors() { return _colors; }
34  const QRgb* colors() const { return _colors; }
35 
36  // Finds a color by key name. Returns null if the key isn't in the map.
37  QRgb* colorForName(const char* name);
38  const QRgb* colorForName(const char* name) const;
39 
40 private:
41  void alloc(int count);
42  void deAlloc();
43 
44  const char** _keyNames;
45  QRgb* _colors;
47 };
48 
49 #endif // COLORMAP_H
QRgb * colors()
Definition: colormap.h:33
const QRgb * colors() const
Definition: colormap.h:34
~ColorMap()
Definition: colormap.cpp:8
void init(const KeyMap &map)
Definition: colormap.cpp:69
int _count
Definition: colormap.h:46
QHashIterator< QString, QRgb > QColorMapIterator
Definition: colormap.h:10
QRgb * colorForName(const char *name)
Definition: colormap.cpp:88
void deAlloc()
Definition: colormap.cpp:55
QHash< QString, QRgb > QColorMap
Definition: colormap.h:9
ColorMap()
Definition: colormap.cpp:3
bool operator==(const ColorMap &rhs) const
Definition: colormap.cpp:27
const char *const * keyNames() const
Definition: colormap.h:32
Definition: keymap.h:49
const ColorMap & operator=(const ColorMap &rhs)
Definition: colormap.cpp:18
const char ** _keyNames
Definition: colormap.h:44
QMutableHashIterator< QString, QRgb > QMutableColorMapIterator
Definition: colormap.h:11
int _mapCount
Definition: colormap.h:46
int count() const
Definition: colormap.h:31
QRgb * _colors
Definition: colormap.h:45
void clear()
Definition: colormap.cpp:61
void alloc(int count)
Definition: colormap.cpp:43