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

#include <src/ckb/kblightwidget.h>

+ Inheritance diagram for KbLightWidget:
+ Collaboration diagram for KbLightWidget:

Public Member Functions

 KbLightWidget (QWidget *parent=0)
 
 ~KbLightWidget ()
 
void setLight (KbLight *newLight)
 
void setMonochrome ()
 

Private Slots

void updateLight ()
 
void newSelection (QStringList selection)
 
void changeColor (QColor newColor)
 
void changeAnim (KbAnim *newAnim)
 
void changeAnimKeys (QStringList keys)
 
void on_brightnessBox_activated (int index)
 
void on_animButton_clicked ()
 
void on_bgButton_clicked ()
 
void on_showAnimBox_clicked (bool checked)
 
void toggleSidelight ()
 

Private Attributes

KbLightlight
 
QStringList currentSelection
 
Ui::KbLightWidgetui
 

Detailed Description

Definition at line 15 of file kblightwidget.h.

Constructor & Destructor Documentation

KbLightWidget::KbLightWidget ( QWidget parent = 0)
explicit

Definition at line 6 of file kblightwidget.cpp.

References Ui_KbLightWidget::animButton, Ui_KbLightWidget::animWidget, Ui_KbLightWidget::bgButton, changeAnim(), changeAnimKeys(), changeColor(), AnimScript::count(), CkbSettings::get(), Ui_KbLightWidget::keyWidget, newSelection(), Ui_KbLightWidget::setupUi(), Ui_KbLightWidget::showAnimBox, toggleSidelight(), and ui.

6  :
7  QWidget(parent), light(0),
9 {
10  ui->setupUi(this);
11  if(AnimScript::count() == 0)
12  ui->animButton->setVisible(false);
13 
14  connect(ui->bgButton, SIGNAL(colorChanged(QColor)), this, SLOT(changeColor(QColor)));
15  connect(ui->keyWidget, SIGNAL(selectionChanged(QStringList)), this, SLOT(newSelection(QStringList)));
16  connect(ui->keyWidget, SIGNAL(sidelightToggled()), this, SLOT(toggleSidelight())); // click on a toggle button, like sidelight
17  connect(ui->animWidget, SIGNAL(animChanged(KbAnim*)), this, SLOT(changeAnim(KbAnim*)));
18  connect(ui->animWidget, SIGNAL(didUpdateSelection(QStringList)), this, SLOT(changeAnimKeys(QStringList)));
19 
20  // Restore "show animated" setting
21  ui->showAnimBox->setChecked(!CkbSettings::get("UI/Light/ShowBaseOnly").toBool());
22 }
void changeAnimKeys(QStringList keys)
void setupUi(QWidget *KbLightWidget)
static int count()
Definition: animscript.h:54
void toggleSidelight()
KeyWidget * keyWidget
void changeAnim(KbAnim *newAnim)
static QVariant get(const QString &key, const QVariant &defaultValue=QVariant())
void newSelection(QStringList selection)
KbLight * light
Definition: kblightwidget.h:43
KbAnimWidget * animWidget
Ui::KbLightWidget * ui
Definition: kblightwidget.h:46
void changeColor(QColor newColor)
Definition: kbanim.h:11
ColorButton * bgButton
QPushButton * animButton
QCheckBox * showAnimBox

+ Here is the call graph for this function:

KbLightWidget::~KbLightWidget ( )

Definition at line 24 of file kblightwidget.cpp.

References ui.

24  {
25  delete ui;
26 }
Ui::KbLightWidget * ui
Definition: kblightwidget.h:46

Member Function Documentation

void KbLightWidget::changeAnim ( KbAnim newAnim)
privateslot

Definition at line 121 of file kblightwidget.cpp.

References KeyWidget::clearSelection(), KbAnim::keys(), Ui_KbLightWidget::keyWidget, KeyWidget::setAnimationToSelection(), KeyWidget::setSelection(), and ui.

Referenced by KbLightWidget().

