From cb4ee1b30dd76d165f6f8ae9b34452216903dc60 Mon Sep 17 00:00:00 2001 From: elecpower Date: Tue, 2 Mar 2021 22:23:31 +1100 Subject: [PATCH] Revert RepeatComboBox to standard ComboBox and add item model --- .../src/firmwares/customfunctiondata.cpp | 2 +- companion/src/modeledit/customfunctions.cpp | 62 +++---------------- companion/src/modeledit/customfunctions.h | 32 ++-------- 3 files changed, 16 insertions(+), 80 deletions(-) diff --git a/companion/src/firmwares/customfunctiondata.cpp b/companion/src/firmwares/customfunctiondata.cpp index 428e4eead..84e49ceb3 100644 --- a/companion/src/firmwares/customfunctiondata.cpp +++ b/companion/src/firmwares/customfunctiondata.cpp @@ -222,7 +222,7 @@ QString CustomFunctionData::repeatToString(int value) return tr("No repeat"); } else { - return tr("Repeat(%1s)").arg(value); + return tr("Repeat %1s").arg(value); } } diff --git a/companion/src/modeledit/customfunctions.cpp b/companion/src/modeledit/customfunctions.cpp index f2f2e07f1..6be75f28f 100644 --- a/companion/src/modeledit/customfunctions.cpp +++ b/companion/src/modeledit/customfunctions.cpp @@ -19,54 +19,11 @@ */ #include "customfunctions.h" -#include "compounditemmodels.h" -#include "filtereditemmodels.h" #include "helpers.h" #include "appdata.h" #include -RepeatComboBox::RepeatComboBox(QWidget *parent, int & repeatParam): - QComboBox(parent), - repeatParam(repeatParam) -{ - unsigned int step = 1; - int value = repeatParam / step; - - setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed); - - if (step == 1) { - addItem(tr("Played once, not during startup"), -1); - value++; - } - - addItem(tr("No repeat"), 0); - - for (unsigned int i = step; i <= 60; i += step) { - addItem(tr("%1s").arg(i), i); - } - - setCurrentIndex(value); - - connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onIndexChanged(int))); -} - -void RepeatComboBox::onIndexChanged(int index) -{ - repeatParam = itemData(index).toInt(); - emit modified(); -} - -void RepeatComboBox::update() -{ - unsigned int step = 1; - int value = repeatParam / step; - if (step == 1) { - value++; - } - setCurrentIndex(value); -} - CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, GeneralSettings & generalSettings, Firmware * firmware, CompoundItemModelFactory * sharedItemModels): GenericPanel(parent, model, generalSettings, firmware), @@ -81,6 +38,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, tabModelFactory = new CompoundItemModelFactory(&generalSettings, model); playSoundId = tabModelFactory->registerItemModel(CustomFunctionData::playSoundItemModel()); harpicId = tabModelFactory->registerItemModel(CustomFunctionData::harpicItemModel()); + repeatId = tabModelFactory->registerItemModel(CustomFunctionData::repeatItemModel()); tabFilterFactory = new FilteredItemModelFactory(); @@ -239,9 +197,12 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model, QHBoxLayout * repeatLayout = new QHBoxLayout(); tableLayout->addLayout(i, 4, repeatLayout); - fswtchRepeat[i] = new RepeatComboBox(this, functions[i].repeatParam); + fswtchRepeat[i] = new QComboBox(this); + fswtchRepeat[i]->setProperty("index", i); + fswtchRepeat[i]->setModel(tabModelFactory->getItemModel(repeatId)); + fswtchRepeat[i]->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed); repeatLayout->addWidget(fswtchRepeat[i], i + 1); - connect(fswtchRepeat[i], SIGNAL(modified()), this, SLOT(onRepeatModified())); + connect(fswtchRepeat[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited())); fswtchEnable[i] = new QCheckBox(this); fswtchEnable[i]->setProperty("index", i); @@ -375,11 +336,6 @@ void CustomFunctionsPanel::functionEdited() } } -void CustomFunctionsPanel::onRepeatModified() -{ - emit modified(); -} - void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) { CustomFunctionData & cfn = functions[i]; @@ -480,8 +436,10 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) } else if (func == FuncPlaySound || func == FuncPlayHaptic || func == FuncPlayValue || func == FuncPlayPrompt || func == FuncPlayBoth || func == FuncBackgroundMusic) { if (func != FuncBackgroundMusic) { + if (modified) + cfn.repeatParam = fswtchRepeat[i]->currentData().toInt(); widgetsMask |= CUSTOM_FUNCTION_REPEAT; - fswtchRepeat[i]->update(); + fswtchRepeat[i]->setCurrentIndex(fswtchRepeat[i]->findData(cfn.repeatParam)); } if (func == FuncPlayValue) { if (modified) @@ -505,7 +463,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified) if (modified) { if (fswtchParamGV[i]->isChecked()) { fswtchParam[i]->setMinimum(1); - cfn.param = std::min(fswtchParam[i]->value(),5.0)+(fswtchParamGV[i]->isChecked() ? 250 : 0); + cfn.param = std::min(fswtchParam[i]->value(), 5.0) + (fswtchParamGV[i]->isChecked() ? 250 : 0); } else { cfn.param = fswtchParam[i]->value(); diff --git a/companion/src/modeledit/customfunctions.h b/companion/src/modeledit/customfunctions.h index e74ce0d66..1085e78b1 100644 --- a/companion/src/modeledit/customfunctions.h +++ b/companion/src/modeledit/customfunctions.h @@ -18,39 +18,19 @@ * GNU General Public License for more details. */ -#ifndef _CUSTOMFUNCTIONS_H_ -#define _CUSTOMFUNCTIONS_H_ +#pragma once #include "modeledit.h" #include "eeprominterface.h" +#include "compounditemmodels.h" +#include "filtereditemmodels.h" #include -class CompoundItemModelFactory; -class FilteredItemModelFactory; -class FilteredItemModel; class TimerEdit; constexpr char MIMETYPE_CUSTOM_FUNCTION[] = "application/x-companion-custom-function"; -class RepeatComboBox: public QComboBox -{ - Q_OBJECT - - public: - RepeatComboBox(QWidget * parent, int & repeatParam); - void update(); - - signals: - void modified(); - - private slots: - void onIndexChanged(int); - - protected: - int & repeatParam; -}; - class CustomFunctionsPanel : public GenericPanel { Q_OBJECT @@ -69,7 +49,6 @@ class CustomFunctionsPanel : public GenericPanel void functionEdited(); void onCustomContextMenuRequested(QPoint pos); void refreshCustomFunction(int index, bool modified=false); - void onRepeatModified(); bool playSound(int index); void stopSound(int index); void toggleSound(bool play); @@ -108,6 +87,7 @@ class CustomFunctionsPanel : public GenericPanel int rawSourceGVarsId; int playSoundId; int harpicId; + int repeatId; QSet tracksSet; QSet scriptsSet; @@ -121,7 +101,7 @@ class CustomFunctionsPanel : public GenericPanel QComboBox * fswtchParamT[CPN_MAX_SPECIAL_FUNCTIONS]; QComboBox * fswtchParamArmT[CPN_MAX_SPECIAL_FUNCTIONS]; QCheckBox * fswtchEnable[CPN_MAX_SPECIAL_FUNCTIONS]; - RepeatComboBox * fswtchRepeat[CPN_MAX_SPECIAL_FUNCTIONS]; + QComboBox * fswtchRepeat[CPN_MAX_SPECIAL_FUNCTIONS]; QComboBox * fswtchGVmode[CPN_MAX_SPECIAL_FUNCTIONS]; QSlider * fswtchBLcolor[CPN_MAX_SPECIAL_FUNCTIONS]; QMediaPlayer * mediaPlayer; @@ -130,5 +110,3 @@ class CustomFunctionsPanel : public GenericPanel int fswCapability; int modelsUpdateCnt; }; - -#endif // _CUSTOMFUNCTIONS_H_