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

#include <src/ckb/kblight.h>

+ Inheritance diagram for KbLight:
+ Collaboration diagram for KbLight:

Public Types

typedef QList< KbAnim * > AnimList
 

Signals

void didLoad ()
 
void updated ()
 
void frameDisplayed (const ColorMap &animatedColors, const QSet< QString > &indicatorList)
 

Public Member Functions

 KbLight (KbMode *parent, const KeyMap &keyMap)
 
 KbLight (KbMode *parent, const KeyMap &keyMap, const KbLight &other)
 
 ~KbLight ()
 
const KeyMapmap ()
 
void map (const KeyMap &map)
 
const QColorMapcolorMap ()
 
void color (const QString &key, const QColor &newColor)
 
void color (const QColor &newColor)
 
int dimming ()
 
void dimming (int newDimming)
 
KbAnimaddAnim (const AnimScript *base, const QStringList &keys, const QString &name, const QMap< QString, QVariant > &preset)
 
KbAnimduplicateAnim (KbAnim *oldAnim)
 
const AnimListanimList ()
 
void animList (const AnimList &newAnimList)
 
KbAnimfindAnim (const QUuid &guid) const
 
int findAnimIdx (const QUuid &guid) const
 
void previewAnim (const AnimScript *base, const QStringList &keys, const QMap< QString, QVariant > &preset)
 
void stopPreview ()
 
void restartAnimation ()
 
void animKeypress (const QString &key, bool down)
 
void open ()
 
bool isStarted ()
 
void close ()
 
void resetIndicators ()
 
void setIndicator (const char *name, QRgb argb)
 
void frameUpdate (QFile &cmd, bool monochrome=false)
 
void base (QFile &cmd, bool ignoreDim=false, bool monochrome=false)
 
void load (CkbSettings &settings)
 
void save (CkbSettings &settings)
 
bool needsSave () const
 

Static Public Member Functions

static int shareDimming ()
 
static void shareDimming (int newShareDimming)
 

Static Public Attributes

static const int MAX_DIM = 3
 

Private Member Functions

void rebuildBaseMap ()
 
void printRGB (QFile &cmd, const ColorMap &animMap)
 

Private Attributes

AnimList _animList
 
KbAnim_previewAnim
 
KeyMap _map
 
QColorMap _qColorMap
 
ColorMap _colorMap
 
ColorMap _animMap
 
ColorMap _lastFrameAnimMap
 
ColorMap _indicatorMap
 
ColorMap _lastFrameIndicatorMap
 
QSet< QString > _indicatorList
 
quint64 lastFrameSignal
 
int _dimming
 
int _lastFrameDimming
 
bool _start
 
bool _needsSave
 
bool _needsMapRefresh
 

Detailed Description

Definition at line 17 of file kblight.h.

Member Typedef Documentation

typedef QList<KbAnim*> KbLight::AnimList

Definition at line 46 of file kblight.h.

Constructor & Destructor Documentation

KbLight::KbLight ( KbMode parent,
const KeyMap keyMap 
)

Definition at line 10 of file kblight.cpp.

References map().

10  :
12 {
13  map(keyMap);
14 }
quint64 lastFrameSignal
Definition: kblight.h:95
const KeyMap & map()
Definition: kblight.h:28
bool _needsSave
Definition: kblight.h:98
bool _start
Definition: kblight.h:97
bool _needsMapRefresh
Definition: kblight.h:98
int _lastFrameDimming
Definition: kblight.h:96
KbAnim * _previewAnim
Definition: kblight.h:90
int _dimming
Definition: kblight.h:96

+ Here is the call graph for this function:

KbLight::KbLight ( KbMode parent,
const KeyMap keyMap,
const KbLight other 
)

Definition at line 16 of file kblight.cpp.

References _animList, and map().

16  :
18 {
19  map(keyMap);
20  // Duplicate animations
21  foreach(KbAnim* animation, other._animList)
22  _animList.append(new KbAnim(this, keyMap, *animation));
23 }
quint64 lastFrameSignal
Definition: kblight.h:95
KeyMap _map
Definition: kblight.h:91
AnimList _animList
Definition: kblight.h:89
const KeyMap & map()
Definition: kblight.h:28
QColorMap _qColorMap
Definition: kblight.h:92
Definition: kbanim.h:11
bool _needsSave
Definition: kblight.h:98
bool _start
Definition: kblight.h:97
bool _needsMapRefresh
Definition: kblight.h:98
int _lastFrameDimming
Definition: kblight.h:96
KbAnim * _previewAnim
Definition: kblight.h:90
int _dimming
Definition: kblight.h:96

+ Here is the call graph for this function:

KbLight::~KbLight ( )

Definition at line 45 of file kblight.cpp.

References activeLights.

45  {
46  activeLights.remove(this);
47 }
static QSet< KbLight * > activeLights
Definition: kblight.cpp:8

Member Function Documentation

KbAnim * KbLight::addAnim ( const AnimScript base,
const QStringList &  keys,
const QString &  name,
const QMap< QString, QVariant > &  preset 
)

Definition at line 100 of file kblight.cpp.

References _animList, _map, _needsSave, _start, anim, KbAnim::commitParams(), KbAnim::parameter(), KbAnim::stop(), stopPreview(), and KbAnim::trigger().

