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
keywidget.h
Go to the documentation of this file.
1 #ifndef RGBWIDGET_H
2 #define RGBWIDGET_H
3 
4 #include <QBitArray>
5 #include <QMouseEvent>
6 #include <QPaintEvent>
7 #include <QWidget>
8 #include "keymap.h"
9 #include "colormap.h"
10 
11 class KeyWidget : public QWidget
12 {
13  Q_OBJECT
14 public:
15  // New key widget. rgbMode = true to display colors, false to display key names
16  explicit KeyWidget(QWidget *parent = 0, bool rgbMode = true);
17  inline bool rgbMode() { return _rgbMode; }
18  inline void rgbMode(bool newRgbMode) { _rgbMode = newRgbMode; update(); }
19  // For RGB maps, monochrome = true to covert everything to grayscale
20  inline bool monochrome() { return _monochrome; }
21  inline void monochrome(bool newMono) { _monochrome = newMono; update(); }
22 
23  // Key map
24  const KeyMap& map() const { return keyMap; }
25  void map(const KeyMap& newMap);
26  // Key -> color map (must contain exactly the keys in the key map)
27  const QColorMap& colorMap() const { return _colorMap; }
28  void colorMap(const QColorMap& newColorMap);
29  // Key -> binding map
30  typedef QHash<QString, QString> BindMap;
31  const BindMap& bindMap() const { return _bindMap; }
32  void bindMap(const BindMap& newBindMap);
33 
34  // Set current selection (highlighted in blue)
35  void setSelection(const QStringList& keys);
36  void selectAll();
37  void clearSelection();
38 
39  // Set animated keys (highlighted in green)
40  void setAnimation(const QStringList& keys);
42  void clearAnimation();
43 
44 public slots:
45  // Sets display colors. Pass an empty map to clear.
46  // These will be displayed instead of the regular color map, if supplied.
47  void displayColorMap(const ColorMap& newDisplayMap, const QSet<QString>& indicators = QSet<QString>());
48 
49 signals:
50  // Emitted when the selection is changed.
51  void selectionChanged(QStringList selected);
52  void sidelightToggled();
53 
54 private:
59  QSet<QString> _indicators;
60 
61  QBitArray selection;
62  QBitArray newSelection;
63  QBitArray animation;
66  enum {
68  SET,
69  ADD,
72  } mouseDownMode;
74 
75  void paintEvent(QPaintEvent*);
76  void mousePressEvent(QMouseEvent* event);
77  void mouseMoveEvent(QMouseEvent* event);
78  void mouseReleaseEvent(QMouseEvent* event);
79 
80  // Get drawing scale/offset. drawX = (keymapX + offsetX) * scale
81  void drawInfo(float& scale, float& offsetX, float& offsetY, int ratio = 1);
82 };
83 
84 #endif // RGBWIDGET_H
void clearSelection()
Definition: keywidget.cpp:617
void selectAll()
Definition: keywidget.cpp:596
void clearAnimation()
Definition: keywidget.cpp:644
bool rgbMode()
Definition: keywidget.h:17
const BindMap & bindMap() const
Definition: keywidget.h:31
void setSelection(const QStringList &keys)
Definition: keywidget.cpp:582
void drawInfo(float &scale, float &offsetX, float &offsetY, int ratio=1)
Definition: keywidget.cpp:43
int mouseDownX
Definition: keywidget.h:64
const KeyMap & map() const
Definition: keywidget.h:24
void mouseReleaseEvent(QMouseEvent *event)
Definition: keywidget.cpp:548
QHash< QString, QString > BindMap
Definition: keywidget.h:30
int mouseCurrentY
Definition: keywidget.h:65
void selectionChanged(QStringList selected)
bool _monochrome
Definition: keywidget.h:73
bool monochrome()
Definition: keywidget.h:20
void mouseMoveEvent(QMouseEvent *event)
Definition: keywidget.cpp:487
const QColorMap & colorMap() const
Definition: keywidget.h:27
ColorMap _displayColorMap
Definition: keywidget.h:57
void sidelightToggled()
enum KeyWidget::@2 mouseDownMode
bool _rgbMode
Definition: keywidget.h:73
void mousePressEvent(QMouseEvent *event)
Definition: keywidget.cpp:455
QBitArray selection
Definition: keywidget.h:61
void paintEvent(QPaintEvent *)
Definition: keywidget.cpp:70
QBitArray animation
Definition: keywidget.h:63
KeyMap keyMap
Definition: keywidget.h:55
void setAnimationToSelection()
Definition: keywidget.cpp:639
QHash< QString, QRgb > QColorMap
Definition: colormap.h:9
int mouseDownY
Definition: keywidget.h:64
KeyWidget(QWidget *parent=0, bool rgbMode=true)
Definition: keywidget.cpp:17
Definition: keymap.h:49
BindMap _bindMap
Definition: keywidget.h:58
QSet< QString > _indicators
Definition: keywidget.h:59
QColorMap _colorMap
Definition: keywidget.h:56
void rgbMode(bool newRgbMode)
Definition: keywidget.h:18
void displayColorMap(const ColorMap &newDisplayMap, const QSet< QString > &indicators=QSet< QString >())
Definition: keywidget.cpp:57
QBitArray newSelection
Definition: keywidget.h:62
void setAnimation(const QStringList &keys)
Definition: keywidget.cpp:625
void monochrome(bool newMono)
Definition: keywidget.h:21
int mouseCurrentX
Definition: keywidget.h:65