-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpausewindow.cpp
More file actions
131 lines (126 loc) · 3.72 KB
/
pausewindow.cpp
File metadata and controls
131 lines (126 loc) · 3.72 KB
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
131
#include "pausewindow.h"
PauseWindow::PauseWindow(int my_plane_,int diff_,QWidget *parent) : QWidget(parent)
{
my_plane=my_plane_;
diff=diff_;
resize(PE_WIDTH,PE_HEIGHT);
move(GM_WIDTH/4,GM_HEIGHT/5);
setWindowFlags(Qt::FramelessWindowHint|windowFlags());//消除边框
setAttribute(Qt::WA_TranslucentBackground);//背景透明
setAttribute(Qt::WA_DeleteOnClose,true);
QFont font("华文中宋",20);//设置字体和大小
PauseLabel = new QLabel();
PauseLabel->setFont(font);
PauseLabel->move(PE_WIDTH/5+30,PE_HEIGHT*0.35);
PauseLabel->setText(tr("游戏暂停"));
PauseLabel->hide();
for(int i=0;i<PAUSE_BUTTON_CNT;i++){
PauseButton[i] = new QPushButton(this);
PauseButton[i]->setFont(font);
switch(i){
case 0:
PauseButton[i]->move(PE_WIDTH/5,PE_HEIGHT/4+120);
PauseButton[i]->setText(tr("游戏暂停解除"));
break;
case 1:
PauseButton[i]->move(PE_WIDTH/5,PE_HEIGHT/2);
PauseButton[i]->setText(tr("返回标题画面"));
break;
case 2:
PauseButton[i]->move(PE_WIDTH/5,3*PE_HEIGHT/4-120);
PauseButton[i]->setText(tr("从头开始游戏"));
break;
default:break;
}
PauseButton[i]->hide();
}
now_button=0;//开始定位在“游戏暂停解除”上面
update();
}
void PauseWindow::paintEvent(QPaintEvent *){
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing,true);
QPen pen;
pen.setWidth(1);
pen.setColor(Qt::black);
painter.setPen(pen);
QLinearGradient linearGrad;
QFont font;
qreal x,y;
QString str;
QPainterPath ltextPath;
str=PauseLabel->text();
x=PauseLabel->x();
y=PauseLabel->y();
font=PauseLabel->font();
linearGrad.setColorAt(0,Qt::blue);
ltextPath.addText(x,y,font,str);
painter.setBrush(linearGrad);
painter.drawPath(ltextPath);
for(int i=0;i<PAUSE_BUTTON_CNT;i++){
QPainterPath textPath;
str=PauseButton[i]->text();
x=PauseButton[i]->x();
y=PauseButton[i]->y();
font=PauseButton[i]->font();
if(i==now_button){
linearGrad.setColorAt(0,PE_BUTTON_LIGHT);
}
else{
linearGrad.setColorAt(0,PE_BUTTON_DARK);
}
textPath.addText(x,y,font,str);
painter.setBrush(linearGrad);
painter.drawPath(textPath);
}
}
void PauseWindow::keyPressEvent(QKeyEvent *ke){
switch(ke->key()){
case Qt::Key_Up:
ke->accept();
if(now_button>0){
now_button--;
}
break;
case Qt::Key_Down:
ke->accept();
if(now_button<PAUSE_BUTTON_CNT-1){
now_button++;
}
break;
case Qt::Key_Return:
ke->accept();
switch(now_button){
case 0:
emit ReturnPressed();
break;
case 1:
QuitPress();
emit QuitPressed();
break;
case 2:
RetryPress();
close();
emit RetryPressed();
break;
default:break;
}
break;
case Qt::Key_Escape:
ke->accept();
emit ReturnPressed();
break;
default:
ke->ignore();
break;
}
update();
}
void PauseWindow::RetryPress(){
Stage *s = new Stage(my_plane,diff);
s->show();
}
void PauseWindow::QuitPress(){
mainwindow* w = new mainwindow();
w->show();
}