28 #include <QResizeEvent>
37 , m_mixerUI(new Ui::MixerCurvePlot)
39 m_mixerUI->setupUi(
this);
42 m_curve = m_mixerUI->CurveWidget;
43 m_settings = m_mixerUI->CurveSettings;
46 m_mixerUI->CBCurve2Source->hide();
48 m_mixerUI->SettingsGroup->hide();
68 connect(m_mixerUI->CurveType, QOverload<int>::of(&QComboBox::currentIndexChanged),
this,
69 &MixerCurve::CurveTypeChanged);
75 connect(m_settings, &QTableWidget::cellChanged,
this, &MixerCurve::SettingsTableChanged);
76 connect(m_mixerUI->CurveMin, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this,
77 &MixerCurve::CurveMinChanged);
78 connect(m_mixerUI->CurveMax, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this,
79 &MixerCurve::CurveMaxChanged);
80 connect(m_mixerUI->CurveStep, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this,
87 delete m_spinDelegate;
92 m_curveType = curveType;
94 m_mixerUI->CurveMin->setMaximum(1.0);
95 m_mixerUI->CurveMax->setMaximum(1.0);
97 switch (m_curveType) {
99 m_mixerUI->SettingsGroup->setTitle(
"Throttle Curve");
101 m_mixerUI->CurveMin->setMinimum(0.0);
102 m_mixerUI->CurveMax->setMinimum(0.0);
106 m_mixerUI->SettingsGroup->setTitle(
"Pitch Curve");
108 m_curve->setPositiveColor(
"#0000aa",
"#0000aa");
109 m_mixerUI->CurveMin->setMinimum(-1.0);
110 m_mixerUI->CurveMax->setMinimum(-1.0);
116 m_mixerUI->CBCurve2Source->show();
117 m_mixerUI->inputLabelCurve2Source->setText(
"Input:");
119 m_mixerUI->inputLabelCurve2Source->setText(
"Input: Throttle");
122 m_spinDelegate->
setRange(m_mixerUI->CurveMin->minimum(), m_mixerUI->CurveMax->maximum());
124 m_settings->setItemDelegateForRow(
i, m_spinDelegate);
132 m_mixerUI->CurveMin->setValue(m_mixerUI->CurveMin->minimum());
133 m_mixerUI->CurveMax->setValue(m_mixerUI->CurveMax->maximum());
134 m_mixerUI->CurveType->setCurrentIndex(m_mixerUI->CurveType->findText(
"Linear"));
147 m_mixerUI->SettingsGroup->show();
148 m_mixerUI->PopupCurve->hide();
153 m_mixerUI->SettingsGroup->hide();
154 m_mixerUI->PopupCurve->show();
158 void MixerCurve::UpdateCurveUI()
161 QString curveType = m_mixerUI->CurveType->currentText();
166 m_curve->
showCommand(
"StepPlus", cmdsActive && curveType !=
"Linear");
167 m_curve->
showCommand(
"StepMinus", cmdsActive && curveType !=
"Linear");
168 m_curve->
showCommand(
"StepValue", cmdsActive && curveType !=
"Linear");
170 m_mixerUI->CurveStep->setMinimum(0.0);
171 m_mixerUI->CurveStep->setMaximum(100.0);
172 m_mixerUI->CurveStep->setSingleStep(1.00);
175 m_mixerUI->minLabel->setVisible(
true);
176 m_mixerUI->CurveMin->setVisible(
true);
177 m_mixerUI->maxLabel->setVisible(
false);
178 m_mixerUI->CurveMax->setVisible(
false);
179 m_mixerUI->stepLabel->setVisible(
false);
180 m_mixerUI->CurveStep->setVisible(
false);
182 if (curveType.compare(
"Flat") == 0) {
183 m_mixerUI->minLabel->setVisible(
false);
184 m_mixerUI->CurveMin->setVisible(
false);
185 m_mixerUI->stepLabel->setVisible(
true);
186 m_mixerUI->CurveStep->setVisible(
true);
187 m_mixerUI->CurveStep->setMinimum(m_mixerUI->CurveMin->minimum());
188 m_mixerUI->CurveStep->setMaximum(m_mixerUI->CurveMax->maximum());
189 m_mixerUI->CurveStep->setSingleStep(0.01);
190 m_mixerUI->CurveStep->setValue(m_mixerUI->CurveMax->value() / 2);
192 if (curveType.compare(
"Linear") == 0) {
193 m_mixerUI->maxLabel->setVisible(
true);
194 m_mixerUI->CurveMax->setVisible(
true);
196 if (curveType.compare(
"Step") == 0) {
197 m_mixerUI->maxLabel->setVisible(
true);
198 m_mixerUI->CurveMax->setVisible(
true);
199 m_mixerUI->stepLabel->setText(
"Step at");
200 m_mixerUI->stepLabel->setVisible(
true);
201 m_mixerUI->CurveStep->setVisible(
true);
203 m_mixerUI->CurveStep->setMinimum(1.0);
205 if (curveType.compare(
"Exp") == 0) {
206 m_mixerUI->maxLabel->setVisible(
true);
207 m_mixerUI->CurveMax->setVisible(
true);
208 m_mixerUI->stepLabel->setText(
"Power");
209 m_mixerUI->stepLabel->setVisible(
true);
210 m_mixerUI->CurveStep->setVisible(
true);
212 m_mixerUI->CurveStep->setMinimum(1.0);
214 if (curveType.compare(
"Log") == 0) {
215 m_mixerUI->maxLabel->setVisible(
true);
216 m_mixerUI->CurveMax->setVisible(
true);
217 m_mixerUI->stepLabel->setText(
"Power");
218 m_mixerUI->stepLabel->setVisible(
true);
219 m_mixerUI->CurveStep->setVisible(
true);
220 m_mixerUI->CurveStep->setMinimum(1.0);
238 QString CurveType = m_mixerUI->CurveType->currentText();
243 scale = ((double)
i / (
double)(MixerCurveWidget::NODE_NUMELEM - 1));
245 if (CurveType.compare(
"Flat") == 0) {
246 points.append(value3);
248 if (CurveType.compare(
"Linear") == 0) {
249 newValue = value1 + (scale * (value2 - value1));
250 points.append(newValue);
252 if (CurveType.compare(
"Step") == 0) {
253 if (scale * 100 < value3) {
254 points.append(value1);
256 points.append(value2);
259 if (CurveType.compare(
"Exp") == 0) {
260 newValue = value1 + (((exp(scale * (value3 / 10)) - 1)) / (exp((value3 / 10)) - 1)
261 * (value2 - value1));
262 points.append(newValue);
264 if (CurveType.compare(
"Log") == 0) {
266 + (((log(scale * (value3 * 2) + 1)) / (log(1 + (value3 * 2)))) * (value2 - value1));
267 points.append(newValue);
294 m_spinDelegate->
setRange(minValue, maxValue);
304 m_mixerUI->CurveMin->setMinimum(value);
313 m_mixerUI->CurveMax->setMaximum(value);
326 return m_mixerUI->CurveMin->value();
330 return m_mixerUI->CurveMax->value();
335 return m_mixerUI->CurveStep->value();
341 int ptCnt = points.count();
343 for (
int i = 0;
i < ptCnt;
i++) {
344 QTableWidgetItem *item = m_settings->item(
i, 0);
346 item->setText(QString().sprintf(
"%.2f", points.at((ptCnt - 1) -
i)));
350 void MixerCurve::SettingsTableChanged()
354 for (
int i = 0;
i < m_settings->rowCount();
i++) {
355 QTableWidgetItem *item = m_settings->item(
i, 0);
358 points.push_front(item->text().toDouble());
361 m_mixerUI->CurveMin->setValue(points.first());
362 m_mixerUI->CurveMax->setValue(points.last());
367 void MixerCurve::CommandActivated(
MixerNode *node)
369 QString name = (node) ? node->getName() :
"Reset";
371 if (name ==
"Reset") {
374 }
else if (name ==
"Commands") {
376 }
else if (name ==
"Popup") {
378 }
else if (name ==
"Linear") {
379 m_mixerUI->CurveType->setCurrentIndex(m_mixerUI->CurveType->findText(
"Linear"));
380 }
else if (name ==
"Log") {
381 m_mixerUI->CurveType->setCurrentIndex(m_mixerUI->CurveType->findText(
"Log"));
382 }
else if (name ==
"Exp") {
383 m_mixerUI->CurveType->setCurrentIndex(m_mixerUI->CurveType->findText(
"Exp"));
384 }
else if (name ==
"Flat") {
385 m_mixerUI->CurveType->setCurrentIndex(m_mixerUI->CurveType->findText(
"Flat"));
386 }
else if (name ==
"Step") {
387 m_mixerUI->CurveType->setCurrentIndex(m_mixerUI->CurveType->findText(
"Step"));
388 }
else if (name ==
"MinPlus") {
389 m_mixerUI->CurveMin->stepUp();
390 }
else if (name ==
"MinMinus") {
391 m_mixerUI->CurveMin->stepDown();
392 }
else if (name ==
"MaxPlus") {
393 m_mixerUI->CurveMax->stepUp();
394 }
else if (name ==
"MaxMinus") {
395 m_mixerUI->CurveMax->stepDown();
396 }
else if (name ==
"StepPlus") {
397 m_mixerUI->CurveStep->stepUp();
399 }
else if (name ==
"StepMinus") {
400 m_mixerUI->CurveStep->stepDown();
407 void MixerCurve::CurveTypeChanged()
413 void MixerCurve::CurveMinChanged(
double value)
416 points.removeFirst();
417 points.push_front(value);
421 void MixerCurve::CurveMaxChanged(
double value)
427 points.append(value);
435 m_settings->resizeColumnsToContents();
436 m_settings->setColumnWidth(0, (m_settings->width() - m_settings->verticalHeader()->width()));
439 (m_settings->height() - m_settings->horizontalHeader()->height()) / m_settings->rowCount();
440 for (
int i = 0;
i < m_settings->rowCount();
i++)
441 m_settings->setRowHeight(
i, h);
448 m_settings->resizeColumnsToContents();
449 m_settings->setColumnWidth(0, (m_settings->width() - m_settings->verticalHeader()->width()));
452 (m_settings->height() - m_settings->horizontalHeader()->height()) / m_settings->rowCount();
453 for (
int i = 0;
i < m_settings->rowCount();
i++)
454 m_settings->setRowHeight(
i, h);
void setMin(double value)
void UpdateSettingsTable()
void initLinearCurve(int numPoints, double maxValue=1, double minValue=0)
void setMax(double value)
void showEvent(QShowEvent *event)
void initCurve(const QList< double > *points)
void setCurve(const QList< double > *points)
double setRange(double min, double max)
void resizeEvent(QResizeEvent *event)
QList< double > getCurve()
MixerCurve(QWidget *parent=nullptr)
void setRange(double min, double max)
void setMixerType(MixerCurveType curveType, bool isCurve1=true)