-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainwindow.hh
114 lines (94 loc) · 3.12 KB
/
mainwindow.hh
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
/* Class MainWindow
* ----------
* COMP.CS.110 SPRING 2021
* ----------
* Class for the main window. Creates the GUI for this program.
* */
#ifndef MAINWINDOW_HH
#define MAINWINDOW_HH
#include "cardbutton.hh"
#include "player.hh"
#include "utils.hh"
#include "gamelogic.hh"
#include <QMainWindow>
#include <QGridLayout>
#include <QTextBrowser>
#include <QLabel>
#include <QLCDNumber>
#include <QTimer>
#include <vector>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
/**
* Constructor, initializes the creation of the main GUI window.
*
* \param card_count UInt amount of cards to use in the game
* \param players vector of player object pointers, the players in this game
* \param parent QWidget* parent for this object
* \return MainWindow object
*/
explicit MainWindow(unsigned card_count, const std::vector<Player*>& players, QWidget* parent = nullptr);
/**
* Sets the player in turn for the QLabel ui component.
*
* \param player QString player's name
*/
void set_player_in_turn(const QString& player) const;
/**
* Appends text to the QTextBrowser ui component.
*
* \param text QString text to append
*/
void append_to_text_browser(const QString& text) const;
//disables all cards in the playing field
void disable_all_cards() const;
//restores all cards in the playing field from the disabled state
void restore_all_cards() const;
//returns whether all card buttons are hidden, true if they are
bool all_buttons_hidden() const;
//runs code related to ending the game
void end_game();
private slots:
//receiver the play time timer's signals
void timer_callback();
private:
//spacing amount between ui components
const int GRID_SPACING = 6;
const int TEXT_BROWSER_HEIGHT = 210;
const QString PLAYER_IN_TURN = "Player in turn:\n";
unsigned card_count_;
//vector to contain pointers for each cardbutton
std::vector<CardButton*> cardbuttons_{};
//ui components
QWidget* central_widget_{};
QWidget* grid_layout_widget_{};
QTextBrowser* text_browser_{};
QLabel* player_indicator_label_{};
QGridLayout* grid_layout_{};
QLCDNumber* lcd_number_{};
//timer to handle counting game time
QTimer timer_;
//pointer to the game logic object, gets created in this class's constructor
GameLogic* game_logic_{};
//amount of seconds passed in this game
int timer_secs_{};
//initializes most of the widgets
void init_widgets();
/**
* Initializes card buttons.
*
* \param card_rows UInt amount of rows in the playing field
* \param card_columns UInt amount of columns in the playing field
*/
void init_cardbuttons(unsigned card_rows, unsigned card_columns);
/**
* Initializes widget sizes and positions based off the playing field size.
*
* \param card_rows UInt amount of rows in the playing field
* \param card_columns UInt amount of columns in the playing field
*/
void init_widget_sizes(unsigned card_rows, unsigned card_columns);
};
#endif // MAINWINDOW_HH