-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewgamedialog.cpp
More file actions
110 lines (87 loc) · 3.17 KB
/
newgamedialog.cpp
File metadata and controls
110 lines (87 loc) · 3.17 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
110
#include "newgamedialog.h"
#include "ui_newgamedialog.h"
NewGameDialog::NewGameDialog(QWidget* parent, QSize fieldSize, QSize cellSize, QSize borderSize, unsigned char minesPercents)
: QDialog(parent)
, ui(new Ui::NewGameDialog)
{
ui->setupUi(this);
ui->fieldWidth->setValidator(new QIntValidator(1, 3000, this));
ui->fieldHeight->setValidator(new QIntValidator(1, 3000, this));
ui->cellWidth->setValidator(new QIntValidator(1, 100, this));
ui->cellHeight->setValidator(new QIntValidator(1, 100, this));
ui->borderWidth->setValidator(new QIntValidator(1, 100, this));
ui->borderHeight->setValidator(new QIntValidator(1, 100, this));
ui->minesPercent->setValidator(new QIntValidator(1, 100, this));
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(updateData()));
ui->stackedWidget->setCurrentIndex(1);
ui->fieldWidth->setText(QString::number(fieldSize.width()));
ui->fieldHeight->setText(QString::number(fieldSize.height()));
ui->cellWidth->setText(QString::number(cellSize.width()));
ui->cellHeight->setText(QString::number(cellSize.height()));
ui->borderWidth->setText(QString::number(borderSize.width()));
ui->borderHeight->setText(QString::number(borderSize.height()));
ui->minesPercent->setText(QString::number(minesPercents));
}
NewGameDialog::~NewGameDialog()
{
delete ui;
}
NewGameDialogData NewGameDialog::getEnteredData() const
{
return data;
}
void NewGameDialog::updateData()
{
// bool isOk = false;
data.fieldSize.setWidth(ui->fieldWidth->text().toInt());
data.fieldSize.setHeight(ui->fieldHeight->text().toInt());
data.cellSize.setWidth(ui->cellWidth->text().toInt());
data.cellSize.setHeight(ui->cellHeight->text().toInt());
data.borderSize.setWidth(ui->borderWidth->text().toInt());
data.borderSize.setHeight(ui->borderHeight->text().toInt());
if (data.fieldSize.width() < 1)
data.fieldSize.setWidth(1);
if (data.fieldSize.height() < 1)
data.fieldSize.setHeight(1);
if (data.cellSize.width() < 1)
data.cellSize.setWidth(1);
if (data.cellSize.height() < 1)
data.cellSize.setHeight(1);
if (data.borderSize.width() < 0)
data.borderSize.setWidth(0);
if (data.borderSize.height() < 0)
data.borderSize.setHeight(0);
data.minesPercent = ui->minesPercent->text().toInt();
if (data.minesPercent < 1)
data.minesPercent = 1;
else if (data.minesPercent > 100)
data.minesPercent = 100;
}
void NewGameDialog::on_pushButtonEasy_clicked()
{
data.fieldSize = QSize(25, 25);
data.cellSize = QSize(25, 25);
data.borderSize = QSize(0, 0);
data.minesPercent = 20;
accept();
}
void NewGameDialog::on_pushButtonLIttleHarder_clicked()
{
data.fieldSize = QSize(50, 50);
data.cellSize = QSize(25, 25);
data.borderSize = QSize(1, 1);
data.minesPercent = 20;
accept();
}
void NewGameDialog::on_pushButtonAsianMode_clicked()
{
data.fieldSize = QSize(1000, 1000);
data.cellSize = QSize(1, 1);
data.borderSize = QSize(0, 0);
data.minesPercent = 10;
accept();
}
void NewGameDialog::on_pushButtonManually_clicked()
{
ui->stackedWidget->setCurrentIndex(0);
}