[DeckEditor] Don't change widget focus when adding card (#6503)

This commit is contained in:
RickyRister 2026-01-09 18:27:54 -08:00 committed by GitHub
parent 7c7755b61d
commit 0deaa9d9b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 11 additions and 7 deletions

View file

@ -459,12 +459,15 @@ void DeckEditorDeckDockWidget::syncBannerCardComboBoxSelectionWithDeck()
} }
} }
void DeckEditorDeckDockWidget::setSelectedIndex(const QModelIndex &newCardIndex) void DeckEditorDeckDockWidget::setSelectedIndex(const QModelIndex &newCardIndex, bool preserveWidgetFocus)
{ {
deckView->clearSelection(); deckView->clearSelection();
deckView->setCurrentIndex(newCardIndex); deckView->setCurrentIndex(newCardIndex);
recursiveExpand(newCardIndex); recursiveExpand(newCardIndex);
deckView->setFocus(Qt::FocusReason::MouseFocusReason);
if (!preserveWidgetFocus) {
deckView->setFocus(Qt::FocusReason::MouseFocusReason);
}
} }
void DeckEditorDeckDockWidget::syncDisplayWidgetsToModel() void DeckEditorDeckDockWidget::syncDisplayWidgetsToModel()

View file

@ -100,7 +100,7 @@ private slots:
void writeComments(); void writeComments();
void writeBannerCard(int); void writeBannerCard(int);
void applyActiveGroupCriteria(); void applyActiveGroupCriteria();
void setSelectedIndex(const QModelIndex &newCardIndex); void setSelectedIndex(const QModelIndex &newCardIndex, bool preserveWidgetFocus);
void updateHash(); void updateHash();
void refreshShortcuts(); void refreshShortcuts();
void updateShowBannerCardComboBox(bool visible); void updateShowBannerCardComboBox(bool visible);

View file

@ -182,7 +182,7 @@ QModelIndex DeckStateManager::addCard(const ExactCard &card, const QString &zone
QModelIndex idx = modifyDeck(reason, [&card, &zone](auto model) { return model->addCard(card, zone); }); QModelIndex idx = modifyDeck(reason, [&card, &zone](auto model) { return model->addCard(card, zone); });
if (idx.isValid()) { if (idx.isValid()) {
emit focusIndexChanged(idx); emit focusIndexChanged(idx, true);
} }
return idx; return idx;
@ -208,7 +208,7 @@ QModelIndex DeckStateManager::decrementCard(const ExactCard &card, const QString
} }
if (idx.isValid()) { if (idx.isValid()) {
emit focusIndexChanged(idx); emit focusIndexChanged(idx, true);
} }
return idx; return idx;

View file

@ -290,8 +290,9 @@ signals:
/** /**
* The selected card on any views connected to this deck should be changed to this index. * The selected card on any views connected to this deck should be changed to this index.
* @param index The model index * @param index The model index
* @param preserveWidgetFocus Whether to keep the widget focus unchanged
*/ */
void focusIndexChanged(QModelIndex index); void focusIndexChanged(QModelIndex index, bool preserveWidgetFocus);
}; };
#endif // COCKATRICE_DECK_STATE_MANAGER_H #endif // COCKATRICE_DECK_STATE_MANAGER_H

View file

@ -198,7 +198,7 @@ void CardAmountWidget::addPrinting(const QString &zone)
}); });
if (newCardIndex.isValid()) { if (newCardIndex.isValid()) {
emit deckStateManager->focusIndexChanged(newCardIndex); emit deckStateManager->focusIndexChanged(newCardIndex, false);
} }
} }