LP-311 Remove basic/advanced stabilization tab auto-switch (autotune/txpid lock issues)
[librepilot.git] / ground / gcs / src / plugins / config / inputchannelform.cpp
blob5a4f206221692292cc7ecb276db9a3e0b91d89a3
1 #include "inputchannelform.h"
2 #include "ui_inputchannelform.h"
4 #include "manualcontrolsettings.h"
5 #include "gcsreceiver.h"
7 InputChannelForm::InputChannelForm(const int index, QWidget *parent) :
8 ChannelForm(index, parent), ui(new Ui::InputChannelForm)
10 ui->setupUi(this);
12 connect(ui->channelMin, SIGNAL(valueChanged(int)), this, SLOT(minMaxUpdated()));
13 connect(ui->channelMax, SIGNAL(valueChanged(int)), this, SLOT(minMaxUpdated()));
14 connect(ui->neutralValue, SIGNAL(valueChanged(int)), this, SLOT(neutralUpdated()));
15 connect(ui->channelGroup, SIGNAL(currentIndexChanged(int)), this, SLOT(groupUpdated()));
16 connect(ui->channelRev, SIGNAL(toggled(bool)), this, SLOT(reversedUpdated()));
18 disableMouseWheelEvents();
21 InputChannelForm::~InputChannelForm()
23 delete ui;
26 QString InputChannelForm::name()
28 return ui->channelName->text();
31 /**
32 * Set the channel assignment label.
34 void InputChannelForm::setName(const QString &name)
36 ui->channelName->setText(name);
39 /**
40 * Update the direction of the slider and boundaries
42 void InputChannelForm::minMaxUpdated()
44 bool reverse = ui->channelMin->value() > ui->channelMax->value();
46 if (reverse) {
47 ui->channelNeutral->setMinimum(ui->channelMax->value());
48 ui->channelNeutral->setMaximum(ui->channelMin->value());
49 } else {
50 ui->channelNeutral->setMinimum(ui->channelMin->value());
51 ui->channelNeutral->setMaximum(ui->channelMax->value());
53 ui->channelRev->setChecked(reverse);
54 ui->channelNeutral->setInvertedAppearance(reverse);
55 ui->channelNeutral->setInvertedControls(reverse);
57 updateNeutralMark();
60 void InputChannelForm::neutralUpdated()
62 int neutralValue = ui->neutralValue->value();
64 if (ui->channelRev->isChecked()) {
65 if (neutralValue > ui->channelMin->value()) {
66 ui->channelMin->setValue(neutralValue);
67 } else if (neutralValue < ui->channelMax->value()) {
68 ui->channelMax->setValue(neutralValue);
70 } else {
71 if (neutralValue < ui->channelMin->value()) {
72 ui->channelMin->setValue(neutralValue);
73 } else if (neutralValue > ui->channelMax->value()) {
74 ui->channelMax->setValue(neutralValue);
78 updateNeutralMark();
81 void InputChannelForm::updateNeutralMark()
83 // Add a small neutral red mark on groove background
84 int neutral = ui->neutralValue->value();
85 int min = ui->channelMin->value();
86 int max = ui->channelMax->value();
88 float range = max - min;
89 float offset = neutral - min;
90 float neutralPosition = offset / range;
92 ui->channelNeutral->setStyleSheet(
93 "QSlider::groove:horizontal { border: 1px solid rgb(196, 196, 196); margin: 0px 23px 0px 23px; height: 6px; border-radius: 2px; "
94 "background: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:" + QString::number(neutralPosition - 0.01) + " transparent, stop:"
95 + QString::number(neutralPosition) + " red, stop:" + QString::number(neutralPosition + 0.01) + " transparent); }"
96 "QSlider::add-page:horizontal { background: rgba(255,255,255,120); border: 1px solid #777; margin: 0px 23px 0px 2px; border-radius: 4px; }"
97 "QSlider::sub-page:horizontal { background: rgba(78,147,246,120); border: 1px solid #777; margin: 0px 2px 0px 23px; border-radius: 4px; }"
99 "QSlider::handle:horizontal { background: qlineargradient(x1:0, y1:0, x2:1, y2:0, "
100 "stop: 0 rgba(196, 196, 196, 180), stop: 0.45 rgba(196, 196, 196, 180), "
101 "stop: 0.46 rgba(255,0,0,100), stop: 0.54 rgba(255,0,0,100), "
102 "stop: 0.55 rgba(196, 196, 196, 180), stop: 1 rgba(196, 196, 196, 180)); "
103 "width: 46px; height: 28px; margin: -6px -23px -6px -23px; border-radius: 6px; border: 1px solid #777; }"
107 void InputChannelForm::reversedUpdated()
109 int value = ui->channelNeutral->value();
110 int min = ui->channelMin->value();
111 int max = ui->channelMax->value();
113 if (ui->channelRev->isChecked()) {
114 if (min < max) {
115 ui->channelMax->setValue(min);
116 ui->channelMin->setValue(max);
117 ui->channelNeutral->setValue(value);
119 } else {
120 if (min > max) {
121 ui->channelMax->setValue(min);
122 ui->channelMin->setValue(max);
123 ui->channelNeutral->setValue(value);
129 * Update the channel options based on the selected receiver type
131 * I fully admit this is terrible practice to embed data within UI
132 * like this. Open to suggestions. JC 2011-09-07
134 void InputChannelForm::groupUpdated()
136 ui->channelNumber->clear();
137 ui->channelNumber->addItem("Disabled");
139 quint8 count = 0;
141 switch (ui->channelGroup->currentIndex()) {
142 case -1: // Nothing selected
143 count = 0;
144 break;
145 case ManualControlSettings::CHANNELGROUPS_PWM:
146 case ManualControlSettings::CHANNELGROUPS_OPLINK:
147 count = 8; // Need to make this 6 for CC
148 break;
149 case ManualControlSettings::CHANNELGROUPS_PPM:
150 case ManualControlSettings::CHANNELGROUPS_DSMMAINPORT:
151 case ManualControlSettings::CHANNELGROUPS_DSMFLEXIPORT:
152 count = 12;
153 break;
154 case ManualControlSettings::CHANNELGROUPS_SRXL:
155 case ManualControlSettings::CHANNELGROUPS_EXBUS:
156 count = 16;
157 break;
158 case ManualControlSettings::CHANNELGROUPS_SBUS:
159 count = 18;
160 break;
161 case ManualControlSettings::CHANNELGROUPS_HOTT:
162 count = 32;
163 break;
164 case ManualControlSettings::CHANNELGROUPS_GCS:
165 count = GCSReceiver::CHANNEL_NUMELEM;
166 break;
167 case ManualControlSettings::CHANNELGROUPS_NONE:
168 count = 0;
169 break;
170 default:
171 Q_ASSERT(0);
174 for (int i = 0; i < count; i++) {
175 ui->channelNumber->addItem(QString(tr("Chan %1").arg(i + 1)));