1- #include " ConnectionPainter .hpp"
1+ #include " DefaultConnectionPainter .hpp"
22
33#include < QtGui/QIcon>
44
1111
1212namespace QtNodes {
1313
14- static QPainterPath cubicPath (ConnectionGraphicsObject const &connection)
14+ QPainterPath DefaultConnectionPainter:: cubicPath (ConnectionGraphicsObject const &connection) const
1515{
1616 QPointF const &in = connection.endPoint (PortType::In);
1717 QPointF const &out = connection.endPoint (PortType::Out);
@@ -26,67 +26,15 @@ static QPainterPath cubicPath(ConnectionGraphicsObject const &connection)
2626 return cubic;
2727}
2828
29- QPainterPath ConnectionPainter::getPainterStroke (ConnectionGraphicsObject const &connection)
30- {
31- auto cubic = cubicPath (connection);
32-
33- QPointF const &out = connection.endPoint (PortType::Out);
34- QPainterPath result (out);
35-
36- unsigned segments = 20 ;
37-
38- for (auto i = 0ul ; i < segments; ++i) {
39- double ratio = double (i + 1 ) / segments;
40- result.lineTo (cubic.pointAtPercent (ratio));
41- }
42-
43- QPainterPathStroker stroker;
44- stroker.setWidth (10.0 );
45-
46- return stroker.createStroke (result);
47- }
48-
49- #ifdef NODE_DEBUG_DRAWING
50- static void debugDrawing (QPainter *painter, ConnectionGraphicsObject const &cgo)
51- {
52- Q_UNUSED (painter);
53-
54- {
55- QPointF const &in = cgo.endPoint (PortType::In);
56- QPointF const &out = cgo.endPoint (PortType::Out);
57-
58- auto const points = cgo.pointsC1C2 ();
59-
60- painter->setPen (Qt::red);
61- painter->setBrush (Qt::red);
62-
63- painter->drawLine (QLineF (out, points.first ));
64- painter->drawLine (QLineF (points.first , points.second ));
65- painter->drawLine (QLineF (points.second , in));
66- painter->drawEllipse (points.first , 3 , 3 );
67- painter->drawEllipse (points.second , 3 , 3 );
68-
69- painter->setBrush (Qt::NoBrush);
70- painter->drawPath (cubicPath (cgo));
71- }
72-
73- {
74- painter->setPen (Qt::yellow);
75- painter->drawRect (cgo.boundingRect ());
76- }
77- }
78-
79- #endif
80-
81- static void drawSketchLine (QPainter *painter, ConnectionGraphicsObject const &cgo)
29+ void DefaultConnectionPainter::drawSketchLine (QPainter *painter, ConnectionGraphicsObject const &cgo) const
8230{
8331 ConnectionState const &state = cgo.connectionState ();
8432
8533 if (state.requiresPort ()) {
8634 auto const &connectionStyle = QtNodes::StyleCollection::connectionStyle ();
8735
8836 QPen pen;
89- pen.setWidth (connectionStyle.constructionLineWidth ());
37+ pen.setWidth (static_cast < int >( connectionStyle.constructionLineWidth () ));
9038 pen.setColor (connectionStyle.constructionColor ());
9139 pen.setStyle (Qt::DashLine);
9240
@@ -100,7 +48,7 @@ static void drawSketchLine(QPainter *painter, ConnectionGraphicsObject const &cg
10048 }
10149}
10250
103- static void drawHoveredOrSelected (QPainter *painter, ConnectionGraphicsObject const &cgo)
51+ void DefaultConnectionPainter:: drawHoveredOrSelected (QPainter *painter, ConnectionGraphicsObject const &cgo) const
10452{
10553 bool const hovered = cgo.connectionState ().hovered ();
10654 bool const selected = cgo.isSelected ();
@@ -112,7 +60,7 @@ static void drawHoveredOrSelected(QPainter *painter, ConnectionGraphicsObject co
11260 double const lineWidth = connectionStyle.lineWidth ();
11361
11462 QPen pen;
115- pen.setWidth (2 * lineWidth);
63+ pen.setWidth (static_cast < int >( 2 * lineWidth) );
11664 pen.setColor (selected ? connectionStyle.selectedHaloColor ()
11765 : connectionStyle.hoveredColor ());
11866
@@ -125,7 +73,7 @@ static void drawHoveredOrSelected(QPainter *painter, ConnectionGraphicsObject co
12573 }
12674}
12775
128- static void drawNormalLine (QPainter *painter, ConnectionGraphicsObject const &cgo)
76+ void DefaultConnectionPainter:: drawNormalLine (QPainter *painter, ConnectionGraphicsObject const &cgo) const
12977{
13078 ConnectionState const &state = cgo.connectionState ();
13179
@@ -188,7 +136,7 @@ static void drawNormalLine(QPainter *painter, ConnectionGraphicsObject const &cg
188136 p.setColor (cOut);
189137 painter->setPen (p);
190138
191- unsigned int const segments = 60 ;
139+ unsigned int constexpr segments = 60 ;
192140
193141 for (unsigned int i = 0ul ; i < segments; ++i) {
194142 double ratioPrev = double (i) / segments;
@@ -227,7 +175,7 @@ static void drawNormalLine(QPainter *painter, ConnectionGraphicsObject const &cg
227175 }
228176}
229177
230- void ConnectionPainter ::paint (QPainter *painter, ConnectionGraphicsObject const &cgo)
178+ void DefaultConnectionPainter ::paint (QPainter *painter, ConnectionGraphicsObject const &cgo) const
231179{
232180 drawHoveredOrSelected (painter, cgo);
233181
@@ -251,4 +199,55 @@ void ConnectionPainter::paint(QPainter *painter, ConnectionGraphicsObject const
251199 painter->drawEllipse (cgo.in (), pointRadius, pointRadius);
252200}
253201
202+ QPainterPath DefaultConnectionPainter::getPainterStroke (ConnectionGraphicsObject const &connection) const
203+ {
204+ auto cubic = cubicPath (connection);
205+
206+ QPointF const &out = connection.endPoint (PortType::Out);
207+ QPainterPath result (out);
208+
209+ unsigned int constexpr segments = 20 ;
210+
211+ for (auto i = 0ul ; i < segments; ++i) {
212+ double ratio = double (i + 1 ) / segments;
213+ result.lineTo (cubic.pointAtPercent (ratio));
214+ }
215+
216+ QPainterPathStroker stroker;
217+ stroker.setWidth (10.0 );
218+
219+ return stroker.createStroke (result);
220+ }
221+
222+ #ifdef NODE_DEBUG_DRAWING
223+ void DefaultConnectionPainter::debugDrawing (QPainter *painter, ConnectionGraphicsObject const &cgo)
224+ {
225+ Q_UNUSED (painter);
226+
227+ {
228+ QPointF const &in = cgo.endPoint (PortType::In);
229+ QPointF const &out = cgo.endPoint (PortType::Out);
230+
231+ auto const points = cgo.pointsC1C2 ();
232+
233+ painter->setPen (Qt::red);
234+ painter->setBrush (Qt::red);
235+
236+ painter->drawLine (QLineF (out, points.first ));
237+ painter->drawLine (QLineF (points.first , points.second ));
238+ painter->drawLine (QLineF (points.second , in));
239+ painter->drawEllipse (points.first , 3 , 3 );
240+ painter->drawEllipse (points.second , 3 , 3 );
241+
242+ painter->setBrush (Qt::NoBrush);
243+ painter->drawPath (cubicPath (cgo));
244+ }
245+
246+ {
247+ painter->setPen (Qt::yellow);
248+ painter->drawRect (cgo.boundingRect ());
249+ }
250+ }
251+ #endif
252+
254253} // namespace QtNodes
0 commit comments