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

#include <src/ckb/kbanimwidget.h>

+ Inheritance diagram for KbAnimWidget:
+ Collaboration diagram for KbAnimWidget:

Signals

void animChanged (KbAnim *selection)
 
void didUpdateSelection (QStringList keys)
 

Public Member Functions

 KbAnimWidget (QWidget *parent=0)
 
 ~KbAnimWidget ()
 
void setLight (KbLight *newLight)
 
void addAnim (const AnimScript *base, const QStringList &keyList, const QString &name, const QMap< QString, QVariant > &preset)
 
void duplicateAnim (KbAnim *old)
 
void clearSelection ()
 
void setSelectedKeys (const QStringList &keys)
 

Private Slots

void on_animList_currentItemChanged (QListWidgetItem *current, QListWidgetItem *previous)
 
void on_animList_itemChanged (QListWidgetItem *item)
 
void on_animList_customContextMenuRequested (const QPoint &pos)
 
void on_nameBox_textEdited (const QString &arg1)
 
void on_opacityBox_valueChanged (double arg1)
 
void on_blendBox_activated (int index)
 
void on_keyButton_clicked ()
 
void on_deleteButton_clicked ()
 
void refreshList ()
 
void reorderAnims ()
 
void on_propertyButton_clicked ()
 

Private Member Functions

void setCurrent (KbAnim *newCurrent)
 

Private Attributes

KbLightlight
 
QHash< QUuid, KbAnim * > animations
 
KbAnimcurrent
 
QStringList selectedKeys
 
bool noReorder
 
Ui::KbAnimWidgetui
 

Detailed Description

Definition at line 15 of file kbanimwidget.h.

Constructor & Destructor Documentation

KbAnimWidget::KbAnimWidget ( QWidget parent = 0)
explicit

Definition at line 7 of file kbanimwidget.cpp.

References Ui_KbAnimWidget::animList, reorderAnims(), setCurrent(), Ui_KbAnimWidget::setupUi(), and ui.

7  :
8  QWidget(parent), light(0), current(0), noReorder(false),
10 {
11  ui->setupUi(this);
12  ui->animList->setVisible(false);
13  setCurrent(0);
14  connect(ui->animList, SIGNAL(orderChanged()), this, SLOT(reorderAnims()));
15 }
void setCurrent(KbAnim *newCurrent)
KbLight * light
Definition: kbanimwidget.h:52
void reorderAnims()
RListWidget * animList
KbAnim * current
Definition: kbanimwidget.h:55
void setupUi(QWidget *KbAnimWidget)
Ui::KbAnimWidget * ui
Definition: kbanimwidget.h:60

+ Here is the call graph for this function:

KbAnimWidget::~KbAnimWidget ( )

Definition at line 17 of file kbanimwidget.cpp.

References ui.

17  {
18  delete ui;
19 }
Ui::KbAnimWidget * ui
Definition: kbanimwidget.h:60

Member Function Documentation

void KbAnimWidget::addAnim ( const AnimScript base,
const QStringList &  keyList,
const QString &  name,
const QMap< QString, QVariant > &  preset 
)

Definition at line 82 of file kbanimwidget.cpp.

References KbLight::addAnim(), animations, Ui_KbAnimWidget::animList, KbAnim::guid(), light, KbAnim::name(), Ui_KbAnimWidget::noAnimLabel, noReorder, on_propertyButton_clicked(), setCurrent(), and ui.

Referenced by KbLightWidget::on_animButton_clicked().

