-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainmenu.cpp
More file actions
160 lines (133 loc) · 5.86 KB
/
mainmenu.cpp
File metadata and controls
160 lines (133 loc) · 5.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include "mainmenu.h"
#include <QFont>
#include <QPushButton>
#include <QApplication>
#include <QMessageBox>
#include <QGridLayout>
#include <QLabel>
#include <QSpacerItem>
/**
* @file mainmenu.cpp
* @brief Implémentation du menu principal de l'application.
*
* Cette classe gère l'affichage et les interactions du menu principal, y compris les boutons
* pour commencer une nouvelle partie, accéder aux paramètres ou quitter l'application.
*/
/**
* @brief Constructeur de la classe MainMenu.
*
* Initialise le menu principal en configurant le layout et en appelant la méthode
* pour configurer les composants du menu.
*
* @param parent Pointeur vers le widget parent (par défaut nullptr).
*/
MainMenu::MainMenu(QWidget* parent) : QWidget(parent)
{
layout = new QGridLayout(this);
// Configure les éléments du menu principal
setup_main_menu();
}
/**
* @brief Configure les composants du menu principal.
*
* Cette méthode initialise les éléments graphiques du menu, y compris le titre,
* les boutons, et leur organisation dans le layout.
*/
void MainMenu::setup_main_menu()
{
// Ajout de marges et d'espaces dans le layout
layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding), 0, 0);
QLabel* title = new QLabel("Menu Principal");
title->setAlignment(Qt::AlignCenter);
QString label_style = "QLabel {"
"font-family: 'Arial', sans-serif;"
"font-size: 28px;"
"font-weight: bold;"
"color: white;"
"text-shadow: 2px 2px 10px rgba(0, 0, 0, 0.7);"
"padding: 10px;"
"background: rgba(0, 0, 0, 0.4); "
"border-radius: 5px;"
"}";
title->setStyleSheet(label_style);
layout->addWidget(title, 1, 1);
layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding), 2, 1);
// Ajout des boutons
QPushButton* new_game_button = new QPushButton("Nouvelle Partie");
layout->addWidget(new_game_button, 3, 1);
pimper(new_game_button);
layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding), 4, 1);
QPushButton* settings_button = new QPushButton("Paramètres");
layout->addWidget(settings_button, 5, 1);
pimper(settings_button);
layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding), 6, 1);
QPushButton* quit_button = new QPushButton("Quitter");
layout->addWidget(quit_button, 7, 1);
pimper(quit_button);
layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding), 8, 2);
// Configuration des proportions des colonnes et lignes
layout->setColumnStretch(0, 1);
layout->setColumnStretch(1, 2);
layout->setColumnStretch(2, 1);
layout->setRowStretch(0, 2);
layout->setRowStretch(1, 1);
layout->setRowStretch(2, 1);
layout->setRowStretch(3, 1);
layout->setRowStretch(4, 1);
layout->setRowStretch(5, 1);
layout->setRowStretch(6, 1);
layout->setRowStretch(7, 1);
layout->setRowStretch(8, 2);
// Connexions des signaux des boutons aux slots correspondants
connect(new_game_button, &QPushButton::clicked, this, &MainMenu::go_to_new_game);
connect(settings_button, &QPushButton::clicked, this, &MainMenu::go_to_settings);
connect(quit_button, &QPushButton::clicked, this, &MainMenu::quit_application);
}
/**
* @brief Enjolive un bouton
*/
void MainMenu::pimper_c(QPushButton *b, QColor bouton_couleur)
{
QString style_sheet = QString("QPushButton {"
"background-color: rgba(%1, %2, %3, 180); " // Semi-transparent background with button color
"color: white; " // White text for contrast
"border: 2px solid %1; " // Border color matches button color
"border-radius: 12px; " // Rounded corners
"font-size: 18px; " // Font size for prominence
"font-weight: bold; " // Bold text for emphasis
"text-align: center; " // Center aligned text
"padding: 12px 20px; " // Padding around the text
"}"
// Hover effect to make the button stand out
"QPushButton:hover {"
"background-color: rgba(%1, %2, %3, 255); " // Solid color on hover
"border: 2px solid %1; " // Border color matches button color
"}");
// Apply the style sheet to the button
// Pass the button color to the stylesheet as RGB values
QString color_style = style_sheet.arg(bouton_couleur.red())
.arg(bouton_couleur.green())
.arg(bouton_couleur.blue());
b->setStyleSheet(color_style);
}
/**
* @brief Enjolive un bouton, par défaut en rouge
*/
void MainMenu::pimper(QPushButton *b)
{
pimper_c(b, Qt::red);
}
/**
* @brief Gère la fermeture de l'application.
*
* Affiche une boîte de dialogue de confirmation avant de quitter l'application.
*/
void MainMenu::quit_application()
{
QMessageBox::StandardButton reply = QMessageBox::question(nullptr, "Quitter",
"Êtes-vous sûr de vouloir quitter ?",
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes) {
qApp->quit();
}
}