-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyview.cpp
54 lines (46 loc) · 1.66 KB
/
myview.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
#include "myview.h"
#include "myplane.h"
#include "flowback.h"
#include <QDir>
#include <QDebug>
#include <QWidget>
#include <QPixmap>
#include <QDateTime>
#include <QMediaPlayer>
#include <QMediaPlaylist>
#include <QMediaPlayerControl>
MyView::MyView(QWidget *parent):
QGraphicsView(parent)
{
QMediaPlayer * player = new QMediaPlayer(this); //背景音乐
QMediaPlaylist * list = new QMediaPlaylist(this);
list->addMedia(QUrl(QDir::currentPath() + "/a.mp3"));
list->setCurrentIndex(0);
list->setPlaybackMode(QMediaPlaylist::CurrentItemInLoop);
player->setPlaylist(list);
player->play();
icon = new QIcon("://images/Icon.png");
setRenderHint(QPainter::Antialiasing); //抗锯齿
setMinimumSize(viewWidth + 10, viewHeight + 10); //设置窗口
setMaximumSize(viewWidth + 10, viewHeight + 10);
if(loadmode) setWindowTitle(tr("飞机大战 [上帝模式]"));
else setWindowTitle(tr("飞机大战"));
setWindowIcon(*icon);
scene = new QGraphicsScene;
scene->setSceneRect(0, 0, viewWidth, viewHeight);
setScene(scene);
game = new GameController(scene, this);
connect(game, SIGNAL(exitApp()), this, SLOT(close()));
}
void MyView::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::RightButton) {
QPixmap pix(viewWidth, viewHeight);
QPainter painter(&pix);
render(&painter, QRect(0, 0, viewWidth, viewHeight), QRect(0, 0, viewWidth, viewHeight));
QString fileName = QString("%1.png").arg(qrand());
qDebug() << fileName;
pix.save(fileName);
}
QGraphicsView::mousePressEvent(event);
}