2011-08-04 17:58:41 +02:00
|
|
|
#include "inputchannelform.h"
|
|
|
|
#include "ui_inputchannelform.h"
|
|
|
|
|
2011-09-07 08:47:10 +02:00
|
|
|
#include "manualcontrolsettings.h"
|
2012-03-10 03:00:00 +01:00
|
|
|
#include "gcsreceiver.h"
|
2011-09-07 08:47:10 +02:00
|
|
|
|
2011-08-04 17:58:41 +02:00
|
|
|
inputChannelForm::inputChannelForm(QWidget *parent,bool showlegend) :
|
2012-04-26 13:29:00 +02:00
|
|
|
ConfigTaskWidget(parent),
|
2011-08-04 17:58:41 +02:00
|
|
|
ui(new Ui::inputChannelForm)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2012-03-26 17:49:10 +02:00
|
|
|
|
2012-09-09 03:35:14 +02:00
|
|
|
//The first time through the loop, keep the legend. All other times, delete it.
|
|
|
|
if(!showlegend)
|
|
|
|
{
|
|
|
|
layout()->removeWidget(ui->legend0);
|
|
|
|
layout()->removeWidget(ui->legend1);
|
|
|
|
layout()->removeWidget(ui->legend2);
|
|
|
|
layout()->removeWidget(ui->legend3);
|
|
|
|
layout()->removeWidget(ui->legend4);
|
|
|
|
layout()->removeWidget(ui->legend5);
|
|
|
|
delete ui->legend0;
|
|
|
|
delete ui->legend1;
|
|
|
|
delete ui->legend2;
|
|
|
|
delete ui->legend3;
|
|
|
|
delete ui->legend4;
|
|
|
|
delete ui->legend5;
|
2012-07-29 23:51:39 +02:00
|
|
|
|
2012-09-09 03:35:14 +02:00
|
|
|
}
|
2012-03-10 19:50:14 +01:00
|
|
|
|
2011-09-09 07:54:47 +02:00
|
|
|
connect(ui->channelMin,SIGNAL(valueChanged(int)),this,SLOT(minMaxUpdated()));
|
|
|
|
connect(ui->channelMax,SIGNAL(valueChanged(int)),this,SLOT(minMaxUpdated()));
|
2011-09-07 08:47:10 +02:00
|
|
|
connect(ui->channelGroup,SIGNAL(currentIndexChanged(int)),this,SLOT(groupUpdated()));
|
2011-09-09 07:54:47 +02:00
|
|
|
connect(ui->channelNeutral,SIGNAL(valueChanged(int)), this, SLOT(neutralUpdated(int)));
|
2011-09-07 08:47:10 +02:00
|
|
|
|
|
|
|
// This is awkward but since we want the UI to be a dropdown but the field is not an enum
|
|
|
|
// it breaks the UAUVObject widget relation of the task gadget. Running the data through
|
|
|
|
// a spin box fixes this
|
|
|
|
connect(ui->channelNumberDropdown,SIGNAL(currentIndexChanged(int)),this,SLOT(channelDropdownUpdated(int)));
|
|
|
|
connect(ui->channelNumber,SIGNAL(valueChanged(int)),this,SLOT(channelNumberUpdated(int)));
|
2012-04-19 19:00:20 +02:00
|
|
|
|
2012-05-22 00:20:23 +02:00
|
|
|
disableMouseWheelEvents();
|
2011-08-04 17:58:41 +02:00
|
|
|
}
|
|
|
|
|
2012-04-19 19:00:20 +02:00
|
|
|
|
2011-08-04 17:58:41 +02:00
|
|
|
inputChannelForm::~inputChannelForm()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
2012-04-19 19:00:20 +02:00
|
|
|
|
2012-02-18 21:37:30 +01:00
|
|
|
void inputChannelForm::setName(QString &name)
|
|
|
|
{
|
|
|
|
ui->channelName->setText(name);
|
|
|
|
QFontMetrics metrics(ui->channelName->font());
|
|
|
|
int width=metrics.width(name)+5;
|
|
|
|
foreach(inputChannelForm * form,parent()->findChildren<inputChannelForm*>())
|
|
|
|
{
|
|
|
|
if(form==this)
|
|
|
|
continue;
|
|
|
|
if(form->ui->channelName->minimumSize().width()<width)
|
|
|
|
form->ui->channelName->setMinimumSize(width,0);
|
|
|
|
else
|
|
|
|
width=form->ui->channelName->minimumSize().width();
|
|
|
|
}
|
|
|
|
ui->channelName->setMinimumSize(width,0);
|
|
|
|
}
|
2011-09-07 08:47:10 +02:00
|
|
|
|
2011-09-09 07:54:47 +02:00
|
|
|
/**
|
|
|
|
* Update the direction of the slider and boundaries
|
|
|
|
*/
|
|
|
|
void inputChannelForm::minMaxUpdated()
|
2011-09-07 08:47:10 +02:00
|
|
|
{
|
2011-09-09 07:54:47 +02:00
|
|
|
bool reverse = ui->channelMin->value() > ui->channelMax->value();
|
|
|
|
if(reverse) {
|
|
|
|
ui->channelNeutral->setMinimum(ui->channelMax->value());
|
|
|
|
ui->channelNeutral->setMaximum(ui->channelMin->value());
|
|
|
|
} else {
|
|
|
|
ui->channelNeutral->setMinimum(ui->channelMin->value());
|
|
|
|
ui->channelNeutral->setMaximum(ui->channelMax->value());
|
|
|
|
}
|
|
|
|
ui->channelRev->setChecked(reverse);
|
|
|
|
ui->channelNeutral->setInvertedAppearance(reverse);
|
|
|
|
ui->channelNeutral->setInvertedControls(reverse);
|
2011-09-07 08:47:10 +02:00
|
|
|
}
|
|
|
|
|
2011-09-09 07:54:47 +02:00
|
|
|
void inputChannelForm::neutralUpdated(int newval)
|
2011-09-07 08:47:10 +02:00
|
|
|
{
|
2011-09-09 07:54:47 +02:00
|
|
|
ui->neutral->setText(QString::number(newval));
|
2011-09-07 08:47:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the channel options based on the selected receiver type
|
|
|
|
*
|
|
|
|
* I fully admit this is terrible practice to embed data within UI
|
|
|
|
* like this. Open to suggestions. JC 2011-09-07
|
|
|
|
*/
|
|
|
|
void inputChannelForm::groupUpdated()
|
|
|
|
{
|
|
|
|
ui->channelNumberDropdown->clear();
|
|
|
|
ui->channelNumberDropdown->addItem("Disabled");
|
|
|
|
|
|
|
|
quint8 count = 0;
|
|
|
|
|
|
|
|
switch(ui->channelGroup->currentIndex()) {
|
|
|
|
case -1: // Nothing selected
|
|
|
|
count = 0;
|
|
|
|
break;
|
|
|
|
case ManualControlSettings::CHANNELGROUPS_PWM:
|
|
|
|
count = 8; // Need to make this 6 for CC
|
|
|
|
break;
|
|
|
|
case ManualControlSettings::CHANNELGROUPS_PPM:
|
2011-10-30 18:29:03 +01:00
|
|
|
case ManualControlSettings::CHANNELGROUPS_DSMMAINPORT:
|
|
|
|
case ManualControlSettings::CHANNELGROUPS_DSMFLEXIPORT:
|
2011-09-07 08:47:10 +02:00
|
|
|
count = 12;
|
|
|
|
break;
|
2011-09-11 21:04:03 +02:00
|
|
|
case ManualControlSettings::CHANNELGROUPS_SBUS:
|
|
|
|
count = 18;
|
|
|
|
break;
|
2011-09-07 08:47:10 +02:00
|
|
|
case ManualControlSettings::CHANNELGROUPS_GCS:
|
2012-03-10 03:00:00 +01:00
|
|
|
count = GCSReceiver::CHANNEL_NUMELEM;
|
2011-12-05 05:33:27 +01:00
|
|
|
break;
|
2011-09-07 08:47:10 +02:00
|
|
|
case ManualControlSettings::CHANNELGROUPS_NONE:
|
|
|
|
count = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_ASSERT(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
ui->channelNumberDropdown->addItem(QString(tr("Chan %1").arg(i+1)));
|
|
|
|
|
|
|
|
ui->channelNumber->setMaximum(count);
|
|
|
|
ui->channelNumber->setMinimum(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the dropdown from the hidden control
|
|
|
|
*/
|
|
|
|
void inputChannelForm::channelDropdownUpdated(int newval)
|
|
|
|
{
|
|
|
|
ui->channelNumber->setValue(newval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the hidden control from the dropdown
|
|
|
|
*/
|
|
|
|
void inputChannelForm::channelNumberUpdated(int newval)
|
|
|
|
{
|
|
|
|
ui->channelNumberDropdown->setCurrentIndex(newval);
|
|
|
|
}
|