mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
[Game] Raise rubber band above count label and collapse multi-selection on click (#7451)
* [Game] Raise rubber band above count label and collapse multi-selection on click Raise rubber band on start and collapse multi-selection to clicked card when left-clicking an already-selected card with no modifiers. * [Game] Collapse multi-selection on release instead of press Collapsing at press time dropped the selection before the drag started, which broke dragging multiple cards. Keep the selection on press and collapse it on release when the pointer stayed within the drag distance. * [Game] Defer selection collapse until the double-click window passes A release without drag collapsed the multi-selection immediately, so a double-click that followed (playSelected acts on scene()->selectedItems()) only ever saw the single clicked card. When the card handles double-clicks on the selection, arm the collapse on a single-shot timer for QApplication::doubleClickInterval() instead and cancel it from the double-click handler; a new press disarms the other cards and a selection-count guard covers rubber-band/ctrl changes meanwhile. * [Game] Keep sideboard multi-selection on double-click DeckViewCard overrides doubleClickActsOnSelection to preserve the selection, restoring master behavior where double-clicking moves all selected cards between main and side. DeckView cancels any pending collapse before reading the selection. * [Game] Remove duplicated inline selection-collapse declarations * [Game] Fix DeckView collapse call visibility and multi-selection collapse Make cancelPendingSelectionCollapse() public so DeckView can call it on selected DeckViewCards. Always arm the deferred collapse on release instead of skipping cards whose double-click acts on the selection; the double-click-interval timer plus the cancel calls in CardItem::mouseDoubleClickEvent and DeckView::mouseDoubleClickEvent already preserve the selection for double-clicks. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
fea12a74e2
commit
677692500b
7 changed files with 91 additions and 1 deletions
|
|
@ -12,6 +12,7 @@
|
|||
#include "libcockatrice/card/printing/exact_card.h"
|
||||
#include "libcockatrice/utility/card_ref.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QBrush>
|
||||
#include <QChar>
|
||||
#include <QCursor>
|
||||
|
|
@ -28,6 +29,7 @@
|
|||
#include <QPixmap>
|
||||
#include <QPointF>
|
||||
#include <QRectF>
|
||||
#include <QTimer>
|
||||
#include <QTransform>
|
||||
#include <QVariant>
|
||||
#include <QtGlobal>
|
||||
|
|
@ -42,7 +44,7 @@ class QSizeF;
|
|||
|
||||
AbstractCardItem::AbstractCardItem(QGraphicsItem *parent, const CardRef &cardRef, PlayerLogic *_owner, int _id)
|
||||
: ArrowTarget(_owner, parent), id(_id), cardRef(cardRef), tapped(false), facedown(false), tapAngle(0),
|
||||
bgColor(Qt::transparent), isHovered(false), realZValue(0)
|
||||
bgColor(Qt::transparent), isHovered(false), realZValue(0), pendingSelectionCollapse(false)
|
||||
{
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
setFlag(ItemIsSelectable);
|
||||
|
|
@ -344,6 +346,16 @@ void AbstractCardItem::setFaceDown(bool _facedown)
|
|||
|
||||
void AbstractCardItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
cancelPendingSelectionCollapse();
|
||||
if (scene() != nullptr) {
|
||||
// A new press starts a new gesture: no card may collapse the selection out from under it afterwards.
|
||||
for (QGraphicsItem *selectedItem : scene()->selectedItems()) {
|
||||
auto *selectedCard = qgraphicsitem_cast<AbstractCardItem *>(selectedItem);
|
||||
if (selectedCard != nullptr && selectedCard != this) {
|
||||
selectedCard->cancelPendingSelectionCollapse();
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((event->modifiers() & Qt::AltModifier) && event->button() == Qt::LeftButton) {
|
||||
emit cardShiftClicked(cardRef.name);
|
||||
} else if ((event->modifiers() & Qt::ControlModifier)) {
|
||||
|
|
@ -351,6 +363,10 @@ void AbstractCardItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||
} else if (!isSelected()) {
|
||||
scene()->clearSelection();
|
||||
setSelected(true);
|
||||
} else if (event->button() == Qt::LeftButton && scene()->selectedItems().count() > 1) {
|
||||
// Part of a multi-selection; collapse only if this turns out to be a click rather than a drag,
|
||||
// so that dragging the whole selection keeps it intact.
|
||||
pendingSelectionCollapse = true;
|
||||
}
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
|
|
@ -362,6 +378,32 @@ void AbstractCardItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|||
|
||||
void AbstractCardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (pendingSelectionCollapse) {
|
||||
pendingSelectionCollapse = false;
|
||||
bool dragged = (event->screenPos() - event->buttonDownScreenPos(event->button())).manhattanLength() >=
|
||||
2 * QApplication::startDragDistance();
|
||||
if (!dragged) {
|
||||
if (doubleClickActsOnSelection()) {
|
||||
// A double-click may still arrive and must act on the whole multi-selection, so collapse only
|
||||
// once the double-click window has passed without one. The generation guard (and the receiver
|
||||
// context) drops the collapse if the item is gone, deselected, or a double-click cancelled it;
|
||||
// the count guard drops it if the selection changed meanwhile (rubber band, ctrl-toggle).
|
||||
const int generation = ++selectionCollapseGeneration;
|
||||
const int armedSelectionCount = scene()->selectedItems().count();
|
||||
QTimer::singleShot(QApplication::doubleClickInterval(), this, [this, generation, armedSelectionCount] {
|
||||
if (generation == selectionCollapseGeneration && scene() != nullptr && isSelected() &&
|
||||
scene()->selectedItems().count() == armedSelectionCount && armedSelectionCount > 1) {
|
||||
scene()->clearSelection();
|
||||
setSelected(true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
scene()->clearSelection();
|
||||
setSelected(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event->button() == Qt::MiddleButton) {
|
||||
emit deleteCardInfoPopup(cardRef.name);
|
||||
}
|
||||
|
|
@ -370,6 +412,17 @@ void AbstractCardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|||
event->accept();
|
||||
}
|
||||
|
||||
void AbstractCardItem::cancelPendingSelectionCollapse()
|
||||
{
|
||||
pendingSelectionCollapse = false;
|
||||
++selectionCollapseGeneration;
|
||||
}
|
||||
|
||||
bool AbstractCardItem::doubleClickActsOnSelection() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void AbstractCardItem::processHoverEvent()
|
||||
{
|
||||
emit hovered(this);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue