2011-08-04 16:58:41 +01:00
|
|
|
#include "inputchannelform.h"
|
|
|
|
#include "ui_inputchannelform.h"
|
|
|
|
|
2011-09-07 01:47:10 -05:00
|
|
|
#include "manualcontrolsettings.h"
|
2012-03-10 06:00:00 +04:00
|
|
|
#include "gcsreceiver.h"
|
2011-09-07 01:47:10 -05:00
|
|
|
|
2014-05-12 22:30:50 +02:00
|
|
|
InputChannelForm::InputChannelForm(const int index, QWidget *parent) :
|
|
|
|
ChannelForm(index, parent), ui(new Ui::InputChannelForm)
|
2011-08-04 16:58:41 +01:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2013-05-05 12:45:35 +02:00
|
|
|
|
2014-05-10 20:40:14 +02:00
|
|
|
connect(ui->channelMin, SIGNAL(valueChanged(int)), this, SLOT(minMaxUpdated()));
|
|
|
|
connect(ui->channelMax, SIGNAL(valueChanged(int)), this, SLOT(minMaxUpdated()));
|
|
|
|
connect(ui->neutralValue, SIGNAL(valueChanged(int)), this, SLOT(neutralUpdated()));
|
2014-12-27 08:09:59 +01:00
|
|
|
connect(ui->channelNeutral, SIGNAL(valueChanged(int)), this, SLOT(updateTooltip()));
|
2014-05-10 20:40:14 +02:00
|
|
|
connect(ui->channelGroup, SIGNAL(currentIndexChanged(int)), this, SLOT(groupUpdated()));
|
|
|
|
connect(ui->channelRev, SIGNAL(toggled(bool)), this, SLOT(reversedUpdated()));
|
|
|
|
|
|
|
|
disableMouseWheelEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
InputChannelForm::~InputChannelForm()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2014-05-12 22:30:50 +02:00
|
|
|
QString InputChannelForm::name()
|
2014-05-10 20:40:14 +02:00
|
|
|
{
|
2014-05-12 22:30:50 +02:00
|
|
|
return ui->channelName->text();
|
2011-08-04 16:58:41 +01:00
|
|
|
}
|
2012-04-19 13:00:20 -04:00
|
|
|
|
2014-05-12 22:30:50 +02:00
|
|
|
/**
|
|
|
|
* Set the channel assignment label.
|
|
|
|
*/
|
|
|
|
void InputChannelForm::setName(const QString &name)
|
2012-02-18 20:37:30 +00:00
|
|
|
{
|
|
|
|
ui->channelName->setText(name);
|
|
|
|
}
|
2011-09-07 01:47:10 -05:00
|
|
|
|
2011-09-09 00:54:47 -05:00
|
|
|
/**
|
2013-05-05 12:45:35 +02:00
|
|
|
* Update the direction of the slider and boundaries
|
|
|
|
*/
|
2014-01-21 00:06:20 +01:00
|
|
|
void InputChannelForm::minMaxUpdated()
|
2011-09-07 01:47:10 -05:00
|
|
|
{
|
2011-09-09 00:54:47 -05:00
|
|
|
bool reverse = ui->channelMin->value() > ui->channelMax->value();
|
2013-05-05 12:45:35 +02:00
|
|
|
|
|
|
|
if (reverse) {
|
2011-09-09 00:54:47 -05:00
|
|
|
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);
|
2014-12-27 08:09:59 +01:00
|
|
|
|
|
|
|
updateNeutralMark();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputChannelForm::updateTooltip()
|
|
|
|
{
|
|
|
|
int currentValue = ui->channelNeutral->value();
|
2014-12-29 01:07:11 +01:00
|
|
|
|
2014-12-27 08:09:59 +01:00
|
|
|
ui->channelNeutral->setToolTip(QString::number(currentValue));
|
2011-09-07 01:47:10 -05:00
|
|
|
}
|
|
|
|
|
2014-01-21 00:49:46 +01:00
|
|
|
void InputChannelForm::neutralUpdated()
|
2011-09-07 01:47:10 -05:00
|
|
|
{
|
2014-01-21 00:49:46 +01:00
|
|
|
int neutralValue = ui->neutralValue->value();
|
2014-01-22 18:30:30 +01:00
|
|
|
|
|
|
|
if (ui->channelRev->isChecked()) {
|
|
|
|
if (neutralValue > ui->channelMin->value()) {
|
2014-01-21 00:49:46 +01:00
|
|
|
ui->channelMin->setValue(neutralValue);
|
2014-01-22 18:30:30 +01:00
|
|
|
} else if (neutralValue < ui->channelMax->value()) {
|
2014-01-21 00:49:46 +01:00
|
|
|
ui->channelMax->setValue(neutralValue);
|
|
|
|
}
|
|
|
|
} else {
|
2014-01-22 18:30:30 +01:00
|
|
|
if (neutralValue < ui->channelMin->value()) {
|
2014-01-21 00:49:46 +01:00
|
|
|
ui->channelMin->setValue(neutralValue);
|
2014-01-22 18:30:30 +01:00
|
|
|
} else if (neutralValue > ui->channelMax->value()) {
|
2014-01-21 00:49:46 +01:00
|
|
|
ui->channelMax->setValue(neutralValue);
|
|
|
|
}
|
|
|
|
}
|
2014-12-27 08:09:59 +01:00
|
|
|
|
|
|
|
updateNeutralMark();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputChannelForm::updateNeutralMark()
|
|
|
|
{
|
|
|
|
// Add a small neutral red mark on groove background
|
|
|
|
int neutral = ui->neutralValue->value();
|
|
|
|
int min = ui->channelMin->value();
|
|
|
|
int max = ui->channelMax->value();
|
|
|
|
|
|
|
|
float range = max - min;
|
|
|
|
float offset = neutral - min;
|
|
|
|
float neutralPosition = offset / range;
|
|
|
|
|
|
|
|
ui->channelNeutral->setStyleSheet(
|
|
|
|
"QSlider::groove:horizontal { border: 1px solid rgb(196, 196, 196); height: 6px; border-radius: 2px; margin 10px 10px; "
|
|
|
|
"background: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:" + QString::number(neutralPosition - 0.01) + " transparent, stop:"
|
|
|
|
+ QString::number(neutralPosition) + " red, stop:" + QString::number(neutralPosition + 0.01) + " transparent); }"
|
|
|
|
"QSlider::add-page:horizontal { background: rgba(255,255,255,180); border: 1px solid #777; margin: 0px 2px; border-radius: 4px; }"
|
|
|
|
"QSlider::sub-page:horizontal { background: rgba(78,147,246,180); border: 1px solid #777; margin: 0px 2px; border-radius: 4px; }"
|
|
|
|
"QSlider::handle:horizontal { background: rgba(196,196,196,180); width: 18px; height: 28px; margin: -2px 0px; border-radius: 3px; "
|
|
|
|
"border: 1px solid #777; }"
|
|
|
|
);
|
2014-01-21 00:49:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputChannelForm::reversedUpdated()
|
|
|
|
{
|
|
|
|
int value = ui->channelNeutral->value();
|
2014-01-22 18:30:30 +01:00
|
|
|
int min = ui->channelMin->value();
|
|
|
|
int max = ui->channelMax->value();
|
2014-01-21 00:49:46 +01:00
|
|
|
|
2014-01-22 18:30:30 +01:00
|
|
|
if (ui->channelRev->isChecked()) {
|
|
|
|
if (min < max) {
|
2014-01-21 00:49:46 +01:00
|
|
|
ui->channelMax->setValue(min);
|
|
|
|
ui->channelMin->setValue(max);
|
|
|
|
ui->channelNeutral->setValue(value);
|
|
|
|
}
|
|
|
|
} else {
|
2014-01-22 18:30:30 +01:00
|
|
|
if (min > max) {
|
2014-01-21 00:49:46 +01:00
|
|
|
ui->channelMax->setValue(min);
|
|
|
|
ui->channelMin->setValue(max);
|
|
|
|
ui->channelNeutral->setValue(value);
|
|
|
|
}
|
|
|
|
}
|
2011-09-07 01:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-05 12:45:35 +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
|
|
|
|
*/
|
2014-01-21 00:06:20 +01:00
|
|
|
void InputChannelForm::groupUpdated()
|
2011-09-07 01:47:10 -05:00
|
|
|
{
|
2014-05-10 20:40:14 +02:00
|
|
|
ui->channelNumber->clear();
|
|
|
|
ui->channelNumber->addItem("Disabled");
|
2011-09-07 01:47:10 -05:00
|
|
|
|
|
|
|
quint8 count = 0;
|
|
|
|
|
2013-05-05 12:45:35 +02:00
|
|
|
switch (ui->channelGroup->currentIndex()) {
|
2011-09-07 01:47:10 -05:00
|
|
|
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:
|
2012-12-13 21:07:19 -07:00
|
|
|
case ManualControlSettings::CHANNELGROUPS_OPLINK:
|
2011-10-30 19:29:03 +02:00
|
|
|
case ManualControlSettings::CHANNELGROUPS_DSMMAINPORT:
|
|
|
|
case ManualControlSettings::CHANNELGROUPS_DSMFLEXIPORT:
|
2011-09-07 01:47:10 -05:00
|
|
|
count = 12;
|
|
|
|
break;
|
2011-09-11 22:04:03 +03:00
|
|
|
case ManualControlSettings::CHANNELGROUPS_SBUS:
|
|
|
|
count = 18;
|
|
|
|
break;
|
2011-09-07 01:47:10 -05:00
|
|
|
case ManualControlSettings::CHANNELGROUPS_GCS:
|
2012-03-10 06:00:00 +04:00
|
|
|
count = GCSReceiver::CHANNEL_NUMELEM;
|
2011-12-04 22:33:27 -06:00
|
|
|
break;
|
2011-09-07 01:47:10 -05:00
|
|
|
case ManualControlSettings::CHANNELGROUPS_NONE:
|
|
|
|
count = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_ASSERT(0);
|
|
|
|
}
|
|
|
|
|
2013-05-05 12:45:35 +02:00
|
|
|
for (int i = 0; i < count; i++) {
|
2014-05-10 20:40:14 +02:00
|
|
|
ui->channelNumber->addItem(QString(tr("Chan %1").arg(i + 1)));
|
2013-05-05 12:45:35 +02:00
|
|
|
}
|
2011-09-07 01:47:10 -05:00
|
|
|
}
|