-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstartpage.cpp
300 lines (263 loc) · 10.3 KB
/
startpage.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#include<windows.h>
#include<stdio.h>
#include <QDesktopServices>
#include "startpage.h"
#include "ui_startpage.h"
#include "CGammaRamp.h"
#include "qmessagebox.h"
StartPage::StartPage(QWidget *parent) :
QWidget(parent),
ui(new Ui::StartPage)
{
ui->setupUi(this);
//select=new selectlevel();
//循环播放背景音乐
qDebug()<<QCoreApplication::applicationDirPath();
sound=new QSoundEffect(this);
sound->setSource(QUrl::fromLocalFile(QCoreApplication::applicationDirPath()+""));
sound->setLoopCount(QSoundEffect::Infinite);
sound->play();
startButton=new HoverButton();
recordButton=new HoverButton();
settingButton=new HoverButton();
loginButton = new HoverButton();
registerButton = new HoverButton();
logoutButton = new HoverButton();
// startButton->setSound(":/music/button/button_mouseover.wav", ":/music/button/button_mouseleave.wav", ":/music/button/button_press.wav", ":/music/button/button_release.wav"); //默认音效
// recordButton->setSound(":/music/button/button_mouseover.wav", ":/music/button/button_mouseleave.wav", ":/music/button/button_press.wav", ":/music/button/button_release.wav"); //默认音效
// settingButton->setSound(":/music/button/button_mouseover.wav", ":/music/button/button_mouseleave.wav", ":/music/button/button_press.wav", ":/music/button/button_release.wav"); //默认音效
//禁用最大化按钮、设置窗口大小固定
this->setWindowFlags(windowFlags()& ~Qt::WindowMaximizeButtonHint);
this->setFixedSize(this->width(),this->height());
//全屏
QWidget::showFullScreen();
//设置窗口背景黑色
QPalette palette(this->palette());
palette.setColor(QPalette::Background, Qt::black);
this->setPalette(palette);
//设置鼠标-普通
setCursor(QCursor(QPixmap("://picture/mouse1.png")));
QParallelAnimationGroup *group = new QParallelAnimationGroup;
group->addAnimation(ShowBackground());
SetButton();
startButton->showContent("Start",40);
recordButton->showContent("Record",20);
settingButton->showContent("Setting",20);
loginButton->showContent("login",10);
registerButton->showContent("register",10);
logoutButton->showContent("logout",10);
group->addAnimation(startButton->textAnim);
group->addAnimation(recordButton->textAnim);
group->addAnimation(settingButton->textAnim);
group->addAnimation(loginButton->textAnim);
group->addAnimation(registerButton->textAnim);
group->addAnimation(logoutButton->textAnim);
group->addAnimation(ShowTitle());
Sleep(200);
group->start(QAbstractAnimation::DeleteWhenStopped);
}
StartPage::~StartPage()
{
delete ui;
}
QPropertyAnimation * StartPage::ShowTitle(){
QPixmap pix;
QLabel *title = new QLabel(this);
title->setGeometry(this->width()/2-1000,-title->height()-300,2000,500);
setAdaptedImg(":/picture/StartPage/title.png",title);
title->show();
QPropertyAnimation *animation = new QPropertyAnimation(title, "geometry",this);
animation->setDuration(2000);
animation->setStartValue(QRect(title->x(), title->y(), title->width(), title->height()));
animation->setEndValue(QRect(title->x(), 200, title->width(), title->height()));
animation->setEasingCurve(QEasingCurve::OutExpo);
return animation;
}
QPropertyAnimation * StartPage::ShowBackground(){
QPixmap pix;
QLabel *background = new QLabel(this);
bkAnim = new QPropertyAnimation(background, "geometry",this);
setBkImg(":/picture/StartPage/background.png",background);
background->show();
bkAnim->setDuration(2000);
bkAnim->setStartValue(QRect(background->x(), background->y(), background->width(), background->height()));
bkAnim->setEndValue(QRect(background->x(), this->height() - background->height(), background->width(), background->height()));
bkAnim->setEasingCurve(QEasingCurve::InOutCubic);
return bkAnim;
}
void StartPage::SetButton(){
startButton->setCircle(this->width()/10, this->width()/2, this->height()/2+100, this->width(), this->height(),\
":/picture/button/ball.png", "", this);
recordButton->setCircle(this->width()/100*5, this->width()/6, this->height()/2+100, this->width(), this->height(),\
":/picture/button/ball.png", "", this);
settingButton->setCircle(this->width()/100*5, this->width()/6*5, this->height()/2+100, this->width(), this->height(),\
":/picture/button/ball.png", "", this);
loginButton->setCircle(this->width()/20, this->width()/2, this->height()/2+500, this->width(), this->height(),\
":/picture/button/ball.png", "", this);
registerButton->setCircle(this->width()/20, this->width()/6, this->height()/2+500, this->width(), this->height(),\
":/picture/button/ball.png", "", this);
logoutButton->setCircle(this->width()/20, this->width()/6*5, this->height()/2+500, this->width(), this->height(),\
":/picture/button/ball.png", "", this);
//语言切换
connect(&settingP,&settingpage::selectLan,[=](int index){
this->ForGameL=index;
});
connect(select,&selectlevel::selectDone,[=](int difficulty){
this->hide();
sound->stop();
if(difficulty==8){
gameWidget->challenge=1;
difficulty=7;
}
gameWidget->DIFFICULITY=difficulty;
gameWidget->setupScene(this->ForGameL);
gameWidget->show();
});
//语言切换
connect(&settingP,&settingpage::selectLan,[=](int index){
if(index==0){
select->level1L->setText("简单");
select->level2L->setText("普通");
select->level2L->setGeometry(260,130,81,21);
select->level3L->setText("困难");
select->level4L->setText("挑战");
select->levelL->setText("设置");
select->DoneL->setText("开始");
}else{
select->level1L->setText("Easy");
select->level2L->setText("Medium");
select->level3L->setText("Hard");
select->level4L->setText("Challenge");
select->levelL->setText("Settings");
select->DoneL->setText("Done");
}
});
connect(startButton, &HoverButton::clicked, [=](){
select->setParent(this);
select->setGeometry(700,400,800,555);
select->setVisible(true);
});
connect(gameWidget, &GameWidget::showStartPage, [=](){
this->show();
sound->setLoopCount(QSoundEffect::Infinite);
sound->play();
}) ;
//打开设置界面
connect(settingButton, &HoverButton::clicked, [=](){
settingP.setParent(this);
settingP.setGeometry(560,262,800,555);
settingP.show();
}) ;
//语言切换
connect(&settingP,&settingpage::selectLan,[=](int index){
if(index==0){
startButton->showContent("开始",40);
recordButton->showContent("记录",20);
settingButton->showContent("设置",20);
loginButton->showContent("登录",10);
registerButton->showContent("注册",10);
logoutButton->showContent("登出",10);
}
if(index==1){
startButton->showContent("Start",40);
recordButton->showContent("Record",20);
settingButton->showContent("Settings",20);
loginButton->showContent("login",10);
registerButton->showContent("register",10);
logoutButton->showContent("logout",10);
}
});
connect(recordButton, &HoverButton::clicked, [=](){
this->hide();
sound->stop();
client->getProfile();
client->getRankList();
QString s = client->ranklist;
QString s1 = client->userlist;
ranklist->setRankList(s);
ranklist->setUserRankList(s1);
ranklist->show();
}) ;
connect(loginButton, &HoverButton::clicked, [=](){
this->hide();
sound->stop();
login->show();
}) ;
connect(registerButton, &HoverButton::clicked, [=](){
this->hide();
sound->stop();
regist->show();
}) ;
connect(logoutButton, &HoverButton::clicked, [=](){
QMessageBox msgBox; // 生成对象
if(client->logined == true) {
client->logined = false;
msgBox.setText("The user log out"); // 设置文本
} else {
msgBox.setText("No user log in");
}
msgBox.exec();
}) ;
connect(ranklist, &rankListPage::showStartPage, [=](){
this->show();
sound->setLoopCount(QSoundEffect::Infinite);
sound->play();
}) ;
connect(login, &loginPage::showStartPage, [=](){
this->show();
sound->setLoopCount(QSoundEffect::Infinite);
sound->play();
}) ;
connect(regist, ®isterPage::showStartPage, [=](){
this->show();
sound->setLoopCount(QSoundEffect::Infinite);
sound->play();
}) ;
}
//将path的图片放置到label上,自适应label大小
void StartPage::setAdaptedImg(QString path,QLabel *label)
{
QImage image(path);
QSize size=label->size();
QImage image2=image.scaled(size,Qt::IgnoreAspectRatio);//重新调整图像大小以适应label
label->setPixmap(QPixmap::fromImage(image2));//显示
}
//将path的图片放置到label上,自适应label大小
void StartPage::setBkImg(QString path,QLabel *label)
{
QImage image = QImage(path);
if(image.isNull()){
qDebug()<<"background:empty";
}
double ratio=(double)image.height()/(double)image.width();
QImage image2=image.scaled(this->width(),ratio*this->width(),Qt::IgnoreAspectRatio);//重新调整图像大小以适应label
label->setPixmap(QPixmap::fromImage(image2));//显示
label->setGeometry(0,0,this->width(),ratio*this->width());
}
void StartPage::keyPressEvent(QKeyEvent *ev)
{
//Esc退出全屏
if(ev->key() == Qt::Key_Escape)
{
QWidget::showNormal();
return;
}
//F11全屏
if(ev->key() == Qt::Key_F11)
{
QWidget::showFullScreen();
return;
}
QWidget::keyPressEvent(ev);
}
void StartPage::Sleep(int msec)
{
QTime dieTime = QTime::currentTime().addMSecs(msec);
while( QTime::currentTime() < dieTime )
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
//主窗口关闭则选择界面关闭
void StartPage::closeEvent(QCloseEvent *event)
{
select->close();
}