This repository was archived by the owner on Aug 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputs_widget.cpp
More file actions
88 lines (68 loc) · 2.68 KB
/
inputs_widget.cpp
File metadata and controls
88 lines (68 loc) · 2.68 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
#include "inputs_widget.h"
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include "life_game.h"
InputsWidget::InputsWidget(QWidget* parent)
: QWidget(parent)
, _startGameButton(nullptr)
, _stopGameButton(nullptr)
{
initUI();
}
void InputsWidget::initUI()
{
QGroupBox* gameStatusControls = nullptr;
QHBoxLayout* gameStatusLayout = nullptr;
QGroupBox* fieldSettingControls = nullptr;
QVBoxLayout* fieldSettingLayout = nullptr;
try {
// Game status controls
gameStatusControls = new QGroupBox;
gameStatusLayout = new QHBoxLayout;
_startGameButton = new QPushButton("Start");
_stopGameButton = new QPushButton("Stop");
gameStatusLayout->addWidget(_startGameButton);
gameStatusLayout->addWidget(_stopGameButton);
gameStatusControls->setLayout(gameStatusLayout);
fieldSettingControls = new QGroupBox;
fieldSettingLayout = new QVBoxLayout;
// Game options controls
auto* rowCountLabel = new QLabel("Rows count");
_rowCountInput = new QLineEdit;
auto* rowsCountForm = new QHBoxLayout;
rowsCountForm->addWidget(rowCountLabel);
rowsCountForm->addWidget(_rowCountInput);
auto* columnCountLabel = new QLabel("Column count");
_columnCountInput = new QLineEdit;
auto* columnsCountForm = new QHBoxLayout;
columnsCountForm->addWidget(columnCountLabel);
columnsCountForm->addWidget(_columnCountInput);
auto* acceptOptionsButton = new QPushButton("Accept");
connect(acceptOptionsButton, &QPushButton::clicked, this, [this]() {
_rowCount = _rowCountInput->text().toInt();
_columnCount = _columnCountInput->text().toInt();
emit settingsChanged();
});
fieldSettingLayout->addLayout(rowsCountForm);
fieldSettingLayout->addLayout(columnsCountForm);
fieldSettingLayout->addWidget(acceptOptionsButton);
fieldSettingControls->setLayout(fieldSettingLayout);
} catch (std::bad_alloc& exception) {
std::terminate();
}
auto* layout = new QVBoxLayout;
layout->addWidget(gameStatusControls);
layout->addWidget(fieldSettingControls);
setLayout(layout);
connect(_startGameButton, &QPushButton::clicked, this, [&]() { emit startGame(); });
connect(_stopGameButton, &QPushButton::clicked, this, [&]() { emit stopGame(); });
}
LifeGameOptions InputsWidget::options() const
{
LifeGameOptions options;
options.rowCount = _rowCount;
options.columnCount = _columnCount;
return options;
}