fix: edge positioning to sockets

This commit is contained in:
parker
2025-06-22 16:30:46 +01:00
parent 1f1250c076
commit 2b9544cfae
4 changed files with 20 additions and 6 deletions

View File

@@ -128,8 +128,12 @@ void Network::socketClicked(SocketGraphic* socket, QMouseEvent *event)
// connect to opposite type
else if (socket->getIO()!=startSocket_->getIO())
{
NodeEdgeGraphic* newEdge = new NodeEdgeGraphic(startSocket_, socket);
newEdge->setPos(startSocket_->scenePos(), socket->scenePos());
auto inputSocket = startSocket_->getIO()==SocketGraphic::SocketType::Input ? startSocket_ : socket;
auto outputSocket = socket->getIO()==SocketGraphic::SocketType::Output ? socket : startSocket_;
NodeEdgeGraphic* newEdge = new NodeEdgeGraphic(inputSocket, outputSocket);
newEdge->setPos(inputSocket->scenePos(), outputSocket->scenePos());
scene_->addItem(newEdge);
destroyFloatingEdge();
}

View File

@@ -26,6 +26,7 @@ void NodeEdgeGraphic::updatePath()
path_.clear();
path_.moveTo(pos1_);
path_.lineTo(pos2_);
update();
}
@@ -33,27 +34,28 @@ void NodeEdgeGraphic::setPos(QPointF pos1, QPointF pos2)
{
pos1_ = pos1;
pos2_ = pos2;
prepareGeometryChange();
updatePath();
// prepareGeometryChange();
}
void NodeEdgeGraphic::setStartPos(QPointF pos)
{
pos1_ = pos;
prepareGeometryChange();
updatePath();
// prepareGeometryChange();
}
void NodeEdgeGraphic::setEndPos(QPointF pos)
{
pos2_ = pos;
prepareGeometryChange();
updatePath();
// prepareGeometryChange();
}
QRectF NodeEdgeGraphic::boundingRect() const
{
// std::cout << "bounds set" << socket1_->scenePos().x() << " " << socket1_->scenePos().y() << " " << socket2_->scenePos().x() << " " << socket2_->scenePos().y() << "\n";
// QRectF boundRect_ = QRectF(socket1_->scenePos(), socket1_->scenePos()).normalized();
QRectF boundRect_ = QRectF(pos1_, pos2_).normalized();
return boundRect_;
}

View File

@@ -5,6 +5,7 @@
#include <stdexcept>
#include <string>
#include "gui/network/SocketGraphic.h"
#include <QGraphicsScene>
NodeGraphic::NodeGraphic(QGraphicsItem *parent)
: QGraphicsItem(parent)

View File

@@ -40,8 +40,15 @@ void SocketGraphic::posChanged(QPointF pos)
for(auto* edge : edges_)
{
// edge->setPos(startSocket_->scenePos(), socket->scenePos());
if(type_==SocketType::Input)
{
edge->setStartPos(this->scenePos());
}
else if(type_==SocketType::Output)
{
edge->setEndPos(this->scenePos());
}
}
}