mirror of
https://github.com/opentx/opentx.git
synced 2025-07-16 21:05:26 +03:00
Fixes #2465 - A little bit refactoring done while fixing this one
This commit is contained in:
parent
2b804f92b5
commit
90ebaf2d88
8 changed files with 76 additions and 72 deletions
|
@ -95,6 +95,36 @@ void populateGvSourceCB(QComboBox *b, int value)
|
|||
b->setCurrentIndex(value);
|
||||
}
|
||||
|
||||
void populateFileComboBox(QComboBox * b, const QSet<QString> & set, const QString & current)
|
||||
{
|
||||
b->addItem("----");
|
||||
|
||||
bool added = false;
|
||||
// Convert set into list and sort it alphabetically case insensitive
|
||||
QStringList list = QStringList::fromSet(set);
|
||||
qSort(list.begin(), list.end(), caseInsensitiveLessThan);
|
||||
foreach (QString entry, list) {
|
||||
b->addItem(entry);
|
||||
if (entry == current) {
|
||||
b->setCurrentIndex(b->count()-1);
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!added && !current.isEmpty()) {
|
||||
b->addItem(current);
|
||||
b->setCurrentIndex(b->count()-1);
|
||||
}
|
||||
}
|
||||
|
||||
void getFileComboBoxValue(QComboBox * b, char * dest, int length)
|
||||
{
|
||||
memset(dest, 0, length+1);
|
||||
if (b->currentText() != "----") {
|
||||
strncpy(dest, b->currentText().toAscii(), length);
|
||||
}
|
||||
}
|
||||
|
||||
QString getProtocolStr(const int proto)
|
||||
{
|
||||
static const char *strings[] = { "OFF",
|
||||
|
|
|
@ -26,6 +26,8 @@ extern const QColor colors[C9X_MAX_CURVES];
|
|||
#define TRIM_MODE_NONE 0x1F // 0b11111
|
||||
|
||||
void populateGvSourceCB(QComboBox *b, int value);
|
||||
void populateFileComboBox(QComboBox * b, const QSet<QString> & set, const QString & current);
|
||||
void getFileComboBoxValue(QComboBox * b, char * dest, int length);
|
||||
void populateRotEncCB(QComboBox *b, int value, int renumber);
|
||||
|
||||
QString getTheme();
|
||||
|
|
|
@ -442,16 +442,9 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
|
|||
else {
|
||||
widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM;
|
||||
if (modified) {
|
||||
memset(cfn.paramarm, 0, sizeof(cfn.paramarm));
|
||||
int vml = firmware->getCapability(VoicesMaxLength);
|
||||
if (fswtchParamArmT[i]->currentText() != "----") {
|
||||
widgetsMask |= CUSTOM_FUNCTION_PLAY;
|
||||
for (int j=0; j<std::min(fswtchParamArmT[i]->currentText().length(), vml); j++) {
|
||||
cfn.paramarm[j] = fswtchParamArmT[i]->currentText().toAscii().at(j);
|
||||
getFileComboBoxValue(fswtchParamArmT[i], cfn.paramarm, firmware->getCapability(VoicesMaxLength));
|
||||
}
|
||||
}
|
||||
}
|
||||
populateFuncParamArmTCB(fswtchParamArmT[i], cfn.paramarm, tracksSet);
|
||||
populateFileComboBox(fswtchParamArmT[i], tracksSet, cfn.paramarm);
|
||||
if (fswtchParamArmT[i]->currentText() != "----") {
|
||||
widgetsMask |= CUSTOM_FUNCTION_PLAY;
|
||||
}
|
||||
|
@ -460,17 +453,13 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
|
|||
else if (func==FuncBackgroundMusic) {
|
||||
widgetsMask |= CUSTOM_FUNCTION_FILE_PARAM;
|
||||
if (modified) {
|
||||
memset(cfn.paramarm, 0, sizeof(cfn.paramarm));
|
||||
int vml=firmware->getCapability(VoicesMaxLength);
|
||||
getFileComboBoxValue(fswtchParamArmT[i], cfn.paramarm, firmware->getCapability(VoicesMaxLength));
|
||||
}
|
||||
populateFileComboBox(fswtchParamArmT[i], tracksSet, cfn.paramarm);
|
||||
if (fswtchParamArmT[i]->currentText() != "----") {
|
||||
widgetsMask |= CUSTOM_FUNCTION_PLAY;
|
||||
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, tracksSet);
|
||||
}
|
||||
else if (func==FuncPlaySound) {
|
||||
if (modified) cfn.param = (uint8_t)fswtchParamT[i]->currentIndex();
|
||||
populateFuncParamCB(fswtchParamT[i], func, cfn.param);
|
||||
|
@ -485,27 +474,9 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
|
|||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
getFileComboBoxValue(fswtchParamArmT[i], cfn.paramarm, 8);
|
||||
}
|
||||
populateFileComboBox(fswtchParamArmT[i], scriptsSet, cfn.paramarm);
|
||||
}
|
||||
else if (func==FuncBacklight && IS_TARANIS_PLUS(GetEepromInterface()->getBoard())) {
|
||||
if (modified) cfn.param = (uint8_t)fswtchBLcolor[i]->value();
|
||||
|
@ -659,30 +630,6 @@ void CustomFunctionsPanel::populateGVmodeCB(QComboBox *b, unsigned int value)
|
|||
b->setCurrentIndex(value);
|
||||
}
|
||||
|
||||
void CustomFunctionsPanel::populateFuncParamArmTCB(QComboBox *b, char * value, const QSet<QString> ¶msList)
|
||||
{
|
||||
b->clear();
|
||||
b->addItem("----");
|
||||
|
||||
bool added = false;
|
||||
QString currentvalue(value);
|
||||
// Convert set into list and sort it alphabetically case insensitive
|
||||
QStringList list = QStringList::fromSet(paramsList);
|
||||
qSort(list.begin(), list.end(), caseInsensitiveLessThan);
|
||||
foreach (QString entry, list) {
|
||||
b->addItem(entry);
|
||||
if (entry==currentvalue) {
|
||||
b->setCurrentIndex(b->count()-1);
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!added && strlen(value)) {
|
||||
b->addItem(value);
|
||||
b->setCurrentIndex(b->count()-1);
|
||||
}
|
||||
}
|
||||
|
||||
void CustomFunctionsPanel::populateFuncParamCB(QComboBox *b, uint function, unsigned int value, unsigned int adjustmode)
|
||||
{
|
||||
QStringList qs;
|
||||
|
|
|
@ -65,7 +65,6 @@ class CustomFunctionsPanel : public GenericPanel
|
|||
void populateFuncCB(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 populateFuncParamArmTCB(QComboBox *b, char * value, const QSet<QString> & paramsList);
|
||||
|
||||
bool initialized;
|
||||
QSet<QString> tracksSet;
|
||||
|
|
|
@ -340,6 +340,13 @@ TelemetryCustomScreen::TelemetryCustomScreen(QWidget *parent, ModelData & model,
|
|||
ui->screenType->setField(screen.type, this);
|
||||
lock = false;
|
||||
|
||||
if (IS_TARANIS(firmware->getBoard())) {
|
||||
QSet<QString> scriptsSet = getFilesSet(g.profile[g.id()].sdPath() + "/SCRIPTS/TELEMETRY", QStringList() << "*.lua", 8);
|
||||
populateFileComboBox(ui->scriptName, scriptsSet, screen.body.script.filename);
|
||||
connect(ui->scriptName, SIGNAL(currentIndexChanged(int)), this, SLOT(scriptNameEdited()));
|
||||
connect(ui->scriptName, SIGNAL(editTextChanged ( const QString)), this, SLOT(scriptNameEdited()));
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
|
@ -362,6 +369,7 @@ void TelemetryCustomScreen::update()
|
|||
{
|
||||
lock = true;
|
||||
|
||||
ui->scriptName->setVisible(screen.type == TELEMETRY_SCREEN_SCRIPT);
|
||||
ui->screenNums->setVisible(screen.type == TELEMETRY_SCREEN_NUMBERS);
|
||||
ui->screenBars->setVisible(screen.type == TELEMETRY_SCREEN_BARS);
|
||||
|
||||
|
@ -424,6 +432,16 @@ void TelemetryCustomScreen::on_screenType_currentIndexChanged(int index)
|
|||
}
|
||||
}
|
||||
|
||||
void TelemetryCustomScreen::scriptNameEdited()
|
||||
{
|
||||
if (!lock) {
|
||||
lock = true;
|
||||
getFileComboBoxValue(ui->scriptName, screen.body.script.filename, 8);
|
||||
emit modified();
|
||||
lock = false;
|
||||
}
|
||||
}
|
||||
|
||||
void TelemetryCustomScreen::customFieldChanged(int value)
|
||||
{
|
||||
if (!lock) {
|
||||
|
|
|
@ -60,6 +60,7 @@ class TelemetryCustomScreen: public ModelPanel
|
|||
|
||||
private slots:
|
||||
void on_screenType_currentIndexChanged(int index);
|
||||
void scriptNameEdited();
|
||||
void customFieldChanged(int index);
|
||||
void barSourceChanged(int index);
|
||||
void barMinChanged(double value);
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>283</width>
|
||||
<height>86</height>
|
||||
<width>915</width>
|
||||
<height>305</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -15,7 +15,7 @@
|
|||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="screenScript" stretch="0,0,1">
|
||||
<layout class="QHBoxLayout" name="screenScript" stretch="0,0,0,1">
|
||||
<item>
|
||||
<widget class="QLabel" name="screenTypeLabel">
|
||||
<property name="sizePolicy">
|
||||
|
@ -52,7 +52,14 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_16">
|
||||
<widget class="QComboBox" name="scriptName">
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
|
@ -70,7 +77,7 @@
|
|||
<widget class="QGroupBox" name="screenBars">
|
||||
<layout class="QGridLayout" name="screenBarsLayout" columnstretch="1,0,1,0">
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label_266">
|
||||
<widget class="QLabel" name="minLabel">
|
||||
<property name="text">
|
||||
<string>Min</string>
|
||||
</property>
|
||||
|
@ -80,7 +87,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_265">
|
||||
<widget class="QLabel" name="sourceLabel">
|
||||
<property name="text">
|
||||
<string>Source</string>
|
||||
</property>
|
||||
|
@ -90,7 +97,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label_267">
|
||||
<widget class="QLabel" name="gaugeLabel">
|
||||
<property name="text">
|
||||
<string>Gauge</string>
|
||||
</property>
|
||||
|
@ -100,7 +107,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLabel" name="label_268">
|
||||
<widget class="QLabel" name="maxLabel">
|
||||
<property name="text">
|
||||
<string>Max</string>
|
||||
</property>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <QComboBox>
|
||||
#include "genericpanel.h"
|
||||
#include <QDebug>
|
||||
|
||||
class AutoComboBox: public QComboBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue