From e7240370e24bfd61369e98d5b96225153f1e079c Mon Sep 17 00:00:00 2001 From: Kalle Bracht Date: Thu, 19 Mar 2026 22:43:40 +0100 Subject: [PATCH] Fixes cable behaviour --- src/nodeeditor/graphicsitems/cable.cpp | 1 - src/nodeeditor/graphicsitems/cable.h | 4 +++ src/nodeeditor/nodeeditor_scene.cpp | 41 +++++++++++++++----------- src/nodeeditor/nodeeditor_scene.h | 2 ++ 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/nodeeditor/graphicsitems/cable.cpp b/src/nodeeditor/graphicsitems/cable.cpp index cac0876..1af4e68 100644 --- a/src/nodeeditor/graphicsitems/cable.cpp +++ b/src/nodeeditor/graphicsitems/cable.cpp @@ -45,7 +45,6 @@ void Cable::corner(QPoint point) { std::pair restriced_points = getRestrictedCablePath(m_corner.last(), point); m_corner.append(restriced_points.first); - m_corner.append(restriced_points.second); switchPlane(); update(); } diff --git a/src/nodeeditor/graphicsitems/cable.h b/src/nodeeditor/graphicsitems/cable.h index 5477477..07c6b36 100644 --- a/src/nodeeditor/graphicsitems/cable.h +++ b/src/nodeeditor/graphicsitems/cable.h @@ -6,6 +6,10 @@ enum class DirectionalPlane { Horizontal, Vertical }; +struct CableSegment { + +}; + class Cable : public QGraphicsItem { public: diff --git a/src/nodeeditor/nodeeditor_scene.cpp b/src/nodeeditor/nodeeditor_scene.cpp index c33fc6d..5677622 100644 --- a/src/nodeeditor/nodeeditor_scene.cpp +++ b/src/nodeeditor/nodeeditor_scene.cpp @@ -43,6 +43,13 @@ void NodeEditorScene::handlePadTrigger(Pad *pad) enableCableConnectionState(pad); } } +void NodeEditorScene::handlePadHover(Pad *pad) +{ + pad->setHover(true); + if (isCableConnectionState()) { + m_active_cable->previewCable(pad->getSceneDockPoint()); + } +} void NodeEditorScene::connectPads(Pad *first, Pad *second) { @@ -57,6 +64,15 @@ void NodeEditorScene::handleCornerTrigger(QPoint corner_pos) } } +void NodeEditorScene::removePadHoverStates() +{ + for (QGraphicsItem *item : items()) { + if (Pad *pad = qgraphicsitem_cast(item)) { + pad->setHover(false); + } + } +} + void NodeEditorScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { @@ -81,27 +97,18 @@ void NodeEditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) QPointF scene_pos = event->scenePos(); QList items_at_pos = items(scene_pos); + // Set all pads to no hover as it is the default value + removePadHoverStates(); + + bool mouse_on_pad = false; for (QGraphicsItem *item : items_at_pos) { if (Pad *pad = qgraphicsitem_cast(item)) { - pad->setHover(true); - for (QGraphicsItem *other : items_at_pos) { - if (Pad *other_pad = qgraphicsitem_cast(other)) { - if (other_pad != pad) { - other_pad->setHover(false); - } - } - } - return; + mouse_on_pad = true; + handlePadHover(pad); } } - for (QGraphicsItem *item : items()) { - if (Pad *pad = qgraphicsitem_cast(item)) { - pad->setHover(false); - } - } - - if (isCableConnectionState()) { + if (isCableConnectionState() && !mouse_on_pad) { m_active_cable->previewCable(event->scenePos().toPoint()); } -} \ No newline at end of file +} diff --git a/src/nodeeditor/nodeeditor_scene.h b/src/nodeeditor/nodeeditor_scene.h index 7d941c0..f0014a6 100644 --- a/src/nodeeditor/nodeeditor_scene.h +++ b/src/nodeeditor/nodeeditor_scene.h @@ -32,10 +32,12 @@ protected: private: void handlePadTrigger(Pad *); + void handlePadHover(Pad *); void connectPads(Pad *first, Pad *second); void handleCornerTrigger(QPoint corner_pos); void disableCableConnectionState(); void enableCableConnectionState(Pad *); + void removePadHoverStates(); int m_debug_x = 0; QList m_nodes;