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 Class Reference

#include <src/ckb/kperfwidget.h>

+ Inheritance diagram for KPerfWidget:
+ Collaboration diagram for KPerfWidget:

Data Structures

struct  IndicatorUi
 

Public Types

typedef KbPerf::indicator indicator
 
typedef KbPerf::i_hw i_hw
 

Public Member Functions

 KPerfWidget (QWidget *parent=0)
 KPerfWidget::KPerfWidget sets up the UI for Keyboard Performace panel. More...
 
 ~KPerfWidget ()
 KPerfWidget::~KPerfWidget nothing unusual - just delete the ui object. More...
 
void setPerf (KbPerf *newPerf, KbProfile *newProfile)
 

Static Public Attributes

static const int I_COUNT = KbPerf::I_COUNT
 
static const int HW_I_COUNT = KbPerf::HW_I_COUNT
 

Private Types

enum  HwMode {
  NORMAL, ALWAYS_ON, ALWAYS_OFF, RGB,
  BOTH
}
 

Private Slots

void uiUpdated (int index)
 
void on_intensityBox_valueChanged (int arg1)
 
void on_copyButton_clicked ()
 

Private Member Functions

HwMode raw2Mode (bool sw_enable, i_hw hw_enable)
 KPerfWidget::raw2Mode return hardware mode depending on setiings in sw_enable and hw_enable. More...
 
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 mode. More...
 

Private Attributes

Ui::KPerfWidgetui
 
KbPerfperf
 
KbProfileprofile
 
IndicatorUi indicators [I_COUNT]
 
QList< QWidget * > k95Widgets
 
QSignalMapper updateMapper
 

Detailed Description

Definition at line 16 of file kperfwidget.h.


Data Structure Documentation

struct KPerfWidget::IndicatorUi

Definition at line 54 of file kperfwidget.h.

+ Collaboration diagram for KPerfWidget::IndicatorUi:
Data Fields
ColorButton * color1
ColorButton * color2
ColorButton * color3
QCheckBox * enable
QComboBox * hwEnable

Member Typedef Documentation

Definition at line 29 of file kperfwidget.h.

Definition at line 28 of file kperfwidget.h.

Member Enumeration Documentation

enum KPerfWidget::HwMode
private
Enumerator
NORMAL 
ALWAYS_ON 
ALWAYS_OFF 
RGB 
BOTH 

Definition at line 38 of file kperfwidget.h.

Constructor & Destructor Documentation

KPerfWidget::KPerfWidget ( QWidget parent = 0)
explicit
Parameters
parent

Definition at line 10 of file kperfwidget.cpp.

References ColorButton::allowAlpha(), ColorButton::bigIcons(), Ui_KPerfWidget::capsBox, Ui_KPerfWidget::capsColorOff, Ui_KPerfWidget::capsColorOn, KPerfWidget::IndicatorUi::color1, KPerfWidget::IndicatorUi::color2, KPerfWidget::IndicatorUi::color3, KPerfWidget::IndicatorUi::enable, KPerfWidget::IndicatorUi::hwEnable, I_COUNT, indicators, Ui_KPerfWidget::k95Label1, Ui_KPerfWidget::k95Label2, Ui_KPerfWidget::k95Label3, Ui_KPerfWidget::k95Label4, Ui_KPerfWidget::k95Label5, Ui_KPerfWidget::k95Label6, Ui_KPerfWidget::k95Line, Ui_KPerfWidget::k95Spacer, k95Widgets, Ui_KPerfWidget::lightBox, Ui_KPerfWidget::lightColor1, Ui_KPerfWidget::lightColor2, Ui_KPerfWidget::lightColor3, Ui_KPerfWidget::lockBox, Ui_KPerfWidget::lockColorOff, Ui_KPerfWidget::lockColorOn, Ui_KPerfWidget::macroBox, Ui_KPerfWidget::macroColorOff, Ui_KPerfWidget::macroColorOn, Ui_KPerfWidget::modeBox, Ui_KPerfWidget::modeColorOff, Ui_KPerfWidget::modeColorOn, Ui_KPerfWidget::muteBox, Ui_KPerfWidget::muteColorNA, Ui_KPerfWidget::muteColorOff, Ui_KPerfWidget::muteColorOn, Ui_KPerfWidget::numBox, Ui_KPerfWidget::numColorOff, Ui_KPerfWidget::numColorOn, Ui_KPerfWidget::scrollBox, Ui_KPerfWidget::scrollColorOff, Ui_KPerfWidget::scrollColorOn, ColorButton::setLabel(), Ui_KPerfWidget::setupUi(), ui, uiUpdated(), and updateMapper.

