#include "mform.h"#include "ui_mform.h"mform::mform(QWidget *parent) : QMainWindow(parent), ui(new Ui::mform){ ui->setupUi(this); createConnections(); ui->graphView->setScene( &sceneField ); ui->graphView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); ui->graphView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); createField();}mform::~mform(){ delete ui;}void mform::createConnections(){ connect(ui->spWidth, SIGNAL(valueChanged(int)), this, SLOT(createField())); connect(ui->spHeight, SIGNAL(valueChanged(int)), this, SLOT(createField())); //connect(ui->spWidth, &QSpinBox::valueChanged, this, &mform::createField); //QObject::connect(ui->spHeight, &QSpinBox::valueChanged, this, mform::createField());}void mform::resizeEvent(QResizeEvent *event){ ui->graphView->fitInView( sceneField.sceneRect(), Qt::KeepAspectRatio); QWidget::resizeEvent(event);}bool mform::event(QEvent *event){ if ( event->type() == QEvent::Show ) ui->graphView->fitInView(sceneField.sceneRect(), Qt::KeepAspectRatio); return QWidget::event(event);}void mform::createField(){ deleteField(); const int sizeCell = 10; fieldCells.resize( ui->spHeight->value() ); bArrCells.resize( ui->spHeight->value() ); for (int y = 0; y < ui->spHeight->value(); y++) { fieldCells[y].resize( ui->spWidth->value() ); bArrCells[y].resize( ui->spWidth->value() ); for (int x = 0; x < ui->spWidth->value(); x++) { fieldCells[y][x] = sceneField.addRect(x * sizeCell, y * sizeCell, sizeCell, sizeCell); } } ui->graphView->fitInView( sceneField.sceneRect(), Qt::KeepAspectRatio);}void mform::deleteField(){ sceneField.clear(); fieldCells.clear(); bArrCells.clear();}