82  {
83  if(!light)
84  return;
85  noReorder = true;
86  KbAnim* animation = light->addAnim(base, keyList, name, preset);
87  QListWidgetItem* item = new QListWidgetItem(animation->name(), ui->animList);
88  item->setData(Qt::UserRole, animation->guid());
89  item->setFlags(item->flags() | Qt::ItemIsEditable);
90  animations[animation->guid()] = animation;
91  ui->animList->addItem(item);
92  ui->animList->setCurrentItem(item);
93  ui->animList->setVisible(true);
94  ui->noAnimLabel->setVisible(false);
95 
96  setCurrent(animation);
97  noReorder = false;
98 
99  // Activate settings dialog
101 }
void on_propertyButton_clicked()
void setCurrent(KbAnim *newCurrent)
KbLight * light
Definition: kbanimwidget.h:52
KbAnim * addAnim(const AnimScript *base, const QStringList &keys, const QString &name, const QMap< QString, QVariant > &preset)
Definition: kblight.cpp:100
QLabel * noAnimLabel
const QString & name() const
Definition: kbanim.h:73
RListWidget * animList
Definition: kbanim.h:11
const QUuid & guid() const
Definition: kbanim.h:71
QHash< QUuid, KbAnim * > animations
Definition: kbanimwidget.h:53
Ui::KbAnimWidget * ui
Definition: kbanimwidget.h:60

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbAnimWidget::animChanged ( KbAnim selection)
signal

Definition at line 213 of file moc_kbanimwidget.cpp.

Referenced by setCurrent().

214 {
215  void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
216  QMetaObject::activate(this, &staticMetaObject, 0, _a);
217 }

+ Here is the caller graph for this function:

void KbAnimWidget::clearSelection ( )

Definition at line 77 of file kbanimwidget.cpp.

References Ui_KbAnimWidget::animList, setCurrent(), and ui.

Referenced by KbLightWidget::setLight().

77  {
78  ui->animList->setCurrentItem(0);
79  setCurrent(0);
80 }
void setCurrent(KbAnim *newCurrent)
RListWidget * animList
Ui::KbAnimWidget * ui
Definition: kbanimwidget.h:60

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbAnimWidget::didUpdateSelection ( QStringList  keys)
signal

Definition at line 220 of file moc_kbanimwidget.cpp.

Referenced by on_keyButton_clicked().

221 {
222  void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
223  QMetaObject::activate(this, &staticMetaObject, 1, _a);
224 }

+ Here is the caller graph for this function:

void KbAnimWidget::duplicateAnim ( KbAnim old)

Definition at line 103 of file kbanimwidget.cpp.

References KbLight::animList(), Ui_KbAnimWidget::animList, KbLight::duplicateAnim(), light, Ui_KbAnimWidget::noAnimLabel, noReorder, refreshList(), setCurrent(), and ui.

Referenced by on_animList_customContextMenuRequested().

103  {
104  if(!light)
105  return;
106  noReorder = true;
107  KbAnim* animation = light->duplicateAnim(old);
108  // Refresh the list. insertItem doesn't seem to place the item in the correct position on its own...
109  refreshList();
110  ui->animList->setCurrentRow(light->animList().indexOf(animation));
111  ui->animList->setVisible(true);
112  ui->noAnimLabel->setVisible(false);
113 
114  setCurrent(animation);
115  noReorder = false;
116 }
KbAnim * duplicateAnim(KbAnim *oldAnim)
Definition: kblight.cpp:148
void setCurrent(KbAnim *newCurrent)
const AnimList & animList()
Definition: kblight.h:49
KbLight * light
Definition: kbanimwidget.h:52
QLabel * noAnimLabel
RListWidget * animList
void refreshList()
Definition: kbanim.h:11
Ui::KbAnimWidget * ui
Definition: kbanimwidget.h:60

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbAnimWidget::on_animList_currentItemChanged ( QListWidgetItem *  current,
QListWidgetItem *  previous 
)
privateslot

Definition at line 151 of file kbanimwidget.cpp.

References animations, and setCurrent().

151  {
152  if(!current)
153  setCurrent(0);
154  else
155  setCurrent(animations[current->data(Qt::UserRole).toUuid()]);
156 }
void setCurrent(KbAnim *newCurrent)
KbAnim * current
Definition: kbanimwidget.h:55
QHash< QUuid, KbAnim * > animations
Definition: kbanimwidget.h:53

