1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-03-15 07:29:15 +01:00

MixerCurveWidget: make Node smarter by storing a value whenever pos changes;

getCurve now reports back the list of node->getValue()
This commit is contained in:
Mike LaBranche 2012-06-19 16:51:22 -07:00
parent 9da2ffff2f
commit 02cdc6feff
4 changed files with 38 additions and 5 deletions

View File

@ -43,6 +43,7 @@ Node::Node(MixerCurveWidget *graphWidget)
setCacheMode(DeviceCoordinateCache);
setZValue(-1);
vertical = false;
value = 0;
}
void Node::addEdge(Edge *edge)
@ -98,6 +99,15 @@ void Node::verticalMove(bool flag){
vertical = flag;
}
double Node::getValue() {
return value;
}
void Node::setValue(double val) {
value = val;
}
QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
{
@ -117,11 +127,19 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
newPos.setY(h);
return newPos;
}
case ItemPositionHasChanged:
case ItemPositionHasChanged: {
foreach (Edge *edge, edgeList)
edge->adjust();
graph->itemMoved((h-newPos.y())/h);
double min = graph->getMin();
double range = graph->getMax() - min;
double ratio = (h - newPos.y()) / h;
double val = (range * ratio ) + min;
setValue(val);
graph->itemMoved(val);
break;
}
default:
break;
};

View File

@ -48,12 +48,16 @@ public:
enum { Type = UserType + 1 };
int type() const { return Type; }
void verticalMove(bool flag);
QRectF boundingRect() const;
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void setValue(double val);
double getValue();
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
@ -61,6 +65,8 @@ protected:
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
private:
double value;
QList<Edge *> edgeList;
QPointF newPos;
MixerCurveWidget *graph;

View File

@ -175,12 +175,11 @@ void MixerCurveWidget::initNodes(int numPoints)
Returns the current curve settings
*/
QList<double> MixerCurveWidget::getCurve() {
QList<double> list;
qreal h = plot->boundingRect().height();
foreach(Node *node, nodeList) {
double val = ((curveMax-curveMin)*(h-node->pos().y())/h)+curveMin;
list.append(val);
list.append(node->getValue());
}
return list;
@ -271,6 +270,14 @@ void MixerCurveWidget::setMax(double value)
{
curveMax = value;
}
double MixerCurveWidget::getMin()
{
return curveMin;
}
double MixerCurveWidget::getMax()
{
return curveMax;
}
void MixerCurveWidget::setRange(double min, double max)
{
curveMin = min;

View File

@ -49,7 +49,9 @@ public:
void initLinearCurve(quint32 numPoints, double maxValue = 1, double minValue = 0);
void setCurve(QList<double>);
void setMin(double value);
double getMin();
void setMax(double value);
double getMax();
void setRange(double min, double max);
static const int NODE_NUMELEM = 5;