Referenced by KbAnimWidget::addAnim().

100  {
101  // Stop and restart all existing animations
102  stopPreview();
103  quint64 timestamp = QDateTime::currentMSecsSinceEpoch();
104  foreach(KbAnim* anim, _animList){
105  anim->stop();
106  anim->trigger(timestamp);
107  }
108  // Load the new animation and set preset parameters
109  KbAnim* anim = new KbAnim(this, _map, name, keys, base);
110  QMapIterator<QString, QVariant> i(preset);
111  while(i.hasNext()){
112  i.next();
113  anim->parameter(i.key(), i.value());
114  }
115  anim->commitParams();
116  // Add the animation and start it
117  _animList.append(anim);
118  anim->trigger(timestamp);
119  _start = true;
120  _needsSave = true;
121  return anim;
122 }
void stop()
Definition: kbanim.cpp:312
void stopPreview()
Definition: kblight.cpp:143
KeyMap _map
Definition: kblight.h:91
AnimList _animList
Definition: kblight.h:89
void trigger(quint64 timestamp, bool ignoreParameter=false)
Definition: kbanim.cpp:209
Definition: kbanim.h:11
bool _needsSave
Definition: kblight.h:98
bool _start
Definition: kblight.h:97
QVariant parameter(const QString &name) const
Definition: kbanim.h:45
struct keyAnim * anim
Definition: main.c:55
void commitParams()
Definition: kbanim.cpp:121

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLight::animKeypress ( const QString &  key,
bool  down 
)

Definition at line 189 of file kblight.cpp.

References _animList, _previewAnim, anim, KbAnim::keypress(), and KbAnim::keys().

Referenced by Kb::readNotify().

189  {
190  foreach(KbAnim* anim, _animList){
191  if(anim->keys().contains(key))
192  anim->keypress(key, down, QDateTime::currentMSecsSinceEpoch());
193  }
194  if(_previewAnim){
195  if(_previewAnim->keys().contains(key))
196  _previewAnim->keypress(key, down, QDateTime::currentMSecsSinceEpoch());
197  }
198 }
const QStringList & keys()
Definition: kbanim.h:40
AnimList _animList
Definition: kblight.h:89
Definition: keymap.h:49
Definition: kbanim.h:11
void keypress(const QString &key, bool pressed, quint64 timestamp)
Definition: kbanim.cpp:250
KbAnim * _previewAnim
Definition: kblight.h:90
struct keyAnim * anim
Definition: main.c:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const AnimList& KbLight::animList ( )
inline
void KbLight::animList ( const AnimList newAnimList)
inline

Definition at line 50 of file kblight.h.

References _animList, and _needsSave.

50 { _needsSave = true; _animList = newAnimList; }
AnimList _animList
Definition: kblight.h:89
bool _needsSave
Definition: kblight.h:98
void KbLight::base ( QFile &  cmd,
bool  ignoreDim = false,
bool  monochrome = false 
)

Definition at line 378 of file kblight.cpp.

References _animMap, _colorMap, _dimming, close(), ColorMap::colorForName(), ColorMap::colors(), ColorMap::count(), MAX_DIM, monoRgb(), printRGB(), and rebuildBaseMap().

Referenced by Kb::hwSave().

378  {
379  close();
380  if(_dimming == MAX_DIM && !ignoreDim){
381  cmd.write(QString().sprintf("rgb 000000").toLatin1());
382  return;
383  }
384  // Set just the background color, ignoring any animation
385  rebuildBaseMap();
387  // If monochrome is active, create grayscale
388  if(monochrome){
389  int count = _animMap.count();
390  QRgb* colors = _animMap.colors();
391  for(int i = 0; i < count; i++){
392  QRgb& rgb = colors[i];
393  rgb = monoRgb(qRed(rgb), qGreen(rgb), qBlue(rgb));
394  }
395  }
396  // Set a few indicators to black as the hardware handles them differently
397  QRgb* mr = _animMap.colorForName("mr"), *m1 = _animMap.colorForName("m1"), *m2 = _animMap.colorForName("m2"), *m3 = _animMap.colorForName("m3"), *lock = _animMap.colorForName("lock");
398  if(mr) *mr = 0;
399  if(m1) *m1 = 0;
400  if(m2) *m2 = 0;
401  if(m3) *m3 = 0;
402  if(lock) *lock = 0;
403  // Send to driver
404  cmd.write("rgb");
406 }
QRgb * colors()
Definition: colormap.h:33
cmd
Definition: command.h:7
void rebuildBaseMap()
Definition: kblight.cpp:238
static const int MAX_DIM
Definition: kblight.h:38
ColorMap _animMap
Definition: kblight.h:93
QRgb * colorForName(const char *name)
Definition: colormap.cpp:88
Definition: main.c:42
void close()
Definition: kblight.cpp:215
ColorMap _colorMap
Definition: kblight.h:93
void printRGB(QFile &cmd, const ColorMap &animMap)
Definition: kblight.cpp:223
int count() const
Definition: colormap.h:31
QRgb monoRgb(float r, float g, float b)
Definition: kblight.cpp:284
int _dimming
Definition: kblight.h:96

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLight::close ( )

