Revert RepeatComboBox to standard ComboBox and add item model

This commit is contained in:
elecpower
2021-03-02 22:23:31 +11:00
parent e6e41f18d7
commit cb4ee1b30d
3 changed files with 16 additions and 80 deletions
@@ -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);
}
}
+10 -52
View File
@@ -19,54 +19,11 @@
*/
#include "customfunctions.h"
#include "compounditemmodels.h"
#include "filtereditemmodels.h"
#include "helpers.h"
#include "appdata.h"
#include <TimerEdit>
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();
+5 -27
View File
@@ -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 <QMediaPlayer>
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<QString> tracksSet;
QSet<QString> 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_