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.cpp
Go to the documentation of this file.
1 #include "animadddialog.h"
2 #include "ckbsettings.h"
3 #include "kblightwidget.h"
4 #include "ui_kblightwidget.h"
5 
7  QWidget(parent), light(0),
8  ui(new Ui::KbLightWidget)
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 }
23 
25  delete ui;
26 }
27 
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 }
47 
49  ui->keyWidget->monochrome(true);
50 }
51 
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 }
65 
67  ui->keyWidget->map(light->map());
69  ui->brightnessBox->setCurrentIndex(light->dimming());
70 }
71 
72 void KbLightWidget::newSelection(QStringList selection){
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 }
98 
99 void KbLightWidget::changeColor(QColor newColor){
100  if(light){
101  foreach(QString key, currentSelection)
102  light->color(key, newColor);
104  }
105 }
106 
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 }
119 
120 
122  if(newAnim)
123  ui->keyWidget->setSelection(newAnim->keys());
124  else
127 }
128 
129 void KbLightWidget::changeAnimKeys(QStringList keys){
130  ui->keyWidget->setAnimation(keys);
131 }
132 
134  if(light)
135  light->dimming(index);
136 }
137 
139  if(currentSelection.isEmpty())
140  ui->keyWidget->selectAll();
141 }
142 
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 }
void changeAnimKeys(QStringList keys)
void setupUi(QWidget *KbLightWidget)
static int count()
Definition: animscript.h:54
void clearSelection()
Definition: keywidget.cpp:617
void selectAll()
Definition: keywidget.cpp:596
void toggleSidelight()
static void set(const QString &key, const QVariant &value)
const QStringList & keys()
Definition: kbanim.h:40
void clearAnimation()
Definition: keywidget.cpp:644
void setMonochrome()
void on_brightnessBox_activated(int index)
const QColor & color() const
Definition: colorbutton.h:13
void on_animButton_clicked()
static bool isMouse(Model model)
Definition: keymap.h:111
KbLightWidget(QWidget *parent=0)
void setSelection(const QStringList &keys)
Definition: keywidget.cpp:582
KeyWidget * keyWidget
const KeyMap & map() const
Definition: keywidget.h:24
void changeAnim(KbAnim *newAnim)
const PresetValue & preset(int index) const
Definition: animscript.h:69
void setLight(KbLight *newLight)
static QVariant get(const QString &key, const QVariant &defaultValue=QVariant())
const QColorMap & colorMap()
Definition: kblight.h:31
void on_showAnimBox_clicked(bool checked)
Definition: keymap.h:49
void on_bgButton_clicked()
void newSelection(QStringList selection)
bool monochrome()
Definition: keywidget.h:20
KbLight * light
Definition: kblightwidget.h:43
const QColorMap & colorMap() const
Definition: keywidget.h:27
const KeyMap & map()
Definition: kblight.h:28
void setLight(KbLight *newLight)
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
void changeColor(QColor newColor)
const QStringList & presets() const
Definition: animscript.h:68
Definition: kbanim.h:11
void color(const QString &key, const QColor &newColor)
Definition: kblight.cpp:49
void setAnimationToSelection()
Definition: keywidget.cpp:639
QHash< QString, QRgb > QColorMap
Definition: colormap.h:9
void setSelectedKeys(const QStringList &keys)
ColorButton * bgButton
void restartAnimation()
Definition: kblight.cpp:179
const AnimScript * chosenScript()
void clearSelection()
int dimming()
Definition: kblight.h:39
void displayColorMap(const ColorMap &newDisplayMap, const QSet< QString > &indicators=QSet< QString >())
Definition: keywidget.cpp:57
QStringList currentSelection
Definition: kblightwidget.h:44
QPushButton * animButton
QComboBox * brightnessBox
void setAnimation(const QStringList &keys)
Definition: keywidget.cpp:625
QCheckBox * showAnimBox