Definition at line 215 of file kblight.cpp.

References _animList, _start, activeLights, anim, KbAnim::stop(), and stopPreview().

Referenced by base(), Kb::frameUpdate(), Kb::hwSave(), and Kb::updateLayout().

215  {
216  activeLights.remove(this);
217  foreach(KbAnim* anim, _animList)
218  anim->stop();
219  stopPreview();
220  _start = false;
221 }
void stop()
Definition: kbanim.cpp:312
void stopPreview()
Definition: kblight.cpp:143
AnimList _animList
Definition: kblight.h:89
Definition: kbanim.h:11
static QSet< KbLight * > activeLights
Definition: kblight.cpp:8
bool _start
Definition: kblight.h:97
struct keyAnim * anim
Definition: main.c:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLight::color ( const QString &  key,
const QColor &  newColor 
)

Definition at line 49 of file kblight.cpp.

References _colorMap, _needsMapRefresh, _needsSave, _qColorMap, and ColorMap::colorForName().

Referenced by KbLightWidget::changeColor(), load(), printRGB(), Kb::readNotify(), rebuildBaseMap(), and KbLightWidget::toggleSidelight().

49  {
50  QRgb newRgb = newColor.rgb();
51  _qColorMap[key] = newRgb;
52  _needsSave = true;
53  if(!_needsMapRefresh){
54  // Update flat map if we're not scheduled to rebuild it
55  QByteArray rawName = key.toLatin1();
56  QRgb* rawRgb = _colorMap.colorForName(rawName.data());
57  if(rawRgb)
58  *rawRgb = newRgb;
59  }
60 }
Definition: keymap.h:49
QRgb * colorForName(const char *name)
Definition: colormap.cpp:88
QColorMap _qColorMap
Definition: kblight.h:92
ColorMap _colorMap
Definition: kblight.h:93
bool _needsSave
Definition: kblight.h:98
bool _needsMapRefresh
Definition: kblight.h:98

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLight::color ( const QColor &  newColor)

Definition at line 62 of file kblight.cpp.

References _colorMap, _needsMapRefresh, _needsSave, _qColorMap, ColorMap::colors(), and ColorMap::count().

62  {
63  QRgb newRgb = newColor.rgb();
65  while(i.hasNext()){
66  i.next();
67  i.value() = newRgb;
68  }
69  _needsSave = true;
70  // Reset flat map
71  _needsMapRefresh = false;
72  int mapCount = _colorMap.count();
73  QRgb* flat = _colorMap.colors();
74  for(int i = 0; i < mapCount; i++)
75  flat[i] = mapCount;
76 }
QRgb * colors()
Definition: colormap.h:33
QColorMap _qColorMap
Definition: kblight.h:92
ColorMap _colorMap
Definition: kblight.h:93
bool _needsSave
Definition: kblight.h:98
bool _needsMapRefresh
Definition: kblight.h:98
QMutableHashIterator< QString, QRgb > QMutableColorMapIterator
Definition: colormap.h:11
int count() const
Definition: colormap.h:31

+ Here is the call graph for this function:

const QColorMap& KbLight::colorMap ( )
inline

Definition at line 31 of file kblight.h.

References _qColorMap.

Referenced by KbLightWidget::changeColor(), KbLightWidget::newSelection(), KbLightWidget::toggleSidelight(), and KbLightWidget::updateLight().

31 { return _qColorMap; }
QColorMap _qColorMap
Definition: kblight.h:92

+ Here is the caller graph for this function:

void KbLight::didLoad ( )
signal

Definition at line 162 of file moc_kblight.cpp.

Referenced by load().

163 {
164  QMetaObject::activate(this, &staticMetaObject, 0, Q_NULLPTR);
165 }

+ Here is the caller graph for this function:

int KbLight::dimming ( )
inline

Definition at line 39 of file kblight.h.

References _dimming.

Referenced by KeyAction::keyEvent(), KbLightWidget::on_brightnessBox_activated(), open(), shareDimming(), and KbLightWidget::updateLight().

39 { return _dimming; }
int _dimming
Definition: kblight.h:96

+ Here is the caller graph for this function:

void KbLight::dimming ( int  newDimming)

Definition at line 92 of file kblight.cpp.

References _dimming, _needsSave, _shareDimming, shareDimming(), and updated().

92  {
93  if(_shareDimming != -1)
94  shareDimming(newDimming);
95  _needsSave = true;
96  _dimming = newDimming;
97  emit updated();
98 }
static int _shareDimming
Definition: kblight.cpp:7
void updated()
static int shareDimming()
Definition: kblight.cpp:78
bool _needsSave
Definition: kblight.h:98
int _dimming
Definition: kblight.h:96

+ Here is the call graph for this function:

KbAnim * KbLight::duplicateAnim ( KbAnim oldAnim)

Definition at line 148 of file kblight.cpp.

References _animList, _map, _needsSave, _start, anim, KbAnim::newId(), KbAnim::stop(), and KbAnim::trigger().

Referenced by KbAnimWidget::duplicateAnim().

