1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-19 06:15:10 +03:00
Conflicts:
	companion/src/modeledit/customfunctions.cpp
	companion/src/modeledit/customfunctions.h
This commit is contained in:
bsongis 2014-12-08 22:56:52 +01:00
parent 65ff9dcefa
commit f608985a54
4 changed files with 76 additions and 32 deletions

View file

@ -1023,3 +1023,29 @@ QString generateProcessUniqueTempFileName(const QString & fileName)
sanitizedFileName.remove('/'); sanitizedFileName.remove('/');
return QDir::tempPath() + QString("/%1-").arg(QCoreApplication::applicationPid()) + sanitizedFileName; return QDir::tempPath() + QString("/%1-").arg(QCoreApplication::applicationPid()) + sanitizedFileName;
} }
QString getSoundsPath(const GeneralSettings &generalSettings)
{
QString path = g.profile[g.id()].sdPath() + "/SOUNDS/";
QString lang = generalSettings.ttsLanguage;
if (lang.isEmpty())
lang = "en";
path.append(lang);
return path;
}
QSet<QString> getFilesSet(const QString &path, const QStringList &filter, int maxLen)
{
QSet<QString> result;
QDir dir(path);
if (dir.exists()) {
foreach (QString filename, dir.entryList(filter, QDir::Files)) {
QFileInfo file(filename);
QString name = file.completeBaseName();
if (name.length() <= maxLen) {
result.insert(name);
}
}
}
return result;
}

View file

@ -154,4 +154,7 @@ int qunlink(const QString & fileName);
QString generateProcessUniqueTempFileName(const QString & fileName); QString generateProcessUniqueTempFileName(const QString & fileName);
QString getSoundsPath(const GeneralSettings &generalSettings);
QSet<QString> getFilesSet(const QString &path, const QStringList &filter, int maxLen);
#endif // HELPERS_H #endif // HELPERS_H

View file

