Skip to content

Commit

Permalink
Update ConnectionPainter.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
paceholder authored Aug 16, 2024
1 parent 43a39bc commit 1913361
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions src/ConnectionPainter.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ConnectionPainter.hpp"
#include "DefaultConnectionPainter.hpp"

#include <QtGui/QIcon>

Expand All @@ -11,7 +11,7 @@

namespace QtNodes {

QPainterPath ConnectionPainter::cubicPath(ConnectionGraphicsObject const &connection)
QPainterPath DefaultConnectionPainter::cubicPath(ConnectionGraphicsObject const &connection)
{
QPointF const &in = connection.endPoint(PortType::In);
QPointF const &out = connection.endPoint(PortType::Out);
Expand All @@ -26,28 +26,10 @@ QPainterPath ConnectionPainter::cubicPath(ConnectionGraphicsObject const &connec
return cubic;
}

QPainterPath ConnectionPainter::getPainterStroke(ConnectionGraphicsObject const &connection) const
{
auto cubic = cubicPath(connection);

QPointF const &out = connection.endPoint(PortType::Out);
QPainterPath result(out);

unsigned segments = 20;

for (auto i = 0ul; i < segments; ++i) {
double ratio = double(i + 1) / segments;
result.lineTo(cubic.pointAtPercent(ratio));
}

QPainterPathStroker stroker;
stroker.setWidth(10.0);

return stroker.createStroke(result);
}

#ifdef NODE_DEBUG_DRAWING
static void debugDrawing(QPainter *painter, ConnectionGraphicsObject const &cgo)
void DefaultConnectionPainter::debugDrawing(QPainter *painter, ConnectionGraphicsObject const &cgo)
{
Q_UNUSED(painter);

Expand Down Expand Up @@ -78,7 +60,7 @@ static void debugDrawing(QPainter *painter, ConnectionGraphicsObject const &cgo)

#endif

void ConnectionPainter::drawSketchLine(QPainter *painter, ConnectionGraphicsObject const &cgo)
void DefaultConnectionPainter::drawSketchLine(QPainter *painter, ConnectionGraphicsObject const &cgo)
{
ConnectionState const &state = cgo.connectionState();

Expand All @@ -100,7 +82,7 @@ void ConnectionPainter::drawSketchLine(QPainter *painter, ConnectionGraphicsObje
}
}

void ConnectionPainter::drawHoveredOrSelected(QPainter *painter, ConnectionGraphicsObject const &cgo)
void DefaultConnectionPainter::drawHoveredOrSelected(QPainter *painter, ConnectionGraphicsObject const &cgo)
{
bool const hovered = cgo.connectionState().hovered();
bool const selected = cgo.isSelected();
Expand All @@ -125,7 +107,7 @@ void ConnectionPainter::drawHoveredOrSelected(QPainter *painter, ConnectionGraph
}
}

void ConnectionPainter::drawNormalLine(QPainter *painter, ConnectionGraphicsObject const &cgo)
void DefaultConnectionPainter::drawNormalLine(QPainter *painter, ConnectionGraphicsObject const &cgo)
{
ConnectionState const &state = cgo.connectionState();

Expand Down Expand Up @@ -227,7 +209,7 @@ void ConnectionPainter::drawNormalLine(QPainter *painter, ConnectionGraphicsObje
}
}

void ConnectionPainter::paint(QPainter *painter, ConnectionGraphicsObject const &cgo) const
void DefaultConnectionPainter::paint(QPainter *painter, ConnectionGraphicsObject const &cgo) const
{
drawHoveredOrSelected(painter, cgo);

Expand All @@ -251,4 +233,24 @@ void ConnectionPainter::paint(QPainter *painter, ConnectionGraphicsObject const
painter->drawEllipse(cgo.in(), pointRadius, pointRadius);
}

QPainterPath DefaultConnectionPainter::getPainterStroke(ConnectionGraphicsObject const &connection) const
{
auto cubic = cubicPath(connection);

QPointF const &out = connection.endPoint(PortType::Out);
QPainterPath result(out);

unsigned segments = 20;

for (auto i = 0ul; i < segments; ++i) {
double ratio = double(i + 1) / segments;
result.lineTo(cubic.pointAtPercent(ratio));
}

QPainterPathStroker stroker;
stroker.setWidth(10.0);

return stroker.createStroke(result);
}

} // namespace QtNodes

0 comments on commit 1913361

Please sign in to comment.