148  {
149  // Stop and restart all existing animations
150  quint64 timestamp = QDateTime::currentMSecsSinceEpoch();
151  foreach(KbAnim* anim, _animList){
152  anim->stop();
153  anim->trigger(timestamp);
154  }
155  // Same as addAnim, just duplicate the existing one
156  KbAnim* anim = new KbAnim(this, _map, *oldAnim);
157  anim->newId();
158  int index = _animList.indexOf(oldAnim);
159  if(index < 0)
160  _animList.append(anim);
161  else
162  _animList.insert(index + 1, anim);
163  anim->trigger(timestamp);
164  _start = true;
165  _needsSave = true;
166  return anim;
167 }
void stop()
Definition: kbanim.cpp:312
KeyMap _map
Definition: kblight.h:91
AnimList _animList
Definition: kblight.h:89
void trigger(quint64 timestamp, bool ignoreParameter=false)
Definition: kbanim.cpp:209
void newId()
Definition: kbanim.h:72
Definition: kbanim.h:11
bool _needsSave
Definition: kblight.h:98
bool _start
Definition: kblight.h:97
struct keyAnim * anim
Definition: main.c:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

KbAnim* KbLight::findAnim ( const QUuid &  guid) const
inline

Definition at line 51 of file kblight.h.

References _animList, anim, and KbAnim::guid().

Referenced by findAnimIdx(), and KeyAction::keyEvent().

51 { foreach(KbAnim* anim, _animList) { if(anim->guid() == guid) return anim; } return 0; }
AnimList _animList
Definition: kblight.h:89
Definition: kbanim.h:11
const QUuid & guid() const
Definition: kbanim.h:71
struct keyAnim * anim
Definition: main.c:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int KbLight::findAnimIdx ( const QUuid &  guid) const
inline

Definition at line 52 of file kblight.h.

References _animList, and findAnim().

Referenced by RebindWidget::setSelection().

52 { return _animList.indexOf(findAnim(guid)); }
AnimList _animList
Definition: kblight.h:89
KbAnim * findAnim(const QUuid &guid) const
Definition: kblight.h:51

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLight::frameDisplayed ( const ColorMap animatedColors,
const QSet< QString > &  indicatorList 
)
signal

Definition at line 174 of file moc_kblight.cpp.

Referenced by frameUpdate().

175 {
176  void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)), const_cast<void*>(reinterpret_cast<const void*>(&_t2)) };
177  QMetaObject::activate(this, &staticMetaObject, 2, _a);
178 }

+ Here is the caller graph for this function:

void KbLight::frameUpdate ( QFile &  cmd,
bool  monochrome = false 
)

Definition at line 296 of file kblight.cpp.

References _animList, _animMap, _colorMap, _dimming, _indicatorList, _indicatorMap, _lastFrameAnimMap, _lastFrameDimming, _lastFrameIndicatorMap, _previewAnim, anim, KbAnim::blend(), ColorMap::colors(), ColorMap::count(), frameDisplayed(), lastFrameSignal, lToS(), monoRgb(), printRGB(), rebuildBaseMap(), and sToL().

Referenced by Kb::frameUpdate().

296  {
297  rebuildBaseMap();
299  // Advance animations
300  quint64 timestamp = QDateTime::currentMSecsSinceEpoch();
301  foreach(KbAnim* anim, _animList)
302  anim->blend(_animMap, timestamp);
303  if(_previewAnim)
304  _previewAnim->blend(_animMap, timestamp);
305 
306  // Avoid expensive processing if nothing has changed from the last frame.
308  return;
312 
313  int count = _animMap.count();
314  QRgb* colors = _animMap.colors();
315  // Apply active indicators and/or perform monochrome conversion
316  if(monochrome || !_indicatorList.isEmpty()){
317  QRgb* indicators = _indicatorMap.colors();
318  for(int i = 0; i < count; i++){
319  QRgb& rgb = colors[i];
320  float r = qRed(rgb);
321  float g = qGreen(rgb);
322  float b = qBlue(rgb);
323  // Apply indicators
324  QRgb rgb2 = indicators[i];
325  if(qAlpha(rgb2) != 0){
326  float r2 = qRed(rgb2);
327  float g2 = qGreen(rgb2);
328  float b2 = qBlue(rgb2);
329  float a2 = qAlpha(rgb2) / 255.f;
330  r = round(r2 * a2 + r * (1.f - a2));
331  g = round(g2 * a2 + g * (1.f - a2));
332  b = round(b2 * a2 + b * (1.f - a2));
333  }
334  // If monochrome mode is active, average the channels to get a grayscale image
335  if(monochrome)
336  rgb = monoRgb(r, g, b);
337  else
338  rgb = qRgb(r, g, b);
339  }
340  }
341 
342  // Emit signals for the animation (only do this every 50ms - it can cause a lot of CPU usage)
343  if(timestamp >= lastFrameSignal + 50){
345  lastFrameSignal = timestamp;
346  }
347 
348  // If brightness is at 0%, turn off lighting entirely
349  if(_dimming == 3){
350  cmd.write("rgb 000000");
351  return;
352  }
353 
354  float light = (3 - _dimming) / 3.f;
355  // Apply global dimming
356  if(light != 1.f || monochrome){
357  for(int i = 0; i < count; i++){
358  QRgb& rgb = colors[i];
359  // Like the monochrome conversion, this should be done in a linear colorspace
360  float r = sToL(qRed(rgb));
361  float g = sToL(qGreen(rgb));
362  float b = sToL(qBlue(rgb));
363  r *= light;
364  g *= light;
365  b *= light;
366  r = round(lToS(r));
367  g = round(lToS(g));
368  b = round(lToS(b));
369  rgb = qRgb(r, g, b);
370  }
371  }
372 
373  // Apply light
374  cmd.write("rgb");
376 }
QRgb * colors()
Definition: colormap.h:33
QSet< QString > _indicatorList
Definition: kblight.h:94
static float sToL(float srgb)
Definition: kblight.cpp:270
void frameDisplayed(const ColorMap &animatedColors, const QSet< QString > &indicatorList)
quint64 lastFrameSignal
Definition: kblight.h:95
cmd
Definition: command.h:7
AnimList _animList
Definition: kblight.h:89
void rebuildBaseMap()
Definition: kblight.cpp:238
ColorMap _indicatorMap
Definition: kblight.h:93
static float lToS(float linear)
Definition: kblight.cpp:277
ColorMap _animMap
Definition: kblight.h:93
Definition: main.c:42
Definition: kbanim.h:11
ColorMap _lastFrameIndicatorMap
Definition: kblight.h:93
ColorMap _colorMap
Definition: kblight.h:93
ColorMap _lastFrameAnimMap
Definition: kblight.h:93
void printRGB(QFile &cmd, const ColorMap &animMap)
Definition: kblight.cpp:223
int _lastFrameDimming
Definition: kblight.h:96
int count() const
Definition: colormap.h:31
KbAnim * _previewAnim
Definition: kblight.h:90
QRgb monoRgb(float r, float g, float b)
Definition: kblight.cpp:284
void blend(ColorMap &animMap, quint64 timestamp)
Definition: kbanim.cpp:365
int _dimming
Definition: kblight.h:96
struct keyAnim * anim
Definition: main.c:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool KbLight::isStarted ( )