@ -70,36 +70,29 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
int num_fsw = firmware->getCapability(CustomFunctions); int num_fsw = firmware->getCapability(CustomFunctions);
if (!firmware->getCapability(VoicesAsNumbers)) { if (!firmware->getCapability(VoicesAsNumbers)) {
tracksSet = getFilesSet(getSoundsPath(generalSettings), QStringList() << "*.wav" << "*.WAV", firmware->getCapability(VoicesMaxLength));
for (int i=0; i<num_fsw; i++) { for (int i=0; i<num_fsw; i++) {
if (functions[i].func==FuncPlayPrompt || functions[i].func==FuncBackgroundMusic) { if (functions[i].func==FuncPlayPrompt || functions[i].func==FuncBackgroundMusic) {
QString temp = functions[i].paramarm; QString temp = functions[i].paramarm;
if (!temp.isEmpty()) { if (!temp.isEmpty()) {
if (!paramarmList.contains(temp)) { tracksSet.insert(temp);
paramarmList.append(temp);
} }
} }
} }
qDebug() << tracksSet;
} }
QString path = g.profile[g.id()].sdPath(); if (IS_TARANIS(firmware->getBoard())) {
path.append("/SOUNDS/"); scriptsSet = getFilesSet(g.profile[g.id()].sdPath() + "/SCRIPTS", QStringList() << "*.lua", firmware->getCapability(VoicesMaxLength));
QString lang = generalSettings.ttsLanguage; for (int i=0; i<num_fsw; i++) {
if (lang.isEmpty()) if (functions[i].func==FuncPlayScript) {
lang="en"; QString temp = functions[i].paramarm;
path.append(lang); if (!temp.isEmpty()) {
QDir qd(path); scriptsSet.insert(temp);
int vml= firmware->getCapability(VoicesMaxLength);
if (qd.exists()) {
QStringList filters;
filters << "*.wav" << "*.WAV";
foreach ( QString file, qd.entryList(filters, QDir::Files) ) {
QFileInfo fi(file);
QString temp=fi.completeBaseName();
if (!paramarmList.contains(temp) && temp.length()<=vml) {
paramarmList.append(temp);
} }
} }
} }
qDebug() << scriptsSet;
} }
CompanionIcon playIcon("play.png"); CompanionIcon playIcon("play.png");
@ -129,7 +122,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
// The function // The function
fswtchFunc[i] = new QComboBox(this); fswtchFunc[i] = new QComboBox(this);
fswtchFunc[i]->setProperty("index", i); fswtchFunc[i]->setProperty("index", i);
connect(fswtchFunc[i], SIGNAL(currentIndexChanged(int)), this, SLOT(customFunctionEdited())); connect(fswtchFunc[i], SIGNAL(currentIndexChanged(int)), this, SLOT(functionEdited()));
gridLayout->addWidget(fswtchFunc[i], i+1, 2); gridLayout->addWidget(fswtchFunc[i], i+1, 2);
QHBoxLayout *paramLayout = new QHBoxLayout(); QHBoxLayout *paramLayout = new QHBoxLayout();
@ -297,10 +290,20 @@ void CustomFunctionsPanel::customFunctionEdited()
{ {
if (!lock) { if (!lock) {
lock = true; lock = true;
int index = sender()->property("index").toInt(); int index = sender()->property("index").toInt();
refreshCustomFunction(index, true); refreshCustomFunction(index, true);
emit modified();
lock = false;
}
}
void CustomFunctionsPanel::functionEdited()
{
if (!lock) {
lock = true;
int index = sender()->property("index").toInt();
fswtchParamArmT[index]->setCurrentIndex(0);
refreshCustomFunction(index, true);
emit modified(); emit modified();
lock = false; lock = false;
} }
@ -446,14 +449,12 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
} }
} }
} }
else { populateFuncParamArmTCB(fswtchParamArmT[i], cfn.paramarm, tracksSet);
populateFuncParamArmTCB(fswtchParamArmT[i], cfn.paramarm, paramarmList);
if (fswtchParamArmT[i]->currentText() != "----") { if (fswtchParamArmT[i]->currentText() != "----") {
widgetsMask |= CUSTOM_FUNCTION_PLAY; widgetsMask |= CUSTOM_FUNCTION_PLAY;
} }
} }
} }
}
else if (func==FuncBackgroundMusic) { else if (func==FuncBackgroundMusic) {
widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM; widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM;
if (modified) { if (modified) {
@ -466,6 +467,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
} }
} }
} }
populateFuncParamArmTCB(fswtchParamArmT[i], cfn.paramarm, tracksSet);
} }
else if (func==FuncPlaySound) { else if (func==FuncPlaySound) {
if (modified) cfn.param = (uint8_t)fswtchParamT[i]->currentIndex(); if (modified) cfn.param = (uint8_t)fswtchParamT[i]->currentIndex();
@ -478,6 +480,19 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM; widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM;
} }
} }
else if (func==FuncPlayScript) {
widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM;
if (modified) {
memset(cfn.paramarm, 0, sizeof(cfn.paramarm));
int vml = 8/*TODO*/;
if (fswtchParamArmT[i]->currentText() != "----") {
for (int j=0; j<std::min(fswtchParamArmT[i]->currentText().length(), vml); j++) {
cfn.paramarm[j] = fswtchParamArmT[i]->currentText().toAscii().at(j);
}
}
}
populateFuncParamArmTCB(fswtchParamArmT[i], cfn.paramarm, scriptsSet);
}
else if (func==FuncPlayScript) { else if (func==FuncPlayScript) {
widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM; widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM;
if (modified) { if (modified) {
@ -531,7 +546,6 @@ void CustomFunctionsPanel::update()
populateFuncCB(fswtchFunc[i], functions[i].func); populateFuncCB(fswtchFunc[i], functions[i].func);
populateGVmodeCB(fswtchGVmode[i], functions[i].adjustMode); populateGVmodeCB(fswtchGVmode[i], functions[i].adjustMode);
populateFuncParamCB(fswtchParamT[i], functions[i].func, functions[i].param, functions[i].adjustMode); populateFuncParamCB(fswtchParamT[i], functions[i].func, functions[i].param, functions[i].adjustMode);
populateFuncParamArmTCB(fswtchParamArmT[i], functions[i].paramarm, paramarmList);
} }
refreshCustomFunction(i); refreshCustomFunction(i);
} }
@ -552,7 +566,6 @@ void CustomFunctionsPanel::fswPaste()
populateFuncCB(fswtchFunc[selectedFunction], functions[selectedFunction].func); populateFuncCB(fswtchFunc[selectedFunction], functions[selectedFunction].func);
populateGVmodeCB(fswtchGVmode[selectedFunction], functions[selectedFunction].adjustMode); populateGVmodeCB(fswtchGVmode[selectedFunction], functions[selectedFunction].adjustMode);
populateFuncParamCB(fswtchParamT[selectedFunction], functions[selectedFunction].func, functions[selectedFunction].param, functions[selectedFunction].adjustMode); populateFuncParamCB(fswtchParamT[selectedFunction], functions[selectedFunction].func, functions[selectedFunction].param, functions[selectedFunction].adjustMode);
populateFuncParamArmTCB(fswtchParamArmT[selectedFunction], functions[selectedFunction].paramarm, paramarmList);
refreshCustomFunction(selectedFunction); refreshCustomFunction(selectedFunction);
lock = false; lock = false;
emit modified(); emit modified();
@ -643,7 +656,7 @@ void CustomFunctionsPanel::populateGVmodeCB(QComboBox *b, unsigned int value)
b->setCurrentIndex(value); b->setCurrentIndex(value);
} }
void CustomFunctionsPanel::populateFuncParamArmTCB(QComboBox *b, char * value, QStringList & paramsList) void CustomFunctionsPanel::populateFuncParamArmTCB(QComboBox *b, char * value, const QSet<QString> &paramsList)
{ {
b->clear(); b->clear();
b->addItem("----"); b->addItem("----");

View file

@ -47,6 +47,7 @@ class CustomFunctionsPanel : public GenericPanel
private slots: private slots:
void customFunctionEdited(); void customFunctionEdited();
void functionEdited();
void fsw_customContextMenuRequested(QPoint pos); void fsw_customContextMenuRequested(QPoint pos);
void refreshCustomFunction(int index, bool modified=false); void refreshCustomFunction(int index, bool modified=false);
void onChildModified(); void onChildModified();
@ -63,10 +64,11 @@ class CustomFunctionsPanel : public GenericPanel
void populateFuncCB(QComboBox *b, unsigned int value); void populateFuncCB(QComboBox *b, unsigned int value);
void populateGVmodeCB(QComboBox *b, unsigned int value); void populateGVmodeCB(QComboBox *b, unsigned int value);
void populateFuncParamCB(QComboBox *b, uint function, unsigned int value, unsigned int adjustmode=0); void populateFuncParamCB(QComboBox *b, uint function, unsigned int value, unsigned int adjustmode=0);
void populateFuncParamArmTCB(QComboBox *b, char * value, QStringList & paramsList); void populateFuncParamArmTCB(QComboBox *b, char * value, const QSet<QString> & paramsList);
bool initialized; bool initialized;
QStringList paramarmList; QSet<QString> tracksSet;
QSet<QString> scriptsSet;
int phononCurrent; int phononCurrent;
QComboBox * fswtchSwtch[C9X_MAX_CUSTOM_FUNCTIONS]; QComboBox * fswtchSwtch[C9X_MAX_CUSTOM_FUNCTIONS];
QComboBox * fswtchFunc[C9X_MAX_CUSTOM_FUNCTIONS]; QComboBox * fswtchFunc[C9X_MAX_CUSTOM_FUNCTIONS];