Improve drag & drop behavior (#4963)

* Improve drag & drop behavior

This patch tweaks the drag & drop behavior (in particular, the grid
placement) to be more intuitive. More precisely, with this patch the
drag & drop will:

 - Only use the "hot spot" (i.e. position of the cursor on the card)
   for zones where the card is actually displayed around the cursor (in
   particular, not on the table where the card snaps to the grid).

 - Use better boundaries computed with respect to the center of the
   card (rather than its top left corner) for determining which grid
   cell a card should go to

 - Align behavior of the preview and the actual effect when overflow of
   the 3-card stacks occurs

 - Avoid visual glitches where the cursor ends up outside of the card or
   at incorrect offsets when moving the mouse too fast (which translates
   to overflows of the hot spot computation)

* Address review comments

 - Use simpler computation for restricting hotSpot range
 - Prevent dropping cards onto full 3-card slots
This commit is contained in:
Basile Clement 2024-01-01 22:51:36 +01:00 committed by GitHub
parent badd8952f5
commit 6d032c378f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 14 deletions

View file

@ -348,7 +348,9 @@ void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
bool forceFaceDown = event->modifiers().testFlag(Qt::ShiftModifier);
createDragItem(id, event->pos(), event->scenePos(), facedown || forceFaceDown);
// Use the buttonDownPos to align the hot spot with the position when
// the user originally clicked
createDragItem(id, event->buttonDownPos(Qt::LeftButton), event->scenePos(), facedown || forceFaceDown);
dragItem->grabMouse();
int childIndex = 0;