Definition at line 169 of file kblight.cpp.

References _animList, _start, and KbAnim::isRunning().

Referenced by Kb::frameUpdate().

169  {
170  if(!_start)
171  return false;
172  foreach(KbAnim* animation, _animList){
173  if(!animation->isRunning())
174  return false;
175  }
176  return true;
177 }
AnimList _animList
Definition: kblight.h:89
bool isRunning() const
Definition: kbanim.cpp:325
Definition: kbanim.h:11
bool _start
Definition: kblight.h:97

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLight::load ( CkbSettings settings)

Definition at line 408 of file kblight.cpp.

References _animList, _dimming, _map, _needsMapRefresh, _needsSave, _qColorMap, anim, CkbSettings::childKeys(), color(), didLoad(), KeyMap::fromName(), KeyMap::fromStorage(), map(), MAX_DIM, and CkbSettings::value().

Referenced by KbMode::KbMode().

408  {
409  // Load light settings
410  _needsSave = false;
411  SGroup group(settings, "Lighting");
412  KeyMap currentMap = _map;
413  _map = KeyMap::fromName(settings.value("KeyMap").toString());
414  _dimming = settings.value("Brightness").toUInt();
415  if(_dimming > MAX_DIM)
416  _dimming = MAX_DIM;
417  // Load RGB settings
418  bool useReal = settings.value("UseRealNames").toBool();
419  {
420  SGroup group(settings, "Keys");
421  foreach(QString key, settings.childKeys()){
422  QString name = key.toLower();
423  if(!useReal)
424  name = _map.fromStorage(name);
425  QColor color = settings.value(key).toString();
426  if(!color.isValid())
427  color = QColor(255, 255, 255);
428  _qColorMap[name] = color.rgb();
429  }
430  _needsMapRefresh = true;
431  }
432  // Load animations
433  foreach(KbAnim* anim, _animList)
434  anim->deleteLater();
435  _animList.clear();
436  {
437  SGroup group(settings, "Animations");
438  foreach(QString anim, settings.value("List").toStringList()){
439  QUuid id = anim;
440  _animList.append(new KbAnim(this, _map, id, settings));
441  }
442  }
443  emit didLoad();
444  map(currentMap);
445 }
KeyMap _map
Definition: kblight.h:91
QStringList childKeys() const
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
void didLoad()
AnimList _animList
Definition: kblight.h:89
QString fromStorage(const QString &storage)
Definition: keymap.h:151
Definition: keymap.h:49
static const int MAX_DIM
Definition: kblight.h:38
const KeyMap & map()
Definition: kblight.h:28
QColorMap _qColorMap
Definition: kblight.h:92
Definition: kbanim.h:11
void color(const QString &key, const QColor &newColor)
Definition: kblight.cpp:49
bool _needsSave
Definition: kblight.h:98
bool _needsMapRefresh
Definition: kblight.h:98
Definition: keymap.h:49
static KeyMap fromName(const QString &name)
Definition: keymap.cpp:835
int _dimming
Definition: kblight.h:96
struct keyAnim * anim
Definition: main.c:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const KeyMap& KbLight::map ( )
inline

Definition at line 28 of file kblight.h.

References _map.