10  :
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 }
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
QComboBox * capsBox
QLabel * k95Label4
QComboBox * scrollBox
ColorButton * capsColorOn
QCheckBox * lockBox
QLabel * k95Label3
void uiUpdated(int index)
ColorButton * modeColorOff
ColorButton * color3
Definition: kperfwidget.h:57
ColorButton * lockColorOn
void setupUi(QWidget *KPerfWidget)
ColorButton * macroColorOn
QLabel * k95Label1
ColorButton * capsColorOff
ColorButton * muteColorNA
ColorButton * numColorOff
QLabel * k95Label2
QSignalMapper updateMapper
Definition: kperfwidget.h:62
ColorButton * muteColorOn
ColorButton * lightColor3
QLabel * k95Label6
QCheckBox * muteBox
QCheckBox * lightBox
ColorButton * color2
Definition: kperfwidget.h:57
bool allowAlpha() const
Definition: colorbutton.h:17
QLabel * k95Label5
QCheckBox * macroBox
ColorButton * color1
Definition: kperfwidget.h:57
QComboBox * numBox
QFrame * k95Line
ColorButton * muteColorOff
QCheckBox * modeBox
ColorButton * numColorOn
ColorButton * modeColorOn
QWidget * k95Spacer
ColorButton * scrollColorOn
bool bigIcons() const
Definition: colorbutton.h:23
QList< QWidget * > k95Widgets
Definition: kperfwidget.h:60
ColorButton * scrollColorOff
bool setLabel() const
Definition: colorbutton.h:20

+ Here is the call graph for this function:

KPerfWidget::~KPerfWidget ( )

Definition at line 61 of file kperfwidget.cpp.

References ui.

61  {
62  delete ui;
63 }
Ui::KPerfWidget * ui
Definition: kperfwidget.h:32

Member Function Documentation

void KPerfWidget::mode2Raw ( HwMode  mode,
bool &  sw_enable,
i_hw hw_enable 
)
private
Parameters
[IN]mode
[OUT]sw_enable
[OUT]hw_enable
[IN]mode
[OUT]sw_enable
[OUT]hw_enable mode determines how colors at a key and separate indicators should be handled: Mode | sw | hw _ | _ | _ NORMAL | No color change at the key | use the separate indicator depending on key state ALWAYS_ON | No color change at the key | switch on separate indicator ALWAYS_OFF | No color change at the key | switch off separate indicator RGB | use color change at the key depending on color sliders | switch off separate indicator BOTH | use color change at the key depending on color sliders | use the separate indicator depending on key state

Definition at line 100 of file kperfwidget.cpp.

References ALWAYS_OFF, ALWAYS_ON, BOTH, NORMAL, KbPerf::NORMAL, KbPerf::OFF, KbPerf::ON, and RGB.

Referenced by uiUpdated().

100  {
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 }

+ Here is the caller graph for this function:

void KPerfWidget::on_copyButton_clicked ( )
privateslot

Definition at line 221 of file kperfwidget.cpp.

References KbProfile::currentMode(), KbProfile::modes(), perf, KbMode::perf(), profile, and ModeSelectDialog::selection().

