From ad3f1f0c784cd38357b652e566d681f09a425996 Mon Sep 17 00:00:00 2001 From: Aotrix <9aotrix@protonmail.com> Date: Thu, 3 Sep 2026 22:38:25 +0200 Subject: Create ControlCentre --- gameView/main.cpp | 183 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 128 insertions(+), 55 deletions(-) (limited to 'gameView') diff --git a/gameView/main.cpp b/gameView/main.cpp index 0a212d4..2478735 100644 --- a/gameView/main.cpp +++ b/gameView/main.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include @@ -16,36 +16,68 @@ #include #include -class ControlInterface : public QObject { +class ControlInterface : public QObject +{ public: - ControlInterface ®isterListOfCardsWidget(std::shared_ptr &iListOfCards) { + ControlInterface& registerListOfCardsWidget(std::shared_ptr& iListOfCards) + { _listOfCardsWidget = iListOfCards; return *this; } - ControlInterface ®isterMainWindow(std::shared_ptr &iMainWindow) { + + ControlInterface& registerMainWindow(std::shared_ptr& iMainWindow) + { _mainWindow = iMainWindow; return *this; } - ControlInterface ®isterMainMenuBar(std::shared_ptr &iMenuBar) { + + ControlInterface& registerMainMenuBar(std::shared_ptr& iMenuBar) + { _mainMenuBar = iMenuBar; return *this; } - ControlInterface ®isterRightView(std::shared_ptr &iRightView) { + + ControlInterface& registerRightView(std::shared_ptr& iRightView) + { _rightView = iRightView; return *this; } - std::shared_ptr listOfCardsWidget() { return _listOfCardsWidget; } - std::shared_ptr mainWindow() { return _mainWindow; } - std::shared_ptr mainMenuBar() { return _mainMenuBar; } - std::shared_ptr rightView() { return _rightView; } - ControlInterface &configure() { + std::shared_ptr listOfCardsWidget() + { + return _listOfCardsWidget; + } + + std::shared_ptr mainWindow() + { + return _mainWindow; + } + + std::shared_ptr mainMenuBar() + { + return _mainMenuBar; + } + + std::shared_ptr rightView() + { + return _rightView; + } + + ControlInterface& configure() + { configureListOfCardsWidget().configureMainMenuBar().configureRightGraphicsView(); return *this; } public slots: - void display_card(QListWidgetItem *) { std::cout << "coucou\n"; } + + void display_card(QListWidgetItem* iItem) + { + _popUpWindowSelectCard = std::make_shared(_mainWindow.get()); + _popUpWindowSelectCard->resize(400, 500); + _popUpWindowSelectCard->setWindowFlag(Qt::WindowType::Dialog); + _popUpWindowSelectCard->show(); + } private: std::shared_ptr _listOfCardsWidget; @@ -55,13 +87,16 @@ class ControlInterface : public QObject { std::shared_ptr _rightScene; std::vector> _cards; + std::shared_ptr _popUpWindowSelectCard; - ControlInterface &fillListOfCards(const std::string &iCardsJsonPath) { + 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)) { + for (auto& aCard : nlohmann::json::parse(aCardsJsonFile)) + { _cards.push_back(aCard); _listOfCardsWidget->insertItem(aCardIndex++, std::format("{} ({})", aCard["name"].get(), @@ -76,63 +111,101 @@ class ControlInterface : public QObject { _mainWindow->resize(1500, 1000); return *this; } - ControlInterface &configureListOfCardsWidget() { + + ControlInterface& configureListOfCardsWidget() + { _listOfCardsWidget->hide(); return *this; } - ControlInterface &configureMainMenuBar() { - QMenu *aOpenMenu = _mainMenuBar->addMenu("File"); - aOpenMenu->addAction("Open JSON file", [this] { - QFileDialog aFileDialog; - aFileDialog.setWindowTitle("Choose JSON file"); - QDir aCurrentDir{QDir::currentPath()}; - aFileDialog.setDirectory(aCurrentDir); - aFileDialog.setFileMode(QFileDialog::ExistingFile); - aFileDialog.setOption(QFileDialog::ShowDirsOnly, false); - aFileDialog.setNameFilter("*.json"); - aFileDialog.exec(); - const QStringList kFilePaths{aFileDialog.selectedFiles()}; - if (kFilePaths.size() > 0) { - fillListOfCards(kFilePaths[0].toStdString()); - _rightView->setVisible(true); - } - }); + + ControlInterface& configureMainMenuBar() + { + QMenu* aOpenMenu = _mainMenuBar->addMenu("File"); + aOpenMenu->addAction("Open JSON file", + [this] + { + QFileDialog aFileDialog; + aFileDialog.setWindowTitle("Choose JSON file"); + QDir aCurrentDir{QDir::currentPath()}; + aFileDialog.setDirectory(aCurrentDir); + aFileDialog.setFileMode(QFileDialog::ExistingFile); + aFileDialog.setOption(QFileDialog::ShowDirsOnly, false); + aFileDialog.setNameFilter("*.json"); + aFileDialog.exec(); + const QStringList kFilePaths{aFileDialog.selectedFiles()}; + if (kFilePaths.size() > 0) + { + fillListOfCards(kFilePaths[0].toStdString()); + _rightView->setVisible(true); + } + }); aOpenMenu->addAction("Quit", [this] { _mainWindow->close(); }); return *this; } - ControlInterface &configureRightGraphicsView() { - _rightScene = std::make_shared(); - QGraphicsRectItem *rect = _rightScene->addRect(QRectF(0, 0, 100, 100)); - QGraphicsItem *item = _rightScene->itemAt(50, 50, QTransform()); + + ControlInterface& configureRightGraphicsView() + { + _rightScene = std::make_shared(); + QGraphicsRectItem* rect = _rightScene->addRect(QRectF(0, 0, 100, 100)); + QGraphicsItem* item = _rightScene->itemAt(50, 50, QTransform()); _rightView->setScene(_rightScene.get()); _rightView->hide(); return *this; } }; -int main(int argc, char *argv[]) { +// int main(int argc, +// char* argv[]) +//{ +// QApplication aApplication(argc, argv); +// auto aWindow = std::make_shared(); +// aWindow->resize(400, 50); +// // Set Dialog flag for i3 users +// aWindow->setWindowFlag(Qt::WindowType::Dialog); +// +// QGridLayout aLayout(aWindow.get()); +// QHBoxLayout aHLayout(aLayout.widget()); +// auto aMenuBar = std::make_shared(); +// aLayout.addWidget(aMenuBar.get(), 0, 0); +// auto aListOfCards = std::make_shared(); +// aLayout.addLayout(&aHLayout, 1, 0); +// aHLayout.addWidget(aListOfCards.get()); +// auto aRightView = std::make_shared(); +// aHLayout.addWidget(aRightView.get()); +// +// ControlInterface aControlInterface; +// aControlInterface.registerListOfCardsWidget(aListOfCards) +// .registerMainWindow(aWindow) +// .registerMainMenuBar(aMenuBar) +// .registerRightView(aRightView) +// .configure(); +// aWindow->show(); +// aWindow->setWindowTitle("Hearthstone simulator"); +// return aApplication.exec(); +// } + +class ControlCentre : public QObject +{ + Q_OBJECT + public: + /* view */ + public slots: + void setView(/* View */); + + signals: + void viewSelected(/* selected view */); + + private: +}; + +auto main(int argc, + char* argv[]) -> int +{ QApplication aApplication(argc, argv); auto aWindow = std::make_shared(); - aWindow->resize(400, 50); + aWindow->resize(1400, 800); // Set Dialog flag for i3 users aWindow->setWindowFlag(Qt::WindowType::Dialog); - - QGridLayout aLayout(aWindow.get()); - QHBoxLayout aHLayout(aLayout.widget()); - auto aMenuBar = std::make_shared(); - aLayout.addWidget(aMenuBar.get(), 0, 0); - auto aListOfCards = std::make_shared(); - aLayout.addLayout(&aHLayout, 1, 0); - aHLayout.addWidget(aListOfCards.get()); - auto aRightView = std::make_shared(); - aHLayout.addWidget(aRightView.get()); - - ControlInterface aControlInterface; - aControlInterface.registerListOfCardsWidget(aListOfCards) - .registerMainWindow(aWindow) - .registerMainMenuBar(aMenuBar) - .registerRightView(aRightView) - .configure(); aWindow->show(); aWindow->setWindowTitle("Hearthstone simulator"); return aApplication.exec(); -- cgit v1.2.3