From a0a7ca6a7b5457f1426c6df23d4e628c12749c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Sun, 22 Dec 2024 15:59:12 +0100 Subject: [PATCH] Add deck loading functionality. --- cockatrice/CMakeLists.txt | 1 + .../tab_deck_storage_visual.cpp | 18 +++++---- .../tab_deck_storage_visual.h | 4 +- ...rd_info_picture_with_text_overlay_widget.h | 2 +- .../deck_preview_card_picture_widget.cpp | 37 +++++++++++++++++++ .../cards/deck_preview_card_picture_widget.h | 34 +++++++++++++++++ 6 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 cockatrice/src/client/ui/widgets/cards/deck_preview_card_picture_widget.cpp create mode 100644 cockatrice/src/client/ui/widgets/cards/deck_preview_card_picture_widget.h diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index 51ecf8559..6c46bb524 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -160,6 +160,7 @@ set(cockatrice_SOURCES src/game/zones/view_zone_widget.cpp src/game/zones/view_zone.cpp src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp + src/client/ui/widgets/cards/deck_preview_card_picture_widget.cpp ${VERSION_STRING_CPP} ) diff --git a/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp b/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp index 442a90a62..bad7402d1 100644 --- a/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp +++ b/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp @@ -11,8 +11,10 @@ #include "../../ui/picture_loader.h" #include "../../ui/widgets/cards/card_info_picture_widget.h" #include "../../ui/widgets/cards/card_info_picture_with_text_overlay_widget.h" +#include "../../ui/widgets/cards/deck_preview_card_picture_widget.h" #include "../../ui/widgets/general/layout_containers/flow_widget.h" #include "../../ui/widgets/general/layout_containers/overlap_widget.h" +#include "../tab_supervisor.h" #include "pb/command_deck_del.pb.h" #include @@ -55,6 +57,8 @@ TabDeckStorageVisual::TabDeckStorageVisual(TabSupervisor *_tabSupervisor, Abstra aDeleteLocalDeck->setIcon(QPixmap("theme:icons/remove_row")); connect(aDeleteLocalDeck, SIGNAL(triggered()), this, SLOT(actDeleteLocalDeck())); + connect(this, &TabDeckStorageVisual::openDeckEditor, tabSupervisor, &TabSupervisor::addDeckEditorTab); + leftToolBar->addAction(aOpenLocalDeck); leftToolBar->addAction(aDeleteLocalDeck); retranslateUi(); @@ -90,27 +94,25 @@ QStringList TabDeckStorageVisual::getBannerCardsForDecks() deck_loader->loadFromFile(file, DeckLoader::CockatriceFormat); deck_list_model->setDeckList(new DeckLoader(*deck_loader)); - auto *display = new CardInfoPictureWithTextOverlayWidget(flow_widget, true); + auto *display = new DeckPreviewCardPictureWidget(flow_widget, true); qDebug() << "Banner card is: " << deck_loader->getBannerCard(); display->setCard(CardDatabaseManager::getInstance()->getCard(deck_loader->getBannerCard())); display->setOverlayText(deck_loader->getName().isEmpty() ? QFileInfo(deck_loader->getLastFileName()).fileName() : deck_loader->getName()); display->setFontSize(24); + display->setFilePath(deck_loader->getLastFileName()); + connect(display, &DeckPreviewCardPictureWidget::imageClicked, this, &TabDeckStorageVisual::actOpenLocalDeck); flow_widget->addWidget(display); } return QStringList("lol"); } -void TabDeckStorageVisual::actOpenLocalDeck() +void TabDeckStorageVisual::actOpenLocalDeck(QMouseEvent *event, DeckPreviewCardPictureWidget *instance) { - QModelIndex curLeft = localDirView->selectionModel()->currentIndex(); - if (localDirModel->isDir(curLeft)) - return; - QString filePath = localDirModel->filePath(curLeft); - + qDebug() << event; DeckLoader deckLoader; - if (!deckLoader.loadFromFile(filePath, DeckLoader::CockatriceFormat)) + if (!deckLoader.loadFromFile(instance->filePath, DeckLoader::CockatriceFormat)) return; emit openDeckEditor(&deckLoader); diff --git a/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.h b/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.h index 65d49bf33..8ba37efba 100644 --- a/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.h +++ b/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.h @@ -5,6 +5,8 @@ #include "../../../deck/deck_view.h" #include "../../ui/layouts/flow_layout.h" #include "../../ui/layouts/overlap_layout.h" +#include "../../ui/widgets/cards/card_info_picture_with_text_overlay_widget.h" +#include "../../ui/widgets/cards/deck_preview_card_picture_widget.h" #include "../../ui/widgets/general/layout_containers/flow_widget.h" #include "../tab.h" @@ -38,7 +40,7 @@ private: QString getTargetPath() const; QStringList getBannerCardsForDecks(); private slots: - void actOpenLocalDeck(); + void actOpenLocalDeck(QMouseEvent *event, DeckPreviewCardPictureWidget *instance); void actDeleteLocalDeck(); public: diff --git a/cockatrice/src/client/ui/widgets/cards/card_info_picture_with_text_overlay_widget.h b/cockatrice/src/client/ui/widgets/cards/card_info_picture_with_text_overlay_widget.h index 0290ce3eb..44107362a 100644 --- a/cockatrice/src/client/ui/widgets/cards/card_info_picture_with_text_overlay_widget.h +++ b/cockatrice/src/client/ui/widgets/cards/card_info_picture_with_text_overlay_widget.h @@ -7,7 +7,7 @@ #include #include -class CardInfoPictureWithTextOverlayWidget final : public CardInfoPictureWidget +class CardInfoPictureWithTextOverlayWidget : public CardInfoPictureWidget { Q_OBJECT diff --git a/cockatrice/src/client/ui/widgets/cards/deck_preview_card_picture_widget.cpp b/cockatrice/src/client/ui/widgets/cards/deck_preview_card_picture_widget.cpp new file mode 100644 index 000000000..7038dbc44 --- /dev/null +++ b/cockatrice/src/client/ui/widgets/cards/deck_preview_card_picture_widget.cpp @@ -0,0 +1,37 @@ +#include "deck_preview_card_picture_widget.h" + +#include +#include +#include +#include + +/** + * @brief Constructs a CardPictureWithTextOverlay widget. + * @param parent The parent widget. + * @param hoverToZoomEnabled If this widget will spawn a larger widget when hovered over. + * @param textColor The color of the overlay text. + * @param outlineColor The color of the outline around the text. + * @param fontSize The font size of the overlay text. + * @param alignment The alignment of the text within the overlay. + * + * Sets the widget's size policy and default border style. + */ +DeckPreviewCardPictureWidget::DeckPreviewCardPictureWidget(QWidget *parent, + const bool hoverToZoomEnabled, + const QColor &textColor, + const QColor &outlineColor, + const int fontSize, + const Qt::Alignment alignment) + : CardInfoPictureWithTextOverlayWidget(parent, hoverToZoomEnabled, textColor, outlineColor, fontSize, alignment) +{ +} + +void DeckPreviewCardPictureWidget::mousePressEvent(QMouseEvent *event) +{ + emit imageClicked(event, this); +} + +void DeckPreviewCardPictureWidget::setFilePath(const QString &_filePath) +{ + filePath = _filePath; +} diff --git a/cockatrice/src/client/ui/widgets/cards/deck_preview_card_picture_widget.h b/cockatrice/src/client/ui/widgets/cards/deck_preview_card_picture_widget.h new file mode 100644 index 000000000..86ab689f2 --- /dev/null +++ b/cockatrice/src/client/ui/widgets/cards/deck_preview_card_picture_widget.h @@ -0,0 +1,34 @@ +#ifndef DECK_PREVIEW_CARD_PICTURE_WIDGET_H +#define DECK_PREVIEW_CARD_PICTURE_WIDGET_H + +#include "card_info_picture_with_text_overlay_widget.h" + +#include +#include +#include + +class DeckPreviewCardPictureWidget final : public CardInfoPictureWithTextOverlayWidget +{ + Q_OBJECT + +public: + explicit DeckPreviewCardPictureWidget(QWidget *parent = nullptr, + bool hoverToZoomEnabled = false, + const QColor &textColor = Qt::white, + const QColor &outlineColor = Qt::black, + int fontSize = 12, + Qt::Alignment alignment = Qt::AlignCenter); + + QString filePath; + +signals: + void imageClicked(QMouseEvent *event, DeckPreviewCardPictureWidget *instance); + +public slots: + void setFilePath(const QString &filePath); + +protected: + void mousePressEvent(QMouseEvent *event) override; +}; + +#endif // DECK_PREVIEW_CARD_PICTURE_WIDGET_H