fix: edge 1 frame lag
This commit is contained in:
@@ -75,6 +75,7 @@ void Network::resizeEvent(QResizeEvent *event)
|
||||
|
||||
void Network::deleteEdge(QGraphicsItem* edge)
|
||||
{
|
||||
std::cout << "----\ndeleting edge\n";
|
||||
if(prevHoverItem_==edge)
|
||||
{
|
||||
prevHoverItem_=nullptr;
|
||||
@@ -85,6 +86,7 @@ void Network::deleteEdge(QGraphicsItem* edge)
|
||||
// NOTE: deleting edge kept giving me segmentation faults
|
||||
// I coundn't figure it out so I'm just leaving it for now
|
||||
// delete edge;
|
||||
std::cout << "finished deleting edge\n----\n";
|
||||
}
|
||||
|
||||
void Network::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
@@ -86,7 +86,7 @@ void NodeEdgeGraphic::useDefaultColor()
|
||||
|
||||
void NodeEdgeGraphic::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
std::cout << "painting\n";
|
||||
// std::cout << "painting\n";
|
||||
pen_.setCapStyle(Qt::RoundCap);
|
||||
painter->setPen(pen_);
|
||||
painter->drawPath(path_);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <string>
|
||||
#include "gui/network/SocketGraphic.h"
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
|
||||
NodeGraphic::NodeGraphic(QGraphicsItem *parent)
|
||||
: QGraphicsItem(parent)
|
||||
@@ -15,7 +16,7 @@ NodeGraphic::NodeGraphic(QGraphicsItem *parent)
|
||||
title_ = "hello world";
|
||||
bodyRect_ = QRect(-10, -10, 10*maxTitleLen_, 20);
|
||||
|
||||
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
|
||||
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
||||
|
||||
initSockets();
|
||||
}
|
||||
@@ -23,11 +24,11 @@ NodeGraphic::NodeGraphic(QGraphicsItem *parent)
|
||||
void NodeGraphic::initSockets()
|
||||
{
|
||||
auto* socketInput = new SocketGraphic(SocketGraphic::SocketType::Input, this);
|
||||
socketInput->setPos(bodyRect_.center().x(), bodyRect_.top());
|
||||
socketInput->setPos(getSocketPosition(0, SocketGraphic::SocketType::Input));
|
||||
inputs_.push_back(socketInput);
|
||||
|
||||
auto* socketOutput = new SocketGraphic(SocketGraphic::SocketType::Output, this);
|
||||
socketOutput->setPos(bodyRect_.center().x(), bodyRect_.bottom());
|
||||
socketOutput->setPos(getSocketPosition(0, SocketGraphic::SocketType::Output));
|
||||
outputs_.push_back(socketOutput);
|
||||
}
|
||||
|
||||
@@ -96,19 +97,58 @@ void NodeGraphic::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio
|
||||
|
||||
}
|
||||
|
||||
void NodeGraphic::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
QGraphicsItem::mouseMoveEvent(event);
|
||||
updatePositions(event->scenePos());
|
||||
}
|
||||
|
||||
QVariant NodeGraphic::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||
{
|
||||
if (change == ItemPositionChange && scene()) {
|
||||
for(auto socket : inputs_)
|
||||
{
|
||||
socket->posChanged(value.toPointF());
|
||||
}
|
||||
for(auto socket : outputs_)
|
||||
{
|
||||
socket->posChanged(value.toPointF());
|
||||
}
|
||||
};
|
||||
// void NodeGraphic::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
// {
|
||||
// updatePositions(event->scenePos());
|
||||
// QGraphicsItem::mouseReleaseEvent(event);
|
||||
// }
|
||||
|
||||
return QGraphicsItem::itemChange(change, value);
|
||||
void NodeGraphic::updatePositions(QPointF pos)
|
||||
{
|
||||
// NOTE: in the future I might store socket ids as internal member variables,
|
||||
// but for now I'm just going based on order
|
||||
for(int socketIndex=0; socketIndex<inputs_.size(); ++socketIndex)
|
||||
{
|
||||
inputs_[socketIndex]->posChanged(getSocketScenePosition(socketIndex, SocketGraphic::SocketType::Input));
|
||||
}
|
||||
for(int socketIndex=0; socketIndex<outputs_.size(); ++socketIndex)
|
||||
{
|
||||
outputs_[socketIndex]->posChanged(getSocketScenePosition(socketIndex, SocketGraphic::SocketType::Output));
|
||||
}
|
||||
}
|
||||
|
||||
QPointF NodeGraphic::getSocketPosition(int socketIndex, SocketGraphic::SocketType socketType)
|
||||
{
|
||||
float xPos, yPos;
|
||||
xPos = bodyRect_.center().x();
|
||||
yPos = socketType == SocketGraphic::SocketType::Input ? bodyRect_.top() : bodyRect_.bottom();
|
||||
|
||||
return QPointF(xPos, yPos);
|
||||
}
|
||||
QPointF NodeGraphic::getSocketScenePosition(int socketIndex, SocketGraphic::SocketType socketType)
|
||||
{
|
||||
return this->pos()+getSocketPosition(socketIndex, socketType);
|
||||
}
|
||||
|
||||
|
||||
// QVariant NodeGraphic::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||
// {
|
||||
// if (change == ItemPositionChange && scene()) {
|
||||
// for(auto socket : inputs_)
|
||||
// {
|
||||
// socket->posChanged(value.toPointF());
|
||||
// }
|
||||
// for(auto socket : outputs_)
|
||||
// {
|
||||
// socket->posChanged(value.toPointF());
|
||||
// }
|
||||
// };
|
||||
|
||||
// return QGraphicsItem::itemChange(change, value);
|
||||
// }
|
||||
|
||||
@@ -14,6 +14,8 @@ public:
|
||||
|
||||
SocketGraphic* getInput(int indx) const;
|
||||
SocketGraphic* getOutput(int indx) const;
|
||||
QPointF getSocketPosition(int socketIndex, SocketGraphic::SocketType socketType);
|
||||
QPointF getSocketScenePosition(int socketIndex, SocketGraphic::SocketType socketType);
|
||||
|
||||
// void addEdge(NodeEdgeGraphic* edge);
|
||||
|
||||
@@ -38,8 +40,12 @@ private:
|
||||
int socketSize_ = 1;
|
||||
int inputSocketCnt_=0;
|
||||
int outputSocketCnt_=0;
|
||||
|
||||
void updatePositions(QPointF pos);
|
||||
protected:
|
||||
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) override;
|
||||
// QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) override;
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
// void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -53,11 +53,11 @@ void SocketGraphic::posChanged(QPointF pos)
|
||||
// edge->setPos(startSocket_->scenePos(), socket->scenePos());
|
||||
if(type_==SocketType::Input)
|
||||
{
|
||||
edge->setStartPos(this->scenePos());
|
||||
edge->setStartPos(pos);
|
||||
}
|
||||
else if(type_==SocketType::Output)
|
||||
{
|
||||
edge->setEndPos(this->scenePos());
|
||||
edge->setEndPos(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user