121  {
122  if(newAnim)
123  ui->keyWidget->setSelection(newAnim->keys());
124  else
127 }
void clearSelection()
Definition: keywidget.cpp:617
const QStringList & keys()
Definition: kbanim.h:40
void setSelection(const QStringList &keys)
Definition: keywidget.cpp:582
KeyWidget * keyWidget
Ui::KbLightWidget * ui
Definition: kblightwidget.h:46
void setAnimationToSelection()
Definition: keywidget.cpp:639

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLightWidget::changeAnimKeys ( QStringList  keys)
privateslot

Definition at line 129 of file kblightwidget.cpp.

References Ui_KbLightWidget::keyWidget, KeyWidget::setAnimation(), and ui.

Referenced by KbLightWidget().

129  {
130  ui->keyWidget->setAnimation(keys);
131 }
KeyWidget * keyWidget
Ui::KbLightWidget * ui
Definition: kblightwidget.h:46
void setAnimation(const QStringList &keys)
Definition: keywidget.cpp:625

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLightWidget::changeColor ( QColor  newColor)
privateslot

Definition at line 99 of file kblightwidget.cpp.

References KbLight::color(), KeyWidget::colorMap(), KbLight::colorMap(), currentSelection, Ui_KbLightWidget::keyWidget, light, and ui.

Referenced by KbLightWidget().

99  {
100  if(light){
101  foreach(QString key, currentSelection)
102  light->color(key, newColor);
104  }
105 }
KeyWidget * keyWidget
const QColorMap & colorMap()
Definition: kblight.h:31
Definition: keymap.h:49
KbLight * light
Definition: kblightwidget.h:43
const QColorMap & colorMap() const
Definition: keywidget.h:27
Ui::KbLightWidget * ui
Definition: kblightwidget.h:46
void color(const QString &key, const QColor &newColor)
Definition: kblight.cpp:49
QStringList currentSelection
Definition: kblightwidget.h:44

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLightWidget::newSelection ( QStringList  selection)
privateslot

Definition at line 72 of file kblightwidget.cpp.

References Ui_KbLightWidget::animWidget, Ui_KbLightWidget::bgButton, ColorButton::color(), KbLight::colorMap(), currentSelection, KeyMap::isMouse(), light, KbLight::map(), Ui_KbLightWidget::selLabel, KbAnimWidget::setSelectedKeys(), and ui.

Referenced by KbLightWidget().

72  {
73  // Determine selected color (invalid color if no selection or if they're not all the same)
74  QColor selectedColor;
75  const QColorMap& colorMap = light->colorMap();
76  foreach(const QString& key, selection){
77  QColor color = colorMap.value(key);
78  if(!selectedColor.isValid())
79  selectedColor = color;
80  else if(color != selectedColor){
81  selectedColor = QColor();
82  break;
83  }
84  }
85 
86  currentSelection = selection;
87  ui->animWidget->setSelectedKeys(selection);
88  ui->bgButton->color(selectedColor);
89  int count = selection.count();
90  if(count == 0){
91  ui->selLabel->setText("Click to select");
92  return;
93  } else if(count == 1)
94  ui->selLabel->setText(tr("1 %1 selected").arg(light->map().isMouse() ? "zone" : "key"));
95  else
96  ui->selLabel->setText(tr("%1 %2 selected").arg(count).arg(light->map().isMouse() ? "zones" : "keys"));
97 }
const QColor & color() const
Definition: colorbutton.h:13
static bool isMouse(Model model)
Definition: keymap.h:111
const QColorMap & colorMap()
Definition: kblight.h:31
Definition: keymap.h:49
KbLight * light
Definition: kblightwidget.h:43
const KeyMap & map()
Definition: kblight.h:28
KbAnimWidget * animWidget
Ui::KbLightWidget * ui
Definition: kblightwidget.h:46
QHash< QString, QRgb > QColorMap
Definition: colormap.h:9
void setSelectedKeys(const QStringList &keys)
ColorButton * bgButton
QStringList currentSelection
Definition: kblightwidget.h:44

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLightWidget::on_animButton_clicked ( )
privateslot

Definition at line 143 of file kblightwidget.cpp.

