Fix doc path
[opentx.git] / companion / src / simulation / widgets / radiotrimwidget.h
blob54659b0a4b93593fc0888b3dc0cbf314259a7a3b
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef _RADIOTRIMWIDGET_H_
22 #define _RADIOTRIMWIDGET_H_
24 #include "radiowidget.h"
25 #include "boards.h"
26 #include "sliderwidget.h"
28 #include <QToolButton>
30 class RadioTrimWidget : public RadioWidget
32 Q_OBJECT
34 public:
36 explicit RadioTrimWidget(Qt::Orientation orientation = Qt::Vertical, QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()) :
37 RadioWidget(parent, f),
38 m_slider(NULL)
40 init(orientation);
43 void setIndices(int sliderIdx = -1, int decrBtnIdx = -1, int incrBtnIdx = -1)
45 setIndex(sliderIdx);
46 m_btnDecIndex = decrBtnIdx;
47 m_btnIncIndex = incrBtnIdx;
50 void setTrimRange(int min, int max)
52 if (m_slider)
53 m_slider->setRange(min, max);
56 void setTrimRangeQual(const int index, const int min, const int max)
58 if (index == m_index || index == Board::TRIM_AXIS_COUNT)
59 setTrimRange(min, max);
62 void setTrimValue(const int index, const int value)
64 if (index == m_index || index == Board::TRIM_AXIS_COUNT)
65 setValue(value);
68 void setValue(const int & value)
70 if (sender() && qobject_cast<SliderWidget *>(sender())) {
71 RadioWidget::setValue(value);
73 else if (m_slider) {
74 m_slider->setValue(value);
78 protected slots:
80 void init(Qt::Orientation orientation)
82 m_type = RADIO_WIDGET_TRIM;
83 m_slider = new SliderWidget(this);
84 m_slider->setOrientation(orientation);
86 setTrimRange(-125, 125);
87 setIndices();
89 const QSize btnSz(18, 18);
90 QWidget * trimWidget = new QWidget(this);
91 QBoxLayout * trimLayout = new QVBoxLayout(trimWidget);
92 trimLayout->setSpacing(4);
93 QToolButton * trimBtnInc = new QToolButton(trimWidget);
94 trimBtnInc->setMaximumSize(btnSz);
95 QToolButton * trimBtnDec = new QToolButton(trimWidget);
96 trimBtnDec->setMaximumSize(btnSz);
98 Qt::Alignment algn;
99 if (orientation == Qt::Horizontal) {
100 trimWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
101 trimLayout->setDirection(QBoxLayout::RightToLeft);
102 trimLayout->setContentsMargins(0, 8, 0, 8);
103 trimBtnInc->setArrowType(Qt::RightArrow);
104 trimBtnDec->setArrowType(Qt::LeftArrow);
105 algn = Qt::AlignVCenter;
107 else {
108 trimWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
109 trimLayout->setDirection(QBoxLayout::TopToBottom);
110 trimLayout->setContentsMargins(8, 0, 8, 0);
111 trimBtnInc->setArrowType(Qt::UpArrow);
112 trimBtnDec->setArrowType(Qt::DownArrow);
113 algn = Qt::AlignHCenter;
116 trimLayout->addWidget(trimBtnInc, 0, algn);
117 trimLayout->addWidget(m_slider, 1, algn);
118 trimLayout->addWidget(trimBtnDec, 0, algn);
120 setWidget(trimWidget, algn);
122 connect(m_slider, &SliderWidget::valueChanged, this, &RadioTrimWidget::setValue);
123 connect(trimBtnInc, &QToolButton::pressed, [this]() { emit valueChange(m_type, m_btnIncIndex, RADIO_TRIM_BTN_ON); });
124 connect(trimBtnInc, &QToolButton::released, [this]() { emit valueChange(m_type, m_btnIncIndex, RADIO_TRIM_BTN_OFF); });
125 connect(trimBtnDec, &QToolButton::pressed, [this]() { emit valueChange(m_type, m_btnDecIndex, RADIO_TRIM_BTN_ON); });
126 connect(trimBtnDec, &QToolButton::released, [this]() { emit valueChange(m_type, m_btnDecIndex, RADIO_TRIM_BTN_OFF); });
129 protected:
130 SliderWidget * m_slider;
131 int m_btnDecIndex;
132 int m_btnIncIndex;
135 #endif // _RADIOTRIMWIDGET_H_