1 /*****************************************************************************
2  * LibreMines                                                                *
3  * Copyright (C) 2020-2021  Bruno Bollos Correa                              *
4  *                                                                           *
5  * This program is free software: you can redistribute it and/or modify      *
6  * it under the terms of the GNU General Public License as published by      *
7  * the Free Software Foundation, either version 3 of the License, or         *
8  * (at your option) any later version.                                       *
9  *                                                                           *
10  * This program is distributed in the hope that it will be useful,           *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
13  * GNU General Public License for more details.                              *
14  *                                                                           *
15  * You should have received a copy of the GNU General Public License         *
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.     *
17  *****************************************************************************
18  */
19 
20 
21 #ifndef LIBREMINESGUI_H
22 #define LIBREMINESGUI_H
23 
24 #include <QSpinBox>
25 #include <QTimer>
26 #include <QLCDNumber>
27 #include <QCheckBox>
28 #include <QMainWindow>
29 #include <QGridLayout>
30 #include <QScrollArea>
31 #include <QProgressBar>
32 
33 #include "common.h"
34 #include "libreminespreferencesdialog.h"
35 #include "libreminesgameengine.h"
36 #include "qlabel_adapted.h"
37 #include "qpushbutton_adapted.h"
38 #include "minefieldtheme.h"
39 
40 /**
41  * @brief
42  *
43  */
44 class LibreMinesGui : public QMainWindow
45 {
46     Q_OBJECT
47 
48 private:
49     class CellGui
50     {
51     public:
52         CellGui();
53 
54         QPushButton_adapted *button; /**< TODO: describe */
55         QLabel_adapted *label; /**< TODO: describe */
56     };
57 
58 public:
59     /**
60      * @brief
61      *
62      * @param parent
63      */
64     LibreMinesGui(QWidget *parent = nullptr, const int thatWidth = -1, const int thatHeight = -1);
65     /**
66      * @brief
67      *
68      */
69     ~LibreMinesGui();
70 
71     /**
72      * @brief
73      *
74      * @param _X
75      * @param _Y
76      * @param i_nMines_
77      * @param i_X_Clean
78      * @param i_Y_Clean
79      */
80 
81 protected:
82     bool eventFilter(QObject* object, QEvent* event);
83 
84     void resizeEvent(QResizeEvent* e);
85 
86     void closeEvent(QCloseEvent* e);
87 private:
88     void vNewGame(const uchar _X,
89                   const uchar _Y,
90                   ushort i_nMines_);
91 
92     void vAttributeAllCells();
93     void vResetPrincipalMatrix();
94     /**
95      * @brief
96      *
97      */
98     void vCreateGUI(const int width, const int height);
99     /**
100      * @brief
101      *
102      */
103     void vHideMainMenu();
104     /**
105      * @brief
106      *
107      */
108     void vShowMainMenu();
109     /**
110      * @brief
111      *
112      */
113     void vAdjustMainMenu();
114     void vAdjustInterfaceInGame();
115     /**
116      * @brief
117      *
118      */
119     void vHideInterfaceInGame();
120     /**
121      * @brief
122      *
123      */
124     void vShowInterfaceInGame();
125 
126     void vSetApplicationTheme(const QString& theme);
127     void vSetFacesReaction(const QString& which);
128 
129     void vKeyboardControllerSetCurrentCell(const uchar x, const uchar y);
130     void vKeyboardControllUnsetCurrentCell();
131     void vKeyboardControllerMoveLeft();
132     void vKeyboardControllerMoveRight();
133     void vKeyboardControllerMoveDown();
134     void vKeyboardControllerMoveUp();
135     void vKeyboardControllerCenterCurrentCell();
136 
137     void vLastSessionLoadConfigurationFile();
138     void vLastSessionSaveConfigurationFile();
139 
140     void vUpdatePreferences();
141 
142 private Q_SLOTS:
143     /**
144      * @brief
145      *
146      */
147     void SLOT_Easy();
148     /**
149      * @brief
150      *
151      */
152     void SLOT_Medium();
153     /**
154      * @brief
155      *
156      */
157     void SLOT_Hard();
158     /**
159      * @brief
160      *
161      */
162     void SLOT_Customized();
163 
164     /**
165      * @brief
166      *
167      */
168     void SLOT_QuitGame();
169     /**
170      * @brief
171      *
172      */
173     void SLOT_RestartGame();
174 
175     /**
176      * @brief
177      *
178      * @param e
179      */
180     void SLOT_OnCellButtonReleased(const QMouseEvent*const e);
181     void SLOT_OnCellButtonClicked(const QMouseEvent*const e);
182 
183     void SLOT_onCellLabelReleased(const QMouseEvent*const e);
184     void SLOT_onCellLabelClicked(const QMouseEvent*const e);
185 
186     void SLOT_showCell(const uchar _X, const uchar _Y);
187     void SLOT_endGameScore(LibreMinesScore score,
188                            int iCorrectFlags,
189                            int iWrongFlags,
190                            int iUnlockedCells,
191                            double dFlagsPerSecond,
192                            double dCellsPerSecond,
193                            bool ignorePreferences=false);
194     void SLOT_currentTime(const ushort time);
195     void SLOT_minesLeft(const ushort minesLeft);
196     void SLOT_flagCell(const uchar _X, const uchar _Y);
197     void SLOT_unflagCell(const uchar _X, const uchar _Y);
198 
199     void SLOT_remakeGame();
200     void SLOT_gameWon();
201     void SLOT_gameLost(const uchar _X, const uchar _Y);
202 
203     void SLOT_optionChanged(const QString& name, const QString& value);
204 
205     void SLOT_quitApplication();
206 
207     void SLOT_showAboutDialog();
208 
209     void SLOT_showHighScores();
210 
211     void SLOT_toggleFullScreen();
212 
213     void SLOT_saveMinefieldAsImage();
214 
215 Q_SIGNALS:
216     void SIGNAL_cleanCell(const uchar _X, const uchar _Y);
217     void SIGNAL_cleanNeighborCells(const uchar _X, const uchar _Y);
218     void SIGNAL_addOrRemoveFlag(const uchar _X, const uchar _Y);
219     void SIGNAL_stopGame();
220 
221 private:
222 
223     QScopedPointer<LibreMinesGameEngine> gameEngine;
224     std::vector< std::vector<CellGui> > principalMatrix; /**< TODO: describe */
225 
226     int iLimitHeightField; /**< TODO: describe */
227     int iLimitWidthField; /**< TODO: describe */
228 
229     int cellLength; /**< TODO: describe */
230 
231     GAME_DIFFICULTY difficult; /**< TODO: describe */
232 
233     QPushButton *buttonEasy; /**< TODO: describe */
234     QPushButton *buttonMedium; /**< TODO: describe */
235     QPushButton *buttonHard; /**< TODO: describe */
236 
237     QPushButton *buttonCustomizedNewGame; /**< TODO: describe */
238 
239     QSpinBox *sbCustomizedX; /**< TODO: describe */
240     QSpinBox *sbCustomizedY; /**< TODO: describe */
241     QSpinBox *sbCustomizedPercentageMines; /**< TODO: describe */
242     QSpinBox* sbCustomizedNumbersOfMines;
243 
244     QLabel *labelCustomizedX; /**< TODO: describe */
245     QLabel *labelCustomizedY; /**< TODO: describe */
246     QLabel *labelCustomizedPercentageMines; /**< TODO: describe */
247     QLabel* labelCustomizedNumbersOfMines;
248 
249     QCheckBox* cbCustomizedMinesInPercentage;
250 
251     QLabel* labelFaceReactionInGame;
252     QLabel *labelTimerInGame; /**< TODO: describe */
253     QLCDNumber *lcd_numberMinesLeft; /**< TODO: describe */
254     QProgressBar* progressBarGameCompleteInGame;
255     QPushButton *buttonRestartInGame; /**< TODO: describe */
256     QPushButton *buttonQuitInGame; /**< TODO: describe */
257     QPushButton* buttonSaveMinefieldAsImage;
258     QPushButton* buttonSaveScore;
259 
260     QScrollArea* scrollAreaBoard;
261     QWidget* widgetBoardContents;
262     QGridLayout* layoutBoard;
263 
264     QLabel *labelYouWonYouLost; /**< TODO: describe */
265     QLabel *labelStatisLastMatch; /**< TODO: describe */
266 
267     QMenu* menuOptions;
268     QAction* actionPreferences;
269     QAction* actionHighScores;
270     QAction* actionToggleFullScreen;
271 
272     QMenu* menuHelp;
273     QAction* actionAbout;
274     QAction* actionAboutQt;
275     QAction* actionGitHubHomePage;
276 
277     MinefieldTheme fieldTheme;
278 
279     QScopedPointer<QPixmap> pmDizzyFace;
280     QScopedPointer<QPixmap> pmGrimacingFace;
281     QScopedPointer<QPixmap> pmGrinningFace;
282     QScopedPointer<QPixmap> pmOpenMouthFace;
283     QScopedPointer<QPixmap> pmSleepingFace;
284     QScopedPointer<QPixmap> pmSmillingFace;
285 
286     KeyboardController controller;
287 
288     LibreMinesPreferencesDialog* preferences;
289 
290     QDir dirAppData;
291 };
292 #endif // LIBREMINESGUI_H
293