New visual deck storage (#5290)

* Add TabDeckStorageVisual

* Visual Deck Storage

* Add BannerCard to .cod format, use it in the visual deck storage widget.

* Show filename instead of deckname if deck name is empty.

* Lint.

* Don't delint cmake list through hooks.

* Add deck loading functionality.

* Open Decks on double click, not single click.

* Void event for now.

* Fix build issue with overload?

* Fix build issue with overload?

* Include QDebug.

* Turn the tab into a widget.

* Move the signals down to the widget, move the connections and slots up to the parent widgets.

* No banner card equals an empty CardInfoPtr.

* Add an option to sort by filename or last modified.

* Flip last modified comparison.

* Lint.

* Don't open decks twice in the storage tab.

* Fix unload deck not working by showing/hiding widgets instead of adding/removing to layout.

* Add a search bar.

* Add a card size slider.

* Lint.

* Lint.

* Lint.

* Fix settings mocks.

* No need to QDebug.

* No need to QDebug.

* Member variable.

* Member variable.

* Non-lambda.

* Change set to list conversion.

* Specify overload.

* Include MouseEvent

* Adjust font size dynamically.

* Add an option to show the visual deck storage on database load.

* Fix the close button not working on the tab, add an option to launch the visual deck storage tab to Cockatrice menu.

* Override virtual functions.

* Correct tab text.

* Add a setting to remember last used sorting order for visual deck storage widget.

* Update banner card combo box correctly.

* Fix mocks.

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
Co-authored-by: Zach H <zahalpern+github@gmail.com>
This commit is contained in:
BruebachL 2025-01-06 00:12:20 +01:00 committed by GitHub
parent 7496e79e8c
commit 62f7c7f9ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 834 additions and 31 deletions

View file

@ -26,6 +26,8 @@
#include <QApplication>
#include <QClipboard>
#include <QCloseEvent>
#include <QComboBox>
#include <QDebug>
#include <QDesktopServices>
#include <QDir>
#include <QDockWidget>
@ -95,6 +97,16 @@ void TabDeckEditor::createDeckDock()
commentsEdit->setObjectName("commentsEdit");
commentsLabel->setBuddy(commentsEdit);
connect(commentsEdit, SIGNAL(textChanged()), this, SLOT(updateComments()));
bannerCardLabel = new QLabel();
bannerCardLabel->setObjectName("bannerCardLabel");
bannerCardLabel->setText(tr("Banner Card"));
bannerCardComboBox = new QComboBox(this);
connect(deckModel, &DeckListModel::dataChanged, this, [this]() {
// Delay the update to avoid race conditions
QTimer::singleShot(100, this, &TabDeckEditor::updateBannerCardComboBox);
});
connect(bannerCardComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&TabDeckEditor::setBannerCard);
aIncrement = new QAction(QString(), this);
aIncrement->setIcon(QPixmap("theme:icons/increment"));
@ -128,6 +140,9 @@ void TabDeckEditor::createDeckDock()
upperLayout->addWidget(commentsLabel, 1, 0);
upperLayout->addWidget(commentsEdit, 1, 1);
upperLayout->addWidget(bannerCardLabel, 2, 0);
upperLayout->addWidget(bannerCardComboBox, 2, 1);
hashLabel1 = new QLabel();
hashLabel1->setObjectName("hashLabel1");
auto *hashSizePolicy = new QSizePolicy();
@ -802,6 +817,71 @@ void TabDeckEditor::updateComments()
setSaveStatus(true);
}
void TabDeckEditor::updateBannerCardComboBox()
{
// Store the current text of the combo box
QString currentText = bannerCardComboBox->currentText();
// Block signals temporarily
bool wasBlocked = bannerCardComboBox->blockSignals(true);
// Clear the existing items in the combo box
bannerCardComboBox->clear();
// Prepare the new items with deduplication
QSet<QString> bannerCardSet;
InnerDecklistNode *listRoot = deckModel->getDeckList()->getRoot();
for (int i = 0; i < listRoot->size(); i++) {
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
for (int j = 0; j < currentZone->size(); j++) {
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
if (!currentCard)
continue;
for (int k = 0; k < currentCard->getNumber(); ++k) {
CardInfoPtr info = CardDatabaseManager::getInstance()->getCard(currentCard->getName());
if (info) {
bannerCardSet.insert(currentCard->getName());
}
}
}
}
// Convert the QSet to a sorted QStringList
QStringList bannerCardChoices;
for (const QString &entry : bannerCardSet) {
bannerCardChoices.append(entry);
}
bannerCardChoices.sort(Qt::CaseInsensitive);
// Populate the combo box with new items
bannerCardComboBox->addItems(bannerCardChoices);
// Try to restore the previous selection by finding the currentText
int restoredIndex = bannerCardComboBox->findText(currentText);
if (restoredIndex != -1) {
bannerCardComboBox->setCurrentIndex(restoredIndex);
} else {
// Add a placeholder "-" and set it as the current selection
int bannerIndex = bannerCardComboBox->findText(deckModel->getDeckList()->getBannerCard());
if (bannerIndex != -1) {
bannerCardComboBox->setCurrentIndex(bannerIndex);
} else {
bannerCardComboBox->insertItem(0, "-");
bannerCardComboBox->setCurrentIndex(0);
}
}
// Restore the previous signal blocking state
bannerCardComboBox->blockSignals(wasBlocked);
}
void TabDeckEditor::setBannerCard(int /* changedIndex */)
{
qDebug() << "Banner card was set to: " << bannerCardComboBox->currentText();
deckModel->getDeckList()->setBannerCard(bannerCardComboBox->currentText());
}
void TabDeckEditor::updateCardInfo(CardInfoPtr _card)
{
cardInfo->setCard(_card);
@ -941,6 +1021,7 @@ void TabDeckEditor::actLoadDeck()
QString fileName = dialog.selectedFiles().at(0);
openDeckFromFile(fileName, deckOpenLocation);
updateBannerCardComboBox();
}
void TabDeckEditor::actOpenRecent(const QString &fileName)
@ -966,6 +1047,10 @@ void TabDeckEditor::openDeckFromFile(const QString &fileName, DeckOpenLocation d
auto *l = new DeckLoader;
if (l->loadFromFile(fileName, fmt)) {
SettingsCache::instance().recents().updateRecentlyOpenedDeckPaths(fileName);
updateBannerCardComboBox();
if (!l->getBannerCard().isEmpty()) {
bannerCardComboBox->setCurrentIndex(bannerCardComboBox->findText(l->getBannerCard()));
}
if (deckOpenLocation == NEW_TAB) {
emit openDeckEditor(l);
} else {
@ -1429,10 +1514,14 @@ void TabDeckEditor::actDecrement()
void TabDeckEditor::setDeck(DeckLoader *_deck)
{
qDebug() << " ORIGINAL BANNER CARD " << _deck->getBannerCard();
deckModel->setDeckList(_deck);
nameEdit->setText(deckModel->getDeckList()->getName());
commentsEdit->setText(deckModel->getDeckList()->getComments());
qDebug() << deckModel->getDeckList()->getBannerCard() << " was the banner card";
bannerCardComboBox->setCurrentText(deckModel->getDeckList()->getBannerCard());
updateBannerCardComboBox();
updateHash();
deckModel->sort(deckView->header()->sortIndicatorSection(), deckView->header()->sortIndicatorOrder());
deckView->expandAll();