don't autoclose card view if single card gets dragged into same zone (#5517)

* rename canResize param to toNewZone

* pass toNewZone down

* don't autoclose card view if card gets dragged into same zone
This commit is contained in:
RickyRister 2025-01-24 18:08:28 -08:00 committed by GitHub
parent 085f0dd26c
commit e8b1e3ef0c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 18 additions and 9 deletions

View file

@ -173,7 +173,7 @@ CardItem *CardZone::getCard(int cardId, const QString &cardName)
return c; return c;
} }
CardItem *CardZone::takeCard(int position, int cardId, bool /*canResize*/) CardItem *CardZone::takeCard(int position, int cardId, bool toNewZone)
{ {
if (position == -1) { if (position == -1) {
// position == -1 means either that the zone is indexed by card id // position == -1 means either that the zone is indexed by card id
@ -190,7 +190,7 @@ CardItem *CardZone::takeCard(int position, int cardId, bool /*canResize*/)
return nullptr; return nullptr;
for (auto *view : views) { for (auto *view : views) {
view->removeCard(position); view->removeCard(position, toNewZone);
} }
CardItem *c = cards.takeAt(position); CardItem *c = cards.takeAt(position);

View file

@ -244,10 +244,10 @@ void TableZone::toggleTapped()
player->sendGameCommand(player->prepareGameCommand(cmdList)); player->sendGameCommand(player->prepareGameCommand(cmdList));
} }
CardItem *TableZone::takeCard(int position, int cardId, bool canResize) CardItem *TableZone::takeCard(int position, int cardId, bool toNewZone)
{ {
CardItem *result = CardZone::takeCard(position, cardId); CardItem *result = CardZone::takeCard(position, cardId);
if (canResize) if (toNewZone)
resizeToContents(); resizeToContents();
return result; return result;
} }

View file

@ -147,10 +147,10 @@ public:
@param position card position @param position card position
@param cardId id of card to take @param cardId id of card to take
@param canResize defaults to true @param toNewZone Whether the destination of the card is not the same as the starting zone. Defaults to true
@return CardItem that has been removed @return CardItem that has been removed
*/ */
CardItem *takeCard(int position, int cardId, bool canResize = true) override; CardItem *takeCard(int position, int cardId, bool toNewZone = true) override;
/** /**
Resizes the TableZone in case CardItems are within or Resizes the TableZone in case CardItems are within or

View file

@ -315,6 +315,11 @@ bool ZoneViewZone::prepareAddCard(int x)
} }
} }
// autoclose check is done both here and in removeCard
if (cards.isEmpty() && !doInsert && SettingsCache::instance().getCloseEmptyCardView()) {
close();
}
return doInsert; return doInsert;
} }
@ -365,7 +370,7 @@ void ZoneViewZone::handleDropEvent(const QList<CardDragItem *> &dragItems,
player->sendGameCommand(cmd); player->sendGameCommand(cmd);
} }
void ZoneViewZone::removeCard(int position) void ZoneViewZone::removeCard(int position, bool toNewZone)
{ {
if (isReversed) { if (isReversed) {
position -= cards.first()->getId(); position -= cards.first()->getId();
@ -382,7 +387,11 @@ void ZoneViewZone::removeCard(int position)
CardItem *card = cards.takeAt(position); CardItem *card = cards.takeAt(position);
card->deleteLater(); card->deleteLater();
if (cards.isEmpty() && SettingsCache::instance().getCloseEmptyCardView()) { // The toNewZone check is to prevent the view from auto-closing if the view contains only a single card and that
// card gets dragged within the view.
// Another autoclose check is done in prepareAddCard so that the view autocloses if the last card was moved to an
// unrevealed portion of the same zone.
if (cards.isEmpty() && SettingsCache::instance().getCloseEmptyCardView() && toNewZone) {
close(); close();
return; return;
} }

View file

@ -71,7 +71,7 @@ public:
void reorganizeCards() override; void reorganizeCards() override;
void initializeCards(const QList<const ServerInfo_Card *> &cardList = QList<const ServerInfo_Card *>()); void initializeCards(const QList<const ServerInfo_Card *> &cardList = QList<const ServerInfo_Card *>());
bool prepareAddCard(int x); bool prepareAddCard(int x);
void removeCard(int position); void removeCard(int position, bool toNewZone);
int getNumberCards() const int getNumberCards() const
{ {
return numberCards; return numberCards;