dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
mixercurveline.cpp
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #include <QPainter>
29 
30 #include "mixercurveline.h"
31 #include "mixercurvepoint.h"
32 
33 #include <qmath.h>
34 
35 Edge::Edge(MixerNode *sourceNode, MixerNode *destNode)
36  : arrowSize(10)
37 {
38  setAcceptedMouseButtons(nullptr);
39  source = sourceNode;
40  dest = destNode;
41  source->addEdge(this);
42  dest->addEdge(this);
43  adjust();
44 }
45 
47 {
48 }
49 
51 {
52  return source;
53 }
54 
56 {
57  source = node;
58  adjust();
59 }
60 
62 {
63  return dest;
64 }
65 
67 {
68  dest = node;
69  adjust();
70 }
71 
73 {
74  if (!source || !dest)
75  return;
76 
77  QLineF line(mapFromItem(source, 0, 0), mapFromItem(dest, 0, 0));
78  qreal length = line.length();
79 
80  prepareGeometryChange();
81 
82  if (length > qreal(20.)) {
83  QPointF edgeOffset((line.dx() * 13) / length, (line.dy() * 13) / length);
84  sourcePoint = line.p1() + edgeOffset;
85  destPoint = line.p2() - edgeOffset;
86  } else {
87  sourcePoint = destPoint = line.p1();
88  }
89 }
90 
91 QRectF Edge::boundingRect() const
92 {
93  if (!source || !dest)
94  return QRectF();
95 
96  qreal penWidth = 1;
97  qreal extra = (penWidth + arrowSize) / 2.0;
98 
99  return QRectF(sourcePoint,
100  QSizeF(destPoint.x() - sourcePoint.x(), destPoint.y() - sourcePoint.y()))
101  .normalized()
102  .adjusted(-extra, -extra, extra, extra);
103 }
104 
105 void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
106 {
107  if (!source || !dest)
108  return;
109 
110  QLineF line(sourcePoint, destPoint);
111  if (qFuzzyCompare(line.length(), qreal(0.)))
112  return;
113 
114  // Draw the line itself
115  painter->setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
116  painter->drawLine(line);
117 }
void adjust()
void setDestNode(MixerNode *node)
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
MixerNode * destNode() const
Edge(MixerNode *sourceNode, MixerNode *destNode)
MixerNode * sourceNode() const
QRectF boundingRect() const
void setSourceNode(MixerNode *node)