From 992f3fd3af94c906e6eb85432bae96276f5acf60 Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Wed, 27 Jul 2022 12:15:11 -0700 Subject: [PATCH] nodeview: increase hitbox of node connectors --- app/widget/nodeview/nodeview.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/widget/nodeview/nodeview.cpp b/app/widget/nodeview/nodeview.cpp index e757e6031..c820c902d 100644 --- a/app/widget/nodeview/nodeview.cpp +++ b/app/widget/nodeview/nodeview.cpp @@ -432,7 +432,23 @@ void NodeView::mousePressEvent(QMouseEvent *event) if (HandPress(event)) return; // Get the item that the user clicked on, if any - QGraphicsItem* item = itemAt(event->pos()); + QGraphicsItem* item = nullptr; + { + // Prioritize connectors. I tried overriding boundingRect() and contains() on the connector + // object, but it ended up not working or causing other issues, so this is my hackier solution + const int radius = fontMetrics().height()/2; + QRect connector_rect(event->pos().x()-radius, event->pos().y()-radius, radius*2, radius*2); + QList items = this->items(connector_rect); + for (QGraphicsItem *i : items) { + if (dynamic_cast(i)) { + item = i; + break; + } + } + } + if (!item) { + item = itemAt(event->pos()); + } if (event->button() == Qt::LeftButton) { // Sane defaults