mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
Updated MixerCurveWidget so that it can have ranges other than 0 to 1.
Default behaviour not changed. New functions allow the setting of the max and min values for the curve. 0 to 1 range is needed when output is used for motors. -1 to 1 range is needed when output is used for a servo. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2060 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
7180c4fe2d
commit
0a2cfbacc7
@ -56,6 +56,11 @@ MixerCurveWidget::MixerCurveWidget(QWidget *parent) : QGraphicsView(parent)
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
curveMin=0.0;
|
||||
curveMax=1.0;
|
||||
|
||||
|
||||
|
||||
QGraphicsScene *scene = new QGraphicsScene(this);
|
||||
QSvgRenderer *renderer = new QSvgRenderer();
|
||||
plot = new QGraphicsSvgItem();
|
||||
@ -109,10 +114,12 @@ void MixerCurveWidget::initCurve(QList<double> points)
|
||||
scene()->addItem(node);
|
||||
nodeList.append(node);
|
||||
double val = points.at(i);
|
||||
if (val>1)
|
||||
val=1;
|
||||
if (val<0)
|
||||
val=0;
|
||||
if (val>curveMax)
|
||||
val=curveMax;
|
||||
if (val<curveMin)
|
||||
val=curveMin;
|
||||
val+=curveMin;
|
||||
val/=(curveMax-curveMin);
|
||||
node->setPos(w*i,h-val*h);
|
||||
node->verticalMove(true);
|
||||
}
|
||||
@ -133,7 +140,7 @@ QList<double> MixerCurveWidget::getCurve() {
|
||||
|
||||
qreal h = plot->boundingRect().height();
|
||||
foreach(Node *node, nodeList) {
|
||||
list.append((h-node->pos().y())/h);
|
||||
list.append(((curveMax-curveMin)*(h-node->pos().y())/h)+curveMin);
|
||||
}
|
||||
|
||||
return list;
|
||||
@ -154,10 +161,12 @@ void MixerCurveWidget::setCurve(QList<double> points)
|
||||
qreal h = plot->boundingRect().height();
|
||||
for (int i=0; i<points.length(); i++) {
|
||||
double val = points.at(i);
|
||||
if (val>1)
|
||||
val=1;
|
||||
if (val<0)
|
||||
val=0;
|
||||
if (val>curveMax)
|
||||
val=curveMax;
|
||||
if (val<curveMin)
|
||||
val=curveMin;
|
||||
val-=curveMin;
|
||||
val/=(curveMax-curveMin);
|
||||
nodeList.at(i)->setPos(w*i,h-val*h);
|
||||
}
|
||||
}
|
||||
@ -187,3 +196,17 @@ void MixerCurveWidget::itemMoved(double itemValue)
|
||||
QList<double> list = getCurve();
|
||||
emit curveUpdated(list, itemValue);
|
||||
}
|
||||
|
||||
void MixerCurveWidget::setMin(double value)
|
||||
{
|
||||
curveMin = value;
|
||||
}
|
||||
void MixerCurveWidget::setMax(double value)
|
||||
{
|
||||
curveMax = value;
|
||||
}
|
||||
void MixerCurveWidget::setRange(double min, double max)
|
||||
{
|
||||
curveMin = min;
|
||||
curveMax = max;
|
||||
}
|
||||
|
@ -46,6 +46,9 @@ public:
|
||||
void initCurve (QList<double> points);
|
||||
QList<double> getCurve();
|
||||
void setCurve(QList<double>);
|
||||
void setMin(double value);
|
||||
void setMax(double value);
|
||||
void setRange(double min, double max);
|
||||
|
||||
signals:
|
||||
void curveUpdated(QList<double>, double );
|
||||
@ -55,6 +58,8 @@ private slots:
|
||||
private:
|
||||
QGraphicsSvgItem *plot;
|
||||
QList<Node*> nodeList;
|
||||
double curveMin;
|
||||
double curveMax;
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event);
|
||||
|
Loading…
x
Reference in New Issue
Block a user