+ Here is the call graph for this function:

void KbAnimWidget::on_animList_customContextMenuRequested ( const QPoint &  pos)
privateslot

Definition at line 169 of file kbanimwidget.cpp.

References animations, Ui_KbAnimWidget::animList, current, duplicateAnim(), on_deleteButton_clicked(), setCurrent(), and ui.

169  {
170  QListWidgetItem* item = ui->animList->itemAt(pos);
171  if(!item)
172  return;
173  setCurrent(animations[item->data(Qt::UserRole).toUuid()]);
174 
175  QMenu menu(this);
176  QAction* rename = new QAction("Rename...", this);
177  QAction* duplicate = new QAction("Duplicate", this);
178  QAction* del = new QAction("Delete", this);
179  menu.addAction(rename);
180  menu.addAction(duplicate);
181  menu.addAction(del);
182  QAction* result = menu.exec(QCursor::pos());
183  if(result == rename)
184  ui->animList->editItem(item);
185  else if(result == duplicate)
187  else if(result == del)
189 }
void setCurrent(KbAnim *newCurrent)
void on_deleteButton_clicked()
RListWidget * animList
KbAnim * current
Definition: kbanimwidget.h:55
void duplicateAnim(KbAnim *old)
QHash< QUuid, KbAnim * > animations
Definition: kbanimwidget.h:53
Ui::KbAnimWidget * ui
Definition: kbanimwidget.h:60

+ Here is the call graph for this function:

void KbAnimWidget::on_animList_itemChanged ( QListWidgetItem *  item)
privateslot

Definition at line 158 of file kbanimwidget.cpp.

References anim, animations, current, KbAnim::name(), Ui_KbAnimWidget::nameBox, noReorder, and ui.

158  {
159  if(item){
160  KbAnim* anim = animations[item->data(Qt::UserRole).toUuid()];
161  if(anim){
162  anim->name(item->text().trimmed());
163  if(anim == current && !noReorder)
164  ui->nameBox->setText(anim->name());
165  }
166  }
167 }
QLineEdit * nameBox
const QString & name() const
Definition: kbanim.h:73
KbAnim * current
Definition: kbanimwidget.h:55
Definition: kbanim.h:11
QHash< QUuid, KbAnim * > animations
Definition: kbanimwidget.h:53
Ui::KbAnimWidget * ui
Definition: kbanimwidget.h:60
struct keyAnim * anim
Definition: main.c:55

+ Here is the call graph for this function:

void KbAnimWidget::on_blendBox_activated ( int  index)
privateslot

Definition at line 205 of file kbanimwidget.cpp.

References current, and KbAnim::mode().

205  {
206  if(current)
207  current->mode((KbAnim::Mode)index);
208 }
Mode mode() const
Definition: kbanim.h:77
KbAnim * current
Definition: kbanimwidget.h:55
Mode
Definition: kbanim.h:17

+ Here is the call graph for this function:

void KbAnimWidget::on_deleteButton_clicked ( )
privateslot

Definition at line 226 of file kbanimwidget.cpp.

References animations, KbLight::animList(), Ui_KbAnimWidget::animList, current, KbAnim::guid(), light, Ui_KbAnimWidget::noAnimLabel, KbLight::restartAnimation(), setCurrent(), and ui.

Referenced by on_animList_customContextMenuRequested().

226  {
227  if(current){
228  animations.remove(current->guid());
229  QList<KbAnim*> animList = light->animList();
230  animList.removeAll(current);
231  light->animList(animList);
232  current->deleteLater();
233  setCurrent(0);
234  delete ui->animList->currentItem();
235  if(animations.count() == 0){
236  ui->animList->setVisible(false);
237  ui->noAnimLabel->setVisible(true);
238  }
239  }
241 }
void setCurrent(KbAnim *newCurrent)
const AnimList & animList()
Definition: kblight.h:49
KbLight * light
Definition: kbanimwidget.h:52
QLabel * noAnimLabel
RListWidget * animList
KbAnim * current
Definition: kbanimwidget.h:55
const QUuid & guid() const
Definition: kbanim.h:71
void restartAnimation()
Definition: kblight.cpp:179
QHash< QUuid, KbAnim * > animations
Definition: kbanimwidget.h:53
Ui::KbAnimWidget * ui
Definition: kbanimwidget.h:60

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbAnimWidget::on_keyButton_clicked ( )
privateslot

