diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index 04d6b5ed3..dc1046582 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -12,7 +12,8 @@ QString getPhaseName(int val, char * phasename) phaseName.append(phasename); if (phaseName.isEmpty()) { return QString(val < 0 ? "!" : "") + QObject::tr("FM%1").arg(abs(val) - 1); - } else { + } + else { return QString(val < 0 ? "!" : "") + phaseName; } } diff --git a/companion/src/modeledit/curves.cpp b/companion/src/modeledit/curves.cpp index 612ca60d9..fe54f3d7d 100644 --- a/companion/src/modeledit/curves.cpp +++ b/companion/src/modeledit/curves.cpp @@ -8,8 +8,6 @@ #include #include -// TODO Capability CustomCurves to be removed - #define GFX_MARGIN 16 static const QColor colors[C9X_MAX_CURVES] = { @@ -76,9 +74,11 @@ Curves::Curves(QWidget * parent, ModelData & model): { ui->setupUi(this); + lock = true; + if (!GetEepromInterface()->getCapability(HasCvNames)) { - ui->cname_LE->hide(); - ui->cname_label->hide(); + ui->curveName->hide(); + ui->curveNameLabel->hide(); } QGraphicsScene *scene = new QGraphicsScene(ui->curvePreview); @@ -132,7 +132,20 @@ Curves::Curves(QWidget * parent, ModelData & model): spnx[i]->setAccelerated(true); connect(spnx[i], SIGNAL(valueChanged(int)), this, SLOT(onPointEdited())); ui->pointsLayout->addWidget(spnx[i], i, 1, 1, 1); + + bool insert; + if (GetEepromInterface()->getCapability(EnhancedCurves)) { + insert = (i >= 1); + } + else { + insert = (i==2 || i==4 || i==8 || i==16); + } + if (insert) { + ui->curvePoints->addItem(tr("%1 points").arg(i+1), i+1); + } } + + lock = false; } Curves::~Curves() @@ -173,7 +186,7 @@ void Curves::update() lock = true; if (GetEepromInterface()->getCapability(HasCvNames)) { - ui->cname_LE->setText(model.curves[currentCurve].name); + ui->curveName->setText(model.curves[currentCurve].name); } int count = model.curves[currentCurve].count; @@ -215,14 +228,27 @@ void Curves::setCurrentCurve(int index) void Curves::updateCurveType() { - int index = (model.curves[currentCurve].type == CurveData::CURVE_TYPE_CUSTOM ? 1 : 0); - if (model.curves[currentCurve].count==5) - index += 2; - else if (model.curves[currentCurve].count==9) - index += 4; - else if (model.curves[currentCurve].count==17) - index += 6; - ui->curvetype_CB->setCurrentIndex(index); + lock = true; + + int index = 0; + + if (GetEepromInterface()->getCapability(EnhancedCurves)) { + index = model.curves[currentCurve].count - 2; + } + else { + if (model.curves[currentCurve].count == 5) + index += 2; + else if (model.curves[currentCurve].count == 9) + index += 4; + else if (model.curves[currentCurve].count == 17) + index += 6; + } + + ui->curvePoints->setCurrentIndex(index); + ui->curveCustom->setCurrentIndex(model.curves[currentCurve].type); + ui->curveSmooth->setCurrentIndex(model.curves[currentCurve].smooth); + + lock = false; } void Curves::updateCurve() @@ -333,61 +359,83 @@ void Curves::onNodeUnfocus() updateCurve(); } -void Curves::on_curvetype_CB_currentIndexChanged(int index) +bool Curves::allowCurveType(int points, CurveData::CurveType type) { - static const int numpoint[] = {3,3,5,5,9,9,17,17}; - static const CurveData::CurveType types[] = {CurveData::CURVE_TYPE_STANDARD, CurveData::CURVE_TYPE_CUSTOM, CurveData::CURVE_TYPE_STANDARD, CurveData::CURVE_TYPE_CUSTOM, CurveData::CURVE_TYPE_STANDARD, CurveData::CURVE_TYPE_CUSTOM, CurveData::CURVE_TYPE_STANDARD, CurveData::CURVE_TYPE_CUSTOM}; + int numcurves = GetEepromInterface()->getCapability(NumCurves); - if (!lock) { - lock = true; + int totalpoints = 0; + for (int i=0; igetCapability(NumCurves); - // int currpoints = model.curves[currentCurve].count; - // bool currcustom = model.curves[currentCurve].custom; - - int totalpoints=0; - for (int i=0; igetCapability(NumCurvePoints); - if (fwpoints!=0) { - if (fwpoints < totalpoints) { - QMessageBox::warning(this, "companion", tr("Not enough free points in EEPROM to store the curve.")); - updateCurveType(); - lock = false; - return; - } - } - - model.curves[currentCurve].count = numpoint[index]; - model.curves[currentCurve].type = types[index]; - - // TODO something better! - for (int i=0; i= model.curves[currentCurve].count-1 ? +100 : -100 + (200*i)/(numpoint[index]-1)); - model.curves[currentCurve].points[i].y = 0; - } - - update(); - emit modified(); - lock = false; + int fwpoints = GetEepromInterface()->getCapability(NumCurvePoints); + if (totalpoints > fwpoints) { + QMessageBox::warning(this, "companion", tr("Not enough free points in EEPROM to store the curve.")); + return false; + } + else { + return true; } } -void Curves::on_cname_LE_editingFinished() +void Curves::on_curvePoints_currentIndexChanged(int index) +{ + if (!lock) { + int numpoints = ((QComboBox *)sender())->itemData(index).toInt(); + + if (allowCurveType(numpoints, model.curves[currentCurve].type)) { + model.curves[currentCurve].count = numpoints; + + // TODO something better + reuse! + for (int i=0; i= model.curves[currentCurve].count-1 ? +100 : -100 + (200*i)/(numpoints-1)); + model.curves[currentCurve].points[i].y = 0; + } + + update(); + emit modified(); + } + else { + updateCurveType(); + } + } +} + +void Curves::on_curveCustom_currentIndexChanged(int index) +{ + if (!lock) { + CurveData::CurveType type = (CurveData::CurveType)index; + int numpoints = ui->curvePoints->itemData(ui->curvePoints->currentIndex()).toInt(); + if (allowCurveType(model.curves[currentCurve].count, type)) { + model.curves[currentCurve].type = type; + + // TODO something better + reuse! + for (int i=0; i= model.curves[currentCurve].count-1 ? +100 : -100 + (200*i)/(numpoints-1)); + model.curves[currentCurve].points[i].y = 0; + } + + update(); + emit modified(); + } + else { + updateCurveType(); + } + } +} + +void Curves::on_curveSmooth_currentIndexChanged(int index) +{ + model.curves[currentCurve].smooth = index; + update(); +} + +void Curves::on_curveName_editingFinished() { memset(model.curves[currentCurve].name, 0, sizeof(model.curves[currentCurve].name)); - strcpy(model.curves[currentCurve].name, ui->cname_LE->text().toAscii()); + strcpy(model.curves[currentCurve].name, ui->curveName->text().toAscii()); emit modified(); } @@ -621,47 +669,11 @@ void ModelEdit::clearCurves(bool ask) currentCurve=0; curvesLock=false; ui->curvetype_CB->setCurrentIndex(2); - ui->cname_LE->clear(); + ui->curveName->clear(); updateSettings(); drawCurve(); } -void ModelEdit::setCurve(uint8_t c, int8_t ar[]) -{ - int len=sizeof(ar)/sizeof(int8_t); - if (GetEepromInterface()->getCapability(CustomCurves)) { - if (GetEepromInterface()->getCapability(NumCurves)>c) { - if (len<9) { - model.curves[c].count=5; - model.curves[c].custom=false; - for (int i=0; i< 5; i++) { - model.curves[c].points[i].y=ar[i]; - } - } else { - model.curves[c].count=5; - model.curves[c].custom=false; - for (int i=0; i< 5; i++) { - model.curves[c].points[i].y=ar[i]; - } - } - } - } else { - if (len<9) { - model.curves[c].count=5; - model.curves[c].custom=false; - for (int i=0; i< 5; i++) { - model.curves[c].points[i].y=ar[i]; - } - } else { - model.curves[c+8].count=5; - model.curves[c+8].custom=false; - for (int i=0; i< 5; i++) { - model.curves[c+8].points[i].y=ar[i]; - } - } - } -} - void ModelEdit::ControlCurveSignal(bool flag) { foreach(QSpinBox *sb, findChildren(QRegExp("curvePt[0-9]+"))) { diff --git a/companion/src/modeledit/curves.h b/companion/src/modeledit/curves.h index a1086dde0..e8915cf65 100644 --- a/companion/src/modeledit/curves.h +++ b/companion/src/modeledit/curves.h @@ -22,8 +22,10 @@ class Curves : public ModelPanel void resetCurve(); void editCurve(); void plotCurve(bool checked); - void on_cname_LE_editingFinished(); - void on_curvetype_CB_currentIndexChanged(int index); + void on_curveName_editingFinished(); + void on_curvePoints_currentIndexChanged(int index); + void on_curveCustom_currentIndexChanged(int index); + void on_curveSmooth_currentIndexChanged(int index); void onPointEdited(); void onNodeMoved(int x, int y); void onNodeFocus(); @@ -41,6 +43,7 @@ class Curves : public ModelPanel void setCurrentCurve(int index); void updateCurve(); void updateCurveType(); + bool allowCurveType(int points, CurveData::CurveType type); }; diff --git a/companion/src/modeledit/curves.ui b/companion/src/modeledit/curves.ui index 17ad1d39a..ed9800e89 100644 --- a/companion/src/modeledit/curves.ui +++ b/companion/src/modeledit/curves.ui @@ -20,9 +20,47 @@ - + + + + + 0 + + + + + + + + + Standard + + + + + Custom + + + + + + + + + Lines + + + + + Smooth + + + + + + - + Curve type @@ -31,52 +69,8 @@ - - - - - 3 points - - - - - 3 points custom - - - - - 5 points - - - - - 5 points custom - - - - - 9 points - - - - - 9 points custom - - - - - 17 points - - - - - 17 points custom - - - - - + Curve name @@ -86,7 +80,7 @@ - + 6 @@ -129,7 +123,7 @@ - + Qt::Vertical diff --git a/companion/src/modeledit/templates.cpp b/companion/src/modeledit/templates.cpp index c45b920bf..6bfb52247 100644 --- a/companion/src/modeledit/templates.cpp +++ b/companion/src/modeledit/templates.cpp @@ -2,6 +2,28 @@ #include #include +void ModelEdit::setCurve(uint8_t c, int8_t ar[]) +{ + int len=sizeof(ar)/sizeof(int8_t); + + if (GetEepromInterface()->getCapability(NumCurves)>c) { + if (len<9) { + model.curves[c].count=5; + model.curves[c].custom=false; + for (int i=0; i< 5; i++) { + model.curves[c].points[i].y=ar[i]; + } + } + else { + model.curves[c].count=5; + model.curves[c].custom=false; + for (int i=0; i< 5; i++) { + model.curves[c].points[i].y=ar[i]; + } + } + } +} + Templates::Templates(QWidget * parent, ModelData & model): QWidget(parent), model(model)