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
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  inline QPoint dpi(int index) const { if(index < 0 || index >= DPI_COUNT) return QPoint(); return QPoint(dpiX[index], dpiY[index]); }
49  void dpi(int index, const QPoint& newValue);
50  inline QPoint sniperDpi() const { return dpi(SNIPER); }
51  inline void sniperDpi(const QPoint& newValue) { dpi(SNIPER, newValue); }
52  // Set both X and Y
53  inline void dpi(int index, int newValue) { dpi(index, QPoint(newValue, newValue)); }
54  inline void sniperDpi(int newValue) { sniperDpi(QPoint(newValue, newValue)); }
55 
56  // Current DPI
57  inline QPoint curDpi() const { return QPoint(dpiCurX, dpiCurY); }
58  void curDpi(const QPoint& newDpi);
59  inline void curDpi(int newDpi) { curDpi(QPoint(newDpi, newDpi)); }
60  // DPI index (updated automatically by curDpi). -1 if custom.
61  inline int curDpiIdx() const { return dpiCurIdx; }
62  inline void curDpiIdx(int newIdx) { curDpi(dpi(newIdx)); }
63  void dpiUp();
64  void dpiDown();
65  // DPI stages enabled (default all). Disabled stages will be bypassed when invoking dpiUp/dpiDown (but not any other functions).
66  inline bool dpiEnabled(int index) const { return dpiOn[index]; }
67  inline void dpiEnabled(int index, bool newEnabled) { if(index <= 0) return; dpiOn[index] = newEnabled; _needsUpdate = _needsSave = true; }
68  // Push/pop a DPI state. Useful for toggling custom DPI. pushDpi returns an index which must be passed back to popDpi.
69  // Note that calling curDpi will empty the stack, so any previously-pushed DPIs are automatically popped.
70  quint64 pushDpi(const QPoint& newDpi);
71  inline quint64 pushDpi(int newDpi) { return pushDpi(QPoint(newDpi, newDpi)); }
72  inline quint64 pushSniper() { return pushDpi(sniperDpi()); }
73  void popDpi(quint64 pushIdx);
74 
75  // Indicator opacity [0, 1]
76  inline float iOpacity() const { return _iOpacity; }
77  inline void iOpacity(float newIOpacity) { _iOpacity = newIOpacity; _needsSave = true; }
78  // DPI indicator colors
79  inline bool dpiIndicator() const { return _dpiIndicator; }
80  inline void dpiIndicator(bool newDpiIndicator) { _dpiIndicator = newDpiIndicator; _needsSave = true; }
81  const static int OTHER = DPI_COUNT; // valid only with dpiColor
82  inline QColor dpiColor(int index) const { return dpiClr[index]; }
83  inline void dpiColor(int index, const QColor& newColor) { dpiClr[index] = newColor; _needsUpdate = _needsSave = true; }
84  // KB indicator colors
85  enum indicator {
86  // Hardware
87  NUM,
90  // Software
96  };
97  // Hardware indicator state
98  enum i_hw {
99  NONE = -1, // For non-hardware indicators
101  ON,
103  };
104  const static int I_COUNT = (int)MUTE + 1, HW_I_COUNT = (int)HW_IMAX + 1;
105  // Indicator color and settings. For MUTE, color1 = on, color2 = off, color3 = don't know. For LIGHT, color1 = 33%, color2 = 67%, color3 = 100%.
106  // For all others, color1 = on, color2 = off, color3 unused
107  void getIndicator(indicator index, QColor& color1, QColor& color2, QColor& color3, bool& software_enable, i_hw& hardware_enable);
108  void setIndicator(indicator index, const QColor& color1, const QColor& color2, const QColor& color3 = QColor(), bool software_enable = true, i_hw hardware_enable = NORMAL);
109 
110  // Updates settings to the driver. Write "mode %d" first. Disable saveCustomDpi when writing a hardware profile or other permanent storage.
111  // By default, nothing will be written unless the settings have changed. Use force = true or call setNeedsUpdate() to override.
112  void update(QFile& cmd, int notifyNumber, bool force = false, bool saveCustomDpi = true);
113  inline void setNeedsUpdate() { _needsUpdate = true; }
114 
115  // Get indicator status to send to KbLight
116  void applyIndicators(int modeIndex, const bool indicatorState[HW_I_COUNT]);
117 
118 signals:
119  void didLoad();
120  void settingsUpdated();
121 
122 private:
123  // Related objects
124  inline KbMode* modeParent() const { return (KbMode*)parent(); }
125  KbBind* bind() const;
126  KbLight* light() const;
127 
128  // Send indicator state to KbLight, taking current opacity into account
129  void lightIndicator(const char* name, QRgb rgba);
130 
131  // DPI
135  QColor dpiClr[DPI_COUNT + 1];
137  // Last-set DPI that was on the DPI list, not counting any pushed DPIs or sniper.
139 
140  // Current DPI stack. If non-empty, pushedDpis[0] represents the last DPI set by curDpi.
141  // (not necessarily the same as dpi(dpiLastIdx), since the last-set DPI might not have been on the DPI list)
142  QMap<quint64, QPoint> pushedDpis;
144 
145  // Update DPI without popping stack
146  void _curDpi(const QPoint& newDpi);
147 
148  // Indicators
149  float _iOpacity;
150  QColor iColor[I_COUNT][2];
155 
156  // Mouse settings
159  // Misc
161 };
162 
163 #endif // KBPERF_H
static const int HW_I_COUNT
Definition: kbperf.h:104
void sniperDpi(const QPoint &newValue)
Definition: kbperf.h:51
indicator
Definition: kbperf.h:85
bool _needsUpdate
Definition: kbperf.h:160
void sniperDpi(int newValue)
Definition: kbperf.h:54
KbBind * bind() const
Definition: kbperf.cpp:100
void _curDpi(const QPoint &newDpi)
Definition: kbperf.cpp:262
int dpiCurY
Definition: kbperf.h:134
void dpiIndicator(bool newDpiIndicator)
Definition: kbperf.h:80
void curDpi(int newDpi)
Definition: kbperf.h:59
void dpiEnabled(int index, bool newEnabled)
Definition: kbperf.h:67
QColor light100Color
Definition: kbperf.h:151
bool dpiEnabled(int index) const
Definition: kbperf.h:66
void dpiColor(int index, const QColor &newColor)
Definition: kbperf.h:83
QPoint sniperDpi() const
Definition: kbperf.h:50
cmd
Definition: command.h:7
uint runningPushIdx
Definition: kbperf.h:143
static const int DPI_MIN
Definition: kbperf.h:47
bool iEnable[I_COUNT]
Definition: kbperf.h:152
QColor dpiColor(int index) const
Definition: kbperf.h:82
static const int DPI_MAX
Definition: kbperf.h:47
void iOpacity(float newIOpacity)
Definition: kbperf.h:77
bool dpiOn[DPI_COUNT]
Definition: kbperf.h:136
void update(QFile &cmd, int notifyNumber, bool force=false, bool saveCustomDpi=true)
Definition: kbperf.cpp:373
i_hw hwIType[HW_I_COUNT]
Definition: kbperf.h:153
void setNeedsUpdate()
Definition: kbperf.h:113
void dpiDown()
Definition: kbperf.cpp:319
QMap< quint64, QPoint > pushedDpis
Definition: kbperf.h:142
height liftHeight() const
Definition: kbperf.h:38
float _iOpacity
Definition: kbperf.h:149
height _liftHeight
Definition: kbperf.h:157
void popDpi(quint64 pushIdx)
Definition: kbperf.cpp:296
bool dpiIndicator() const
Definition: kbperf.h:79
KbMode * modeParent() const
Definition: kbperf.h:124
quint64 pushDpi(const QPoint &newDpi)
Definition: kbperf.cpp:284
int dpiLastIdx
Definition: kbperf.h:138
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:48
void curDpiIdx(int newIdx)
Definition: kbperf.h:62
Definition: kbmode.h:36
bool _needsSave
Definition: kbperf.h:160
Definition: kbperf.h:15
static const int DPI_COUNT
Definition: kbperf.h:46
Definition: kbbind.h:20
QColor muteNAColor
Definition: kbperf.h:151
bool _angleSnap
Definition: kbperf.h:158
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:344
void getIndicator(indicator index, QColor &color1, QColor &color2, QColor &color3, bool &software_enable, i_hw &hardware_enable)
Definition: kbperf.cpp:329
quint64 pushSniper()
Definition: kbperf.h:72
int dpiY[DPI_COUNT]
Definition: kbperf.h:133
int dpiCurX
Definition: kbperf.h:134
QPoint curDpi() const
Definition: kbperf.h:57
void dpi(int index, int newValue)
Definition: kbperf.h:53
quint64 pushDpi(int newDpi)
Definition: kbperf.h:71
void dpiUp()
Definition: kbperf.cpp:308
QColor dpiClr[DPI_COUNT+1]
Definition: kbperf.h:135
QColor iColor[I_COUNT][2]
Definition: kbperf.h:150
bool needsSave() const
Definition: kbperf.h:28
int curDpiIdx() const
Definition: kbperf.h:61
const KbPerf & operator=(const KbPerf &rhs)
Definition: kbperf.cpp:78
void lightIndicator(const char *name, QRgb rgba)
Definition: kbperf.cpp:425
int dpiCurIdx
Definition: kbperf.h:134
void applyIndicators(int modeIndex, const bool indicatorState[HW_I_COUNT])
Definition: kbperf.cpp:432
void settingsUpdated()
Definition: moc_kbperf.cpp:140
i_hw
Definition: kbperf.h:98
int dpiX[DPI_COUNT]
Definition: kbperf.h:132
void save(CkbSettings &settings)
Definition: kbperf.cpp:207
KbLight * light() const
Definition: kbperf.cpp:104
static const int SNIPER
Definition: kbperf.h:46
static const int OTHER
Definition: kbperf.h:81
void load(CkbSettings &settings)
Definition: kbperf.cpp:108
float iOpacity() const
Definition: kbperf.h:76
bool _dpiIndicator
Definition: kbperf.h:154
static const int I_COUNT
Definition: kbperf.h:104