Definition at line 210 of file kbanimwidget.cpp.

References KeyMap::contains(), current, didUpdateSelection(), KbAnim::keys(), light, KbLight::map(), KbLight::restartAnimation(), and selectedKeys.

210  {
211  if(current){
212  QStringList keys = selectedKeys;
213  // If any keys were selected previously that aren't in the keymap now, leave them in
214  // This is important for layout compatibility - e.g. being able to select both bslash_iso and bslash, because no single layout contains both
215  const KeyMap& map = light->map();
216  foreach(const QString& key, current->keys()){
217  if(!map.contains(key))
218  keys << key;
219  }
220  current->keys(keys);
222  }
224 }
const QStringList & keys()
Definition: kbanim.h:40
KbLight * light
Definition: kbanimwidget.h:52
bool contains(const QString &name) const
Definition: keymap.h:143
Definition: keymap.h:49
const KeyMap & map()
Definition: kblight.h:28
QStringList selectedKeys
Definition: kbanimwidget.h:57
KbAnim * current
Definition: kbanimwidget.h:55
Definition: keymap.h:49
void restartAnimation()
Definition: kblight.cpp:179
void didUpdateSelection(QStringList keys)

+ Here is the call graph for this function:

void KbAnimWidget::on_nameBox_textEdited ( const QString &  arg1)
privateslot

Definition at line 191 of file kbanimwidget.cpp.

References Ui_KbAnimWidget::animList, current, KbAnim::name(), noReorder, and ui.

Referenced by on_propertyButton_clicked().

191  {
192  if(current){
193  noReorder = true;
194  current->name(arg1.trimmed());
195  ui->animList->currentItem()->setText(current->name());
196  noReorder = false;
197  }
198 }
const QString & name() const
Definition: kbanim.h:73
RListWidget * animList
KbAnim * current
Definition: kbanimwidget.h:55
Ui::KbAnimWidget * ui
Definition: kbanimwidget.h:60

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbAnimWidget::on_opacityBox_valueChanged ( double  arg1)
privateslot

Definition at line 200 of file kbanimwidget.cpp.

References current, and KbAnim::opacity().

200  {
201  if(current)
202  current->opacity(arg1 / 100.);
203 }
KbAnim * current
Definition: kbanimwidget.h:55
float opacity() const
Definition: kbanim.h:75

+ Here is the call graph for this function:

void KbAnimWidget::on_propertyButton_clicked ( )
privateslot

Definition at line 243 of file kbanimwidget.cpp.

References KbAnim::commitParams(), current, light, AnimSettingDialog::name(), Ui_KbAnimWidget::nameBox, on_nameBox_textEdited(), KbAnim::reInit(), KbAnim::resetParams(), KbLight::restartAnimation(), and ui.

Referenced by addAnim().

243  {
244  if(!current)
245  return;
246  // Present animation property popup
247  AnimSettingDialog dialog(this, current);
248  dialog.exec();
249  if(dialog.result() != QDialog::Accepted){
250  current->resetParams();
251  return;
252  }
253  // Apply settings and restart all animations
255  current->reInit();
257  // Update name
258  ui->nameBox->setText(dialog.name());
259  on_nameBox_textEdited(dialog.name());
260 }
void on_nameBox_textEdited(const QString &arg1)
QLineEdit * nameBox
KbLight * light
Definition: kbanimwidget.h:52
KbAnim * current
Definition: kbanimwidget.h:55
void reInit()
Definition: kbanim.cpp:149
void restartAnimation()
Definition: kblight.cpp:179
void resetParams()
Definition: kbanim.cpp:127
Ui::KbAnimWidget * ui
Definition: kbanimwidget.h:60
void commitParams()
Definition: kbanim.cpp:121

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbAnimWidget::refreshList ( )
privateslot

