mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-18 08:22:15 -07:00
DeckDock can handle its own decrement.
This commit is contained in:
parent
a868d37438
commit
e44ba3235b
5 changed files with 123 additions and 121 deletions
|
|
@ -51,6 +51,7 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor) : TabGenericDeckEdit
|
||||||
printingSelectorDockWidget = new DeckEditorPrintingSelectorDockWidget(this, this);
|
printingSelectorDockWidget = new DeckEditorPrintingSelectorDockWidget(this, this);
|
||||||
|
|
||||||
connect(deckDockWidget, &DeckEditorDeckDockWidget::cardChanged, this, &TabGenericDeckEditor::updateCard);
|
connect(deckDockWidget, &DeckEditorDeckDockWidget::cardChanged, this, &TabGenericDeckEditor::updateCard);
|
||||||
|
connect(this, &TabGenericDeckEditor::decrementCard, deckDockWidget, &DeckEditorDeckDockWidget::actDecrementCard);
|
||||||
connect(databaseDisplayDockWidget, &DeckEditorDatabaseDisplayWidget::cardChanged, this,
|
connect(databaseDisplayDockWidget, &DeckEditorDatabaseDisplayWidget::cardChanged, this,
|
||||||
&TabGenericDeckEditor::updateCard);
|
&TabGenericDeckEditor::updateCard);
|
||||||
connect(databaseDisplayDockWidget, &DeckEditorDatabaseDisplayWidget::addCardToMainDeck, this,
|
connect(databaseDisplayDockWidget, &DeckEditorDatabaseDisplayWidget::addCardToMainDeck, this,
|
||||||
|
|
|
||||||
|
|
@ -48,27 +48,83 @@ void TabGenericDeckEditor::updateCard(CardInfoPtr _card)
|
||||||
printingSelectorDockWidget->printingSelector->setCard(_card, DECK_ZONE_MAIN);
|
printingSelectorDockWidget->printingSelector->setCard(_card, DECK_ZONE_MAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TabGenericDeckEditor::confirmClose()
|
void TabGenericDeckEditor::addCardHelper(const CardInfoPtr info, QString zoneName)
|
||||||
{
|
{
|
||||||
if (modified) {
|
if (!info)
|
||||||
tabSupervisor->setCurrentWidget(this);
|
return;
|
||||||
int ret = createSaveConfirmationWindow()->exec();
|
if (info->getIsToken())
|
||||||
if (ret == QMessageBox::Save)
|
zoneName = DECK_ZONE_TOKENS;
|
||||||
return actSaveDeck();
|
|
||||||
else if (ret == QMessageBox::Cancel)
|
QModelIndex newCardIndex = deckDockWidget->deckModel->addPreferredPrintingCard(info->getName(), zoneName, false);
|
||||||
return false;
|
// recursiveExpand(newCardIndex);
|
||||||
}
|
deckDockWidget->deckView->clearSelection();
|
||||||
return true;
|
deckDockWidget->deckView->setCurrentIndex(newCardIndex);
|
||||||
|
setModified(true);
|
||||||
|
databaseDisplayDockWidget->searchEdit->setSelection(0, databaseDisplayDockWidget->searchEdit->text().length());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabGenericDeckEditor::closeRequest(bool forced)
|
void TabGenericDeckEditor::actAddCard(CardInfoPtr info)
|
||||||
{
|
{
|
||||||
if (!forced && !confirmClose()) {
|
if (QApplication::keyboardModifiers() & Qt::ControlModifier)
|
||||||
return;
|
actAddCardToSideboard(info);
|
||||||
}
|
else
|
||||||
|
addCardHelper(info, DECK_ZONE_MAIN);
|
||||||
|
deckMenu->setSaveStatus(true);
|
||||||
|
}
|
||||||
|
|
||||||
emit deckEditorClosing(this);
|
void TabGenericDeckEditor::actAddCardToSideboard(CardInfoPtr info)
|
||||||
close();
|
{
|
||||||
|
addCardHelper(info, DECK_ZONE_SIDE);
|
||||||
|
deckMenu->setSaveStatus(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabGenericDeckEditor::actDecrementCard(CardInfoPtr info)
|
||||||
|
{
|
||||||
|
emit decrementCard(info, DECK_ZONE_MAIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabGenericDeckEditor::actDecrementCardFromSideboard(CardInfoPtr info)
|
||||||
|
{
|
||||||
|
emit decrementCard(info, DECK_ZONE_SIDE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabGenericDeckEditor::actSwapCard(CardInfoPtr info, QString zoneName)
|
||||||
|
{
|
||||||
|
QString providerId = CardDatabaseManager::getInstance()->getSetInfoForCard(info).getProperty("uuid");
|
||||||
|
QString collectorNumber = CardDatabaseManager::getInstance()->getSetInfoForCard(info).getProperty("num");
|
||||||
|
deckDockWidget->swapCard(
|
||||||
|
deckDockWidget->deckModel->findCard(info->getName(), zoneName, providerId, collectorNumber));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabGenericDeckEditor::setDeck(DeckLoader *_deck)
|
||||||
|
{
|
||||||
|
deckDockWidget->setDeck(_deck);
|
||||||
|
PictureLoader::cacheCardPixmaps(CardDatabaseManager::getInstance()->getCards(getDeckList()->getCardList()));
|
||||||
|
setModified(false);
|
||||||
|
|
||||||
|
// If they load a deck, make the deck list appear
|
||||||
|
aDeckDockVisible->setChecked(true);
|
||||||
|
deckDockWidget->setVisible(aDeckDockVisible->isChecked());
|
||||||
|
}
|
||||||
|
|
||||||
|
DeckLoader *TabGenericDeckEditor::getDeckList() const
|
||||||
|
{
|
||||||
|
return deckDockWidget->getDeckList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabGenericDeckEditor::setModified(bool _modified)
|
||||||
|
{
|
||||||
|
modified = _modified;
|
||||||
|
emit tabTextChanged(this, getTabText());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns true if this tab is a blank newly opened tab, as if it was just created with the `New Deck` action.
|
||||||
|
*/
|
||||||
|
bool TabGenericDeckEditor::isBlankNewDeck() const
|
||||||
|
{
|
||||||
|
DeckLoader *deck = getDeckList();
|
||||||
|
return !modified && deck->hasNotBeenLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabGenericDeckEditor::actNewDeck()
|
void TabGenericDeckEditor::actNewDeck()
|
||||||
|
|
@ -387,105 +443,6 @@ void TabGenericDeckEditor::actAnalyzeDeckTappedout()
|
||||||
interface->analyzeDeck(getDeckList());
|
interface->analyzeDeck(getDeckList());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabGenericDeckEditor::addCardHelper(const CardInfoPtr info, QString zoneName)
|
|
||||||
{
|
|
||||||
if (!info)
|
|
||||||
return;
|
|
||||||
if (info->getIsToken())
|
|
||||||
zoneName = DECK_ZONE_TOKENS;
|
|
||||||
|
|
||||||
QModelIndex newCardIndex = deckDockWidget->deckModel->addPreferredPrintingCard(info->getName(), zoneName, false);
|
|
||||||
// recursiveExpand(newCardIndex);
|
|
||||||
deckDockWidget->deckView->clearSelection();
|
|
||||||
deckDockWidget->deckView->setCurrentIndex(newCardIndex);
|
|
||||||
setModified(true);
|
|
||||||
databaseDisplayDockWidget->searchEdit->setSelection(0, databaseDisplayDockWidget->searchEdit->text().length());
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabGenericDeckEditor::actAddCard(CardInfoPtr info)
|
|
||||||
{
|
|
||||||
if (QApplication::keyboardModifiers() & Qt::ControlModifier)
|
|
||||||
actAddCardToSideboard(info);
|
|
||||||
else
|
|
||||||
addCardHelper(info, DECK_ZONE_MAIN);
|
|
||||||
deckMenu->setSaveStatus(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabGenericDeckEditor::actAddCardToSideboard(CardInfoPtr info)
|
|
||||||
{
|
|
||||||
addCardHelper(info, DECK_ZONE_SIDE);
|
|
||||||
deckMenu->setSaveStatus(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabGenericDeckEditor::decrementCardHelper(CardInfoPtr info, QString zoneName)
|
|
||||||
{
|
|
||||||
if (!info)
|
|
||||||
return;
|
|
||||||
if (info->getIsToken())
|
|
||||||
zoneName = DECK_ZONE_TOKENS;
|
|
||||||
|
|
||||||
QString providerId = CardDatabaseManager::getInstance()->getSetInfoForCard(info).getProperty("uuid");
|
|
||||||
QString collectorNumber = CardDatabaseManager::getInstance()->getSetInfoForCard(info).getProperty("num");
|
|
||||||
|
|
||||||
QModelIndex idx = deckDockWidget->deckModel->findCard(info->getName(), zoneName, providerId, collectorNumber);
|
|
||||||
if (!idx.isValid()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
deckDockWidget->deckView->clearSelection();
|
|
||||||
deckDockWidget->deckView->setCurrentIndex(idx);
|
|
||||||
deckDockWidget->offsetCountAtIndex(idx, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabGenericDeckEditor::actSwapCard(CardInfoPtr info, QString zoneName)
|
|
||||||
{
|
|
||||||
QString providerId = CardDatabaseManager::getInstance()->getSetInfoForCard(info).getProperty("uuid");
|
|
||||||
QString collectorNumber = CardDatabaseManager::getInstance()->getSetInfoForCard(info).getProperty("num");
|
|
||||||
deckDockWidget->swapCard(
|
|
||||||
deckDockWidget->deckModel->findCard(info->getName(), zoneName, providerId, collectorNumber));
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabGenericDeckEditor::actDecrementCard(CardInfoPtr info)
|
|
||||||
{
|
|
||||||
decrementCardHelper(info, DECK_ZONE_MAIN);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabGenericDeckEditor::actDecrementCardFromSideboard(CardInfoPtr info)
|
|
||||||
{
|
|
||||||
decrementCardHelper(info, DECK_ZONE_SIDE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabGenericDeckEditor::setDeck(DeckLoader *_deck)
|
|
||||||
{
|
|
||||||
deckDockWidget->setDeck(_deck);
|
|
||||||
PictureLoader::cacheCardPixmaps(CardDatabaseManager::getInstance()->getCards(getDeckList()->getCardList()));
|
|
||||||
setModified(false);
|
|
||||||
|
|
||||||
// If they load a deck, make the deck list appear
|
|
||||||
aDeckDockVisible->setChecked(true);
|
|
||||||
deckDockWidget->setVisible(aDeckDockVisible->isChecked());
|
|
||||||
}
|
|
||||||
|
|
||||||
DeckLoader *TabGenericDeckEditor::getDeckList() const
|
|
||||||
{
|
|
||||||
return deckDockWidget->getDeckList();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabGenericDeckEditor::setModified(bool _modified)
|
|
||||||
{
|
|
||||||
modified = _modified;
|
|
||||||
emit tabTextChanged(this, getTabText());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Returns true if this tab is a blank newly opened tab, as if it was just created with the `New Deck` action.
|
|
||||||
*/
|
|
||||||
bool TabGenericDeckEditor::isBlankNewDeck() const
|
|
||||||
{
|
|
||||||
DeckLoader *deck = getDeckList();
|
|
||||||
return !modified && deck->hasNotBeenLoaded();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TabGenericDeckEditor::filterTreeChanged(FilterTree *filterTree)
|
void TabGenericDeckEditor::filterTreeChanged(FilterTree *filterTree)
|
||||||
{
|
{
|
||||||
databaseDisplayDockWidget->setFilterTree(filterTree);
|
databaseDisplayDockWidget->setFilterTree(filterTree);
|
||||||
|
|
@ -519,4 +476,27 @@ bool TabGenericDeckEditor::eventFilter(QObject *o, QEvent *e)
|
||||||
layouts.setDeckEditorPrintingSelectorSize(printingSelectorDockWidget->size());
|
layouts.setDeckEditorPrintingSelectorSize(printingSelectorDockWidget->size());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TabGenericDeckEditor::confirmClose()
|
||||||
|
{
|
||||||
|
if (modified) {
|
||||||
|
tabSupervisor->setCurrentWidget(this);
|
||||||
|
int ret = createSaveConfirmationWindow()->exec();
|
||||||
|
if (ret == QMessageBox::Save)
|
||||||
|
return actSaveDeck();
|
||||||
|
else if (ret == QMessageBox::Cancel)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabGenericDeckEditor::closeRequest(bool forced)
|
||||||
|
{
|
||||||
|
if (!forced && !confirmClose()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit deckEditorClosing(this);
|
||||||
|
close();
|
||||||
}
|
}
|
||||||
|
|
@ -81,6 +81,7 @@ public slots:
|
||||||
signals:
|
signals:
|
||||||
void openDeckEditor(const DeckLoader *deckLoader);
|
void openDeckEditor(const DeckLoader *deckLoader);
|
||||||
void deckEditorClosing(TabGenericDeckEditor *tab);
|
void deckEditorClosing(TabGenericDeckEditor *tab);
|
||||||
|
void decrementCard(CardInfoPtr card, QString zoneName);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
// Deck Operations
|
// Deck Operations
|
||||||
|
|
@ -129,7 +130,6 @@ protected:
|
||||||
|
|
||||||
// Helper functions for card actions
|
// Helper functions for card actions
|
||||||
void addCardHelper(CardInfoPtr info, QString zoneName);
|
void addCardHelper(CardInfoPtr info, QString zoneName);
|
||||||
void decrementCardHelper(CardInfoPtr info, QString zoneName);
|
|
||||||
void actSwapCard(CardInfoPtr info, QString zoneName);
|
void actSwapCard(CardInfoPtr info, QString zoneName);
|
||||||
virtual void openDeckFromFile(const QString &fileName, DeckOpenLocation deckOpenLocation);
|
virtual void openDeckFromFile(const QString &fileName, DeckOpenLocation deckOpenLocation);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,9 +46,9 @@ void DeckEditorDeckDockWidget::createDeckDock()
|
||||||
connect(&deckViewKeySignals, SIGNAL(onShiftS()), this, SLOT(actSwapCard()));
|
connect(&deckViewKeySignals, SIGNAL(onShiftS()), this, SLOT(actSwapCard()));
|
||||||
connect(&deckViewKeySignals, SIGNAL(onEnter()), this, SLOT(actIncrement()));
|
connect(&deckViewKeySignals, SIGNAL(onEnter()), this, SLOT(actIncrement()));
|
||||||
connect(&deckViewKeySignals, SIGNAL(onCtrlAltEqual()), this, SLOT(actIncrement()));
|
connect(&deckViewKeySignals, SIGNAL(onCtrlAltEqual()), this, SLOT(actIncrement()));
|
||||||
connect(&deckViewKeySignals, SIGNAL(onCtrlAltMinus()), this, SLOT(actDecrement()));
|
connect(&deckViewKeySignals, SIGNAL(onCtrlAltMinus()), this, SLOT(actDecrementSelection()));
|
||||||
connect(&deckViewKeySignals, SIGNAL(onShiftRight()), this, SLOT(actIncrement()));
|
connect(&deckViewKeySignals, SIGNAL(onShiftRight()), this, SLOT(actIncrement()));
|
||||||
connect(&deckViewKeySignals, SIGNAL(onShiftLeft()), this, SLOT(actDecrement()));
|
connect(&deckViewKeySignals, SIGNAL(onShiftLeft()), this, SLOT(actDecrementSelection()));
|
||||||
connect(&deckViewKeySignals, SIGNAL(onDelete()), this, SLOT(actRemoveCard()));
|
connect(&deckViewKeySignals, SIGNAL(onDelete()), this, SLOT(actRemoveCard()));
|
||||||
|
|
||||||
nameLabel = new QLabel();
|
nameLabel = new QLabel();
|
||||||
|
|
@ -87,7 +87,7 @@ void DeckEditorDeckDockWidget::createDeckDock()
|
||||||
|
|
||||||
aDecrement = new QAction(QString(), this);
|
aDecrement = new QAction(QString(), this);
|
||||||
aDecrement->setIcon(QPixmap("theme:icons/decrement"));
|
aDecrement->setIcon(QPixmap("theme:icons/decrement"));
|
||||||
connect(aDecrement, SIGNAL(triggered()), this, SLOT(actDecrement()));
|
connect(aDecrement, SIGNAL(triggered()), this, SLOT(actDecrementSelection()));
|
||||||
auto *tbDecrement = new QToolButton(this);
|
auto *tbDecrement = new QToolButton(this);
|
||||||
tbDecrement->setDefaultAction(aDecrement);
|
tbDecrement->setDefaultAction(aDecrement);
|
||||||
|
|
||||||
|
|
@ -409,7 +409,27 @@ bool DeckEditorDeckDockWidget::swapCard(const QModelIndex ¤tIndex)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckEditorDeckDockWidget::actDecrement()
|
void DeckEditorDeckDockWidget::actDecrementCard(CardInfoPtr info, QString zoneName)
|
||||||
|
{
|
||||||
|
if (!info)
|
||||||
|
return;
|
||||||
|
if (info->getIsToken())
|
||||||
|
zoneName = DECK_ZONE_TOKENS;
|
||||||
|
|
||||||
|
QString providerId = CardDatabaseManager::getInstance()->getSetInfoForCard(info).getProperty("uuid");
|
||||||
|
QString collectorNumber = CardDatabaseManager::getInstance()->getSetInfoForCard(info).getProperty("num");
|
||||||
|
|
||||||
|
QModelIndex idx = deckModel->findCard(info->getName(), zoneName, providerId, collectorNumber);
|
||||||
|
if (!idx.isValid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
deckView->clearSelection();
|
||||||
|
deckView->setCurrentIndex(idx);
|
||||||
|
offsetCountAtIndex(idx, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckEditorDeckDockWidget::actDecrementSelection()
|
||||||
{
|
{
|
||||||
auto selectedRows = getSelectedCardNodes();
|
auto selectedRows = getSelectedCardNodes();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,9 @@ public slots:
|
||||||
DeckLoader *getDeckList();
|
DeckLoader *getDeckList();
|
||||||
void actIncrement();
|
void actIncrement();
|
||||||
bool swapCard(const QModelIndex &idx);
|
bool swapCard(const QModelIndex &idx);
|
||||||
|
void actDecrementCard(CardInfoPtr info, QString zoneName);
|
||||||
|
void actDecrementSelection();
|
||||||
void actSwapCard();
|
void actSwapCard();
|
||||||
void actDecrement();
|
|
||||||
void actRemoveCard();
|
void actRemoveCard();
|
||||||
void offsetCountAtIndex(const QModelIndex &idx, int offset);
|
void offsetCountAtIndex(const QModelIndex &idx, int offset);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue