Introduce T-pro and function switches handling
This commit is contained in:
@@ -45,6 +45,7 @@ set(modeledit_HDRS
|
||||
set(modeledit_UIS
|
||||
setup_timer.ui
|
||||
setup_module.ui
|
||||
setup_function_switches.ui
|
||||
flightmode.ui
|
||||
telemetry_customscreen.ui
|
||||
telemetry_sensor.ui
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "ui_setup.h"
|
||||
#include "ui_setup_timer.h"
|
||||
#include "ui_setup_module.h"
|
||||
#include "ui_setup_function_switches.h"
|
||||
#include "appdata.h"
|
||||
#include "modelprinter.h"
|
||||
#include "multiprotocols.h"
|
||||
@@ -982,6 +983,170 @@ void ModulePanel::onClearAccessRxClicked()
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
FunctionSwitchesPanel::FunctionSwitchesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware):
|
||||
ModelPanel(parent, model, generalSettings, firmware),
|
||||
ui(new Ui::FunctionSwitches)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
lock = true;
|
||||
|
||||
QRegExp rx(CHAR_FOR_NAMES_REGEX);
|
||||
|
||||
switchcnt = Boards::getCapability(firmware->getBoard(), Board::NumFunctionSwitches);
|
||||
|
||||
for (int i = 0; i < switchcnt; i++) {
|
||||
QLabel * lblSwitchId = new QLabel(this);
|
||||
lblSwitchId->setText(tr("SW%1").arg(i + 1));
|
||||
|
||||
AutoLineEdit * aleName = new AutoLineEdit(this);
|
||||
aleName->setProperty("index", i);
|
||||
aleName->setValidator(new QRegExpValidator(rx, this));
|
||||
aleName->setField((char *)model.functionSwitchNames[i], 3);
|
||||
|
||||
// TODO itemmodel
|
||||
QComboBox * cboConfig = new QComboBox(this);
|
||||
cboConfig->setProperty("index", i);
|
||||
cboConfig->addItem(tr("NONE"));
|
||||
cboConfig->addItem(tr("TOGGLE"));
|
||||
cboConfig->addItem(tr("2POS"));
|
||||
|
||||
// TODO itemmodel
|
||||
QComboBox * cboStartPosn = new QComboBox(this);
|
||||
cboStartPosn->setProperty("index", i);
|
||||
cboStartPosn->addItem(CPN_STR_SW_INDICATOR_UP);
|
||||
cboStartPosn->addItem(CPN_STR_SW_INDICATOR_DN);
|
||||
cboStartPosn->addItem("=");
|
||||
|
||||
QSpinBox * sbGroup = new QSpinBox(this);
|
||||
sbGroup->setProperty("index", i);
|
||||
sbGroup->setMaximum(3);
|
||||
|
||||
int row = 0;
|
||||
int coloffset = 1;
|
||||
ui->gridSwitches->addWidget(lblSwitchId, row++, i + coloffset);
|
||||
ui->gridSwitches->addWidget(aleName, row++, i + coloffset);
|
||||
ui->gridSwitches->addWidget(cboConfig, row++, i + coloffset);
|
||||
ui->gridSwitches->addWidget(cboStartPosn, row++, i + coloffset);
|
||||
ui->gridSwitches->addWidget(sbGroup, row++, i + coloffset);
|
||||
|
||||
connect(cboConfig, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FunctionSwitchesPanel::on_configCurrentIndexChanged);
|
||||
connect(cboStartPosn, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FunctionSwitchesPanel::on_startPosnCurrentIndexChanged);
|
||||
connect(sbGroup, QOverload<int>::of(&QSpinBox::valueChanged), this, &FunctionSwitchesPanel::on_groupChanged);
|
||||
|
||||
aleNames << aleName;
|
||||
cboConfigs << cboConfig;
|
||||
cboStartupPosns << cboStartPosn;
|
||||
sbGroups << sbGroup;
|
||||
}
|
||||
|
||||
update();
|
||||
|
||||
lock = false;
|
||||
}
|
||||
|
||||
FunctionSwitchesPanel::~FunctionSwitchesPanel()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void FunctionSwitchesPanel::update()
|
||||
{
|
||||
for (int i = 0; i < switchcnt; i++) {
|
||||
update(i);
|
||||
}
|
||||
}
|
||||
|
||||
void FunctionSwitchesPanel::update(int index)
|
||||
{
|
||||
lock = true;
|
||||
|
||||
for (int i = 0; i < switchcnt; i++) {
|
||||
aleNames[i]->update();
|
||||
cboConfigs[i]->setCurrentIndex((model->functionSwitchConfig >> (2 * i)) & 0x03);
|
||||
cboStartupPosns[i]->setCurrentIndex((model->functionSwitchStartConfig >> (2 * i)) & 0x03);
|
||||
sbGroups[i]->setValue((model->functionSwitchGroup >> (2 * i)) & 0x03);
|
||||
|
||||
if (cboConfigs[i]->currentIndex() < 2)
|
||||
cboStartupPosns[i]->setEnabled(false);
|
||||
else
|
||||
cboStartupPosns[i]->setEnabled(true);
|
||||
|
||||
if (cboConfigs[i]->currentIndex() < 1)
|
||||
sbGroups[i]->setEnabled(false);
|
||||
else
|
||||
sbGroups[i]->setEnabled(true);
|
||||
}
|
||||
|
||||
lock = false;
|
||||
}
|
||||
|
||||
void FunctionSwitchesPanel::on_configCurrentIndexChanged(int index)
|
||||
{
|
||||
if (!sender())
|
||||
return;
|
||||
|
||||
QComboBox * cb = qobject_cast<QComboBox *>(sender());
|
||||
|
||||
if (cb && !lock) {
|
||||
lock = true;
|
||||
bool ok = false;
|
||||
int i = sender()->property("index").toInt(&ok);
|
||||
if (ok && ((model->functionSwitchConfig >> (2 * i)) & 0x03) != (unsigned int)index) {
|
||||
unsigned int mask = ((unsigned int) 0x03 << (2 * i));
|
||||
model->functionSwitchConfig = (model->functionSwitchConfig & ~ mask) | ((unsigned int) index << (2 * i));
|
||||
if (index < 2)
|
||||
model->functionSwitchStartConfig = (model->functionSwitchStartConfig & ~ mask) | ((unsigned int) 0 << (2 * i));
|
||||
if (index < 1)
|
||||
model->functionSwitchGroup = (model->functionSwitchGroup & ~ mask) | ((unsigned int) 0 << (2 * i));
|
||||
update(i);
|
||||
emit modified();
|
||||
}
|
||||
lock = false;
|
||||
}
|
||||
}
|
||||
|
||||
void FunctionSwitchesPanel::on_startPosnCurrentIndexChanged(int index)
|
||||
{
|
||||
if (!sender())
|
||||
return;
|
||||
|
||||
QComboBox * cb = qobject_cast<QComboBox *>(sender());
|
||||
|
||||
if (cb && !lock) {
|
||||
lock = true;
|
||||
bool ok = false;
|
||||
int i = sender()->property("index").toInt(&ok);
|
||||
if (ok && ((model->functionSwitchStartConfig >> (2 * i)) & 0x03) != (unsigned int)index) {
|
||||
unsigned int mask = ((unsigned int) 0x03 << (2 * i));
|
||||
model->functionSwitchStartConfig = (model->functionSwitchStartConfig & ~ mask) | ((unsigned int) index << (2 * i));
|
||||
emit modified();
|
||||
}
|
||||
lock = false;
|
||||
}
|
||||
}
|
||||
|
||||
void FunctionSwitchesPanel::on_groupChanged(int value)
|
||||
{
|
||||
if (!sender())
|
||||
return;
|
||||
|
||||
QSpinBox * sb = qobject_cast<QSpinBox *>(sender());
|
||||
|
||||
if (sb && !lock) {
|
||||
lock = true;
|
||||
bool ok = false;
|
||||
int i = sender()->property("index").toInt(&ok);
|
||||
if (ok && ((model->functionSwitchGroup >> (2 * i)) & 0x03) != (unsigned int)value) {
|
||||
unsigned int mask = ((unsigned int) 0x03 << (2 * i));
|
||||
model->functionSwitchGroup = (model->functionSwitchGroup & ~ mask) | ((unsigned int) value << (2 * i));
|
||||
emit modified();
|
||||
}
|
||||
lock = false;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware,
|
||||
@@ -1221,6 +1386,11 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
|
||||
|
||||
ui->trimsDisplay->setField(model.trimsDisplay, this);
|
||||
|
||||
if (Boards::getCapability(firmware->getBoard(), Board::NumFunctionSwitches) > 0)
|
||||
ui->functionSwitchesLayout->addWidget(new FunctionSwitchesPanel(this, model, generalSettings, firmware));
|
||||
//else
|
||||
// ui->functionSwitchesLayout->hide();
|
||||
|
||||
for (int i = firmware->getCapability(NumFirstUsableModule); i < firmware->getCapability(NumModules); i++) {
|
||||
modules[i] = new ModulePanel(this, model, model.moduleData[i], generalSettings, firmware, i);
|
||||
ui->modulesLayout->addWidget(modules[i]);
|
||||
|
||||
@@ -31,8 +31,11 @@ namespace Ui {
|
||||
class Setup;
|
||||
class Timer;
|
||||
class Module;
|
||||
class FunctionSwitches;
|
||||
}
|
||||
|
||||
class AutoLineEdit;
|
||||
|
||||
class TimerPanel : public ModelPanel
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -128,6 +131,31 @@ class ModulePanel : public ModelPanel
|
||||
void updateFailsafeUI(unsigned channel, quint8 updtSb);
|
||||
};
|
||||
|
||||
class FunctionSwitchesPanel : public ModelPanel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FunctionSwitchesPanel(QWidget * parent, ModelData & model, GeneralSettings & generalSettings, Firmware * firmware);
|
||||
virtual ~FunctionSwitchesPanel();
|
||||
|
||||
virtual void update();
|
||||
void update(int index);
|
||||
|
||||
private slots:
|
||||
void on_configCurrentIndexChanged(int index);
|
||||
void on_startPosnCurrentIndexChanged(int index);
|
||||
void on_groupChanged(int value);
|
||||
|
||||
private:
|
||||
Ui::FunctionSwitches * ui;
|
||||
QVector<AutoLineEdit *> aleNames;
|
||||
QVector<QComboBox *> cboConfigs;
|
||||
QVector<QComboBox *> cboStartupPosns;
|
||||
QVector<QSpinBox *> sbGroups;
|
||||
int switchcnt;
|
||||
};
|
||||
|
||||
class SetupPanel : public ModelPanel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1007</width>
|
||||
<height>405</height>
|
||||
<height>435</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -630,6 +630,9 @@ If this is checked the throttle will be reversed. Idle will be forward, trim wi
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="functionSwitchesLayout"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="modulesLayout"/>
|
||||
</item>
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>FunctionSwitches</class>
|
||||
<widget class="QWidget" name="FunctionSwitches">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>231</width>
|
||||
<height>140</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblSwitch">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Function Switches</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridSwitches">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMinimumSize</enum>
|
||||
</property>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="lblType">
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="lblGroup">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Group</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="lblStartupPosn">
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lblName">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user