From d73b0731593f6ee2918e8480e29ec8082bf43803 Mon Sep 17 00:00:00 2001 From: Aotrix <9aotrix@protonmail.com> Date: Sun, 2 Aug 2026 01:02:09 +0200 Subject: Add event when a card is double clicked --- gameView/main.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'gameView/main.cpp') diff --git a/gameView/main.cpp b/gameView/main.cpp index 95e49a3..0a212d4 100644 --- a/gameView/main.cpp +++ b/gameView/main.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -9,11 +10,13 @@ #include #include #include +#include #include +#include #include #include -class ControlInterface { +class ControlInterface : public QObject { public: ControlInterface ®isterListOfCardsWidget(std::shared_ptr &iListOfCards) { _listOfCardsWidget = iListOfCards; @@ -41,6 +44,9 @@ class ControlInterface { return *this; } + public slots: + void display_card(QListWidgetItem *) { std::cout << "coucou\n"; } + private: std::shared_ptr _listOfCardsWidget; std::shared_ptr _mainWindow; @@ -48,16 +54,22 @@ class ControlInterface { std::shared_ptr _rightView; std::shared_ptr _rightScene; + std::vector> _cards; + ControlInterface &fillListOfCards(const std::string &iCardsJsonPath) { std::ifstream aCardsJsonFile{iCardsJsonPath}; uint64_t aCardIndex{0}; + _cards.clear(); _listOfCardsWidget->clear(); for (auto &aCard : nlohmann::json::parse(aCardsJsonFile)) { + _cards.push_back(aCard); _listOfCardsWidget->insertItem(aCardIndex++, std::format("{} ({})", aCard["name"].get(), aCard["id"].get()) .c_str()); } + QObject::connect(_listOfCardsWidget.get(), &QListWidget::itemDoubleClicked, this, + &ControlInterface::display_card); _listOfCardsWidget->setVisible(true); _listOfCardsWidget->setFixedWidth(_listOfCardsWidget->sizeHintForColumn(0) + 2 * _listOfCardsWidget->frameWidth() + 20); -- cgit v1.2.3