From 24e27d3c31c02bf42d0946ec6135994e469542f6 Mon Sep 17 00:00:00 2001 From: Basile Clement Date: Fri, 2 May 2025 18:58:21 +0200 Subject: [PATCH] fix: Prevent dragged cards getting stuck (#5896) * fix: Prevent dragged cards getting stuck Update the position of the card even if it is not above any zone. * Also update the currentZone --- cockatrice/src/game/board/card_drag_item.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/cockatrice/src/game/board/card_drag_item.cpp b/cockatrice/src/game/board/card_drag_item.cpp index d21e9168b..ab4431958 100644 --- a/cockatrice/src/game/board/card_drag_item.cpp +++ b/cockatrice/src/game/board/card_drag_item.cpp @@ -47,10 +47,25 @@ void CardDragItem::updatePosition(const QPointF &cursorScenePos) cursorZone = zoneViewZone; else if (cardZone) cursorZone = cardZone; - if (!cursorZone) - return; + + // Always update the current zone, even if its null, to cancel the drag + // instead of dropping cards into an non-intuitive location. currentZone = cursorZone; + if (!cursorZone) { + // Avoid the cards getting stuck visually when not over + // any zone. + QPointF newPos = cursorScenePos - hotSpot; + + if (newPos != pos()) { + for (int i = 0; i < childDrags.size(); i++) + childDrags[i]->setPos(newPos + childDrags[i]->getHotSpot()); + setPos(newPos); + } + + return; + } + QPointF zonePos = currentZone->scenePos(); QPointF cursorPosInZone = cursorScenePos - zonePos;