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
)
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()
26 QString
InputChannelForm::name()
28 return ui
->channelName
->text();
32 * Set the channel assignment label.
34 void InputChannelForm::setName(const QString
&name
)
36 ui
->channelName
->setText(name
);
40 * Update the direction of the slider and boundaries
42 void InputChannelForm::minMaxUpdated()
44 bool reverse
= ui
->channelMin
->value() > ui
->channelMax
->value();
47 ui
->channelNeutral
->setMinimum(ui
->channelMax
->value());
48 ui
->channelNeutral
->setMaximum(ui
->channelMin
->value());
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
);
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
);
71 if (neutralValue
< ui
->channelMin
->value()) {
72 ui
->channelMin
->setValue(neutralValue
);
73 } else if (neutralValue
> ui
->channelMax
->value()) {
74 ui
->channelMax
->setValue(neutralValue
);
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()) {
115 ui
->channelMax
->setValue(min
);
116 ui
->channelMin
->setValue(max
);
117 ui
->channelNeutral
->setValue(value
);
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");
141 switch (ui
->channelGroup
->currentIndex()) {
142 case -1: // Nothing selected
145 case ManualControlSettings::CHANNELGROUPS_PWM
:
146 case ManualControlSettings::CHANNELGROUPS_OPLINK
:
147 count
= 8; // Need to make this 6 for CC
149 case ManualControlSettings::CHANNELGROUPS_PPM
:
150 case ManualControlSettings::CHANNELGROUPS_DSMMAINPORT
:
151 case ManualControlSettings::CHANNELGROUPS_DSMFLEXIPORT
:
154 case ManualControlSettings::CHANNELGROUPS_SRXL
:
155 case ManualControlSettings::CHANNELGROUPS_EXBUS
:
158 case ManualControlSettings::CHANNELGROUPS_SBUS
:
161 case ManualControlSettings::CHANNELGROUPS_HOTT
:
164 case ManualControlSettings::CHANNELGROUPS_GCS
:
165 count
= GCSReceiver::CHANNEL_NUMELEM
;
167 case ManualControlSettings::CHANNELGROUPS_NONE
:
174 for (int i
= 0; i
< count
; i
++) {
175 ui
->channelNumber
->addItem(QString(tr("Chan %1").arg(i
+ 1)));