4 * Author: Petr Kubizňák
11 #include "ui_MainForm.h"
12 #include "SettingsForm.h"
13 #include "ScoresForm.h"
14 #include "ScoreRecord.h"
15 #include "AboutForm.h"
16 #include "../../core/board.h"
17 #include "../../threads/thread_controller.h"
18 #include "../../sqlconn/sql_connector.h"
19 #include <QtGui/QMainWindow>
20 #include <QtGui/QPushButton>
26 /***************************** CLASS FieldButton ******************************/
28 /* extends QPushButton, adds information about the buttons position */
29 class FieldButton
: public QPushButton
{
35 QFont
*fontHighlight
, *fontNormal
;
37 /* udalost najeti mysi */
38 void enterEvent(QEvent
*e
);
39 /* udalost odjeti mysi */
40 void leaveEvent(QEvent
*e
);
41 /* udalost stisku tlacitka */
42 void mousePressEvent(QMouseEvent
*e
);
45 FieldButton(MainForm
*mainForm
, int posX
= 0, int posY
= 0, int posZ
= 0);
46 virtual ~FieldButton(void);
48 /* zvyrazni tlacitko zmenou fontu */
50 /* "odvyrazni" tlacitko zpet */
51 void unhighlight(void);
58 /**************************** Class MarksIndicator ****************************/
60 /* Displays number of marks and total count of mines on the status bar */
61 class MarksIndicator
: public QLabel
{
64 QFont
*fontNormal
, *fontBold
;
66 /* prekresli komponentu */
70 MarksIndicator(QWidget
*parent
, int total
= 0);
71 virtual ~MarksIndicator(void);
73 /* nastavi celkovy pocet vlajecek, totez vraci */
74 int setTotal(int value
);
75 /* nastavi oznaceny pocet vlajecek, totez vraci */
76 int setMarked(int value
);
80 /******************************* CLASS MainForm *******************************/
82 class MainForm
: public QMainWindow
{
88 FieldButton
****fieldBtn
;
89 QWidget
**layerWidget
;
90 QGridLayout
**layerGrid
;
91 SettingsForm
*settingsFrm
;
92 ScoresForm
*scoresFrm
;
93 MarksIndicator
*marksIndicator
;
96 int layers
, rows
, cols
, mines
; //pro vetsi rychlost a pohodli duplikuje data z board
98 QString name
; //jmeno uzivatele
100 list
<ScoreRecord
> scoreRookie
, scoreAdvanced
, scoreSuicide
, scoreCustom
;
102 /* vyrobi tlacitka a dalsi komponenty potrebne pro hru */
104 /* uvolni prostredky alokovane metodou buildGui() */
106 /* vytvori novou hru s aktualnim nastavenim */
108 /* ukonci hru -> znemozni stisk tlacitek atp.;
109 * atr success je true, pokud uzivatel vyhral, jinak false */
110 void setGameOver(bool success
);
111 /* nastavi pocatecni cas hry */
112 void startTime(void);
113 /* nacte nastaveni ze standardniho souboru, vraci uspech operace */
114 bool loadSettings(void);
115 /* ulozi nastaveni do standardniho souboru, vraci uspech operace */
116 bool saveSettings(void);
117 /* nacte vsechna skore, vraci uspech operace */
118 bool loadScores(void);
119 /* ulozi vsechna skore, vraci uspech operace */
120 bool saveScores(void);
121 /* nacte skore ze zadaneho souboru do daneho listu, vraci uspech operace */
122 bool loadScoresFile(list
<ScoreRecord
> &scoresList
, const char *filename
);
123 /* ulozi skore do zadaneho souboru z daneho listu, vraci uspech operace */
124 bool saveScoresFile(list
<ScoreRecord
> &scoresList
, const char *filename
);
125 /* vraci true, pokud "a" predchazi pred "b" (podle casu), jinak false */
126 static bool cmpScoreByTime(const ScoreRecord
&a
, const ScoreRecord
&b
);
127 /* pokud je zadany cas v top10, umozni zapis do tabulky a vraci true, jinak false */
128 bool processTopTen(int time
);
132 Thread_controller
* tc
;
133 Sql_connector
* sql_c
;
136 MainForm(QWidget
*parent
= 0);
139 /* volano tridou FieldButton pri udalosti enterEvent, zvyrazni souvisejici tlacitka */
140 void buttonHovered(int l
, int r
, int c
);
141 /* volano tridou FieldButton pri udalosti leaveEvent, odzvyrazni souvisejici tlacitka */
142 void buttonLeft(int l
, int r
, int c
);
143 /* volano tridou FieldButton pri stisku tlacitka, odkryje souvisejici tlacitka */
144 void uncover(int l
, int r
, int c
);
145 /* volano tridou FieldButton pri stisku praveho tlacitka, (od)znaci dane policko */
146 void mark(int l
, int r
, int c
);
149 void actionSettings_Trigger(void);
150 void actionNew_Trigger(void);
151 void actionScores_Trigger(void);
152 void actionAbout_Trigger(void);
156 #endif /* MAINFORM_H_ */