Co-authored-by: eshifri <eshifri@hotmail.com> Co-authored-by: philmoz <philmoz@users.noreply.github.com>
This commit is contained in:
co-authored by
eshifri
philmoz
parent
878a365e72
commit
ee73fa47f0
@@ -229,16 +229,8 @@ QString CustomFunctionData::repeatToString(const int value, const bool abbrev)
|
||||
|
||||
QString CustomFunctionData::enabledToString() const
|
||||
{
|
||||
if ((func >= FuncOverrideCH1 && func <= FuncOverrideCHLast) ||
|
||||
(func >= FuncAdjustGV1 && func <= FuncAdjustGVLast) ||
|
||||
(func == FuncReset) ||
|
||||
(func >= FuncSetTimer1 && func <= FuncSetTimerLast) ||
|
||||
(func == FuncVolume) ||
|
||||
(func == FuncBacklight) ||
|
||||
(func <= FuncInstantTrim)) {
|
||||
if (!enabled) {
|
||||
return tr("DISABLED");
|
||||
}
|
||||
if (!enabled) {
|
||||
return tr("DISABLED");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -23,15 +23,6 @@
|
||||
#include "yaml_rawsource.h"
|
||||
#include "eeprominterface.h"
|
||||
|
||||
static bool fnHasEnable(AssignFunc fn)
|
||||
{
|
||||
return (fn <= FuncInstantTrim)
|
||||
|| (fn >= FuncReset && fn <= FuncSetTimerLast)
|
||||
|| (fn >= FuncAdjustGV1 && fn <= FuncBindExternalModule)
|
||||
|| (fn == FuncVolume)
|
||||
|| (fn == FuncBacklight);
|
||||
}
|
||||
|
||||
static bool fnHasRepeat(AssignFunc fn)
|
||||
{
|
||||
return (fn == FuncPlayPrompt)
|
||||
@@ -226,15 +217,15 @@ Node convert<CustomFunctionData>::encode(const CustomFunctionData& rhs)
|
||||
break;
|
||||
}
|
||||
|
||||
if (fnHasEnable(rhs.func)) {
|
||||
if (add_comma) {
|
||||
def += ",";
|
||||
}
|
||||
def += std::to_string((int)rhs.enabled);
|
||||
} else if(fnHasRepeat(rhs.func)) {
|
||||
if (add_comma) {
|
||||
def += ",";
|
||||
}
|
||||
if (add_comma) {
|
||||
def += ",";
|
||||
}
|
||||
|
||||
def += std::to_string((int)rhs.enabled);
|
||||
|
||||
if(fnHasRepeat(rhs.func)) {
|
||||
def += ",";
|
||||
|
||||
if (rhs.func == FuncPlayScript || rhs.func == FuncRGBLed) {
|
||||
def += ((rhs.repeatParam == 0) ? "On" : "1x");
|
||||
} else if (rhs.repeatParam == 0) {
|
||||
@@ -385,13 +376,27 @@ bool convert<CustomFunctionData>::decode(const Node& node,
|
||||
def.ignore();
|
||||
}
|
||||
|
||||
if (fnHasEnable(rhs.func)) {
|
||||
int en = 0;
|
||||
def >> en;
|
||||
rhs.enabled = en;
|
||||
} else if(fnHasRepeat(rhs.func)) {
|
||||
std::string repeat;
|
||||
getline(def, repeat);
|
||||
// Need to handle older YAML files where only one of enabled/repeat was present
|
||||
std::string en, repeat;
|
||||
getline(def, en, ',');
|
||||
getline(def, repeat);
|
||||
|
||||
if (repeat.empty()) {
|
||||
// Only one value left to parse
|
||||
if (fnHasRepeat(rhs.func)) {
|
||||
// Assume it is repeat and set enabled to true
|
||||
repeat = en;
|
||||
rhs.enabled = 1;
|
||||
} else {
|
||||
// Func does not have repeat
|
||||
rhs.enabled = en[0] == '1' ? 1 : 0;
|
||||
}
|
||||
} else {
|
||||
// Two values - first is 'enabled' flag
|
||||
rhs.enabled = en[0] == '1' ? 1 : 0;
|
||||
}
|
||||
|
||||
if(fnHasRepeat(rhs.func)) {
|
||||
if (rhs.func == FuncPlayScript || rhs.func == FuncRGBLed) {
|
||||
rhs.repeatParam = (repeat == "1x") ? 1 : 0;
|
||||
} else if (repeat == "1x") {
|
||||
|
||||
@@ -112,7 +112,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
|
||||
playIcon.addImage("stop.png", QIcon::Normal, QIcon::On);
|
||||
|
||||
QStringList headerLabels;
|
||||
headerLabels << "#" << tr("Switch") << tr("Action") << tr("Parameters") << "";
|
||||
headerLabels << "#" << tr("Switch") << tr("Action") << tr("Parameters") << tr("Repeat") << tr("Enable");
|
||||
TableLayout * tableLayout = new TableLayout(this, fswCapability, headerLabels);
|
||||
|
||||
for (int i = 0; i < fswCapability; i++) {
|
||||
@@ -215,11 +215,12 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
|
||||
repeatLayout->addWidget(fswtchRepeat[i], i + 1);
|
||||
connect(fswtchRepeat[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited()));
|
||||
|
||||
QHBoxLayout *enableLayout = new QHBoxLayout();
|
||||
tableLayout->addLayout(i, 5, enableLayout);
|
||||
fswtchEnable[i] = new QCheckBox(this);
|
||||
fswtchEnable[i]->setProperty("index", i);
|
||||
fswtchEnable[i]->setText(tr("ON"));
|
||||
fswtchEnable[i]->setFixedWidth(200);
|
||||
repeatLayout->addWidget(fswtchEnable[i], i + 1);
|
||||
enableLayout->addWidget(fswtchEnable[i], i + 1);
|
||||
connect(fswtchEnable[i], SIGNAL(stateChanged(int)), this, SLOT(customFunctionEdited()));
|
||||
}
|
||||
|
||||
@@ -351,6 +352,7 @@ void CustomFunctionsPanel::functionEdited()
|
||||
functions[index].clear();
|
||||
functions[index].swtch = swtch;
|
||||
functions[index].func = (AssignFunc)fswtchFunc[index]->currentData().toInt();
|
||||
functions[index].enabled = true;
|
||||
if (functions[index].func == FuncPlayScript || functions[index].func == FuncRGBLed)
|
||||
fswtchRepeat[index]->setModel(tabModelFactory->getItemModel(repeatLuaId));
|
||||
else
|
||||
@@ -375,10 +377,11 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
|
||||
else {
|
||||
fswtchSwtch[i]->setCurrentIndex(fswtchSwtch[i]->findData(cfn.swtch.toValue()));
|
||||
fswtchFunc[i]->setCurrentIndex(fswtchFunc[i]->findData(cfn.func));
|
||||
fswtchEnable[i]->setChecked(cfn.enabled);
|
||||
}
|
||||
|
||||
if (!cfn.isEmpty()) {
|
||||
widgetsMask |= CUSTOM_FUNCTION_SHOW_FUNC;
|
||||
widgetsMask |= CUSTOM_FUNCTION_SHOW_FUNC | CUSTOM_FUNCTION_ENABLE;
|
||||
|
||||
if (func >= FuncOverrideCH1 && func <= FuncOverrideCH32) {
|
||||
if (model) {
|
||||
@@ -391,7 +394,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
|
||||
cfn.param = fswtchParam[i]->value();
|
||||
}
|
||||
fswtchParam[i]->setValue(cfn.param);
|
||||
widgetsMask |= CUSTOM_FUNCTION_NUMERIC_PARAM | CUSTOM_FUNCTION_ENABLE;
|
||||
widgetsMask |= CUSTOM_FUNCTION_NUMERIC_PARAM;
|
||||
}
|
||||
}
|
||||
else if (func == FuncLogs) {
|
||||
@@ -409,7 +412,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
|
||||
if (modified)
|
||||
cfn.adjustMode = fswtchGVmode[i]->currentData().toInt();
|
||||
fswtchGVmode[i]->setCurrentIndex(fswtchGVmode[i]->findData(cfn.adjustMode));
|
||||
widgetsMask |= CUSTOM_FUNCTION_GV_MODE | CUSTOM_FUNCTION_ENABLE;
|
||||
widgetsMask |= CUSTOM_FUNCTION_GV_MODE;
|
||||
if (cfn.adjustMode == FUNC_ADJUST_GVAR_CONSTANT || cfn.adjustMode == FUNC_ADJUST_GVAR_INCDEC) {
|
||||
if (modified)
|
||||
cfn.param = fswtchParam[i]->value() * model->gvarData[gvidx].multiplierSet();
|
||||
@@ -440,7 +443,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
|
||||
if (modified)
|
||||
cfn.param = fswtchParamT[i]->currentData().toInt();
|
||||
populateFuncParamCB(fswtchParamT[i], func, cfn.param);
|
||||
widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM | CUSTOM_FUNCTION_ENABLE;
|
||||
widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM;
|
||||
}
|
||||
else if (func >= FuncSetTimer1 && func <= FuncSetTimer3) {
|
||||
if (modified)
|
||||
@@ -448,16 +451,13 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
|
||||
RawSourceRange range = RawSource(SOURCE_TYPE_SPECIAL, func - FuncSetTimer1 + 2).getRange(model, generalSettings);
|
||||
fswtchParamTime[i]->setTimeRange((int)range.min, (int)range.max);
|
||||
fswtchParamTime[i]->setTime(cfn.param);
|
||||
widgetsMask |= CUSTOM_FUNCTION_TIME_PARAM | CUSTOM_FUNCTION_ENABLE;
|
||||
}
|
||||
else if (func >= FuncSetFailsafe && func <= FuncBindExternalModule) {
|
||||
widgetsMask |= CUSTOM_FUNCTION_ENABLE;
|
||||
widgetsMask |= CUSTOM_FUNCTION_TIME_PARAM;
|
||||
}
|
||||
else if (func == FuncVolume || func == FuncBacklight) {
|
||||
if (modified)
|
||||
cfn.param = fswtchParamT[i]->currentData().toInt();
|
||||
populateFuncParamCB(fswtchParamT[i], func, cfn.param);
|
||||
widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM | CUSTOM_FUNCTION_ENABLE;
|
||||
widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM;
|
||||
}
|
||||
else if (func == FuncPlaySound || func == FuncPlayHaptic || func == FuncPlayValue || func == FuncPlayPrompt || func == FuncPlayBoth || func == FuncBackgroundMusic || func == FuncSetScreen) {
|
||||
if (func != FuncBackgroundMusic) {
|
||||
@@ -568,11 +568,12 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
|
||||
fswtchParam[i]->setDecimals(0);
|
||||
fswtchParam[i]->setSingleStep(1);
|
||||
fswtchParam[i]->setValue(cfn.param);
|
||||
if (func <= FuncInstantTrim) {
|
||||
widgetsMask |= CUSTOM_FUNCTION_ENABLE;
|
||||
}
|
||||
widgetsMask |= CUSTOM_FUNCTION_ENABLE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
cfn.enabled = true;
|
||||
}
|
||||
|
||||
fswtchFunc[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_SHOW_FUNC);
|
||||
fswtchParam[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_NUMERIC_PARAM);
|
||||
@@ -581,10 +582,6 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
|
||||
fswtchParamT[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_SOURCE_PARAM);
|
||||
fswtchParamArmT[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_FILE_PARAM);
|
||||
fswtchEnable[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_ENABLE);
|
||||
if (widgetsMask & CUSTOM_FUNCTION_ENABLE)
|
||||
fswtchEnable[i]->setChecked(cfn.enabled);
|
||||
else
|
||||
fswtchEnable[i]->setChecked(false);
|
||||
fswtchRepeat[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_REPEAT);
|
||||
fswtchGVmode[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_GV_MODE);
|
||||
playBT[i]->setVisible(widgetsMask & CUSTOM_FUNCTION_PLAY);
|
||||
|
||||
Reference in New Issue
Block a user