2 ******************************************************************************
4 * @file mixercurveline.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
8 * @addtogroup UAVObjectWidgetUtils Plugin
10 * @brief Utility plugin for UAVObject to Widget relation management
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "mixercurveline.h"
31 #include "mixercurvepoint.h"
36 Edge::Edge(MixerNode
*sourceNode
, MixerNode
*destNode
)
39 setAcceptedMouseButtons(0);
42 source
->addEdge(this);
50 MixerNode
*Edge::sourceNode() const
55 void Edge::setSourceNode(MixerNode
*node
)
61 MixerNode
*Edge::destNode() const
66 void Edge::setDestNode(MixerNode
*node
)
74 if (!source
|| !dest
) {
78 QLineF
line(mapFromItem(source
, 0, 0), mapFromItem(dest
, 0, 0));
79 qreal length
= line
.length();
81 prepareGeometryChange();
83 if (length
> qreal(20.)) {
84 QPointF
edgeOffset((line
.dx() * 13) / length
, (line
.dy() * 13) / length
);
85 sourcePoint
= line
.p1() + edgeOffset
;
86 destPoint
= line
.p2() - edgeOffset
;
88 sourcePoint
= destPoint
= line
.p1();
92 QRectF
Edge::boundingRect() const
94 if (!source
|| !dest
) {
99 qreal extra
= (penWidth
+ arrowSize
) / 2.0;
101 return QRectF(sourcePoint
, QSizeF(destPoint
.x() - sourcePoint
.x(),
102 destPoint
.y() - sourcePoint
.y()))
104 .adjusted(-extra
, -extra
, extra
, extra
);
107 void Edge::paint(QPainter
*painter
, const QStyleOptionGraphicsItem
*, QWidget
*)
109 if (!source
|| !dest
) {
113 QLineF
line(sourcePoint
, destPoint
);
114 if (qFuzzyCompare(line
.length(), qreal(0.))) {
118 // Draw the line itself
119 painter
->setPen(QPen(Qt::black
, 1, Qt::SolidLine
, Qt::RoundCap
, Qt::RoundJoin
));
120 painter
->drawLine(line
);