-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
109 lines (90 loc) · 2.78 KB
/
mainwindow.cpp
File metadata and controls
109 lines (90 loc) · 2.78 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <QDebug>
#include <algorithm> //std::min
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "squaregrid.h"
#include "hexgrid.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setFixedSize(QSize(1207, 819));
initialiseUI();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::initialiseUI()
{
ui->denseBox->setEnabled(false);
ui->finishBox->setEnabled(false);
ui->geometryBox->setCurrentIndex(0);
ui->checkRandLayout->setChecked(false);
ui->checkRandFinish->setChecked(false);
ui->checkRandStart->setChecked(false);
ui->widthBox->setValue(40);
ui->heightBox->setValue(25);
ui->denseBox->setValue(30);
ui->finishBox->setValue(1);
ui->pathButton->setEnabled(false);
}
void MainWindow::on_geometryBox_currentIndexChanged(int index)
{
if (index == 2)
{
ui->widthBox->setEnabled(false);
ui->heightBox->setEnabled(false);
ui->checkRandLayout->setEnabled(false);
ui->checkRandStart->setEnabled(false);
ui->checkRandFinish->setEnabled(false);
}
else
{
ui->widthBox->setEnabled(true);
ui->heightBox->setEnabled(true);
ui->checkRandLayout->setEnabled(true);
ui->checkRandStart->setEnabled(true);
ui->checkRandFinish->setEnabled(true);
}
}
void MainWindow::on_gridButton_clicked()
{
int geometry = ui->geometryBox->currentIndex();
Grid* theGrid;
if (geometry == 0)
theGrid = new SquareGrid(ui->gridView,ui->widthBox->value(),ui->heightBox->value());
else if (geometry == 1)
theGrid = new HexGrid(ui->gridView,ui->widthBox->value(),ui->heightBox->value());
else return;
theGrid->Randomise(ui->checkRandLayout->isChecked(),ui->checkRandFinish->isChecked(),
ui->checkRandStart->isChecked(),ui->finishBox->value(),
ui->denseBox->value());
ui->gridView->SetGrid(theGrid);
ui->gridView->update();
}
void MainWindow::on_resetButton_clicked()
{
ui->gridView->SetReset(true);
ui->gridView->update();
initialiseUI();
}
void MainWindow::on_checkRandLayout_stateChanged(int state)
{
ui->denseBox->setEnabled(!!state);
}
void MainWindow::on_checkRandFinish_stateChanged(int state)
{
ui->finishBox->setEnabled(!!state);
}
void MainWindow::on_widthBox_editingFinished()
{
ui->finishBox->setMaximum(std::min(
ui->widthBox->value()*ui->heightBox->value()-1,10));
}
void MainWindow::on_heightBox_editingFinished()
{
ui->finishBox->setMaximum(std::min(
ui->widthBox->value()*ui->heightBox->value()-1,10));
}