mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-01-01 15:49:58 -08:00
[Refactor] Move prev/next card logic out of PrintingSelector (#6450)
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -138,58 +138,6 @@ void PrintingSelector::setCard(const CardInfoPtr &newCard, const QString &_curre
|
||||
flowWidget->repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects the previous card in the list.
|
||||
*/
|
||||
void PrintingSelector::selectPreviousCard()
|
||||
{
|
||||
selectCard(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects the next card in the list.
|
||||
*/
|
||||
void PrintingSelector::selectNextCard()
|
||||
{
|
||||
selectCard(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Selects a card based on the change direction.
|
||||
*
|
||||
* @param changeBy The direction to change, -1 for previous, 1 for next.
|
||||
*/
|
||||
void PrintingSelector::selectCard(const 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 Loads and displays all sets for the current selected card.
|
||||
*/
|
||||
|
||||
@@ -48,13 +48,21 @@ public:
|
||||
public slots:
|
||||
void retranslateUi();
|
||||
void updateDisplay();
|
||||
void selectPreviousCard();
|
||||
void selectNextCard();
|
||||
void toggleVisibilityNavigationButtons(bool _state);
|
||||
|
||||
private slots:
|
||||
void printingsInDeckChanged();
|
||||
|
||||
signals:
|
||||
/**
|
||||
* Requests the previous card in the list
|
||||
*/
|
||||
void prevCardRequested();
|
||||
/**
|
||||
* Requests the next card in the list
|
||||
*/
|
||||
void nextCardRequested();
|
||||
|
||||
private:
|
||||
QVBoxLayout *layout;
|
||||
SettingsButtonWidget *displayOptionsWidget;
|
||||
@@ -73,7 +81,6 @@ private:
|
||||
QString currentZone;
|
||||
QTimer *widgetLoadingBufferTimer;
|
||||
int currentIndex = 0;
|
||||
void selectCard(int changeBy);
|
||||
};
|
||||
|
||||
#endif // PRINTING_SELECTOR_H
|
||||
|
||||
@@ -42,8 +42,8 @@ PrintingSelectorCardSelectionWidget::PrintingSelectorCardSelectionWidget(Printin
|
||||
*/
|
||||
void PrintingSelectorCardSelectionWidget::connectSignals()
|
||||
{
|
||||
connect(previousCardButton, &QPushButton::clicked, parent, &PrintingSelector::selectPreviousCard);
|
||||
connect(nextCardButton, &QPushButton::clicked, parent, &PrintingSelector::selectNextCard);
|
||||
connect(previousCardButton, &QPushButton::clicked, parent, &PrintingSelector::prevCardRequested);
|
||||
connect(nextCardButton, &QPushButton::clicked, parent, &PrintingSelector::nextCardRequested);
|
||||
}
|
||||
|
||||
void PrintingSelectorCardSelectionWidget::selectSetForCards()
|
||||
|
||||
Reference in New Issue
Block a user