diff options
Diffstat (limited to 'examples/widgets/graphicsview/diagramscene')
-rw-r--r-- | examples/widgets/graphicsview/diagramscene/arrow.cpp | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/examples/widgets/graphicsview/diagramscene/arrow.cpp b/examples/widgets/graphicsview/diagramscene/arrow.cpp index 012b9ea2ed..88160d9399 100644 --- a/examples/widgets/graphicsview/diagramscene/arrow.cpp +++ b/examples/widgets/graphicsview/diagramscene/arrow.cpp @@ -51,13 +51,10 @@ #include "arrow.h" -#include <math.h> - +#include <qmath.h> #include <QPen> #include <QPainter> -const qreal Pi = 3.14; - //! [0] Arrow::Arrow(DiagramItem *startItem, DiagramItem *endItem, QGraphicsItem *parent) : QGraphicsLineItem(parent) @@ -132,14 +129,12 @@ void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *, setLine(QLineF(intersectPoint, myStartItem->pos())); //! [5] //! [6] - double angle = ::acos(line().dx() / line().length()); - if (line().dy() >= 0) - angle = (Pi * 2) - angle; + double angle = std::atan2(-line().dy(), line().dx()); - QPointF arrowP1 = line().p1() + QPointF(sin(angle + Pi / 3) * arrowSize, - cos(angle + Pi / 3) * arrowSize); - QPointF arrowP2 = line().p1() + QPointF(sin(angle + Pi - Pi / 3) * arrowSize, - cos(angle + Pi - Pi / 3) * arrowSize); + QPointF arrowP1 = line().p1() + QPointF(sin(angle + M_PI / 3) * arrowSize, + cos(angle + M_PI / 3) * arrowSize); + QPointF arrowP2 = line().p1() + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize, + cos(angle + M_PI - M_PI / 3) * arrowSize); arrowHead.clear(); arrowHead << line().p1() << arrowP1 << arrowP2; |