-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartscene.cpp
More file actions
63 lines (52 loc) · 1.97 KB
/
startscene.cpp
File metadata and controls
63 lines (52 loc) · 1.97 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
#include "startscene.h"
startScene::startScene(QWidget *parent)
: MyMainWindow{parent}
{
this->setWindowTitle("开始场景");
MyPushButton *btnStart=new MyPushButton(":/res/MenuSceneStartButton.png",":/res/MenuSceneStartButton.png",this);
//:/res/OtherSceneBg.png
//:/res/MenuSceneStartButton.png
btnStart->resize(114,114);
btnStart->move((this->width() - btnStart->width())/2,
350);
// int num=this->height()*3/4-btnStart->height()/2;
// qDebug()<<num;
//设置按钮音效
connect(btnStart,&MyPushButton::clicked,[=](){
QSoundEffect *sound=new QSoundEffect(this);
sound->setSource(QUrl::fromLocalFile(":/res/TapButtonSound.wav"));
sound->play();
//点击之后 先将btnStart禁用
btnStart->setEnabled(false);
btnStart->moveDown();
//设置一个定时器 down动画触发后150ms 才能触发up动画
//避免up动画在dow动画还未完成时 就将其覆盖
QTimer::singleShot(150,[=](){
btnStart->moveUp();
});
//2个动画完成后 300ms后 再启用
QTimer::singleShot(300,[=](){
btnStart->setEnabled(true);
});
//点击按钮后 场景切换
this->mSelectScene.move(this->pos());//窗口位置对齐
this->hide();
mSelectScene.show();
});
//当点击back按钮时 返回开始界面 隐藏选择界面
connect(&this->mSelectScene,&selectScene::backBtnClicked,[=](){
//设置按钮音效
QSoundEffect *sound=new QSoundEffect(this);
sound->setSource(QUrl::fromLocalFile(":/res/BackButtonSound.wav"));
sound->play();
this->move(this->mSelectScene.pos());//窗口位置对齐
this->show();
mSelectScene.hide();
});
}
void startScene::paintEvent(QPaintEvent *ev)
{
QPainter painter(this);
QPixmap pix("://res/MenuSceneBg.png");
painter.drawPixmap(0,0,this->width(),this->height(),pix);
}