-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
59 lines (56 loc) · 1.57 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTimer>
#include <QGraphicsView>
#include<QGraphicsTextItem>
#include"button.h"
#include "gamecontroller.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),
scene(new QGraphicsScene(this)),
view(new QGraphicsView(scene, this))
//ui(new Ui::MainWindow)
{
//ui->setupUi(this);
setCentralWidget(view);
resize(600, 600);
initScene();
initSceneBackground();
QTimer::singleShot(0, this, SLOT(adjustViewSize()));
QGraphicsTextItem* titleText = new QGraphicsTextItem(QString("Sokuban"));
QFont titleFont("comic sans", 20);
titleText->setFont(titleFont);
titleText->setPos(-100,-100);
scene->addItem(titleText);
Button* playButton = new Button(QString("Play"));
playButton->setPos(-100, 0);
scene->addItem(playButton);
connect(playButton, SIGNAL(clicked()), this, SLOT(startgame()));
}
MainWindow::~MainWindow()
{
//delete ui;
}
void MainWindow::initScene()
{
scene->setSceneRect(-200, -200, 400,400);
}
void MainWindow::initSceneBackground(){
qreal TILE_SIZE = 50;
QPixmap bg(TILE_SIZE, TILE_SIZE);
QPainter p(&bg);
p.setBrush(QBrush(Qt::gray));
p.drawRect(0, 0, TILE_SIZE, TILE_SIZE);
view->setBackgroundBrush(QBrush(bg));
}
void MainWindow::adjustViewSize()
{
view->fitInView(scene->sceneRect(), Qt::KeepAspectRatioByExpanding);
}
void MainWindow::startgame()
{
QTimer time(0);
scene->clear();
scene->update();
game = new GameController(*scene, this);
}