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
kbperf.h
Go to the documentation of this file.
1 #ifndef KBPERF_H
2 #define KBPERF_H
3 #include <QFile>
4 #include <QMap>
5 #include <QPoint>
6 #include "ckbsettings.h"
7 #include "keymap.h"
8 
9 class KbMode;
10 class KbBind;
11 class KbLight;
12 
13 // DPI/performance settings. Also stores indicator colors. Created as part of KbMode.
14 
15 class KbPerf : public QObject
16 {
17  Q_OBJECT
18 public:
19  // New setup with default settings
20  explicit KbPerf(KbMode* parent);
21  // Copy a setup
22  KbPerf(KbMode* parent, const KbPerf& other);
23  const KbPerf& operator= (const KbPerf& rhs);
24 
25  // Load and save from stored settings
26  void load(CkbSettings& settings);
27  void save(CkbSettings& settings);
28  inline bool needsSave() const { return _needsSave; }
29 
30  // Mouse lift height
31  enum height {
32  LOW = 1,
37  };
38  inline height liftHeight() const { return _liftHeight; }
39  void liftHeight(height newHeight);
40 
41  // Mouse angle snap
42  inline bool angleSnap() const { return _angleSnap; }
43  void angleSnap(bool newAngleSnap);
44 
45  // Stored DPI settings (X/Y)
46  const static int DPI_COUNT = 6, SNIPER = 0;
47  const static int DPI_MIN = 100, DPI_MAX = 12000;
48 
49  // Functions for acessing the DPI table.
50  inline QPoint dpi(int index) const { if(index < 0 || index >= DPI_COUNT) return QPoint(); return QPoint(dpiX[index], dpiY[index]); }
51  void dpi(int index, const QPoint& newValue);
52  inline QPoint sniperDpi() const { return dpi(SNIPER); }
53  inline void sniperDpi(const QPoint& newValue) { dpi(SNIPER, newValue); }
54  // Set both X and Y
55  inline void dpi(int index, int newValue) { dpi(index, QPoint(newValue, newValue)); }
56  inline void sniperDpi(int newValue) { sniperDpi(QPoint(newValue, newValue)); }
57 
58  // The following modify the base DPI by setting the index into the DPI
59  // table. If any DPIs are on the stack, the stack will be cleared and the
60  // DPI corresponding to the new index will be made active.
61  inline int baseDpiIdx() const { return dpiBaseIdx; }
62  void baseDpiIdx(int newIdx);
63  void dpiUp();
64  void dpiDown();
65  void dpiCycleUp();
66  void dpiCycleDown();
67  // DPI stages enabled (default all). Disabled stages will be bypassed when invoking dpiUp/dpiDown (but not any other functions).
68  inline bool dpiEnabled(int index) const { return dpiOn[index]; }
69  inline void dpiEnabled(int index, bool newEnabled) { if(index <= 0) return; dpiOn[index] = newEnabled; _needsUpdate = _needsSave = true; }
70 
71  // Push/pop a DPI state onto the DPI stack. Used for sniper and custom DPIs,
72  // which are only active while a key is held.
73  quint64 pushDpi(const QPoint& newDpi);
74  inline quint64 pushDpi(int newDpi) { return pushDpi(QPoint(newDpi, newDpi)); }
75  inline quint64 pushSniper() { return pushDpi(sniperDpi()); }
76  void popDpi(quint64 pushIdx);
77 
78  // Indicator opacity [0, 1]
79  inline float iOpacity() const { return _iOpacity; }
80  inline void iOpacity(float newIOpacity) { _iOpacity = newIOpacity; _needsSave = true; }
81  // DPI indicator colors
82  inline bool dpiIndicator() const { return _dpiIndicator; }
83  inline void dpiIndicator(bool newDpiIndicator) { _dpiIndicator = newDpiIndicator; _needsSave = true; }
84  const static int OTHER = DPI_COUNT; // valid only with dpiColor
85  inline QColor dpiColor(int index) const { return dpiClr[index]; }
86  inline void dpiColor(int index, const QColor& newColor) { dpiClr[index] = newColor; _needsUpdate = _needsSave = true; }
87  // KB indicator colors
88  enum indicator {
89  // Hardware
90  NUM,
93  // Software
99  };
100  // Hardware indicator state
101  enum i_hw {
102  NONE = -1, // For non-hardware indicators
104  ON,
106  };
107  const static int I_COUNT = (int)MUTE + 1, HW_I_COUNT = (int)HW_IMAX + 1;
108  // Indicator color and settings. For MUTE, color1 = on, color2 = off, color3 = don't know. For LIGHT, color1 = 33%, color2 = 67%, color3 = 100%.
109  // For all others, color1 = on, color2 = off, color3 unused
110  void getIndicator(indicator index, QColor& color1, QColor& color2, QColor& color3, bool& software_enable, i_hw& hardware_enable);
111  void setIndicator(indicator index, const QColor& color1, const QColor& color2, const QColor& color3 = QColor(), bool software_enable = true, i_hw hardware_enable = NORMAL);
112 
113  // Updates settings to the driver. Write "mode %d" first. Disable saveCustomDpi when writing a hardware profile or other permanent storage.
114  // By default, nothing will be written unless the settings have changed. Use force = true or call setNeedsUpdate() to override.
115  void update(QFile& cmd, int notifyNumber, bool force, bool saveCustomDpi);
116  inline void setNeedsUpdate() { _needsUpdate = true; }
117 
118  // Get indicator status to send to KbLight
119  void applyIndicators(int modeIndex, const bool indicatorState[HW_I_COUNT]);
120 
121 signals:
122  void didLoad();
123  void settingsUpdated();
124 
125 private:
126  // Related objects
127  inline KbMode* modeParent() const { return (KbMode*)parent(); }
128  KbBind* bind() const;
129  KbLight* light() const;
130 
131  // Send indicator state to KbLight, taking current opacity into account
132  void lightIndicator(const char* name, QRgb rgba);
133 
134  // DPI
137  // dpiCurX and dpiCurY store the current active DPI.
139 
140  // dpiCurIdx stores the index of the current "base" DPI, which is the DPI
141  // used when the stack is empty.
143  QColor dpiClr[DPI_COUNT + 1];
145 
146  // Current DPI "stack." The value corresponding to the largest key is the
147  // active DPI. If this is empty, we use the base DPI.
148  QMap<quint64, QPoint> pushedDpis;
150 
151  // Update the active DPI.
152  void _curDpi(const QPoint& newDpi);
153 
154  // Indicators
155  float _iOpacity;
156  QColor iColor[I_COUNT][2];
161 
162  // Mouse settings
165  // Misc
167 };
168 
169 #endif // KBPERF_H
static const int HW_I_COUNT
Definition: kbperf.h:107
void sniperDpi(const QPoint &newValue)
Definition: kbperf.h:53
void dpiCycleUp()
Definition: kbperf.cpp:317
indicator
Definition: kbperf.h:88
bool _needsUpdate
Definition: kbperf.h:166
void sniperDpi(int newValue)
Definition: kbperf.h:56
KbBind * bind() const
Definition: kbperf.cpp:98
void _curDpi(const QPoint &newDpi)
Definition: kbperf.cpp:259
int dpiBaseIdx
Definition: kbperf.h:142
int dpiCurY
Definition: kbperf.h:138
void dpiIndicator(bool newDpiIndicator)
Definition: kbperf.h:83
void dpiEnabled(int index, bool newEnabled)
Definition: kbperf.h:69
QColor light100Color
Definition: kbperf.h:157
bool dpiEnabled(int index) const
Definition: kbperf.h:68
void dpiColor(int index, const QColor &newColor)
Definition: kbperf.h:86
QPoint sniperDpi() const
Definition: kbperf.h:52
cmd
Definition: command.h:7
uint runningPushIdx
Definition: kbperf.h:149
static const int DPI_MIN
Definition: kbperf.h:47
bool iEnable[I_COUNT]
Definition: kbperf.h:158
QColor dpiColor(int index) const
Definition: kbperf.h:85
static const int DPI_MAX
Definition: kbperf.h:47
void iOpacity(float newIOpacity)
Definition: kbperf.h:80
void dpiCycleDown()
Definition: kbperf.cpp:329
bool dpiOn[DPI_COUNT]
Definition: kbperf.h:144
i_hw hwIType[HW_I_COUNT]
Definition: kbperf.h:159
void setNeedsUpdate()
Definition: kbperf.h:116
void dpiDown()
Definition: kbperf.cpp:306
QMap< quint64, QPoint > pushedDpis
Definition: kbperf.h:148
height liftHeight() const
Definition: kbperf.h:38
float _iOpacity
Definition: kbperf.h:155
height _liftHeight
Definition: kbperf.h:163
void popDpi(quint64 pushIdx)
Definition: kbperf.cpp:281
bool dpiIndicator() const
Definition: kbperf.h:82
KbMode * modeParent() const
Definition: kbperf.h:127
quint64 pushDpi(const QPoint &newDpi)
Definition: kbperf.cpp:274
KbPerf(KbMode *parent)
Definition: kbperf.cpp:13
height
Definition: kbperf.h:31
void didLoad()
Definition: moc_kbperf.cpp:134
QPoint dpi(int index) const
Definition: kbperf.h:50
Definition: kbmode.h:36
bool _needsSave
Definition: kbperf.h:166
Definition: kbperf.h:15
static const int DPI_COUNT
Definition: kbperf.h:46
Definition: kbbind.h:20
QColor muteNAColor
Definition: kbperf.h:157
bool _angleSnap
Definition: kbperf.h:164
bool angleSnap() const
Definition: kbperf.h:42
void setIndicator(indicator index, const QColor &color1, const QColor &color2, const QColor &color3=QColor(), bool software_enable=true, i_hw hardware_enable=NORMAL)
Definition: kbperf.cpp:356
void getIndicator(indicator index, QColor &color1, QColor &color2, QColor &color3, bool &software_enable, i_hw &hardware_enable)
Definition: kbperf.cpp:341
quint64 pushSniper()
Definition: kbperf.h:75
void update(QFile &cmd, int notifyNumber, bool force, bool saveCustomDpi)
Definition: kbperf.cpp:385
int dpiY[DPI_COUNT]
Definition: kbperf.h:136
int dpiCurX
Definition: kbperf.h:138
int baseDpiIdx() const
Definition: kbperf.h:61
void dpi(int index, int newValue)
Definition: kbperf.h:55
quint64 pushDpi(int newDpi)
Definition: kbperf.h:74
void dpiUp()
Definition: kbperf.cpp:295
QColor dpiClr[DPI_COUNT+1]
Definition: kbperf.h:143
QColor iColor[I_COUNT][2]
Definition: kbperf.h:156
bool needsSave() const
Definition: kbperf.h:28
const KbPerf & operator=(const KbPerf &rhs)
Definition: kbperf.cpp:77
void lightIndicator(const char *name, QRgb rgba)
Definition: kbperf.cpp:432
void applyIndicators(int modeIndex, const bool indicatorState[HW_I_COUNT])
Definition: kbperf.cpp:439
void settingsUpdated()
Definition: moc_kbperf.cpp:140
i_hw
Definition: kbperf.h:101
int dpiX[DPI_COUNT]
Definition: kbperf.h:135
void save(CkbSettings &settings)
Definition: kbperf.cpp:211
KbLight * light() const
Definition: kbperf.cpp:102
static const int SNIPER
Definition: kbperf.h:46
static const int OTHER
Definition: kbperf.h:84
void load(CkbSettings &settings)
Definition: kbperf.cpp:106
float iOpacity() const
Definition: kbperf.h:79
bool _dpiIndicator
Definition: kbperf.h:160
static const int I_COUNT
Definition: kbperf.h:107