Definition at line 32 of file kbanimwidget.cpp.

References anim, animations, KbLight::animList(), Ui_KbAnimWidget::animList, KbAnim::guid(), light, KbAnim::name(), Ui_KbAnimWidget::noAnimLabel, noReorder, setCurrent(), and ui.

Referenced by duplicateAnim(), and setLight().

32  {
33  noReorder = true;
34  setCurrent(0);
35  ui->animList->clear();
36  animations.clear();
37  // Add the animations from the new lighting mode
38  if(!light){
39  ui->animList->setVisible(false);
40  ui->noAnimLabel->setVisible(true);
41  return;
42  }
43  QList<KbAnim*> newAnimations = light->animList();
44  if(newAnimations.count() == 0){
45  ui->animList->setVisible(false);
46  ui->noAnimLabel->setVisible(true);
47  return;
48  }
49  ui->animList->setVisible(true);
50  foreach(KbAnim* anim, newAnimations){
51  QListWidgetItem* item = new QListWidgetItem(anim->name(), ui->animList);
52  item->setData(Qt::UserRole, anim->guid());
53  item->setFlags(item->flags() | Qt::ItemIsEditable);
54  animations[anim->guid()] = anim;
55  ui->animList->addItem(item);
56  }
57  ui->noAnimLabel->setVisible(false);
58  noReorder = false;
59 }
void setCurrent(KbAnim *newCurrent)
const AnimList & animList()
Definition: kblight.h:49
KbLight * light
Definition: kbanimwidget.h:52
QLabel * noAnimLabel
const QString & name() const
Definition: kbanim.h:73
RListWidget * animList
Definition: kbanim.h:11
const QUuid & guid() const
Definition: kbanim.h:71
QHash< QUuid, KbAnim * > animations
Definition: kbanimwidget.h:53
Ui::KbAnimWidget * ui
Definition: kbanimwidget.h:60
struct keyAnim * anim
Definition: main.c:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbAnimWidget::reorderAnims ( )
privateslot

Definition at line 61 of file kbanimwidget.cpp.

References anim, animations, KbLight::animList(), Ui_KbAnimWidget::animList, light, noReorder, and ui.

Referenced by KbAnimWidget().

61  {
62  if(light && !noReorder){
63  // Clear and rebuild the list of animations in case the animation moved
64  int count = ui->animList->count();
65  QList<KbAnim*> animList;
66  for(int i = 0; i < count; i++){
67  QListWidgetItem* item = ui->animList->item(i);
68  KbAnim* anim = animations[item->data(Qt::UserRole).toUuid()];
69  if(anim && !animList.contains(anim))
70  animList.append(anim);
71  item->setFlags(item->flags() | Qt::ItemIsEditable);
72  }
73  light->animList(animList);
74  }
75 }
const AnimList & animList()
Definition: kblight.h:49
KbLight * light
Definition: kbanimwidget.h:52
RListWidget * animList
Definition: kbanim.h:11
QHash< QUuid, KbAnim * > animations
Definition: kbanimwidget.h:53
Ui::KbAnimWidget * ui
Definition: kbanimwidget.h:60
struct keyAnim * anim
Definition: main.c:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbAnimWidget::setCurrent ( KbAnim newCurrent)
private

Definition at line 118 of file kbanimwidget.cpp.

