-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappdialog.cpp
More file actions
95 lines (76 loc) · 2.21 KB
/
appdialog.cpp
File metadata and controls
95 lines (76 loc) · 2.21 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
#include <QDesktopServices>
#include "appdialog.h"
#include "ui_appdialog.h"
AppDialog::AppDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::AppDialog)
{
//set default color (white)
QColor c(255, 255, 255);
qchooser = new QColorDialog(c, this);
//Default color in model
m = Model::getInstance();
m->setColor(c);
ui->setupUi(this);
//Default color on button
this->ui->colorButton->setStyleSheet("* { background-color: rgb("+
QString::number(255)+","+
QString::number(255)+","+
QString::number(255)+")}");
//Save to file
hosts = new QFile("hosts");
if (hosts->open(QIODevice::ReadOnly))
{
QString str = hosts->readLine();
QStringList host = str.split(':');
ui->PlayerName->setText(host[0]);
ui->ServerAddr->setText(host[1]);
hosts->close();
}
nc = new NetworkClient();
ga = new GameApp();
connect(ga, SIGNAL(destroyed()), this, SLOT(reject()));
}
void AppDialog::accept()
{
m->setName(ui->PlayerName->text());
nc->setName(ui->PlayerName->text());
if (!hosts->open(QIODevice::WriteOnly))
{
qDebug() << "Could not open hosts file";
}
else
{
QTextStream out(hosts);
out << ui->PlayerName->text() << ":" << ui->ServerAddr->text() << ":" << ui->ServerPort->value();
hosts->close();
}
nc->startOn(ui->ServerAddr->text(), ui->ServerPort->value());
connect(nc, SIGNAL(networkReady()), ga, SLOT(run()));
//ga->run();
setVisible(false);
hosts->close();
}
void AppDialog::colorChosen(QColor color)
{
int r, g, b;
color.getRgb(&r, &g, &b);
this->ui->colorButton->setStyleSheet("* { background-color: rgb("+
QString::number(r)+","+
QString::number(g)+","+
QString::number(b)+")}");
m->setColor(color);
}
void AppDialog::reject()
{
setVisible(false);
exit(0);
}
AppDialog::~AppDialog()
{
delete ui;
}
void AppDialog::on_colorButton_clicked()
{
qchooser->open(this, SLOT(colorChosen(QColor)));
}