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 "../../sound/CAudio.h"
20 #include <QtGui/QMainWindow>
21 #include <QtGui/QPushButton>
27 /***************************** CLASS FieldButton ******************************/
29 /* extends QPushButton, adds information about the buttons position */
30 class FieldButton
: public QPushButton
{
36 QFont
*fontHighlight
, *fontNormal
;
38 /* udalost najeti mysi */
39 void enterEvent(QEvent
*e
);
40 /* udalost odjeti mysi */
41 void leaveEvent(QEvent
*e
);
42 /* udalost stisku tlacitka */
43 void mousePressEvent(QMouseEvent
*e
);
46 FieldButton(MainForm
*mainForm
, int posX
= 0, int posY
= 0, int posZ
= 0);
47 virtual ~FieldButton(void);
49 /* zvyrazni tlacitko zmenou fontu */
51 /* "odvyrazni" tlacitko zpet */
52 void unhighlight(void);
59 /**************************** Class MarksIndicator ****************************/
61 /* Displays number of marks and total count of mines on the status bar */
62 class MarksIndicator
: public QLabel
{
65 QFont
*fontNormal
, *fontBold
;
67 /* prekresli komponentu */
71 MarksIndicator(QWidget
*parent
, int total
= 0);
72 virtual ~MarksIndicator(void);
74 /* nastavi celkovy pocet vlajecek, totez vraci */
75 int setTotal(int value
);
76 /* nastavi oznaceny pocet vlajecek, totez vraci */
77 int setMarked(int value
);
81 /******************************* CLASS MainForm *******************************/
83 class MainForm
: public QMainWindow
{
89 FieldButton
****fieldBtn
;
90 QWidget
**layerWidget
;
91 QGridLayout
**layerGrid
;
92 SettingsForm
*settingsFrm
;
93 ScoresForm
*scoresFrm
;
94 MarksIndicator
*marksIndicator
;
97 int layers
, rows
, cols
, mines
; //pro vetsi rychlost a pohodli duplikuje data z board
98 int soundMusic
; //!< Type of selected music to play.
100 QString name
; //jmeno uzivatele
101 time_t tStart
, tStop
;
102 list
<ScoreRecord
> scoreRookie
, scoreAdvanced
, scoreSuicide
, scoreCustom
,
103 scoreRookieSql
, scoreAdvancedSql
, scoreSuicideSql
, scoreCustomSql
;
105 /* vyrobi tlacitka a dalsi komponenty potrebne pro hru */
107 /* uvolni prostredky alokovane metodou buildGui() */
109 /* vytvori novou hru s aktualnim nastavenim */
111 /* ukonci hru -> znemozni stisk tlacitek atp.;
112 * atr success je true, pokud uzivatel vyhral, jinak false */
113 void setGameOver(bool success
);
114 /* nastavi pocatecni cas hry */
115 void startTime(void);
116 /* nacte nastaveni ze standardniho souboru, vraci uspech operace */
117 bool loadSettings(void);
118 /* ulozi nastaveni do standardniho souboru, vraci uspech operace */
119 bool saveSettings(void);
120 /* nacte vsechna skore, vraci uspech operace */
121 bool loadScores(void);
122 /* ulozi vsechna skore, vraci uspech operace */
123 bool saveScores(void);
124 /* nacte skore ze zadaneho souboru do daneho listu, vraci uspech operace */
125 bool loadScoresFile(list
<ScoreRecord
> &scoresList
, const char *filename
);
126 /* ulozi skore do zadaneho souboru z daneho listu, vraci uspech operace */
127 bool saveScoresFile(list
<ScoreRecord
> &scoresList
, const char *filename
);
128 /** Loads scores from remote database.
129 * @return True on success, false on fail. */
130 bool loadRemoteScores(void);
131 /* vraci true, pokud "a" predchazi pred "b" (podle casu), jinak false */
132 static bool cmpScoreByTime(const ScoreRecord
&a
, const ScoreRecord
&b
);
133 /* pokud je zadany cas v top10, umozni zapis do tabulky a vraci true, jinak false */
134 bool processTopTen(int time
);
138 CAudio audioController
;
140 Thread_controller
* tc
;
141 Sql_connector
* sql_c
;
144 MainForm(QWidget
*parent
= 0);
147 /* volano tridou FieldButton pri udalosti enterEvent, zvyrazni souvisejici tlacitka */
148 void buttonHovered(int l
, int r
, int c
);
149 /* volano tridou FieldButton pri udalosti leaveEvent, odzvyrazni souvisejici tlacitka */
150 void buttonLeft(int l
, int r
, int c
);
151 /** Uncoveres button on given position (and related buttons). Is called by FieldButton on click.
152 * @return SOUND_BUTTON_SUCCESS if no mine is hidden here, SOUND_GAME_OVER if mine exploded,
153 * SOUND_GAME_VICTORY if no mine is hidden and the last field is uncovered,
154 * SOUND_NOTHING if the field is marked as mined (so it cannot be uncovered). */
155 int uncover(int l
, int r
, int c
);
156 /* volano tridou FieldButton pri stisku praveho tlacitka, (od)znaci dane policko */
157 void mark(int l
, int r
, int c
);
160 void actionSettings_Trigger(void);
161 void actionNew_Trigger(void);
162 void actionScores_Trigger(void);
163 void actionAbout_Trigger(void);
167 #endif /* MAINFORM_H_ */