References Ui_KbAnimWidget::aCopyLabel, Ui_KbAnimWidget::aMissingLabel, Ui_KbAnimWidget::aNameLabel, animChanged(), Ui_KbAnimWidget::aVerLabel, Ui_KbAnimWidget::blendBox, AnimScript::copyright(), current, KbAnim::keys(), KbAnim::mode(), AnimScript::name(), KbAnim::name(), Ui_KbAnimWidget::nameBox, KbAnim::opacity(), Ui_KbAnimWidget::opacityBox, KbAnim::script(), KbAnim::scriptName(), selectedKeys, Ui_KbAnimWidget::selectionStack, ui, and AnimScript::version().

Referenced by addAnim(), clearSelection(), duplicateAnim(), KbAnimWidget(), on_animList_currentItemChanged(), on_animList_customContextMenuRequested(), on_deleteButton_clicked(), and refreshList().

118  {
119  if(newCurrent != current)
120  emit animChanged(current = newCurrent);
121  if(!current){
122  selectedKeys.clear();
123  ui->selectionStack->setCurrentIndex(0);
124  return;
125  }
127  const AnimScript* script = current->script();
128  if(!script){
129  ui->selectionStack->setCurrentIndex(2);
130  ui->aMissingLabel->setText("The \"" + current->scriptName() + "\" script could not be loaded. Please check your animation directory.");
131  return;
132  }
133  ui->selectionStack->setCurrentIndex(1);
134  ui->aNameLabel->setText(script->name());
135  ui->aVerLabel->setText("v" + script->version());
136  ui->aCopyLabel->setText(script->copyright());
137 
138  ui->nameBox->setText(current->name());
139  ui->opacityBox->setValue(current->opacity() * 100.);
140  ui->blendBox->setCurrentIndex((int)current->mode());
141 }
QLabel * aMissingLabel
const QStringList & keys()
Definition: kbanim.h:40
QLineEdit * nameBox
Mode mode() const
Definition: kbanim.h:77
QStackedWidget * selectionStack
const QString & name() const
Definition: kbanim.h:73
QComboBox * blendBox
const QString & scriptName() const
Definition: kbanim.h:82
QString copyright() const
Definition: animscript.h:62
QStringList selectedKeys
Definition: kbanimwidget.h:57
KbAnim * current
Definition: kbanimwidget.h:55
const QString & name() const
Definition: animscript.h:60
void animChanged(KbAnim *selection)
float opacity() const
Definition: kbanim.h:75
const QString & version() const
Definition: animscript.h:61
const AnimScript * script() const
Definition: kbanim.h:81
Ui::KbAnimWidget * ui
Definition: kbanimwidget.h:60
QDoubleSpinBox * opacityBox

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbAnimWidget::setLight ( KbLight newLight)

Definition at line 21 of file kbanimwidget.cpp.

References light, and refreshList().

Referenced by KbLightWidget::setLight().

21  {
22  if(light != newLight){
23  if(light)
24  disconnect(light, SIGNAL(didLoad()), this, SLOT(refreshList()));
25  if(newLight)
26  connect(newLight, SIGNAL(didLoad()), this, SLOT(refreshList()));
27  light = newLight;
28  }
29  refreshList();
30 }
KbLight * light
Definition: kbanimwidget.h:52
void refreshList()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbAnimWidget::setSelectedKeys ( const QStringList &  keys)

Definition at line 143 of file kbanimwidget.cpp.

References Ui_KbAnimWidget::keyButton, selectedKeys, and ui.

Referenced by KbLightWidget::newSelection().

143  {
144  selectedKeys = keys;
145  if(keys.count() == 0)
146  ui->keyButton->setVisible(false);
147  else
148  ui->keyButton->setVisible(true);
149 }
QStringList selectedKeys
Definition: kbanimwidget.h:57
QPushButton * keyButton
Ui::KbAnimWidget * ui
Definition: kbanimwidget.h:60

+ Here is the caller graph for this function:

Field Documentation

bool KbAnimWidget::noReorder
private
QStringList KbAnimWidget::selectedKeys
private

Definition at line 57 of file kbanimwidget.h.

Referenced by on_keyButton_clicked(), setCurrent(), and setSelectedKeys().


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