-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
63 lines (57 loc) · 1.7 KB
/
mainwindow.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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//chooseLevel界面back按钮
chooseLevel=new ChooseLevelScene(this);
connect(chooseLevel,&ChooseLevelScene::backButtonClicked,[=](){
chooseLevel->close();
this->show();
});
QPixmap pix;
pix.load(":/res/MenuSceneStartButton.png");
int x=(this->width()-pix.width())/2;
int y=this->height()-pix.width()-50;
//创建开始音乐
QSound * startSound = new QSound(":/res/TapButtonSound.wav",this);
//创建开始按钮
MyPushButton *startBtn=new MyPushButton(":/res/MenuSceneStartButton.png");
startBtn->setParent(this);
startBtn->setGeometry(x,y,pix.width(),pix.height());
connect(startBtn,&QPushButton::clicked,[=](){
startSound->play();
startBtn->jump(true);
startBtn->jump(false);
//延时进入到选择关卡场景中
QTimer::singleShot(500,this,[=](){
//设置chooseScene场景的位置
chooseLevel->setGeometry(this->geometry());
//自身隐藏
this->hide();
//显示选择关卡场景
chooseLevel->show();
});
});
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionquit_X_triggered()
{
this->close();
}
void MainWindow::paintEvent(QPaintEvent * ev)
{
//创建画家
QPainter painter(this);
//画背景图
QPixmap pix;
pix.load(":/res/PlayLevelSceneBg.png");
painter.drawPixmap(0,0,pix.scaled(this->size()));
pix.load(":/res/Title.png");
painter.drawPixmap(20,30,pix.width()*3/4,pix.height()*3/4,pix);
}