From dc3b55771ff4148b1db13bb6e2b5a1c04404e66d Mon Sep 17 00:00:00 2001 From: Neil Horne Date: Thu, 14 Apr 2022 10:16:57 +1000 Subject: [PATCH] fix: cpn: custom curve edit default points and expand curve tab details column (#1815) --- companion/src/firmwares/curvedata.cpp | 17 +++---- companion/src/helpers.cpp | 8 ++++ companion/src/helpers.h | 1 + companion/src/modeledit/curves.cpp | 3 ++ companion/src/shared/curvedialog.cpp | 64 ++++++++++++++++----------- 5 files changed, 58 insertions(+), 35 deletions(-) diff --git a/companion/src/firmwares/curvedata.cpp b/companion/src/firmwares/curvedata.cpp index 006ce9f46..cd269f19e 100644 --- a/companion/src/firmwares/curvedata.cpp +++ b/companion/src/firmwares/curvedata.cpp @@ -36,18 +36,19 @@ void CurveData::clear(int count) void CurveData::init() { - float incr = 200.0 / ((float)count - 1.0); + memset(points, 0, sizeof(CurvePoint) * CPN_MAX_POINTS); - // points[0].x must be -100 - - for (int i = 0; i < count; i++) { - if (i < count - 1) - points[i].x = -100 + (int)(incr * i); - else - points[i].x = 100; // points[count - 1].x must be +100 do not risk a rounding issue using incr + float incr = 200.0 / (float)(count - 1); + for (int i = 1; i < (count - 1); i++) { + points[i].x = -100 + (int)(incr * (float)i); points[i].y = points[i].x; } + + points[0].x = -100; + points[0].y = -100; + points[count - 1].x = 100; + points[count - 1].y = 100; } bool CurveData::isEmpty() const diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index 7bab4efe2..e4701aea6 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -672,6 +672,14 @@ void TableLayout::pushColumnsLeft(int col) #endif } +void TableLayout::setColumnStretch(int col, int stretch) +{ +#if defined(TABLE_LAYOUT) +#else + gridWidget->setColumnStretch(col, stretch); +#endif +} + QString Helpers::getChecklistsPath() { return QDir::toNativeSeparators(g.profile[g.id()].sdPath() + "/MODELS/"); // TODO : add sub folder to constants diff --git a/companion/src/helpers.h b/companion/src/helpers.h index 312ba766a..fc3492546 100644 --- a/companion/src/helpers.h +++ b/companion/src/helpers.h @@ -196,6 +196,7 @@ public: void setColumnWidth(int col, QString str); void pushRowsUp(int row); void pushColumnsLeft(int col); + void setColumnStretch(int col, int stretch); private: #if defined(TABLE_LAYOUT) diff --git a/companion/src/modeledit/curves.cpp b/companion/src/modeledit/curves.cpp index bfa605ae3..d7a9068ea 100644 --- a/companion/src/modeledit/curves.cpp +++ b/companion/src/modeledit/curves.cpp @@ -62,6 +62,7 @@ CurvesPanel::CurvesPanel(QWidget * parent, ModelData & model, GeneralSettings & connect(image[i], &CurveImageWidget::doubleClicked, this, &CurvesPanel::on_curveImageDoubleClicked); tableLayout->addWidget(i, col++, image[i]); + tableLayout->setColumnStretch(col, 1); grp[i] = new QWidget(); // layouts are not hideable so use widget as parent for grid @@ -80,6 +81,8 @@ CurvesPanel::CurvesPanel(QWidget * parent, ModelData & model, GeneralSettings & numpoints[i] = new QLabel(); grid[i]->addWidget(numpoints[i], row, 1); points[i] = new QLabel(); + points[i]->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + points[i]->setWordWrap(true); grid[i]->addWidget(points[i], row++, 2, Qt::AlignLeft); grid[i]->addWidget(new QLabel(tr("Smooth:")), row, 0, Qt::AlignLeft); diff --git a/companion/src/shared/curvedialog.cpp b/companion/src/shared/curvedialog.cpp index 0bfecca3f..baecf5118 100644 --- a/companion/src/shared/curvedialog.cpp +++ b/companion/src/shared/curvedialog.cpp @@ -333,15 +333,19 @@ void CurveDialog::updateCurvePoints() for (int i = 0; i < count; i++) { spny[i]->show(); spny[i]->setValue(curve.points[i].y); + if (curve.type == CurveData::CURVE_TYPE_CUSTOM) { spnx[i]->show(); if (i == 0 || i == count - 1) { - spnx[i]->setDisabled(true); + spnx[i]->setDisabled(false); spnx[i]->setMaximum(+100); spnx[i]->setMinimum(-100); + spnx[i]->setDisabled(true); } else { spnx[i]->setDisabled(false); + spnx[i]->setMaximum(+100); + spnx[i]->setMinimum(-100); spnx[i]->setMaximum(curve.points[i + 1].x); spnx[i]->setMinimum(curve.points[i - 1].x); } @@ -432,7 +436,8 @@ void CurveDialog::on_curvePointsChanged(int index) if (allowCurveType(numpoints, curve.type)) { curve.count = numpoints; curve.init(); - update(); + updateCurve(); + updateCurvePoints(); } else { updateCurveType(); @@ -447,9 +452,9 @@ void CurveDialog::on_curveTypeChanged(int index) int numpoints = ui->curvePoints->itemData(ui->curvePoints->currentIndex()).toInt(); if (allowCurveType(numpoints, type)) { - //curve.clear(numpoints); curve.type = type; - //curve.init(); + curve.count = numpoints; + curve.init(); update(); } else { @@ -463,6 +468,7 @@ void CurveDialog::resizeEvent(QResizeEvent *event) QRect qr = ui->curvePreview->contentsRect(); ui->curvePreview->scene()->setSceneRect(GFX_MARGIN, GFX_MARGIN, qr.width() - GFX_MARGIN * 2, qr.height() - GFX_MARGIN * 2); updateCurve(); + updateCurvePoints(); } void CurveDialog::on_curveTemplateChanged(int index) @@ -539,37 +545,41 @@ void CurveDialog::onNodeDelete() curve.points[numpoints].x = 0; curve.points[numpoints].y = 0; curve.count = numpoints; - update(); + updateCurve(); + updateCurvePoints(); } } void CurveDialog::onSceneNewPoint(int x, int y) { - if ((curve.type == CurveData::CURVE_TYPE_CUSTOM) && (curve.count < CPN_MAX_POINTS)) { - int newidx = 0; - int numpoints = curve.count; - if (x < curve.points[0].x) { - newidx = 0; - } - else if (x > curve.points[numpoints - 1].x) { - newidx = numpoints; - } - else { - for (int i = 0; i < numpoints; i++) { - if (x < curve.points[i].x) { - newidx = i; - break; + if (!lock) { + if ((curve.type == CurveData::CURVE_TYPE_CUSTOM) && (curve.count < CPN_MAX_POINTS)) { + int newidx = 0; + int numpoints = curve.count; + if (x < curve.points[0].x) { + newidx = 0; + } + else if (x > curve.points[numpoints - 1].x) { + newidx = numpoints; + } + else { + for (int i = 0; i < numpoints; i++) { + if (x < curve.points[i].x) { + newidx = i; + break; + } } } + numpoints++; + curve.count = numpoints; + for (int idx = (numpoints - 1); idx > newidx; idx--) { + curve.points[idx] = curve.points[idx - 1]; + } + curve.points[newidx].x = x; + curve.points[newidx].y = y; + updateCurve(); + updateCurvePoints(); } - numpoints++; - curve.count = numpoints; - for (int idx = (numpoints - 1); idx > newidx; idx--) { - curve.points[idx] = curve.points[idx - 1]; - } - curve.points[newidx].x = x; - curve.points[newidx].y = y; - update(); } }