feat: fix socket hover
This commit is contained in:
@@ -190,6 +190,16 @@ void Network::mouseMoved(QMouseEvent *event)
|
||||
|
||||
QList<QGraphicsItem*> hoverItems = view_->items(event->pos());
|
||||
|
||||
// handle previous items
|
||||
for(QGraphicsItem* item : prevHoverItems_)
|
||||
{
|
||||
if(isType<SocketGraphic>(item))
|
||||
{
|
||||
static_cast<SocketGraphic*>(item)->setHover(false);
|
||||
}
|
||||
}
|
||||
prevHoverItems_.clear();
|
||||
|
||||
if(state_==State::MOVING_NODE)
|
||||
{
|
||||
moveNodes(view_->mapToScene(event->pos())+nodeMoveDelta_);
|
||||
@@ -241,7 +251,11 @@ void Network::mouseMoved(QMouseEvent *event)
|
||||
std::cout << "unhighlighting\n";
|
||||
highlightEdge(prevHoverItem, false);
|
||||
}
|
||||
|
||||
if(auto hoverSocket = closestItemOfType<SocketGraphic>(hoverItems, view_->mapToScene(event->pos())))
|
||||
{
|
||||
static_cast<SocketGraphic*>(hoverSocket)->setHover(true);
|
||||
prevHoverItems_.insert(hoverSocket);
|
||||
}
|
||||
}
|
||||
|
||||
void Network::moveNodes(QPointF pos)
|
||||
@@ -331,14 +345,10 @@ void Network::highlightEdge(QGraphicsItem* edge, bool state)
|
||||
{
|
||||
static_cast<NodeEdgeGraphic*>(edge)->setDeleteHighlight(true);
|
||||
prevHoverItem_=edge;
|
||||
// NOTE: sloppy fix for color not updating
|
||||
view_->update();
|
||||
}
|
||||
else
|
||||
{
|
||||
static_cast<NodeEdgeGraphic*>(edge)->setDeleteHighlight(false);
|
||||
// NOTE: sloppy fix for color not updating
|
||||
view_->update();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ private:
|
||||
SocketGraphic* startSocket_=nullptr;
|
||||
|
||||
QGraphicsItem* prevHoverItem_=nullptr;
|
||||
std::unordered_set<QGraphicsItem*> prevHoverItems_;
|
||||
// nodes currently being moved
|
||||
std::vector<QGraphicsItem*> moveNodeBuffer;
|
||||
QPointF nodeMoveDelta_;
|
||||
|
||||
@@ -10,7 +10,6 @@ SocketGraphic::SocketGraphic(enzo::nt::SocketIOType type, enzo::nt::OpId opId, u
|
||||
brushActive_ = QBrush("white");
|
||||
brushInactive_ = QBrush("#9f9f9f");
|
||||
socketSize_ = 3;
|
||||
setAcceptHoverEvents(true);
|
||||
initBoundingBox();
|
||||
}
|
||||
|
||||
@@ -102,6 +101,17 @@ void SocketGraphic::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
|
||||
|
||||
}
|
||||
|
||||
void SocketGraphic::setHover(bool state)
|
||||
{
|
||||
bool prevState = hovered_;
|
||||
|
||||
hovered_ = state;
|
||||
if(state!=prevState)
|
||||
{
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void SocketGraphic::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
hovered_ = true;
|
||||
|
||||
@@ -25,6 +25,7 @@ public:
|
||||
enzo::nt::OpId getOpId() const;
|
||||
|
||||
unsigned int getIndex() const;
|
||||
void setHover(bool state);
|
||||
|
||||
private:
|
||||
int socketSize_ = 1;
|
||||
@@ -37,6 +38,7 @@ private:
|
||||
qreal paddingScale_=20;
|
||||
QRectF boundRect_;
|
||||
enzo::nt::OpId opId_;
|
||||
bool isHover_ = false;
|
||||
|
||||
void initBoundingBox();
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user