-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_page.cpp
130 lines (115 loc) · 5.79 KB
/
start_page.cpp
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "start_page.h"
#include "game_page.h"
#include "help_page.h"
#include "global.h"
#include <iostream>
Startpage::Startpage(QWidget* parent):QWidget(parent)
{
resource_manager& vault = resource_manager::instance();
//set start page
this->setFixedSize(window_width_1, window_height_1);
start_page_pic = vault.get_pic("start_page");
QPalette palette;
palette.setBrush(this->backgroundRole(), QBrush(start_page_pic));
this->setPalette(palette);
//set all buttons on this page
start_button = new QPushButton(this);
QPixmap start_button_icon = vault.get_pic("start_button");
QPixmap start_button_on_icon = vault.get_pic("start_button_on");
start_button->setIcon(QIcon(start_button_icon));
start_button->setIconSize(start_button_icon.size());
start_button->setFixedSize(start_button_icon.size());
start_button->setGeometry((window_width_1-start_button_icon.width())/2, (window_height_1-start_button_icon.height())/2, start_button_icon.width(), start_button_icon.height());
connect(start_button, SIGNAL(clicked()), this, SLOT(handle_start_button()));
connect(start_button, SIGNAL(toggled()), this, SLOT(on_start_button()));
connect(start_button, SIGNAL(leaveEvent()), this, SLOT(leave_start_button()));
//set border free
start_button->setStyleSheet("QPushButton { border: none; }");
auto *iconSwitcher = new IconSwitcher(start_button, start_button_icon, start_button_on_icon);
start_button->installEventFilter(iconSwitcher);
continue_button = new QPushButton("Continue", this);
QPixmap continue_button_icon = vault.get_pic("continue_button");
continue_button->setIcon(QIcon(continue_button_icon));
continue_button->setGeometry(QRect(QPoint(window_width_1/2-100, ((window_height_1-start_button_icon.height())/2)+160), QSize(200, 60)));
continue_button->setStyleSheet("QPushButton {"
"font-size: 20px;"
"border: 2px solid black; border-radius: 10px; " // border style
"background-color: lightgray;" // background color
"padding: 5px;" // padding
"qproperty-iconSize: 24px 24px;" // icon size
"}"
"QPushButton:hover {"
"font-size: 20px;"
"border: 2px solid blue;border-radius: 10px;" // hover style
" background-color: lightblue;" // hover background
"}");
//connect(continue_button, SIGNAL(clicked()), this, SLOT(load_game()));
exit_button = new QPushButton("Exit", this);
QPixmap exit_button_icon = vault.get_pic("exit_button");
exit_button->setIcon(QIcon(exit_button_icon));
exit_button->setGeometry(QRect(QPoint(window_width_1/2-100, ((window_height_1-start_button_icon.height())/2)+250), QSize(200, 60)));
exit_button->setStyleSheet(("QPushButton {"
"font-size: 20px;"
"border: 2px solid black; border-radius: 10px; " // border style
"background-color: lightgray;" // background color
"padding: 5px;" // padding
"qproperty-iconSize: 24px 24px;" // icon size
"}"
"QPushButton:hover {"
"font-size: 20px;"
"border: 2px solid blue;border-radius: 10px;" // hover style
" background-color: lightblue;" // hover background
"}"));
connect(exit_button, SIGNAL(clicked()), QApplication::instance(), SLOT(quit()));
help_button = new QPushButton("Help", this);
QPixmap help_button_icon = vault.get_pic("help_button");
help_button->setIcon(QIcon(help_button_icon));
help_button->setGeometry(QRect(QPoint(window_width_1/2-100, ((window_height_1-start_button_icon.height())/2)+350), QSize(200, 60)));
help_button->setStyleSheet(("QPushButton {"
"font-size: 20px;"
"border: 2px solid black; border-radius: 10px; " // border style
"background-color: lightgray;" // background color
"padding: 5px;" // padding
"qproperty-iconSize: 24px 24px;" // icon size
"}"
"QPushButton:hover {"
"font-size: 20px;"
"border: 2px solid blue;border-radius: 10px;" // hover style
" background-color: lightblue;" // hover background
"}"));
connect(help_button, SIGNAL(clicked()), this, SLOT(handle_help_button()));
}
Startpage::~Startpage()
{
delete start_button;
delete continue_button;
delete exit_button;
delete help_button;
}
//draw the start page
void Startpage::paintEvent(QPaintEvent *event)
{
QWidget::paintEvent(event);
QPainter painter(this);
painter.drawPixmap(0,0,width(),height(), start_page_pic);
}
void Startpage::handle_start_button()
{
auto *game = new game_page(this->parentWidget());
this->close();
game->show();
}
void Startpage::on_start_button()
{
start_button->setIcon(QIcon(QPixmap(":/start_button.png")));
}
void Startpage::leave_start_button()
{
start_button->setIcon(QIcon(QPixmap(":/start_button_on.png")));
}
void Startpage::handle_help_button()
{
auto *help = new help_page(this->parentWidget());
this->close();
help->show();
}