feat: edge hover detection

This commit is contained in:
parker
2025-06-21 22:31:53 +01:00
parent 06e66f7282
commit 5e70d14d5c
4 changed files with 103 additions and 2 deletions

View File

@@ -5,9 +5,10 @@
#include <qgraphicsitem.h>
NodeEdgeGraphic::NodeEdgeGraphic(SocketGraphic* socket1, SocketGraphic* socket2, QGraphicsItem *parent)
: QGraphicsItem(parent), socket1_{socket1}, socket2_{socket2}
: QGraphicsItem(parent), socket1_{socket1}, socket2_{socket2}, defaultColor_{QColor("white")}
{
setZValue(-1);
color_=defaultColor_;
}
QRectF NodeEdgeGraphic::boundingRect() const
@@ -16,9 +17,29 @@ QRectF NodeEdgeGraphic::boundingRect() const
return boundRect;
}
QPainterPath NodeEdgeGraphic::shape() const{
QPainterPath path;
path.moveTo(socket1_->scenePos());
path.lineTo(socket2_->scenePos());
QPainterPathStroker stroker;
stroker.setWidth(10);
return stroker.createStroke(path);
}
void NodeEdgeGraphic::setColor(QColor color)
{
color_ = color;
}
void NodeEdgeGraphic::useDefaultColor()
{
setColor(defaultColor_);
}
void NodeEdgeGraphic::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
auto pen = QPen("white");
auto pen = QPen(color_);
pen.setCapStyle(Qt::RoundCap);
painter->setPen(pen);
painter->drawLine(socket1_->scenePos(),socket2_->scenePos());