nodeview: prevent default behavior when items are attached

Fixes buggy behavior when dropping attached nodes and moving the cursor
This commit is contained in:
itsmattkc
2022-04-28 10:44:02 -07:00
parent 7825d0e16d
commit 6e08b61ecc
+12 -4
View File
@@ -451,8 +451,10 @@ void NodeView::mousePressEvent(QMouseEvent *event)
} }
} }
// Default QGraphicsView functionality (selecting, dragging, etc.) if (attached_items_.isEmpty()) {
super::mousePressEvent(event); // Default QGraphicsView functionality (selecting, dragging, etc.)
super::mousePressEvent(event);
}
// For any selected item, store its position in case the user is dragging it somewhere else // For any selected item, store its position in case the user is dragging it somewhere else
auto selected_items = scene_.GetSelectedItems(); auto selected_items = scene_.GetSelectedItems();
@@ -473,7 +475,9 @@ void NodeView::mouseMoveEvent(QMouseEvent *event)
return; return;
} }
super::mouseMoveEvent(event); if (attached_items_.isEmpty()) {
super::mouseMoveEvent(event);
}
// See if there are any items attached // See if there are any items attached
if (!attached_items_.isEmpty()) { if (!attached_items_.isEmpty()) {
@@ -560,6 +564,8 @@ void NodeView::mouseReleaseEvent(QMouseEvent *event)
Node *select_context = nullptr; Node *select_context = nullptr;
QVector<Node*> select_nodes; QVector<Node*> select_nodes;
bool had_attached_items = !attached_items_.isEmpty();
if (!attached_items_.isEmpty()) { if (!attached_items_.isEmpty()) {
select_context = nullptr; select_context = nullptr;
@@ -643,7 +649,9 @@ void NodeView::mouseReleaseEvent(QMouseEvent *event)
Core::instance()->undo_stack()->pushIfHasChildren(command); Core::instance()->undo_stack()->pushIfHasChildren(command);
super::mouseReleaseEvent(event); if (!had_attached_items) {
super::mouseReleaseEvent(event);
}
if (select_context) { if (select_context) {
scene_.context_map().value(select_context)->Select(select_nodes); scene_.context_map().value(select_context)->Select(select_nodes);