From be7ff7049105a4a1e669b22b0b5872db0b69a8a9 Mon Sep 17 00:00:00 2001 From: edouard Date: Sun, 19 Sep 2010 05:47:18 +0000 Subject: [PATCH] OP-160 Small progress on the widget, points move vertically only now. Next commit will be fully functional. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1685 ebee16cc-31ac-478f-84a7-5cbb03baadba --- ground/src/plugins/config/mixercurveline.cpp | 4 +++- ground/src/plugins/config/mixercurvepoint.cpp | 14 ++++++++++++++ ground/src/plugins/config/mixercurvepoint.h | 2 ++ .../src/plugins/config/mixercurvewidget.cpp | 19 ++++++++++++------- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/ground/src/plugins/config/mixercurveline.cpp b/ground/src/plugins/config/mixercurveline.cpp index d3ace9220..03daf08ae 100644 --- a/ground/src/plugins/config/mixercurveline.cpp +++ b/ground/src/plugins/config/mixercurveline.cpp @@ -120,6 +120,7 @@ void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) painter->drawLine(line); // Draw the arrows +/* double angle = ::acos(line.dx() / line.length()); if (line.dy() >= 0) angle = TwoPi - angle; @@ -135,5 +136,6 @@ void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) painter->setBrush(Qt::black); painter->drawPolygon(QPolygonF() << line.p1() << sourceArrowP1 << sourceArrowP2); - painter->drawPolygon(QPolygonF() << line.p2() << destArrowP1 << destArrowP2); + painter->drawPolygon(QPolygonF() << line.p2() << destArrowP1 << destArrowP2); + */ } diff --git a/ground/src/plugins/config/mixercurvepoint.cpp b/ground/src/plugins/config/mixercurvepoint.cpp index 127f2d825..7f10ed288 100644 --- a/ground/src/plugins/config/mixercurvepoint.cpp +++ b/ground/src/plugins/config/mixercurvepoint.cpp @@ -42,6 +42,7 @@ Node::Node(MixerCurveWidget *graphWidget) setFlag(ItemSendsGeometryChanges); setCacheMode(DeviceCoordinateCache); setZValue(-1); + vertical = false; } void Node::addEdge(Edge *edge) @@ -145,9 +146,22 @@ void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid painter->drawEllipse(-10, -10, 20, 20); } +void Node::verticalMove(bool flag){ + vertical = flag; +} + QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value) { + switch (change) { + case ItemPositionChange: { + if (!vertical) + break; + // Foce node to move vertically + QPointF newPos = value.toPointF(); + newPos.setX(pos().x()); + return newPos; + } case ItemPositionHasChanged: foreach (Edge *edge, edgeList) edge->adjust(); diff --git a/ground/src/plugins/config/mixercurvepoint.h b/ground/src/plugins/config/mixercurvepoint.h index 75de06543..10b3ba8f7 100644 --- a/ground/src/plugins/config/mixercurvepoint.h +++ b/ground/src/plugins/config/mixercurvepoint.h @@ -49,6 +49,7 @@ public: enum { Type = UserType + 1 }; int type() const { return Type; } + void verticalMove(bool flag); void calculateForces(); bool advance(); @@ -66,6 +67,7 @@ private: QList edgeList; QPointF newPos; MixerCurveWidget *graph; + bool vertical; }; #endif // MIXERCURVEPOINT_H diff --git a/ground/src/plugins/config/mixercurvewidget.cpp b/ground/src/plugins/config/mixercurvewidget.cpp index a7cd15fb1..d2bc59b63 100644 --- a/ground/src/plugins/config/mixercurvewidget.cpp +++ b/ground/src/plugins/config/mixercurvewidget.cpp @@ -83,14 +83,19 @@ MixerCurveWidget::MixerCurveWidget(QWidget *parent) : QGraphicsView(parent) scene->addItem(new Edge(node3, node4)); scene->addItem(new Edge(node4, node5)); - qreal w = plot->boundingRect().width()/5; + qreal w = plot->boundingRect().width()/4; - node1->setPos(w-w/2,50); - node2->setPos(2*w-w/2, 50); - node3->setPos(3*w-w/2, 50); - node4->setPos(4*w-w/2, 50); - node5->setPos(5*w-w/2, 50); + node1->setPos(0,50); + node2->setPos(w, 50); + node3->setPos(2*w, 50); + node4->setPos(3*w, 50); + node5->setPos(4*w, 50); + node1->verticalMove(true); + node2->verticalMove(true); + node3->verticalMove(true); + node4->verticalMove(true); + node5->verticalMove(true); } @@ -119,5 +124,5 @@ void MixerCurveWidget::resizeEvent(QResizeEvent* event) void MixerCurveWidget::itemMoved() { - + qDebug() << "Moved ball"; }