-
Notifications
You must be signed in to change notification settings - Fork 7
/
MainWindow.cpp
48 lines (37 loc) · 999 Bytes
/
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
#include "MainWindow.hpp"
#include "ui_MainWindow.h"
#include "Field.hpp"
#include "CellItem.hpp"
#include <QGLWidget>
#include <QGraphicsScene>
#include <QTimer>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_scene = new QGraphicsScene();
m_field = new Field();
m_field->setSize(8, 8);
m_field->setNumberOfMines(10);
ui->graphicsView->setScene(m_scene);
ui->graphicsView->setViewport(new QGLWidget());
for (int y = 0; y < m_field->height(); ++y) {
for (int x = 0; x < m_field->width(); ++x) {
m_scene->addItem(new CellItem(m_field->cellAt(x, y)));
}
}
m_field->generate();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::resizeEvent(QResizeEvent *event)
{
QTimer::singleShot(0, this, SLOT(updateSceneScale()));
}
void MainWindow::updateSceneScale()
{
ui->graphicsView->fitInView(m_scene->sceneRect(), Qt::KeepAspectRatio);
}