Referenced by KbLight(), KbMode::keyMap(), load(), map(), KbLightWidget::newSelection(), KbAnimWidget::on_keyButton_clicked(), and KbLightWidget::updateLight().

28 { return _map; }
KeyMap _map
Definition: kblight.h:91

+ Here is the caller graph for this function:

void KbLight::map ( const KeyMap map)

Definition at line 25 of file kblight.cpp.

References _animList, _animMap, _colorMap, _indicatorMap, _map, _needsMapRefresh, _needsSave, _qColorMap, anim, ColorMap::init(), map(), KbAnim::map(), and updated().

25  {
26  // If any of the keys are missing from the color map, set them to white
27  QHashIterator<QString, Key> i(map);
28  while(i.hasNext()){
29  i.next();
30  const QString& key = i.key();
31  if(!_qColorMap.contains(key))
32  _qColorMap[key] = 0xFFFFFFFF;
33  }
34  // Set the new map
35  _map = map;
36  foreach(KbAnim* anim, _animList)
37  anim->map(map);
42  emit updated();
43 }
KeyMap _map
Definition: kblight.h:91
void init(const KeyMap &map)
Definition: colormap.cpp:69
AnimList _animList
Definition: kblight.h:89
ColorMap _indicatorMap
Definition: kblight.h:93
Definition: keymap.h:49
const KeyMap & map()
Definition: kbanim.h:37
void updated()
ColorMap _animMap
Definition: kblight.h:93
const KeyMap & map()
Definition: kblight.h:28
QColorMap _qColorMap
Definition: kblight.h:92
Definition: kbanim.h:11
ColorMap _colorMap
Definition: kblight.h:93
bool _needsSave
Definition: kblight.h:98
bool _needsMapRefresh
Definition: kblight.h:98
struct keyAnim * anim
Definition: main.c:55

+ Here is the call graph for this function:

bool KbLight::needsSave ( ) const

Definition at line 474 of file kblight.cpp.

References _animList, _needsSave, anim, and KbAnim::needsSave().

Referenced by KbMode::needsSave().

474  {
475  if(_needsSave)
476  return true;
477  foreach(KbAnim* anim, _animList){
478  if(anim->needsSave())
479  return true;
480  }
481  return false;
482 }
AnimList _animList
Definition: kblight.h:89
Definition: kbanim.h:11
bool needsSave() const
Definition: kbanim.h:29
bool _needsSave
Definition: kblight.h:98
struct keyAnim * anim
Definition: main.c:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLight::open ( )

Definition at line 200 of file kblight.cpp.

References _animList, _dimming, _previewAnim, _shareDimming, _start, activeLights, anim, dimming(), and KbAnim::trigger().

Referenced by Kb::frameUpdate().

200  {
201  // Apply shared dimming if needed
202  if(_shareDimming != -1 && _shareDimming != _dimming)
204  activeLights.insert(this);
205  if(_start)
206  return;
207  quint64 timestamp = QDateTime::currentMSecsSinceEpoch();
208  foreach(KbAnim* anim, _animList)
209  anim->trigger(timestamp);
210  if(_previewAnim)
211  _previewAnim->trigger(timestamp);
212  _start = true;
213 }
AnimList _animList
Definition: kblight.h:89
void trigger(quint64 timestamp, bool ignoreParameter=false)
Definition: kbanim.cpp:209
static int _shareDimming
Definition: kblight.cpp:7
Definition: kbanim.h:11
static QSet< KbLight * > activeLights
Definition: kblight.cpp:8
bool _start
Definition: kblight.h:97
int dimming()
Definition: kblight.h:39
KbAnim * _previewAnim
Definition: kblight.h:90
int _dimming
Definition: kblight.h:96
struct keyAnim * anim
Definition: main.c:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLight::previewAnim ( const AnimScript base,
const QStringList &  keys,
const QMap< QString, QVariant > &  preset 
)

Definition at line 124 of file kblight.cpp.

References _map, _previewAnim, _start, anim, KbAnim::commitParams(), KbAnim::parameter(), KbAnim::reInit(), stopPreview(), and KbAnim::trigger().

Referenced by AnimAddDialog::on_presetBox_activated().

124  {
125  if(_previewAnim)
126  stopPreview();
127  quint64 timestamp = QDateTime::currentMSecsSinceEpoch();
128  // Load the new animation and set preset parameters
129  KbAnim* anim = new KbAnim(this, _map, "", keys, base);
130  QMapIterator<QString, QVariant> i(preset);
131  while(i.hasNext()){
132  i.next();
133  anim->parameter(i.key(), i.value());
134  }
135  anim->commitParams();
136  anim->reInit();
137  // Add the animation and start it
138  _previewAnim = anim;
139  anim->trigger(timestamp);
140  _start = true;
141 }
void stopPreview()
Definition: kblight.cpp:143
KeyMap _map
Definition: kblight.h:91
void trigger(quint64 timestamp, bool ignoreParameter=false)
Definition: kbanim.cpp:209
Definition: kbanim.h:11
void reInit()
Definition: kbanim.cpp:149
bool _start
Definition: kblight.h:97
KbAnim * _previewAnim
Definition: kblight.h:90
QVariant parameter(const QString &name) const
Definition: kbanim.h:45
struct keyAnim * anim
Definition: main.c:55
void commitParams()
Definition: kbanim.cpp:121

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLight::printRGB ( QFile &  cmd,
const ColorMap animMap 
)
private

