diff options
| -rw-r--r-- | gameView/main.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
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 <QtWidgets> #include <format> #include <fstream> +#include <iostream> #include <nlohmann/json.hpp> #include <qapplication.h> #include <qboxlayout.h> @@ -9,11 +10,13 @@ #include <qlistwidget.h> #include <qmenubar.h> #include <qnamespace.h> +#include <qobject.h> #include <qpushbutton.h> +#include <qtmetamacros.h> #include <qtoolbar.h> #include <qwidget.h> -class ControlInterface { +class ControlInterface : public QObject { public: ControlInterface ®isterListOfCardsWidget(std::shared_ptr<QListWidget> &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<QListWidget> _listOfCardsWidget; std::shared_ptr<QWidget> _mainWindow; @@ -48,16 +54,22 @@ class ControlInterface { std::shared_ptr<QGraphicsView> _rightView; std::shared_ptr<QGraphicsScene> _rightScene; + std::vector<nlohmann::basic_json<>> _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<std::string>(), aCard["id"].get<uint64_t>()) .c_str()); } + QObject::connect(_listOfCardsWidget.get(), &QListWidget::itemDoubleClicked, this, + &ControlInterface::display_card); _listOfCardsWidget->setVisible(true); _listOfCardsWidget->setFixedWidth(_listOfCardsWidget->sizeHintForColumn(0) + 2 * _listOfCardsWidget->frameWidth() + 20); |
