mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 00:24:47 -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());
|
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.
|
* @brief Expands all parents of the given index.
|
||||||
* @param sourceIndex The index to expand (model source index)
|
* @param sourceIndex The index to expand (model source index)
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,8 @@ public:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void cleanDeck();
|
void cleanDeck();
|
||||||
|
void selectPrevCard();
|
||||||
|
void selectNextCard();
|
||||||
void updateBannerCardComboBox();
|
void updateBannerCardComboBox();
|
||||||
void setDeck(const LoadedDeck &_deck);
|
void setDeck(const LoadedDeck &_deck);
|
||||||
void syncDisplayWidgetsToModel();
|
void syncDisplayWidgetsToModel();
|
||||||
|
|
@ -122,6 +124,7 @@ private slots:
|
||||||
void updateShowBannerCardComboBox(bool visible);
|
void updateShowBannerCardComboBox(bool visible);
|
||||||
void updateShowTagsWidget(bool visible);
|
void updateShowTagsWidget(bool visible);
|
||||||
void syncBannerCardComboBoxSelectionWithDeck();
|
void syncBannerCardComboBoxSelectionWithDeck();
|
||||||
|
void changeSelectedCard(int changeBy);
|
||||||
void recursiveExpand(const QModelIndex &parent);
|
void recursiveExpand(const QModelIndex &parent);
|
||||||
void expandAll();
|
void expandAll();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,10 @@ void DeckEditorPrintingSelectorDockWidget::createPrintingSelectorDock()
|
||||||
|
|
||||||
installEventFilter(deckEditor);
|
installEventFilter(deckEditor);
|
||||||
connect(this, &QDockWidget::topLevelChanged, deckEditor, &AbstractTabDeckEditor::dockTopLevelChanged);
|
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()
|
void DeckEditorPrintingSelectorDockWidget::retranslateUi()
|
||||||
|
|
|
||||||
|
|
@ -138,58 +138,6 @@ void PrintingSelector::setCard(const CardInfoPtr &newCard, const QString &_curre
|
||||||
flowWidget->repaint();
|
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.
|
* @brief Loads and displays all sets for the current selected card.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -48,13 +48,21 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void updateDisplay();
|
void updateDisplay();
|
||||||
void selectPreviousCard();
|
|
||||||
void selectNextCard();
|
|
||||||
void toggleVisibilityNavigationButtons(bool _state);
|
void toggleVisibilityNavigationButtons(bool _state);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void printingsInDeckChanged();
|
void printingsInDeckChanged();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
/**
|
||||||
|
* Requests the previous card in the list
|
||||||
|
*/
|
||||||
|
void prevCardRequested();
|
||||||
|
/**
|
||||||
|
* Requests the next card in the list
|
||||||
|
*/
|
||||||
|
void nextCardRequested();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVBoxLayout *layout;
|
QVBoxLayout *layout;
|
||||||
SettingsButtonWidget *displayOptionsWidget;
|
SettingsButtonWidget *displayOptionsWidget;
|
||||||
|
|
@ -73,7 +81,6 @@ private:
|
||||||
QString currentZone;
|
QString currentZone;
|
||||||
QTimer *widgetLoadingBufferTimer;
|
QTimer *widgetLoadingBufferTimer;
|
||||||
int currentIndex = 0;
|
int currentIndex = 0;
|
||||||
void selectCard(int changeBy);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PRINTING_SELECTOR_H
|
#endif // PRINTING_SELECTOR_H
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,8 @@ PrintingSelectorCardSelectionWidget::PrintingSelectorCardSelectionWidget(Printin
|
||||||
*/
|
*/
|
||||||
void PrintingSelectorCardSelectionWidget::connectSignals()
|
void PrintingSelectorCardSelectionWidget::connectSignals()
|
||||||
{
|
{
|
||||||
connect(previousCardButton, &QPushButton::clicked, parent, &PrintingSelector::selectPreviousCard);
|
connect(previousCardButton, &QPushButton::clicked, parent, &PrintingSelector::prevCardRequested);
|
||||||
connect(nextCardButton, &QPushButton::clicked, parent, &PrintingSelector::selectNextCard);
|
connect(nextCardButton, &QPushButton::clicked, parent, &PrintingSelector::nextCardRequested);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintingSelectorCardSelectionWidget::selectSetForCards()
|
void PrintingSelectorCardSelectionWidget::selectSetForCards()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue