fix: cpn: custom curve edit default points and expand curve tab details column (#1815)
This commit is contained in:
@@ -36,18 +36,19 @@ void CurveData::clear(int count)
|
|||||||
|
|
||||||
void CurveData::init()
|
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
|
float incr = 200.0 / (float)(count - 1);
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
for (int i = 1; i < (count - 1); i++) {
|
||||||
|
points[i].x = -100 + (int)(incr * (float)i);
|
||||||
points[i].y = points[i].x;
|
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
|
bool CurveData::isEmpty() const
|
||||||
|
|||||||
@@ -672,6 +672,14 @@ void TableLayout::pushColumnsLeft(int col)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TableLayout::setColumnStretch(int col, int stretch)
|
||||||
|
{
|
||||||
|
#if defined(TABLE_LAYOUT)
|
||||||
|
#else
|
||||||
|
gridWidget->setColumnStretch(col, stretch);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
QString Helpers::getChecklistsPath()
|
QString Helpers::getChecklistsPath()
|
||||||
{
|
{
|
||||||
return QDir::toNativeSeparators(g.profile[g.id()].sdPath() + "/MODELS/"); // TODO : add sub folder to constants
|
return QDir::toNativeSeparators(g.profile[g.id()].sdPath() + "/MODELS/"); // TODO : add sub folder to constants
|
||||||
|
|||||||
@@ -196,6 +196,7 @@ public:
|
|||||||
void setColumnWidth(int col, QString str);
|
void setColumnWidth(int col, QString str);
|
||||||
void pushRowsUp(int row);
|
void pushRowsUp(int row);
|
||||||
void pushColumnsLeft(int col);
|
void pushColumnsLeft(int col);
|
||||||
|
void setColumnStretch(int col, int stretch);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if defined(TABLE_LAYOUT)
|
#if defined(TABLE_LAYOUT)
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ CurvesPanel::CurvesPanel(QWidget * parent, ModelData & model, GeneralSettings &
|
|||||||
connect(image[i], &CurveImageWidget::doubleClicked, this, &CurvesPanel::on_curveImageDoubleClicked);
|
connect(image[i], &CurveImageWidget::doubleClicked, this, &CurvesPanel::on_curveImageDoubleClicked);
|
||||||
|
|
||||||
tableLayout->addWidget(i, col++, image[i]);
|
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
|
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();
|
numpoints[i] = new QLabel();
|
||||||
grid[i]->addWidget(numpoints[i], row, 1);
|
grid[i]->addWidget(numpoints[i], row, 1);
|
||||||
points[i] = new QLabel();
|
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(points[i], row++, 2, Qt::AlignLeft);
|
||||||
|
|
||||||
grid[i]->addWidget(new QLabel(tr("Smooth:")), row, 0, Qt::AlignLeft);
|
grid[i]->addWidget(new QLabel(tr("Smooth:")), row, 0, Qt::AlignLeft);
|
||||||
|
|||||||
@@ -333,15 +333,19 @@ void CurveDialog::updateCurvePoints()
|
|||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
spny[i]->show();
|
spny[i]->show();
|
||||||
spny[i]->setValue(curve.points[i].y);
|
spny[i]->setValue(curve.points[i].y);
|
||||||
|
|
||||||
if (curve.type == CurveData::CURVE_TYPE_CUSTOM) {
|
if (curve.type == CurveData::CURVE_TYPE_CUSTOM) {
|
||||||
spnx[i]->show();
|
spnx[i]->show();
|
||||||
if (i == 0 || i == count - 1) {
|
if (i == 0 || i == count - 1) {
|
||||||
spnx[i]->setDisabled(true);
|
spnx[i]->setDisabled(false);
|
||||||
spnx[i]->setMaximum(+100);
|
spnx[i]->setMaximum(+100);
|
||||||
spnx[i]->setMinimum(-100);
|
spnx[i]->setMinimum(-100);
|
||||||
|
spnx[i]->setDisabled(true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
spnx[i]->setDisabled(false);
|
spnx[i]->setDisabled(false);
|
||||||
|
spnx[i]->setMaximum(+100);
|
||||||
|
spnx[i]->setMinimum(-100);
|
||||||
spnx[i]->setMaximum(curve.points[i + 1].x);
|
spnx[i]->setMaximum(curve.points[i + 1].x);
|
||||||
spnx[i]->setMinimum(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)) {
|
if (allowCurveType(numpoints, curve.type)) {
|
||||||
curve.count = numpoints;
|
curve.count = numpoints;
|
||||||
curve.init();
|
curve.init();
|
||||||
update();
|
updateCurve();
|
||||||
|
updateCurvePoints();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
updateCurveType();
|
updateCurveType();
|
||||||
@@ -447,9 +452,9 @@ void CurveDialog::on_curveTypeChanged(int index)
|
|||||||
int numpoints = ui->curvePoints->itemData(ui->curvePoints->currentIndex()).toInt();
|
int numpoints = ui->curvePoints->itemData(ui->curvePoints->currentIndex()).toInt();
|
||||||
|
|
||||||
if (allowCurveType(numpoints, type)) {
|
if (allowCurveType(numpoints, type)) {
|
||||||
//curve.clear(numpoints);
|
|
||||||
curve.type = type;
|
curve.type = type;
|
||||||
//curve.init();
|
curve.count = numpoints;
|
||||||
|
curve.init();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -463,6 +468,7 @@ void CurveDialog::resizeEvent(QResizeEvent *event)
|
|||||||
QRect qr = ui->curvePreview->contentsRect();
|
QRect qr = ui->curvePreview->contentsRect();
|
||||||
ui->curvePreview->scene()->setSceneRect(GFX_MARGIN, GFX_MARGIN, qr.width() - GFX_MARGIN * 2, qr.height() - GFX_MARGIN * 2);
|
ui->curvePreview->scene()->setSceneRect(GFX_MARGIN, GFX_MARGIN, qr.width() - GFX_MARGIN * 2, qr.height() - GFX_MARGIN * 2);
|
||||||
updateCurve();
|
updateCurve();
|
||||||
|
updateCurvePoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CurveDialog::on_curveTemplateChanged(int index)
|
void CurveDialog::on_curveTemplateChanged(int index)
|
||||||
@@ -539,37 +545,41 @@ void CurveDialog::onNodeDelete()
|
|||||||
curve.points[numpoints].x = 0;
|
curve.points[numpoints].x = 0;
|
||||||
curve.points[numpoints].y = 0;
|
curve.points[numpoints].y = 0;
|
||||||
curve.count = numpoints;
|
curve.count = numpoints;
|
||||||
update();
|
updateCurve();
|
||||||
|
updateCurvePoints();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CurveDialog::onSceneNewPoint(int x, int y)
|
void CurveDialog::onSceneNewPoint(int x, int y)
|
||||||
{
|
{
|
||||||
if ((curve.type == CurveData::CURVE_TYPE_CUSTOM) && (curve.count < CPN_MAX_POINTS)) {
|
if (!lock) {
|
||||||
int newidx = 0;
|
if ((curve.type == CurveData::CURVE_TYPE_CUSTOM) && (curve.count < CPN_MAX_POINTS)) {
|
||||||
int numpoints = curve.count;
|
int newidx = 0;
|
||||||
if (x < curve.points[0].x) {
|
int numpoints = curve.count;
|
||||||
newidx = 0;
|
if (x < curve.points[0].x) {
|
||||||
}
|
newidx = 0;
|
||||||
else if (x > curve.points[numpoints - 1].x) {
|
}
|
||||||
newidx = numpoints;
|
else if (x > curve.points[numpoints - 1].x) {
|
||||||
}
|
newidx = numpoints;
|
||||||
else {
|
}
|
||||||
for (int i = 0; i < numpoints; i++) {
|
else {
|
||||||
if (x < curve.points[i].x) {
|
for (int i = 0; i < numpoints; i++) {
|
||||||
newidx = i;
|
if (x < curve.points[i].x) {
|
||||||
break;
|
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user