References KbAnimWidget::addAnim(), Ui_KbLightWidget::animWidget, AnimAddDialog::chosenPreset(), AnimAddDialog::chosenScript(), AnimScript::count(), currentSelection, Ui_KbLightWidget::keyWidget, light, AnimScript::preset(), AnimScript::presets(), KbLight::restartAnimation(), KeyWidget::selectAll(), and ui.

143  {
144  if(AnimScript::count() == 0)
145  return;
146  if(currentSelection.isEmpty())
147  ui->keyWidget->selectAll();
148  AnimAddDialog dialog(this, light, currentSelection);
149  dialog.exec();
150  if(dialog.result() != QDialog::Accepted)
151  return;
152  const AnimScript* script = dialog.chosenScript();
153  int presetId = dialog.chosenPreset();
154  ui->animWidget->addAnim(script, currentSelection, script->presets()[presetId], script->preset(presetId));
156 }
static int count()
Definition: animscript.h:54
void selectAll()
Definition: keywidget.cpp:596
KeyWidget * keyWidget
const PresetValue & preset(int index) const
Definition: animscript.h:69
KbLight * light
Definition: kblightwidget.h:43
KbAnimWidget * animWidget
void addAnim(const AnimScript *base, const QStringList &keyList, const QString &name, const QMap< QString, QVariant > &preset)
Ui::KbLightWidget * ui
Definition: kblightwidget.h:46
const QStringList & presets() const
Definition: animscript.h:68
void restartAnimation()
Definition: kblight.cpp:179
QStringList currentSelection
Definition: kblightwidget.h:44

+ Here is the call graph for this function:

void KbLightWidget::on_bgButton_clicked ( )
privateslot

Definition at line 138 of file kblightwidget.cpp.

References currentSelection, Ui_KbLightWidget::keyWidget, KeyWidget::selectAll(), and ui.

138  {
139  if(currentSelection.isEmpty())
140  ui->keyWidget->selectAll();
141 }
void selectAll()
Definition: keywidget.cpp:596
KeyWidget * keyWidget
Ui::KbLightWidget * ui
Definition: kblightwidget.h:46
QStringList currentSelection
Definition: kblightwidget.h:44

+ Here is the call graph for this function:

void KbLightWidget::on_brightnessBox_activated ( int  index)
privateslot

Definition at line 133 of file kblightwidget.cpp.

References KbLight::dimming(), and light.

133  {
134  if(light)
135  light->dimming(index);
136 }
KbLight * light
Definition: kblightwidget.h:43
int dimming()
Definition: kblight.h:39

+ Here is the call graph for this function:

void KbLightWidget::on_showAnimBox_clicked ( bool  checked)
privateslot

Definition at line 52 of file kblightwidget.cpp.

References KeyWidget::displayColorMap(), Ui_KbLightWidget::keyWidget, light, CkbSettings::set(), and ui.

Referenced by setLight().

52  {
53  // FIXME: set globally if there's more than one KbLightWidget active
54  // Connect/disconnect animation slot
55  if(checked){
56  if(light)
57  connect(light, SIGNAL(frameDisplayed(const ColorMap&,const QSet<QString>&)), ui->keyWidget, SLOT(displayColorMap(const ColorMap&,const QSet<QString>&)));
58  } else {
59  if(light)
60  disconnect(light, SIGNAL(frameDisplayed(const ColorMap&,const QSet<QString>&)), ui->keyWidget, SLOT(displayColorMap(const ColorMap&,const QSet<QString>&)));
62  }
63  CkbSettings::set("UI/Light/ShowBaseOnly", !checked);
64 }
static void set(const QString &key, const QVariant &value)
KeyWidget * keyWidget
KbLight * light
Definition: kblightwidget.h:43
Ui::KbLightWidget * ui
Definition: kblightwidget.h:46
void displayColorMap(const ColorMap &newDisplayMap, const QSet< QString > &indicators=QSet< QString >())
Definition: keywidget.cpp:57

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLightWidget::setLight ( KbLight newLight)

Definition at line 28 of file kblightwidget.cpp.

