AboutForm.ui: About dialog for mines3d v2.
[mines3d.git] / ui / qt / MainForm.h
blobcbc6fffe5b4fc5045890d6371f336f1500641fbc
1 /*
2 * File: MainForm.h
3 * Created: 7.1.2010
4 * Author: Petr Kubizňák
5 * Purpose:
6 */
8 #ifndef MAINFORM_H_
9 #define MAINFORM_H_
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>
21 #include <ctime>
22 #include <list>
24 class MainForm;
26 /***************************** CLASS FieldButton ******************************/
28 /* extends QPushButton, adds information about the buttons position */
29 class FieldButton : public QPushButton {
30 Q_OBJECT
32 protected:
33 MainForm *mainForm;
34 int posX, posY, posZ;
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);
44 public:
45 FieldButton(MainForm *mainForm, int posX = 0, int posY = 0, int posZ = 0);
46 virtual ~FieldButton(void);
48 /* zvyrazni tlacitko zmenou fontu */
49 void highlight(void);
50 /* "odvyrazni" tlacitko zpet */
51 void unhighlight(void);
53 public Q_SLOTS:
54 void onClick(bool b);
58 /**************************** Class MarksIndicator ****************************/
60 /* Displays number of marks and total count of mines on the status bar */
61 class MarksIndicator : public QLabel {
62 protected:
63 int marked, total;
64 QFont *fontNormal, *fontBold;
66 /* prekresli komponentu */
67 void repaint(void);
69 public:
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 {
83 Q_OBJECT
85 protected:
86 Ui::MainForm ui;
87 Board *board;
88 FieldButton ****fieldBtn;
89 QWidget **layerWidget;
90 QGridLayout **layerGrid;
91 SettingsForm *settingsFrm;
92 ScoresForm *scoresFrm;
93 MarksIndicator *marksIndicator;
94 AboutForm *aboutFrm;
96 int layers, rows, cols, mines; //pro vetsi rychlost a pohodli duplikuje data z board
97 bool gameOver;
98 QString name; //jmeno uzivatele
99 time_t tStart, tStop;
100 list<ScoreRecord> scoreRookie, scoreAdvanced, scoreSuicide, scoreCustom;
102 /* vyrobi tlacitka a dalsi komponenty potrebne pro hru */
103 void buildGui(void);
104 /* uvolni prostredky alokovane metodou buildGui() */
105 void freeGui(void);
106 /* vytvori novou hru s aktualnim nastavenim */
107 void newGame(void);
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);
130 public:
132 Thread_controller * tc;
133 Sql_connector * sql_c;
134 bool locked;
136 MainForm(QWidget *parent = 0);
137 virtual ~MainForm();
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);
148 public Q_SLOTS:
149 void actionSettings_Trigger(void);
150 void actionNew_Trigger(void);
151 void actionScores_Trigger(void);
152 void actionAbout_Trigger(void);
156 #endif /* MAINFORM_H_ */