mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
[Refactor] Move prev/next card logic out of PrintingSelector (#6450)
This commit is contained in:
parent
70f9982c29
commit
ca3f6bba02
6 changed files with 65 additions and 57 deletions
|
|
@ -548,6 +548,52 @@ void DeckEditorDeckDockWidget::cleanDeck()
|
|||
deckTagsDisplayWidget->setTags(deckModel->getDeckList()->getTags());
|
||||
}
|
||||
|
||||
void DeckEditorDeckDockWidget::selectPrevCard()
|
||||
{
|
||||
changeSelectedCard(-1);
|
||||
}
|
||||
|
||||
void DeckEditorDeckDockWidget::selectNextCard()
|
||||
{
|
||||
changeSelectedCard(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects a card based on the change direction.
|
||||
*
|
||||
* @param changeBy The direction to change, -1 for previous, 1 for next.
|
||||
*/
|
||||
void DeckEditorDeckDockWidget::changeSelectedCard(int changeBy)
|
||||
{
|
||||
if (changeBy == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the current index of the selected item
|
||||
auto deckViewCurrentIndex = deckView->currentIndex();
|
||||
|
||||
auto nextIndex = deckViewCurrentIndex.siblingAtRow(deckViewCurrentIndex.row() + changeBy);
|
||||
if (!nextIndex.isValid()) {
|
||||
nextIndex = deckViewCurrentIndex;
|
||||
|
||||
// Increment to the next valid index, skipping header rows
|
||||
AbstractDecklistNode *node;
|
||||
do {
|
||||
if (changeBy > 0) {
|
||||
nextIndex = deckView->indexBelow(nextIndex);
|
||||
} else {
|
||||
nextIndex = deckView->indexAbove(nextIndex);
|
||||
}
|
||||
node = static_cast<AbstractDecklistNode *>(nextIndex.internalPointer());
|
||||
} while (node && node->isDeckHeader());
|
||||
}
|
||||
|
||||
if (nextIndex.isValid()) {
|
||||
deckView->setCurrentIndex(nextIndex);
|
||||
deckView->setFocus(Qt::FocusReason::MouseFocusReason);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Expands all parents of the given index.
|
||||
* @param sourceIndex The index to expand (model source index)
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ public:
|
|||
|
||||
public slots:
|
||||
void cleanDeck();
|
||||
void selectPrevCard();
|
||||
void selectNextCard();
|
||||
void updateBannerCardComboBox();
|
||||
void setDeck(const LoadedDeck &_deck);
|
||||
void syncDisplayWidgetsToModel();
|
||||
|
|
@ -122,6 +124,7 @@ private slots:
|
|||
void updateShowBannerCardComboBox(bool visible);
|
||||
void updateShowTagsWidget(bool visible);
|
||||
void syncBannerCardComboBoxSelectionWithDeck();
|
||||
void changeSelectedCard(int changeBy);
|
||||
void recursiveExpand(const QModelIndex &parent);
|
||||
void expandAll();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -33,6 +33,10 @@ void DeckEditorPrintingSelectorDockWidget::createPrintingSelectorDock()
|
|||
|
||||
installEventFilter(deckEditor);
|
||||
connect(this, &QDockWidget::topLevelChanged, deckEditor, &AbstractTabDeckEditor::dockTopLevelChanged);
|
||||
connect(printingSelector, &PrintingSelector::prevCardRequested, deckEditor->getDeckDockWidget(),
|
||||
&DeckEditorDeckDockWidget::selectPrevCard);
|
||||
connect(printingSelector, &PrintingSelector::nextCardRequested, deckEditor->getDeckDockWidget(),
|
||||
&DeckEditorDeckDockWidget::selectNextCard);
|
||||
}
|
||||
|
||||
void DeckEditorPrintingSelectorDockWidget::retranslateUi()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue