void KbMode::save(CkbSettings& settings){ _needsSave = false; _id.newModified(); settings.setValue("GUID", _id.guidString()); settings.setValue("Modified", _id.modifiedString()); settings.setValue("HwModified", _id.hwModifiedString()); settings.setValue("Name", _name); _light->save(settings); _bind->save(settings); _perf->save(settings); }
KbAnim::KbAnim(QObject *parent, const KeyMap& map, const QUuid id, CkbSettings& settings) : QObject(parent), _script(0), _map(map), repeatTime(0), kpRepeatTime(0), stopTime(0), kpStopTime(0), repeatMsec(0), kpRepeatMsec(0), _guid(id), _needsSave(false) { SGroup group(settings, _guid.toString().toUpper()); _keys = settings.value("Keys").toStringList(); // Convert key list from storage names if needed if(!settings.value("UseRealNames").toBool()){ QMutableListIterator<QString> i(_keys); while(i.hasNext()){ i.next(); QString& key = i.value(); key = _map.fromStorage(key); } } _name = settings.value("Name").toString().trimmed(); _opacity = settings.value("Opacity").toString().toDouble(); if(_opacity < 0.) _opacity = 0.; else if(_opacity > 1.) _opacity = 1.; bool modeOk = false; _mode = (Mode)metaObject()->enumerator(metaObject()->indexOfEnumerator("Mode")).keysToValue(settings.value("BlendMode").toString().toLatin1(), &modeOk); if(!modeOk) _mode = Normal; _scriptName = settings.value("ScriptName").toString().trimmed(); _scriptGuid = settings.value("ScriptGuid").toString(); { SGroup group(settings, "Parameters"); foreach(const QString& param, settings.childKeys()) _parameters[param.toLower()] = settings.value(param); } if(!_scriptGuid.isNull()){ _script = AnimScript::copy(this, _scriptGuid); if(_script){ // Remove nonexistant parameters foreach(const QString& name, _parameters.keys()){ AnimScript::Param param = _script->param(name); if(param.type == AnimScript::Param::INVALID || param.type == AnimScript::Param::LABEL) _parameters.remove(name); } // Add defaults for unset parameters QListIterator<AnimScript::Param> i = _script->paramIterator(); while(i.hasNext()){ AnimScript::Param param = i.next(); if(!_parameters.contains(param.name) && param.type != AnimScript::Param::LABEL) _parameters[param.name] = param.defaultValue; } _scriptName = _script->name(); reInit(); } }
KbMode::KbMode(Kb* parent, const KeyMap& keyMap, CkbSettings& settings) : QObject(parent), _name(settings.value("Name").toString().trimmed()), _id(settings.value("GUID").toString().trimmed(), settings.value("Modified").toString().trimmed()), _light(new KbLight(this, keyMap)), _bind(new KbBind(this, parent, keyMap)), _perf(new KbPerf(this)), _needsSave(false) { if(settings.contains("HwModified")) _id.hwModifiedString(settings.value("HwModified").toString()); else _id.hwModified = _id.modified; connect(_light, SIGNAL(updated()), this, SLOT(doUpdate())); if(_id.guid.isNull()) _id.guid = QUuid::createUuid(); if(_name == "") _name = "Unnamed"; _light->load(settings); _bind->load(settings); _perf->load(settings); }
void KbPerf::save(CkbSettings& settings){ _needsSave = false; SGroup group(settings, "Performance"); { SGroup group(settings, "DPI"); for(int i = 0; i < DPI_COUNT; i++){ QString iStr = QString::number(i); settings.setValue(iStr, QPoint(dpiX[i], dpiY[i])); settings.setValue(iStr + "RGB", dpiClr[i].name(QColor::HexArgb)); if(i != 0) settings.setValue(iStr + "Disabled", !dpiOn[i]); } settings.setValue("6RGB", dpiClr[OTHER].name(QColor::HexArgb)); // Ignore pushed modes when saving current DPI. settings.setValue("CurIdx", dpiBaseIdx); } settings.setValue("LiftHeight", _liftHeight); settings.setValue("AngleSnap", _angleSnap); { SGroup group(settings, "Indicators"); settings.setValue("DPI", _dpiIndicator); for(int i = 0; i < I_COUNT; i++){ SGroup group(settings, QString::number(i)); settings.setValue("RGB0", iColor[i][0].name(QColor::HexArgb)); settings.setValue("RGB1", iColor[i][1].name(QColor::HexArgb)); if(i == LIGHT) settings.setValue("RGB2", light100Color.name(QColor::HexArgb)); else if(i == MUTE) settings.setValue("RGB2", muteNAColor.name(QColor::HexArgb)); settings.setValue("Enable", iEnable[i]); if(i <= HW_IMAX) settings.setValue("Hardware", (int)hwIType[i]); } } }
void KbPerf::load(CkbSettings& settings){ pushedDpis.clear(); runningPushIdx = 1; _needsSave = false; bool readIndicators = true; if(!settings.containsGroup("Performance/Indicators")){ // Read old indicator settings from the lighting group, if present // (ckb <= v0.2.0) SGroup group(settings, "Lighting"); if(settings.contains("InactiveIndicators")){ bool inOk = false; int inactive = settings.value("InactiveIndicators").toInt(&inOk); if(!inOk || inactive > 2) inactive = 2; if(inactive == 1) _iOpacity = 0.75f; else if(inactive == 0) _iOpacity = 0.5f; else if(inactive < 0){ // Indicators disabled iEnable[MODE] = iEnable[MACRO] = iEnable[LIGHT] = iEnable[LOCK] = iEnable[MUTE] = false; } bool showMute = (settings.value("ShowMute").toInt(&inOk) != 0); if(inOk && !showMute) iEnable[MUTE] = false; readIndicators = false; } } SGroup group(settings, "Performance"); // Read DPI settings { SGroup group(settings, "DPI"); for(int i = 0; i < DPI_COUNT; i++){ QString iStr = QString::number(i); QPoint value = settings.value(iStr).toPoint(); if(value.isNull()) continue; dpiX[i] = value.x(); dpiY[i] = value.y(); QColor color = settings.value(iStr + "RGB").toString(); if(color.isValid()) dpiClr[i] = color; if(i != 0) dpiOn[i] = !settings.value(iStr + "Disabled").toBool(); } QColor color = settings.value("6RGB").toString(); if(color.isValid()) dpiClr[OTHER] = color; if (settings.contains("CurIdx")) { dpiBaseIdx = settings.value("CurIdx").toInt(); } else { // If there isn't a setting for current DPI stage, pick the first // enabled one. Failing that just pick stage 1. dpiBaseIdx = 1; for (int i = 1; i < DPI_COUNT; i++) { if (dpiOn[i]) { dpiBaseIdx = i; break; } } } _curDpi(dpi(dpiBaseIdx)); } // Read misc. mouse settings _liftHeight = (height)settings.value("LiftHeight").toInt(); if(_liftHeight < LOW || _liftHeight > HIGH) _liftHeight = MEDIUM; _angleSnap = settings.value("AngleSnap").toBool(); if(settings.contains("NoIndicator")){ // ckb <= v0.2.0 _dpiIndicator = !settings.value("NoIndicator").toBool(); } else { _dpiIndicator = settings.value("Indicators/DPI", true).toBool(); } // Read indicator settings if(readIndicators){ SGroup group(settings, "Indicators"); _iOpacity = settings.value("Opacity", 100).toInt() / 100.f; for(int i = 0; i < I_COUNT; i++){ SGroup group(settings, QString::number(i)); QColor color = settings.value("RGB0").toString(); if(color.isValid()) iColor[i][0] = color; color = settings.value("RGB1").toString(); if(color.isValid()) iColor[i][1] = color; if(i == LIGHT){ color = settings.value("RGB2").toString(); if(color.isValid()) light100Color = color; } else if(i == MUTE){ color = settings.value("RGB2").toString(); if(color.isValid()) muteNAColor = color; } if(i <= HW_IMAX){ iEnable[i] = settings.value("Enable", false).toBool(); hwIType[i] = (i_hw)settings.value("Hardware", (int)NORMAL).toInt(); } else { iEnable[i] = settings.value("Enable", true).toBool(); } } } emit didLoad(); }