From 6f50c677767d9602e815e17d4c752f9cda594061 Mon Sep 17 00:00:00 2001 From: Augustin Date: Tue, 16 Apr 2024 19:07:48 +0200 Subject: [PATCH] return home v51425 --- src/screens/endgamescreen.cpp | 19 +++++++++++++++---- src/screens/endgamescreen.hpp | 2 +- src/screens/snakewindow.cpp | 5 +++++ src/screens/snakewindow.hpp | 2 ++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/screens/endgamescreen.cpp b/src/screens/endgamescreen.cpp index 3ba0524..111d12c 100644 --- a/src/screens/endgamescreen.cpp +++ b/src/screens/endgamescreen.cpp @@ -1,4 +1,5 @@ #include "endgamescreen.hpp" +#include "snakewindow.hpp" #include @@ -76,10 +77,19 @@ EndGameScreen::EndGameScreen(const int score, QWidget *parent) connect(submitButton, &QPushButton::clicked, this, &EndGameScreen::submitName); // Création du bouton de retour au menu principal - QPushButton *returnButton = new QPushButton("Return to Main Menu", this); - returnButton->setFont(QFont("Arial", 16)); + QPushButton *returnButton = new QPushButton("Main Menu", this); + snakefont.setPointSize(20); + returnButton->setFont(snakefont); + returnButton->setStyleSheet("padding-left: 20px; padding-right: 20px;"); returnButton->setFixedSize(200, 50); // Taille fixe pour le bouton - connect(returnButton, &QPushButton::clicked, this, &EndGameScreen::returnToMainMenu); + connect(returnButton, &QPushButton::clicked, [this]() { + // widget parent (SnakeWindow) + SnakeWindow *snakeWindow = qobject_cast(parentWidget()); + if (snakeWindow) { + // Appeler returnToMainMenu de SnakeWindow + snakeWindow->returnToMainMenu(); + } + }); @@ -115,5 +125,6 @@ void EndGameScreen::submitName() { void EndGameScreen::returnToMainMenu() { // Mettez ici le code pour revenir au menu principal, par exemple : - emit returnToMainMenuClicked(); // Émet un signal pour informer le parent que le bouton a été cliqué + emit back(); + } \ No newline at end of file diff --git a/src/screens/endgamescreen.hpp b/src/screens/endgamescreen.hpp index 428f0c6..0fbbe5e 100644 --- a/src/screens/endgamescreen.hpp +++ b/src/screens/endgamescreen.hpp @@ -30,7 +30,7 @@ private slots: QLineEdit *nameInput; signals: - void returnToMainMenuClicked(); + void back(); }; #endif //SNAKEQT_ENDGAMESCREEN_HPP diff --git a/src/screens/snakewindow.cpp b/src/screens/snakewindow.cpp index aedf675..ba5f25e 100644 --- a/src/screens/snakewindow.cpp +++ b/src/screens/snakewindow.cpp @@ -161,3 +161,8 @@ void SnakeWindow::handleGameOver(const int score) { update(); } + +void SnakeWindow::returnToMainMenu() { + // Return to the main menu + stackedWidget->setCurrentWidget(mainMenu); +} \ No newline at end of file diff --git a/src/screens/snakewindow.hpp b/src/screens/snakewindow.hpp index 6505f8d..ac849fb 100644 --- a/src/screens/snakewindow.hpp +++ b/src/screens/snakewindow.hpp @@ -33,6 +33,8 @@ public slots: static void handleExitClicked(); + void returnToMainMenu(); + void toggleFullScreen() { if (windowState() & Qt::WindowFullScreen) { showNormal();