Definition at line 223 of file kblight.cpp.

References color(), ColorMap::colors(), ColorMap::count(), and ColorMap::keyNames().

Referenced by base(), and frameUpdate().

223  {
224  int count = animMap.count();
225  const char* const* names = animMap.keyNames();
226  const QRgb* colors = animMap.colors();
227  // Print each color and the corresponding RGB value
228  for(int i = 0; i < count; i++){
229  cmd.write(" ");
230  cmd.write(names[i]);
231  char output[8];
232  QRgb color = colors[i];
233  snprintf(output, sizeof(output), ":%02x%02x%02x", qRed(color), qGreen(color), qBlue(color));
234  cmd.write(output);
235  }
236 }
QRgb * colors()
Definition: colormap.h:33
cmd
Definition: command.h:7
void color(const QString &key, const QColor &newColor)
Definition: kblight.cpp:49
const char *const * keyNames() const
Definition: colormap.h:32
int count() const
Definition: colormap.h:31

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLight::rebuildBaseMap ( )
private

Definition at line 238 of file kblight.cpp.

References _colorMap, _needsMapRefresh, _qColorMap, color(), and ColorMap::colorForName().

Referenced by base(), and frameUpdate().

238  {
239  if(!_needsMapRefresh)
240  return;
241  _needsMapRefresh = false;
242  // Copy RGB values from QColorMap to ColorMap
244  while(i.hasNext()){
245  i.next();
246  QByteArray rawName = i.key().toLatin1();
247  QRgb color = i.value();
248  QRgb* rawColor = _colorMap.colorForName(rawName.data());
249  if(rawColor)
250  *rawColor = color;
251  }
252 }
QHashIterator< QString, QRgb > QColorMapIterator
Definition: colormap.h:10
QRgb * colorForName(const char *name)
Definition: colormap.cpp:88
QColorMap _qColorMap
Definition: kblight.h:92
void color(const QString &key, const QColor &newColor)
Definition: kblight.cpp:49
ColorMap _colorMap
Definition: kblight.h:93
bool _needsMapRefresh
Definition: kblight.h:98

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLight::resetIndicators ( )

Definition at line 254 of file kblight.cpp.

References _indicatorList, _indicatorMap, and ColorMap::clear().

Referenced by KbPerf::applyIndicators().

254  {
256  _indicatorList.clear();
257 }
QSet< QString > _indicatorList
Definition: kblight.h:94
ColorMap _indicatorMap
Definition: kblight.h:93
void clear()
Definition: colormap.cpp:61

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLight::restartAnimation ( )

Definition at line 179 of file kblight.cpp.

References _animList, _start, anim, KbAnim::stop(), stopPreview(), and KbAnim::trigger().

Referenced by KbLightWidget::on_animButton_clicked(), KbAnimWidget::on_deleteButton_clicked(), KbAnimWidget::on_keyButton_clicked(), and KbAnimWidget::on_propertyButton_clicked().

179  {
180  quint64 timestamp = QDateTime::currentMSecsSinceEpoch();
181  foreach(KbAnim* anim, _animList){
182  anim->stop();
183  anim->trigger(timestamp);
184  }
185  stopPreview();
186  _start = true;
187 }
void stop()
Definition: kbanim.cpp:312
void stopPreview()
Definition: kblight.cpp:143
AnimList _animList
Definition: kblight.h:89
void trigger(quint64 timestamp, bool ignoreParameter=false)
Definition: kbanim.cpp:209
Definition: kbanim.h:11
bool _start
Definition: kblight.h:97
struct keyAnim * anim
Definition: main.c:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLight::save ( CkbSettings settings)

Definition at line 447 of file kblight.cpp.

References _animList, _dimming, _map, _needsSave, _qColorMap, anim, KbAnim::guid(), KeyMap::name(), KbAnim::save(), and CkbSettings::setValue().

Referenced by KbMode::save().

447  {
448  _needsSave = false;
449  SGroup group(settings, "Lighting");
450  settings.setValue("KeyMap", _map.name());
451  settings.setValue("Brightness", _dimming);
452  settings.setValue("UseRealNames", true);
453  {
454  // Save RGB settings
455  SGroup group(settings, "Keys");
457  while(i.hasNext()){
458  i.next();
459  settings.setValue(i.key(), QColor(i.value()).name());
460  }
461  }
462  {
463  // Save animations
464  SGroup group(settings, "Animations");
465  QStringList aList;
466  foreach(KbAnim* anim, _animList){
467  aList << anim->guid().toString().toUpper();
468  anim->save(settings);
469  }
470  settings.setValue("List", aList);
471  }
472 }
void setValue(const QString &key, const QVariant &value)
KeyMap _map
Definition: kblight.h:91
AnimList _animList
Definition: kblight.h:89
void save(CkbSettings &settings)
Definition: kbanim.cpp:64
QColorMap _qColorMap
Definition: kblight.h:92
Definition: kbanim.h:11
const QUuid & guid() const
Definition: kbanim.h:71
bool _needsSave
Definition: kblight.h:98
QString name() const
Definition: keymap.h:131
QMutableHashIterator< QString, QRgb > QMutableColorMapIterator
Definition: colormap.h:11
int _dimming
Definition: kblight.h:96
struct keyAnim * anim
Definition: main.c:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KbLight::setIndicator ( const char *  name,
QRgb  argb 
)

