summaryrefslogtreecommitdiff
path: root/gameView/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gameView/main.cpp')
-rw-r--r--gameView/main.cpp183
1 files changed, 128 insertions, 55 deletions
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 <QtWidgets>
#include <format>
#include <fstream>
-#include <iostream>
+#include <memory>
#include <nlohmann/json.hpp>
#include <qapplication.h>
#include <qboxlayout.h>
@@ -16,36 +16,68 @@
#include <qtoolbar.h>
#include <qwidget.h>
-class ControlInterface : public QObject {
+class ControlInterface : public QObject
+{
public:
- ControlInterface &registerListOfCardsWidget(std::shared_ptr<QListWidget> &iListOfCards) {
+ ControlInterface& registerListOfCardsWidget(std::shared_ptr<QListWidget>& iListOfCards)
+ {
_listOfCardsWidget = iListOfCards;
return *this;
}
- ControlInterface &registerMainWindow(std::shared_ptr<QWidget> &iMainWindow) {
+
+ ControlInterface& registerMainWindow(std::shared_ptr<QWidget>& iMainWindow)
+ {
_mainWindow = iMainWindow;
return *this;
}
- ControlInterface &registerMainMenuBar(std::shared_ptr<QMenuBar> &iMenuBar) {
+
+ ControlInterface& registerMainMenuBar(std::shared_ptr<QMenuBar>& iMenuBar)
+ {
_mainMenuBar = iMenuBar;
return *this;
}
- ControlInterface &registerRightView(std::shared_ptr<QGraphicsView> &iRightView) {
+
+ ControlInterface& registerRightView(std::shared_ptr<QGraphicsView>& iRightView)
+ {
_rightView = iRightView;
return *this;
}
- std::shared_ptr<QWidget> listOfCardsWidget() { return _listOfCardsWidget; }
- std::shared_ptr<QWidget> mainWindow() { return _mainWindow; }
- std::shared_ptr<QMenuBar> mainMenuBar() { return _mainMenuBar; }
- std::shared_ptr<QGraphicsView> rightView() { return _rightView; }
- ControlInterface &configure() {
+ std::shared_ptr<QWidget> listOfCardsWidget()
+ {
+ return _listOfCardsWidget;
+ }
+
+ std::shared_ptr<QWidget> mainWindow()
+ {
+ return _mainWindow;
+ }
+
+ std::shared_ptr<QMenuBar> mainMenuBar()
+ {
+ return _mainMenuBar;
+ }
+
+ std::shared_ptr<QGraphicsView> 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<QWidget>(_mainWindow.get());
+ _popUpWindowSelectCard->resize(400, 500);
+ _popUpWindowSelectCard->setWindowFlag(Qt::WindowType::Dialog);
+ _popUpWindowSelectCard->show();
+ }
private:
std::shared_ptr<QListWidget> _listOfCardsWidget;
@@ -55,13 +87,16 @@ class ControlInterface : public QObject {
std::shared_ptr<QGraphicsScene> _rightScene;
std::vector<nlohmann::basic_json<>> _cards;
+ std::shared_ptr<QWidget> _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<std::string>(),
@@ -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<QGraphicsScene>();
- QGraphicsRectItem *rect = _rightScene->addRect(QRectF(0, 0, 100, 100));
- QGraphicsItem *item = _rightScene->itemAt(50, 50, QTransform());
+
+ ControlInterface& configureRightGraphicsView()
+ {
+ _rightScene = std::make_shared<QGraphicsScene>();
+ 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<QWidget>();
+// 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<QMenuBar>();
+// aLayout.addWidget(aMenuBar.get(), 0, 0);
+// auto aListOfCards = std::make_shared<QListWidget>();
+// aLayout.addLayout(&aHLayout, 1, 0);
+// aHLayout.addWidget(aListOfCards.get());
+// auto aRightView = std::make_shared<QGraphicsView>();
+// 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<QWidget>();
- 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<QMenuBar>();
- aLayout.addWidget(aMenuBar.get(), 0, 0);
- auto aListOfCards = std::make_shared<QListWidget>();
- aLayout.addLayout(&aHLayout, 1, 0);
- aHLayout.addWidget(aListOfCards.get());
- auto aRightView = std::make_shared<QGraphicsView>();
- 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();