-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetplayer.cpp
More file actions
75 lines (65 loc) · 2.27 KB
/
Copy pathsetplayer.cpp
File metadata and controls
75 lines (65 loc) · 2.27 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
#include <utility>
#include <QMessageBox>
#include "Setplayer.h"
#include "ui_Setplayer.h"
Setplayer::Setplayer(QWidget *parent)
: QDialog(parent)
, ui(new Ui::Setplayer)
{
ui->setupUi(this);
ui->sb_age->setMinimum(0); // minimum age is 0
}
Setplayer::~Setplayer()
{
delete ui;
}
// this function is for set players informations
// name age color
void Setplayer::page_show(std::map<QString, Color> freeColors, size_t playerID)
{
ui->comboBox_color->clear();
ui->sb_age->setValue(0);
ui->lineEdit_name->setText("");
this->show();
std::string labelText = "Player " + std::to_string(playerID + 1);
ui->lb_player_counter->setText(QString::fromStdString(labelText)); // input texts
this->setWindowTitle(QString::fromStdString(labelText));
for(auto &&freeColor : freeColors)
ui->comboBox_color->addItem(freeColor.first); // comboBox colors*
this->freeColors = freeColors; // marker
QEventLoop loop;
connect(ui->btn_next, SIGNAL(clicked(bool)), &loop, SLOT(quit())); //signal and slots
loop.exec();
disconnect(ui->btn_next, SIGNAL(clicked(bool)), &loop, SLOT(quit())); //signal and slots
}
void Setplayer::on_btn_next_clicked()
{
QString name = ui->lineEdit_name->text();
size_t old = ui->sb_age->value();
QString color = ui->comboBox_color->currentText();
////// check
if(name == "") {
QMessageBox ErrorMessage;
ErrorMessage.setText("name is empty!"); /// check name is empty or no
ErrorMessage.exec();
}
else if (old == 0){
QMessageBox ErrorMessage;
ErrorMessage.setText("age is empty!"); /// check age is empty or no
ErrorMessage.exec();
}
else if (freeColors.find(color) == freeColors.end()) {
QMessageBox ErrorMessage;
ErrorMessage.setText("bad color choice"); /// check color is empty or no
ErrorMessage.exec();
}
else {
Color choiceColor;
choiceColor = freeColors[color]; ///default color
this->hide();
emit get_player(name.toStdString(), old, choiceColor);
}
}
void Setplayer::on_btn_back_clicked()
{
}