Definition at line 259 of file kblight.cpp.

References _indicatorList, _indicatorMap, and ColorMap::colorForName().

Referenced by KbPerf::lightIndicator().

259  {
260  QRgb* dest = _indicatorMap.colorForName(name);
261  if(dest){
262  *dest = argb;
263  _indicatorList.insert(name);
264  }
265 }
QSet< QString > _indicatorList
Definition: kblight.h:94
ColorMap _indicatorMap
Definition: kblight.h:93
QRgb * colorForName(const char *name)
Definition: colormap.cpp:88

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int KbLight::shareDimming ( )
static

Definition at line 78 of file kblight.cpp.

References _shareDimming.

Referenced by dimming(), ExtraSettingsWidget::ExtraSettingsWidget(), ExtraSettingsWidget::on_brightnessBox_clicked(), and ExtraSettingsWidget::pollUpdates().

78  {
79  return _shareDimming;
80 }
static int _shareDimming
Definition: kblight.cpp:7

+ Here is the caller graph for this function:

void KbLight::shareDimming ( int  newShareDimming)
static

Definition at line 82 of file kblight.cpp.

References _shareDimming, activeLights, and dimming().

82  {
83  if(_shareDimming == newShareDimming)
84  return;
85  _shareDimming = newShareDimming;
86  if(newShareDimming != -1){
87  foreach(KbLight* light, activeLights)
88  light->dimming(newShareDimming);
89  }
90 }
static int _shareDimming
Definition: kblight.cpp:7
static QSet< KbLight * > activeLights
Definition: kblight.cpp:8
int dimming()
Definition: kblight.h:39

+ Here is the call graph for this function:

void KbLight::stopPreview ( )

Definition at line 143 of file kblight.cpp.

References _previewAnim.

Referenced by addAnim(), close(), AnimAddDialog::on_previewBox_clicked(), previewAnim(), restartAnimation(), and AnimAddDialog::~AnimAddDialog().

143  {
144  delete _previewAnim;
145  _previewAnim = 0;
146 }
KbAnim * _previewAnim
Definition: kblight.h:90

+ Here is the caller graph for this function:

void KbLight::updated ( )
signal

Definition at line 168 of file moc_kblight.cpp.

Referenced by dimming(), and map().

169 {
170  QMetaObject::activate(this, &staticMetaObject, 1, Q_NULLPTR);
171 }

+ Here is the caller graph for this function:

Field Documentation

ColorMap KbLight::_animMap
private

Definition at line 93 of file kblight.h.

Referenced by base(), frameUpdate(), and map().

ColorMap KbLight::_colorMap
private

Definition at line 93 of file kblight.h.

Referenced by base(), color(), frameUpdate(), map(), and rebuildBaseMap().

int KbLight::_dimming
private

Definition at line 96 of file kblight.h.

Referenced by base(), dimming(), frameUpdate(), load(), open(), and save().

QSet<QString> KbLight::_indicatorList
private

Definition at line 94 of file kblight.h.

Referenced by frameUpdate(), resetIndicators(), and setIndicator().

ColorMap KbLight::_indicatorMap
private

Definition at line 93 of file kblight.h.

Referenced by frameUpdate(), map(), resetIndicators(), and setIndicator().

ColorMap KbLight::_lastFrameAnimMap
private

Definition at line 93 of file kblight.h.

Referenced by frameUpdate().

int KbLight::_lastFrameDimming
private

Definition at line 96 of file kblight.h.

Referenced by frameUpdate().

ColorMap KbLight::_lastFrameIndicatorMap
private

Definition at line 93 of file kblight.h.

Referenced by frameUpdate().

KeyMap KbLight::_map
private

Definition at line 91 of file kblight.h.

Referenced by addAnim(), duplicateAnim(), load(), map(), previewAnim(), and save().

bool KbLight::_needsMapRefresh
private

Definition at line 98 of file kblight.h.

Referenced by color(), load(), map(), and rebuildBaseMap().

bool KbLight::_needsSave
private

Definition at line 98 of file kblight.h.

Referenced by addAnim(), animList(), color(), dimming(), duplicateAnim(), load(), map(), needsSave(), and save().

KbAnim* KbLight::_previewAnim
private

Definition at line 90 of file kblight.h.

Referenced by animKeypress(), frameUpdate(), open(), previewAnim(), and stopPreview().

QColorMap KbLight::_qColorMap
private

Definition at line 92 of file kblight.h.

Referenced by color(), colorMap(), load(), map(), rebuildBaseMap(), and save().

bool KbLight::_start
private

Definition at line 97 of file kblight.h.

Referenced by addAnim(), close(), duplicateAnim(), isStarted(), open(), previewAnim(), and restartAnimation().

quint64 KbLight::lastFrameSignal
private

Definition at line 95 of file kblight.h.

Referenced by frameUpdate().

const int KbLight::MAX_DIM = 3
static

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