-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
80 lines (68 loc) · 2.21 KB
/
Copy pathmainwindow.cpp
File metadata and controls
80 lines (68 loc) · 2.21 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QPainter>
#include<QPaintDevice>
#include<mypushbutton.h>
#include<QTimer>
#include<QSoundEffect>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
//设置主场景
//设置固定大小
this->setFixedSize(320,588);
//设置图标
this->setWindowIcon(QIcon(":/CoinFlip/res/Coin0001.png"));
//设置标题
this->setWindowTitle("翻金币的主页面");
//实现退出功能
connect(ui->actionout,&QAction::triggered,[=](){
this->close();
});
//设置开始按钮音效
QSoundEffect *startBtnSound=new QSoundEffect(this);
startBtnSound->setSource(QUrl::fromLocalFile(":/CoinFlip/res/TapButtonSound.wav"));
startBtnSound->setVolume(0.2f);
//设置开始按钮
myPushButton *startBtn=new myPushButton(":/CoinFlip/res/MenuSceneStartButton.png");
startBtn->setParent(this);
startBtn->move(this->width()*0.5-startBtn->width()*0.5,this->height()*0.7);
this->cho=new chooseLevelScene(this);
connect(startBtn,&QPushButton::clicked,[=](){
//开始按钮音效播放
startBtnSound->play();
startBtn->zoom1();
startBtn->zoom2();
//延时展示选择窗口
QTimer::singleShot(200,this,[=](){
//隐藏主窗口
this->hide();
//使选择关卡窗口位置与当前窗口位置一致
cho->setGeometry(this->geometry());
//显示选择窗口
cho->show();
});
});
connect(cho,&chooseLevelScene::chooseSceneBack,this,[=](){
cho->hide();
this->setGeometry(cho->geometry());
this->show();
});
}
void MainWindow::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QPixmap pix(":/CoinFlip/res/PlayLevelSceneBg.png");
painter.drawPixmap(0,0,this->width(),this->height(),pix);
//画背景图上的图标
pix.load(":/CoinFlip/res/Title.png");
//缩放
pix=pix.scaled(pix.width()*0.5,pix.height()*0.5);
painter.drawPixmap(10,30,pix);
}
MainWindow::~MainWindow()
{
delete ui;
}