#ifndef MAINSCENE_H
#define MAINSCENE_H
#include <QMainWindow>
#include"mypushbutton.h"
#include"chooselevelscene.h"
//解决Qstring下输出中文时出现的乱码情况
#ifdef WIN32
#pragma execution_character_set("utf-8")
#endif
namespace Ui {
class MainScene;
}
class MainScene : public QMainWindow
{
Q_OBJECT
public:
explicit MainScene(QWidget *parent = 0);
ChooseLevelScene * chooseScene ; //选择不同场景的指针
~MainScene();
void paintEvent(QPaintEvent *); //绘图事件函数
private:
Ui::MainScene *ui;
};
#endif // MAINSCENE_H
mainscene.cpp
#include "mainscene.h"
#include "ui_mainscene.h"
#include"qstring.h"
#include"qicon.h"
#include"Qpainter"
#include"QDebug.h"
#include"mypushbutton.h"
#include<QPushButton>
#include<QTimer>
#include"chooselevelscene.h"
MainScene::MainScene(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainScene)
{
ui->setupUi(this);
//翻金币主场景,设置窗口标题,固定大小和标题前的图标
this->setWindowTitle("BitCoin");
this->setFixedSize(320,580);
this->setWindowIcon(QIcon(":/res/Coin0001.png"));
//退出程序
connect(ui->actionquit,&QAction::triggered,this,&MainScene::close);
//创建自定义的开始按钮,移动开始按钮到中心位置,并以当前窗体为父类
MyPushButton * startBtn = new MyPushButton(":/res/MenuSceneStartButton.png");
startBtn->move(this->width()*0.5-startBtn->width()*0.5,this->height()*0.7);
startBtn->setParent(this);
//创建不同选择场景的指针
ChooseLevelScene *chooseScene=new ChooseLevelScene;
//触发选择场景返回功能,返回主场景
connect(chooseScene,&ChooseLevelScene::chooseSceneBack,[=](){
this->show();
});
//触发自定义按钮的上下跳动并延时500ms进入场景选择界面
connect(startBtn,&MyPushButton::clicked,[=](){
startBtn->zoom1();
startBtn->zoom2();
//延时进入选择
QTimer::singleShot(500,this,[=](){
this->hide();
chooseScene->show();
});
});
}
//绘图事件函数
void MainScene::paintEvent(QPaintEvent *)
{
//创建画笔,指定绘图设备
QPainter painter(this);
QPixmap pix;
pix.load(":/res/PlayLevelSceneBg.png");
//绘制背景图
painter.drawPixmap(0,0,this->width(),this->height(),pix);
//加载标题
pix.load(":/res/Title.png");
//大小调整
pix=pix.scaled(pix.width()*0.5,pix.height()*0.5);
//绘制标题
painter.drawPixmap(10,30,pix.width(),pix.height(),pix);
}
MainScene::~MainScene()
{
delete ui;
}