Unified fix to allow cards to be dropped correctly in vertical stacked zones without requiring cross-zone special case

This commit is contained in:
DawnFire42 2026-08-10 11:57:10 -04:00
parent bb2afaadd1
commit f28ceca1de
No known key found for this signature in database
GPG key ID: 24BB855EE2911B33
4 changed files with 12 additions and 17 deletions

View file

@ -105,12 +105,12 @@ void CommandZone::handleDropEvent(const QList<CardDragItem *> &dragItems,
return;
}
const auto &cards = getLogic()->getCards();
int index = calcDropIndexFromY(dropPoint.y(), MIN_CARD_VISIBLE);
// Same-zone no-op: don't move a card onto itself
const auto &cards = getLogic()->getCards();
if (!cards.isEmpty() && index < cards.size() && startZone == getLogic() &&
cards.at(index)->getId() == dragItems.at(0)->getId()) {
// Same-zone no-op: don't move a card onto itself (index may equal size for append)
if (startZone == getLogic() && !cards.isEmpty() &&
cards.at(qMin(index, static_cast<int>(cards.size()) - 1))->getId() == dragItems.at(0)->getId()) {
return;
}

View file

@ -94,7 +94,7 @@ int SelectZone::calcDropIndexFromY(qreal dropY, qreal minOffset) const
if (effectiveOffset <= 0.0) {
return 0;
}
return qBound(0, qRound((dropY - start) / effectiveOffset), params.cardCount - 1);
return qBound(0, qRound((dropY - start) / effectiveOffset), params.cardCount);
}
void SelectZone::restoreStaleEscapedCards()

View file

@ -103,7 +103,7 @@ protected:
/**
* @brief Computes the card index at a given y-coordinate within the zone's vertical layout.
* Returns 0 if the zone has no cards or the offset is zero.
* Returns 0..cardCount (inclusive), where cardCount means append after the last card.
*/
int calcDropIndexFromY(qreal dropY, qreal minOffset = 0.0) const;

View file

@ -48,17 +48,12 @@ void StackZone::handleDropEvent(const QList<CardDragItem *> &dragItems,
}
const auto &cards = getLogic()->getCards();
int index;
if (startZone == getLogic()) {
// Reordering within the zone: use drop position
index = calcDropIndexFromY(dropPoint.y(), MIN_CARD_VISIBLE);
// Same-zone no-op: don't move a card onto itself
if (!cards.isEmpty() && cards.at(index)->getId() == dragItems.at(0)->getId()) {
return;
}
} else {
// Coming from another zone: append at end (top of stack, rendered on top)
index = static_cast<int>(cards.size());
int index = calcDropIndexFromY(dropPoint.y(), MIN_CARD_VISIBLE);
// Same-zone no-op: don't move a card onto itself (index may equal size for append)
if (startZone == getLogic() && !cards.isEmpty() &&
cards.at(qMin(index, static_cast<int>(cards.size()) - 1))->getId() == dragItems.at(0)->getId()) {
return;
}
Command_MoveCard cmd;