-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartwindow.cpp
More file actions
35 lines (31 loc) · 1.07 KB
/
Copy pathstartwindow.cpp
File metadata and controls
35 lines (31 loc) · 1.07 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
#include "startwindow.h"
#include <QGridLayout>
#include <QApplication>
StartWindow::StartWindow(QWidget *parent) : QWidget(parent)
{
startButton = new QPushButton("Start game", this);
exitButton = new QPushButton("Quit", this);
boardSizeLineEdit = new QLineEdit("Enter board size", this);
QGridLayout* layout = new QGridLayout();
layout->addWidget(boardSizeLineEdit, 0, 0, 1, 2);
layout->addWidget(startButton, 1, 0);
layout->addWidget(exitButton, 1,1);
setLayout(layout);
connect(boardSizeLineEdit, SIGNAL (returnPressed()), this, SLOT (slotStartButtonClicked()));
connect(startButton, SIGNAL (clicked()), this, SLOT (slotStartButtonClicked()));
connect(exitButton, SIGNAL (clicked()), QApplication::instance(), SLOT (quit()));
}
void StartWindow::slotStartButtonClicked()
{
QString enteredText {boardSizeLineEdit->text()};
bool ok;
int width = enteredText.toInt(&ok);
if (ok)
{
emit signalStart(static_cast<std::size_t>(width));
}
else
{
boardSizeLineEdit->setText("Enter board size again");
}
}