diff options
Diffstat (limited to 'examples/graphicsview/elasticnodes/edge.cpp')
-rw-r--r-- | examples/graphicsview/elasticnodes/edge.cpp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/examples/graphicsview/elasticnodes/edge.cpp b/examples/graphicsview/elasticnodes/edge.cpp index 25c769b..634fbee 100644 --- a/examples/graphicsview/elasticnodes/edge.cpp +++ b/examples/graphicsview/elasticnodes/edge.cpp @@ -49,6 +49,7 @@ static const double Pi = 3.14159265358979323846264338327950288419717; static double TwoPi = 2.0 * Pi; +//! [0] Edge::Edge(Node *sourceNode, Node *destNode) : arrowSize(10) { @@ -59,33 +60,21 @@ Edge::Edge(Node *sourceNode, Node *destNode) dest->addEdge(this); adjust(); } +//! [0] -Edge::~Edge() -{ -} - +//! [1] Node *Edge::sourceNode() const { return source; } -void Edge::setSourceNode(Node *node) -{ - source = node; - adjust(); -} - Node *Edge::destNode() const { return dest; } +//! [1] -void Edge::setDestNode(Node *node) -{ - dest = node; - adjust(); -} - +//! [2] void Edge::adjust() { if (!source || !dest) @@ -104,7 +93,9 @@ void Edge::adjust() sourcePoint = destPoint = line.p1(); } } +//! [2] +//! [3] QRectF Edge::boundingRect() const { if (!source || !dest) @@ -118,7 +109,9 @@ QRectF Edge::boundingRect() const .normalized() .adjusted(-extra, -extra, extra, extra); } +//! [3] +//! [4] void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { if (!source || !dest) @@ -127,11 +120,15 @@ void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) QLineF line(sourcePoint, destPoint); if (qFuzzyCompare(line.length(), qreal(0.))) return; +//! [4] +//! [5] // Draw the line itself painter->setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter->drawLine(line); +//! [5] +//! [6] // Draw the arrows double angle = ::acos(line.dx() / line.length()); if (line.dy() >= 0) @@ -150,3 +147,4 @@ void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) painter->drawPolygon(QPolygonF() << line.p1() << sourceArrowP1 << sourceArrowP2); painter->drawPolygon(QPolygonF() << line.p2() << destArrowP1 << destArrowP2); } +//! [6] |