221  {
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
KbProfile * profile
Definition: kperfwidget.h:35
Definition: kbmode.h:36
KbPerf * perf
Definition: kperfwidget.h:34
QList< KbMode * > selection()
KbPerf * perf()
Definition: kbmode.h:62

+ Here is the call graph for this function:

void KPerfWidget::on_intensityBox_valueChanged ( int  arg1)
privateslot

Definition at line 215 of file kperfwidget.cpp.

References KbPerf::iOpacity(), and perf.

215  {
216  if(!perf)
217  return;
218  perf->iOpacity(arg1 / 100.f);
219 }
KbPerf * perf
Definition: kperfwidget.h:34
float iOpacity() const
Definition: kbperf.h:79

+ Here is the call graph for this function:

KPerfWidget::HwMode KPerfWidget::raw2Mode ( bool  sw_enable,
i_hw  hw_enable 
)
private
Parameters
sw_enable
hw_enable
Returns
the mode of operation for key-coloring and separate indicators.
See Also
KPerfWidget::mode2Raw for details.

Definition at line 72 of file kperfwidget.cpp.

References ALWAYS_OFF, ALWAYS_ON, BOTH, NORMAL, KbPerf::NORMAL, KbPerf::OFF, KbPerf::ON, and RGB.

Referenced by setPerf().

72  {
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 }

+ Here is the caller graph for this function:

void KPerfWidget::setPerf ( KbPerf newPerf,
KbProfile newProfile 
)

Definition at line 125 of file kperfwidget.cpp.

References BOTH, ColorButton::color(), KPerfWidget::IndicatorUi::color1, KPerfWidget::IndicatorUi::color2, KPerfWidget::IndicatorUi::color3, KPerfWidget::IndicatorUi::enable, KbPerf::getIndicator(), HW_I_COUNT, KPerfWidget::IndicatorUi::hwEnable, I_COUNT, indicators, Ui_KPerfWidget::intensityBox, KbPerf::iOpacity(), KeyMap::K95, k95Widgets, KbProfile::keyMap(), Ui_KPerfWidget::label_12, Ui_KPerfWidget::label_14, Ui_KPerfWidget::label_17, KeyMap::model(), Ui_KPerfWidget::muteBox, Ui_KPerfWidget::muteColorNA, Ui_KPerfWidget::muteColorOff, Ui_KPerfWidget::muteColorOn, perf, profile, raw2Mode(), RGB, KeyMap::STRAFE, and ui.

Referenced by KbWidget::modeChanged().

125  {
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 }
static const int HW_I_COUNT
Definition: kperfwidget.h:27
IndicatorUi indicators[I_COUNT]
Definition: kperfwidget.h:59
Ui::KPerfWidget * ui
Definition: kperfwidget.h:32
static const int I_COUNT
Definition: kperfwidget.h:26
const QColor & color() const
Definition: colorbutton.h:13
QLabel * label_12
KbProfile * profile
Definition: kperfwidget.h:35
QLabel * label_14
KbPerf::indicator indicator
Definition: kperfwidget.h:28
QSpinBox * intensityBox
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
ColorButton * color3
Definition: kperfwidget.h:57
ColorButton * muteColorNA
KbPerf::i_hw i_hw
Definition: kperfwidget.h:29
ColorButton * muteColorOn
void getIndicator(indicator index, QColor &color1, QColor &color2, QColor &color3, bool &software_enable, i_hw &hardware_enable)
Definition: kbperf.cpp:341
const KeyMap & keyMap() const
Definition: kbprofile.h:37
QCheckBox * muteBox
ColorButton * color2
Definition: kperfwidget.h:57
KbPerf * perf
Definition: kperfwidget.h:34
Model model() const
Definition: keymap.h:129
ColorButton * color1
Definition: kperfwidget.h:57
ColorButton * muteColorOff
float iOpacity() const
Definition: kbperf.h:79
QList< QWidget * > k95Widgets
Definition: kperfwidget.h:60
QLabel * label_17

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KPerfWidget::uiUpdated ( int  index)
privateslot

Definition at line 187 of file kperfwidget.cpp.

References ColorButton::color(), KPerfWidget::IndicatorUi::color1, KPerfWidget::IndicatorUi::color2, KPerfWidget::IndicatorUi::color3, KPerfWidget::IndicatorUi::enable, indicators, mode2Raw(), KbPerf::NONE, perf, and KbPerf::setIndicator().

Referenced by KPerfWidget().

187  {
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 }
IndicatorUi indicators[I_COUNT]
Definition: kperfwidget.h:59
const QColor & color() const
Definition: colorbutton.h:13
KbPerf::indicator indicator
Definition: kperfwidget.h:28
ColorButton * color3
Definition: kperfwidget.h:57
KbPerf::i_hw i_hw
Definition: kperfwidget.h:29
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 * color2
Definition: kperfwidget.h:57
KbPerf * perf
Definition: kperfwidget.h:34
ColorButton * color1
Definition: kperfwidget.h:57

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

const int KPerfWidget::HW_I_COUNT = KbPerf::HW_I_COUNT
static

Definition at line 27 of file kperfwidget.h.

Referenced by setPerf().

const int KPerfWidget::I_COUNT = KbPerf::I_COUNT
static

Definition at line 26 of file kperfwidget.h.

Referenced by KPerfWidget(), and setPerf().

IndicatorUi KPerfWidget::indicators[I_COUNT]
private

Definition at line 59 of file kperfwidget.h.

Referenced by KPerfWidget(), setPerf(), and uiUpdated().

QList<QWidget*> KPerfWidget::k95Widgets
private

Definition at line 60 of file kperfwidget.h.

Referenced by KPerfWidget(), and setPerf().

KbPerf* KPerfWidget::perf
private
KbProfile* KPerfWidget::profile
private

Definition at line 35 of file kperfwidget.h.

Referenced by on_copyButton_clicked(), and setPerf().

Ui::KPerfWidget* KPerfWidget::ui
private

Definition at line 32 of file kperfwidget.h.

Referenced by KPerfWidget(), setPerf(), and ~KPerfWidget().

QSignalMapper KPerfWidget::updateMapper
private

Definition at line 62 of file kperfwidget.h.

Referenced by KPerfWidget().


The documentation for this class was generated from the following files: