33 #include "actuatorsettings.h"
39 , m_inChannelTest(false)
46 ActuatorSettings *actuatorSettings = ActuatorSettings::GetInstance(
getObjectManager());
47 Q_ASSERT(actuatorSettings);
51 QGridLayout *grid_layout =
dynamic_cast<QGridLayout *
>(layout());
52 Q_ASSERT(grid_layout);
53 for (
int col = 0; col < grid_layout->columnCount();
55 QLayoutItem *item = grid_layout->itemAtPosition(0, col);
59 QWidget *legend_widget = item->widget();
63 grid_layout->removeWidget(legend_widget);
69 ui.actuatorNumber->setText(QString(
"%1:").arg(m_index + 1));
72 connect(ui.actuatorMin, &QAbstractSpinBox::editingFinished,
this,
73 &OutputChannelForm::setChannelRange);
74 connect(ui.actuatorMax, &QAbstractSpinBox::editingFinished,
this,
75 &OutputChannelForm::setChannelRange);
76 connect(ui.pb_reverseActuator, &QAbstractButton::clicked,
this,
77 &OutputChannelForm::reverseChannel);
80 connect(ui.actuatorNeutral, &QAbstractSlider::valueChanged,
this,
81 &OutputChannelForm::sendChannelTest);
84 connect(ui.actuatorMin, QOverload<int>::of(&QSpinBox::valueChanged),
this,
85 &OutputChannelForm::notifyFormChanged);
86 connect(ui.actuatorMax, QOverload<int>::of(&QSpinBox::valueChanged),
this,
87 &OutputChannelForm::notifyFormChanged);
88 connect(ui.actuatorNeutral, &QAbstractSlider::sliderReleased,
this,
89 &OutputChannelForm::notifyFormChanged);
90 ui.actuatorLink->setChecked(
false);
91 connect(ui.actuatorLink, &QAbstractButton::toggled,
this, &OutputChannelForm::linkToggled);
106 if (m_inChannelTest == state)
108 m_inChannelTest = state;
110 if (m_inChannelTest) {
113 ui.actuatorMin->setEnabled(
false);
114 ui.actuatorMax->setEnabled(
false);
115 ui.pb_reverseActuator->setEnabled(
false);
117 ui.actuatorMin->setEnabled(!minMaxFixed);
118 ui.actuatorMax->setEnabled(!minMaxFixed);
119 ui.pb_reverseActuator->setEnabled(!minMaxFixed);
126 void OutputChannelForm::linkToggled(
bool state)
130 if (!m_inChannelTest)
137 int linked_count = 0;
140 foreach (OutputChannelForm *outputChannelForm, outputChannelForms) {
141 if (!outputChannelForm->ui.actuatorLink->checkState())
143 if (
this == outputChannelForm)
145 int value = outputChannelForm->ui.actuatorNeutral->value();
151 if (linked_count <= 0)
155 foreach (OutputChannelForm *outputChannelForm, outputChannelForms) {
156 if (!outputChannelForm->ui.actuatorLink->checkState())
158 outputChannelForm->ui.actuatorNeutral->setValue(min);
167 setMinmax(ui.actuatorMin->value(), maximum);
175 setMinmax(minimum, ui.actuatorMax->value());
183 inhibitRangeChanges =
true;
186 ui.actuatorMin->setValue(limitMin);
187 ui.actuatorMax->setValue(limitMax);
189 ui.actuatorMin->setValue(minimum);
190 ui.actuatorMax->setValue(maximum);
193 inhibitRangeChanges =
false;
203 ui.actuatorNeutral->setValue(value);
206 void OutputChannelForm::alignFields()
208 int actuatorWidth = 0;
210 foreach (OutputChannelForm *form, parent()->findChildren<OutputChannelForm *>()) {
211 actuatorWidth = fmax(actuatorWidth, form->ui.actuatorMin->minimumSize().width());
212 actuatorWidth = fmax(actuatorWidth, form->ui.actuatorMin->sizeHint().width());
213 actuatorWidth = fmax(actuatorWidth, form->ui.actuatorMax->minimumSize().width());
214 actuatorWidth = fmax(actuatorWidth, form->ui.actuatorMax->sizeHint().width());
217 foreach (OutputChannelForm *form, parent()->findChildren<OutputChannelForm *>()) {
218 form->ui.actuatorMin->setMinimumSize(actuatorWidth, 0);
219 form->ui.actuatorMax->setMinimumSize(actuatorWidth, 0);
228 ui.actuatorName->setText(assignment);
229 QFontMetrics metrics(ui.actuatorName->font());
230 int width = metrics.width(assignment) + 1;
231 foreach (OutputChannelForm *form, parent()->findChildren<OutputChannelForm *>()) {
234 if (form->ui.actuatorName->minimumSize().width() < width)
235 form->ui.actuatorName->setMinimumSize(width, 0);
237 width = form->ui.actuatorName->minimumSize().width();
239 ui.actuatorName->setMinimumSize(width, 0);
249 void OutputChannelForm::setChannelRange()
251 if (inhibitRangeChanges) {
256 ui.actuatorNeutral->setRange(limitMin, limitMax);
257 ui.actuatorNeutral->setEnabled(
true);
258 }
else if (ui.actuatorMin->value() < ui.actuatorMax->value()) {
259 ui.actuatorNeutral->setRange(ui.actuatorMin->value(), ui.actuatorMax->value());
260 ui.actuatorNeutral->setEnabled(
true);
261 }
else if (ui.actuatorMin->value() > ui.actuatorMax->value()) {
262 ui.actuatorNeutral->setRange(ui.actuatorMax->value(), ui.actuatorMin->value());
263 ui.actuatorNeutral->setEnabled(
true);
267 ui.actuatorNeutral->setRange(ui.actuatorMin->value() - 1, ui.actuatorMin->value() + 1);
268 ui.actuatorNeutral->setEnabled(
false);
279 void OutputChannelForm::reverseChannel()
282 if (!ui.actuatorMin->isEnabled() || !ui.actuatorMax->isEnabled())
286 setMinmax(ui.actuatorMax->value(), ui.actuatorMin->value());
297 void OutputChannelForm::updateSlider()
300 if (ui.actuatorMin->value() > ui.actuatorMax->value()) {
301 ui.actuatorNeutral->setInvertedAppearance(
true);
304 ui.actuatorNeutral->setProperty(
"state",
"inverted");
306 ui.actuatorNeutral->setInvertedAppearance(
false);
309 ui.actuatorNeutral->setProperty(
"state",
"normal");
313 ui.actuatorNeutral->setStyle(QApplication::style());
320 void OutputChannelForm::sendChannelTest(
int value)
322 int in_value = value;
324 QSlider *ob =
dynamic_cast<QSlider *
>(QObject::sender());
328 if (ui.actuatorLink->checkState() && parent()) {
330 parent()->findChildren<OutputChannelForm *>();
332 foreach (OutputChannelForm *outputChannelForm, outputChannelForms) {
333 if (
this == outputChannelForm)
335 if (!outputChannelForm->ui.actuatorLink->checkState())
339 if (val < outputChannelForm->ui.actuatorNeutral->minimum())
340 val = outputChannelForm->ui.actuatorNeutral->minimum();
341 if (val > outputChannelForm->ui.actuatorNeutral->maximum())
342 val = outputChannelForm->ui.actuatorNeutral->maximum();
344 if (outputChannelForm->ui.actuatorNeutral->value() == val)
347 outputChannelForm->ui.actuatorNeutral->setValue(val);
351 if (!m_inChannelTest)
360 void OutputChannelForm::notifyFormChanged()
363 if (!m_inChannelTest) {
374 minMaxFixed = digitalProtocol;
376 if (digitalProtocol) {
379 ui.actuatorMin->setRange(0, 0);
380 ui.actuatorMax->setRange(limitMax, limitMax);
382 ui.actuatorMin->setRange(limitMin, limitMax);
383 ui.actuatorMax->setRange(limitMin, limitMax);
386 ui.actuatorMin->setEnabled(!minMaxFixed && !m_inChannelTest);
387 ui.actuatorMax->setEnabled(!minMaxFixed && !m_inChannelTest);
388 ui.pb_reverseActuator->setEnabled(!minMaxFixed && !m_inChannelTest);
void channelChanged(int index, int value)
void setMinmax(int minimum, int maximum)
void setAssignment(const QString &assignment)
void enableChannelTest(bool state)
void updateChannelLimits(int minPulse, int maxPulse, bool digitalProtocol=false)
OutputChannelForm(const int index, QWidget *parent=NULL, const bool showLegend=false)
void setNeutral(int value)