References Ui_KbLightWidget::animWidget, KeyWidget::clearAnimation(), KbAnimWidget::clearSelection(), KeyWidget::clearSelection(), Ui_KbLightWidget::keyWidget, light, on_showAnimBox_clicked(), KeyWidget::setAnimation(), KbAnimWidget::setLight(), Ui_KbLightWidget::showAnimBox, ui, and updateLight().

Referenced by KbWidget::modeChanged().

28  {
32  if(light == newLight)
33  return;
34  if(light){
35  disconnect(light, SIGNAL(updated()), this, SLOT(updateLight()));
36  // Disabled animated colors for previous light
38  }
39  connect(newLight, SIGNAL(updated()), this, SLOT(updateLight()));
40  light = newLight;
41  updateLight();
42  ui->keyWidget->setAnimation(QStringList());
43  ui->animWidget->setLight(newLight);
44  if(ui->showAnimBox->isChecked())
46 }
void clearSelection()
Definition: keywidget.cpp:617
void clearAnimation()
Definition: keywidget.cpp:644
KeyWidget * keyWidget
void setLight(KbLight *newLight)
void on_showAnimBox_clicked(bool checked)
KbLight * light
Definition: kblightwidget.h:43
KbAnimWidget * animWidget
Ui::KbLightWidget * ui
Definition: kblightwidget.h:46
void clearSelection()
void setAnimation(const QStringList &keys)
Definition: keywidget.cpp:625
QCheckBox * showAnimBox

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLightWidget::setMonochrome ( )

Definition at line 48 of file kblightwidget.cpp.

References Ui_KbLightWidget::keyWidget, KeyWidget::monochrome(), and ui.

Referenced by KbWidget::KbWidget().

48  {
49  ui->keyWidget->monochrome(true);
50 }
KeyWidget * keyWidget
bool monochrome()
Definition: keywidget.h:20
Ui::KbLightWidget * ui
Definition: kblightwidget.h:46

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLightWidget::toggleSidelight ( )
privateslot

Definition at line 107 of file kblightwidget.cpp.

References KbLight::color(), KeyWidget::colorMap(), KbLight::colorMap(), Ui_KbLightWidget::keyWidget, light, and ui.

Referenced by KbLightWidget().

107  {
108  if(light){
109  if (light->colorMap()["lsidel"] == 0xFF000000){
110  light->color("lsidel",QRgb(0xFFFFFFFF));
111  light->color("rsidel",QRgb(0xFFFFFFFF));
112  } else {
113  light->color("lsidel", QRgb(0xFF000000));
114  light->color("rsidel", QRgb(0xFF000000));
115  }
117  }
118 }
KeyWidget * keyWidget
const QColorMap & colorMap()
Definition: kblight.h:31
KbLight * light
Definition: kblightwidget.h:43
const QColorMap & colorMap() const
Definition: keywidget.h:27
Ui::KbLightWidget * ui
Definition: kblightwidget.h:46
void color(const QString &key, const QColor &newColor)
Definition: kblight.cpp:49

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLightWidget::updateLight ( )
privateslot

Definition at line 66 of file kblightwidget.cpp.

References Ui_KbLightWidget::brightnessBox, KeyWidget::colorMap(), KbLight::colorMap(), KbLight::dimming(), Ui_KbLightWidget::keyWidget, light, KeyWidget::map(), KbLight::map(), and ui.

Referenced by setLight().

66  {
67  ui->keyWidget->map(light->map());
69  ui->brightnessBox->setCurrentIndex(light->dimming());
70 }
KeyWidget * keyWidget
const KeyMap & map() const
Definition: keywidget.h:24
const QColorMap & colorMap()
Definition: kblight.h:31
KbLight * light
Definition: kblightwidget.h:43
const QColorMap & colorMap() const
Definition: keywidget.h:27
const KeyMap & map()
Definition: kblight.h:28
Ui::KbLightWidget * ui
Definition: kblightwidget.h:46
int dimming()
Definition: kblight.h:39
QComboBox * brightnessBox

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

QStringList KbLightWidget::currentSelection
private

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