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
kperfwidget.cpp
Go to the documentation of this file.
1 #include "kperfwidget.h"
2 #include "ui_kperfwidget.h"
3 #include "modeselectdialog.h"
4 #include <cmath>
5 
11  QWidget(parent),
12  ui(new Ui::KPerfWidget)
13 {
14  ui->setupUi(this);
15  // Set up indicators
24  for(int i = 0; i < I_COUNT; i++){
25  indicators[i].color1->setLabel(false);
26  indicators[i].color1->bigIcons(true);
27  indicators[i].color1->allowAlpha(true);
28  indicators[i].color2->setLabel(false);
29  indicators[i].color2->bigIcons(true);
30  indicators[i].color2->allowAlpha(true);
31  if(indicators[i].color3){
32  indicators[i].color3->setLabel(false);
33  indicators[i].color3->bigIcons(true);
34  indicators[i].color3->allowAlpha(true);
35  }
36  // Map signals
37  if(indicators[i].enable){
38  connect(indicators[i].enable, SIGNAL(clicked(bool)), &updateMapper, SLOT(map()));
39  updateMapper.setMapping(indicators[i].enable, i);
40  }
41  if(indicators[i].hwEnable){
42  connect(indicators[i].hwEnable, SIGNAL(activated(int)), &updateMapper, SLOT(map()));
43  updateMapper.setMapping(indicators[i].hwEnable, i);
44  }
45  connect(indicators[i].color1, SIGNAL(colorChanged(QColor)), &updateMapper, SLOT(map()));
46  updateMapper.setMapping(indicators[i].color1, i);
47  connect(indicators[i].color2, SIGNAL(colorChanged(QColor)), &updateMapper, SLOT(map()));
48  updateMapper.setMapping(indicators[i].color2, i);
49  if(indicators[i].color3){
50  connect(indicators[i].color3, SIGNAL(colorChanged(QColor)), &updateMapper, SLOT(map()));
51  updateMapper.setMapping(indicators[i].color3, i);
52  }
53  }
54  connect(&updateMapper, SIGNAL(mapped(int)), this, SLOT(uiUpdated(int)));
56 }
57 
62  delete ui;
63 }
64 
72 KPerfWidget::HwMode KPerfWidget::raw2Mode(bool sw_enable, i_hw hw_enable){
73  if(sw_enable){
74  if(hw_enable == KbPerf::NORMAL)
75  return BOTH;
76  return RGB;
77  } else {
78  if(hw_enable == KbPerf::ON)
79  return ALWAYS_ON;
80  else if(hw_enable == KbPerf::OFF)
81  return ALWAYS_OFF;
82  return NORMAL;
83  }
84 }
85 
100 void KPerfWidget::mode2Raw(HwMode mode, bool& sw_enable, i_hw& hw_enable){
101  switch(mode){
102  case NORMAL:
103  sw_enable = false;
104  hw_enable = KbPerf::NORMAL;
105  break;
106  case ALWAYS_ON:
107  sw_enable = false;
108  hw_enable = KbPerf::ON;
109  break;
110  case ALWAYS_OFF:
111  sw_enable = false;
112  hw_enable = KbPerf::OFF;
113  break;
114  case RGB:
115  sw_enable = true;
116  hw_enable = KbPerf::OFF;
117  break;
118  case BOTH:
119  sw_enable = true;
120  hw_enable = KbPerf::NORMAL;
121  break;
122  }
123 }
124 
125 void KPerfWidget::setPerf(KbPerf* newPerf, KbProfile* newProfile){
126  perf = newPerf;
127  profile = newProfile;
128  // Set intensity
129  ui->intensityBox->setValue(round(perf->iOpacity() * 100.f));
130  // Set hardware indicator values
131  for(int i = 0; i < HW_I_COUNT; i++){
132  QColor c1, c2, c3;
133  bool software;
134  i_hw hardware;
135  perf->getIndicator((indicator)i, c1, c2, c3, software, hardware);
136  HwMode mode = raw2Mode(software, hardware);
137  indicators[i].hwEnable->setCurrentIndex((int)mode);
138  indicators[i].color1->color(c1);
139  indicators[i].color2->color(c2);
140  if(mode == RGB || mode == BOTH){
141  indicators[i].color1->setEnabled(true);
142  indicators[i].color2->setEnabled(true);
143  } else {
144  indicators[i].color1->setEnabled(false);
145  indicators[i].color2->setEnabled(false);
146  }
147  }
148  // Set software indicators
149  for(int i = HW_I_COUNT; i < I_COUNT; i++){
150  QColor c1, c2, c3;
151  bool software;
152  i_hw hardware;
153  perf->getIndicator((indicator)i, c1, c2, c3, software, hardware);
154  indicators[i].enable->setChecked(software);
155  indicators[i].color1->color(c1);
156  indicators[i].color2->color(c2);
157  if(indicators[i].color3) indicators[i].color3->color(c3);
158  if(software){
159  indicators[i].color1->setEnabled(true);
160  indicators[i].color2->setEnabled(true);
161  if(indicators[i].color3) indicators[i].color3->setEnabled(true);
162  } else {
163  indicators[i].color1->setEnabled(false);
164  indicators[i].color2->setEnabled(false);
165  if(indicators[i].color3) indicators[i].color3->setEnabled(false);
166  }
167  }
168  // Hide K95 indicators on non-K95s
169  if(profile->keyMap().model() == KeyMap::K95){
170  foreach(QWidget* w, k95Widgets)
171  w->show();
172  } else {
173  foreach(QWidget* w, k95Widgets)
174  w->hide();
175  if(profile->keyMap().model() == KeyMap::STRAFE) { // hide indicators unsupported by STRAFE
176  ui->muteBox->hide();
177  ui->muteColorOn->hide();
178  ui->muteColorOff->hide();
179  ui->muteColorNA->hide();
180  ui->label_12->hide();
181  ui->label_14->hide();
182  ui->label_17->hide();
183  }
184  }
185 }
186 
187 void KPerfWidget::uiUpdated(int index){
188  if(!perf)
189  return;
190  // Read HW/SW enable state
191  bool software;
192  i_hw hardware;
193  if(indicators[index].enable){
194  software = indicators[index].enable->isChecked();
195  hardware = KbPerf::NONE;
196  } else {
197  mode2Raw((HwMode)indicators[index].hwEnable->currentIndex(), software, hardware);
198  }
199  // Enable/disable color buttons based on whether or not the indicator is turned on
200  if(software){
201  indicators[index].color1->setEnabled(true);
202  indicators[index].color2->setEnabled(true);
203  if(indicators[index].color3) indicators[index].color3->setEnabled(true);
204  } else {
205  indicators[index].color1->setEnabled(false);
206  indicators[index].color2->setEnabled(false);
207  if(indicators[index].color3) indicators[index].color3->setEnabled(false);
208  }
209  QColor c1 = indicators[index].color1->color();
210  QColor c2 = indicators[index].color2->color();
211  QColor c3 = indicators[index].color3 ? indicators[index].color3->color() : QColor();
212  perf->setIndicator((indicator)index, c1, c2, c3, software, hardware);
213 }
214 
216  if(!perf)
217  return;
218  perf->iOpacity(arg1 / 100.f);
219 }
220 
222  ModeSelectDialog dialog(this, profile->currentMode(), profile->modes(), "Copy performance settings to:");
223  if(dialog.exec() != QDialog::Accepted)
224  return;
225  QList<KbMode*> selectedModes = dialog.selection();
226  foreach(KbMode* mode, selectedModes){
227  *mode->perf() = *perf;
228  }
229 }
KbMode * currentMode() const
Definition: kbprofile.h:54
const ModeList & modes() const
Definition: kbprofile.h:42
static const int HW_I_COUNT
Definition: kperfwidget.h:27
indicator
Definition: kbperf.h:88
void on_intensityBox_valueChanged(int arg1)
ColorButton * lockColorOff
ColorButton * lightColor1
ColorButton * lightColor2
IndicatorUi indicators[I_COUNT]
Definition: kperfwidget.h:59
Ui::KPerfWidget * ui
Definition: kperfwidget.h:32
ColorButton * macroColorOff
static const int I_COUNT
Definition: kperfwidget.h:26
const QColor & color() const
Definition: colorbutton.h:13
QComboBox * capsBox
QLabel * label_12
KbProfile * profile
Definition: kperfwidget.h:35
QLabel * k95Label4
QLabel * label_14
void on_copyButton_clicked()
QSpinBox * intensityBox
QComboBox * scrollBox
KPerfWidget(QWidget *parent=0)
KPerfWidget::KPerfWidget sets up the UI for Keyboard Performace panel.
Definition: kperfwidget.cpp:10
ColorButton * capsColorOn
HwMode raw2Mode(bool sw_enable, i_hw hw_enable)
KPerfWidget::raw2Mode return hardware mode depending on setiings in sw_enable and hw_enable...
Definition: kperfwidget.cpp:72
QCheckBox * lockBox
QLabel * k95Label3
void uiUpdated(int index)
ColorButton * modeColorOff
ColorButton * color3
Definition: kperfwidget.h:57
ColorButton * lockColorOn
void setupUi(QWidget *KPerfWidget)
Definition: kbmode.h:36
ColorButton * macroColorOn
Definition: kbperf.h:15
QLabel * k95Label1
ColorButton * capsColorOff
ColorButton * muteColorNA
ColorButton * numColorOff
QLabel * k95Label2
QSignalMapper updateMapper
Definition: kperfwidget.h:62
void mode2Raw(HwMode mode, bool &sw_enable, i_hw &hw_enable)
KPerfWidget::mode2Raw Set values of sw_enable and hw_enable to hte value corresponding to input var m...
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
ColorButton * muteColorOn
void getIndicator(indicator index, QColor &color1, QColor &color2, QColor &color3, bool &software_enable, i_hw &hardware_enable)
Definition: kbperf.cpp:341
ColorButton * lightColor3
QLabel * k95Label6
const KeyMap & keyMap() const
Definition: kbprofile.h:37
QCheckBox * muteBox
QCheckBox * lightBox
ColorButton * color2
Definition: kperfwidget.h:57
bool allowAlpha() const
Definition: colorbutton.h:17
KbPerf * perf
Definition: kperfwidget.h:34
QLabel * k95Label5
QCheckBox * macroBox
Model model() const
Definition: keymap.h:129
ColorButton * color1
Definition: kperfwidget.h:57
QList< KbMode * > selection()
QComboBox * numBox
QFrame * k95Line
ColorButton * muteColorOff
i_hw
Definition: kbperf.h:101
QCheckBox * modeBox
void setPerf(KbPerf *newPerf, KbProfile *newProfile)
ColorButton * numColorOn
float iOpacity() const
Definition: kbperf.h:79
ColorButton * modeColorOn
QWidget * k95Spacer
ColorButton * scrollColorOn
KbPerf * perf()
Definition: kbmode.h:62
bool bigIcons() const
Definition: colorbutton.h:23
QList< QWidget * > k95Widgets
Definition: kperfwidget.h:60
ColorButton * scrollColorOff
bool setLabel() const
Definition: colorbutton.h:20
~KPerfWidget()
KPerfWidget::~KPerfWidget nothing unusual - just delete the ui object.
Definition: kperfwidget.cpp:61
QLabel * label_17