-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddPlayerToMatchDialog.cpp
More file actions
186 lines (136 loc) · 6.05 KB
/
AddPlayerToMatchDialog.cpp
File metadata and controls
186 lines (136 loc) · 6.05 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include "AddPlayerToMatchDialog.h"
#include "ui_AddPlayerToMatchDialog.h"
#include <QDebug>
AddPlayerToMatchDialog::AddPlayerToMatchDialog(std::shared_ptr<Round> r, int x, QWidget *parent) :
QDialog(parent),
ui(new Ui::AddPlayerToMatchDialog)
{
ui->setupUi(this);
round = r;
match = r->getListOfMatches().at(x);
this->setWindowTitle("Add To Match Dialog");
QString output;
ui->menuLabel->setText(QString::fromStdString(match->getName()) + " Menu");
ui->menuLabel->setWordWrap(true);
ui->menuLabel->setAlignment(Qt::AlignCenter);
printRoundPlayers();
printMatchPlayers();
//removeFromMatchButton
ui->addToMatchButton->setEnabled(false);
ui->removeFromMatchButton->setEnabled(false);
ui->addAllPlayersButton->setEnabled(true);
ui->removeAllPlayersButton->setEnabled(true);
this->setStyleSheet("background-color: #58CCED;");
ui->roundRosterListWidget->setStyleSheet("background-color: #FFFFFF;");
ui->matchRosterListWidget->setStyleSheet("background-color: #FFFFFF;");
ui->addToMatchButton->setStyleSheet("QPushButton::hover{background-color : lightgreen;}"
"QPushButton{background-color: #FFFFFF;}");
ui->removeFromMatchButton->setStyleSheet("QPushButton::hover{background-color : lightgreen;}"
"QPushButton{background-color: #FFFFFF;}");
ui->addAllPlayersButton->setStyleSheet("QPushButton::hover{background-color : lightgreen;}"
"QPushButton{background-color: #FFFFFF;}");
ui->removeAllPlayersButton->setStyleSheet("QPushButton::hover{background-color : lightgreen;}"
"QPushButton{background-color: #FFFFFF;}");
ui->buttonBox->button(QDialogButtonBox::Ok)->setStyleSheet("QPushButton::hover{background-color : lightgreen;}"
"QPushButton {background-color: #FFFFFF}");
ui->buttonBox->button(QDialogButtonBox::Cancel)->setStyleSheet("QPushButton::hover{background-color : lightgreen;}"
"QPushButton {background-color: #FFFFFF}");
}
AddPlayerToMatchDialog::~AddPlayerToMatchDialog()
{
delete ui;
}
void AddPlayerToMatchDialog::printRoundPlayers(){
QString output;
for(int i = 0; i < this->round->getNumberOfPlayers(); i++){
int j = i+1;
output = QString::number(j) + ". " + round->getRoundListOfPlayers().at(i)->getQName();
//output = output + "\n";
ui->roundRosterListWidget->addItem(output);
}
}
void AddPlayerToMatchDialog::printMatchPlayers(){
QString output;
ui->matchRosterListWidget->clear();
if(match->getMatchListOfPlayers().size() > 0){
for(int i = 0; i < match->getNumOfPlayers(); i++){
int j = i+1;
output = QString::number(j) + ". " + match->getMatchListOfPlayers().at(i)->getQName();
//output = output + "\n";
ui->matchRosterListWidget->addItem(output);
}
}
}
void AddPlayerToMatchDialog::on_addToMatchButton_clicked()
{
QListWidgetItem *item = ui->roundRosterListWidget->currentItem();
int x = ui->roundRosterListWidget->row(item);
//Duplicating shared ptr from Tournament List to put in Round List.
std::shared_ptr<Player> p(round->getRoundListOfPlayers().at(x));
//Create a variable pointing directly to round instead of having to do Tournament->getRoundList->getPlayerList->.....
std::shared_ptr<Match> m(round->getListOfMatches().back());
match->addPlayer(p);
ui->matchRosterListWidget->clear();
//Print players in Match.
printMatchPlayers();
}
void AddPlayerToMatchDialog::on_roundRosterListWidget_itemDoubleClicked(QListWidgetItem *item)
{
item = ui->roundRosterListWidget->currentItem();
int x = ui->roundRosterListWidget->row(item);
//Duplicating shared ptr from Tournament List to put in Round List.
std::shared_ptr<Player> p(round->getRoundListOfPlayers().at(x));
//Create a variable pointing directly to round instead of having to do Tournament->getRoundList->getPlayerList->.....
std::shared_ptr<Match> m(round->getListOfMatches().back());
match->addPlayer(p);
ui->matchRosterListWidget->clear();
//Print players in Round.
printMatchPlayers();
}
void AddPlayerToMatchDialog::on_roundRosterListWidget_itemClicked(QListWidgetItem *item)
{
ui->addToMatchButton->setEnabled(true);
}
void AddPlayerToMatchDialog::on_buttonBox_accepted()
{
this->close();
}
void AddPlayerToMatchDialog::on_removeFromMatchButton_clicked()
{
//ui->matchRosterListWidget->clear();
QListWidgetItem *item = ui->matchRosterListWidget->currentItem();
int x = ui->matchRosterListWidget->row(item);
match->deletePlayer(x);
ui->matchRosterListWidget->clear();
//Print players in match.
printMatchPlayers();
ui->removeFromMatchButton->setEnabled(false);
}
void AddPlayerToMatchDialog::on_matchRosterListWidget_itemClicked(QListWidgetItem *item)
{
ui->removeFromMatchButton->setEnabled(true);
}
void AddPlayerToMatchDialog::on_matchRosterListWidget_itemDoubleClicked(QListWidgetItem *item)
{
item = ui->matchRosterListWidget->currentItem();
int indexToDelete = ui->matchRosterListWidget->row(item);
match->deletePlayer(indexToDelete);
ui->matchRosterListWidget->clear();
printMatchPlayers();
//Updates players in match roster.
ui->removeFromMatchButton->setEnabled(false);
//Prevent out_of_range errors.
}
void AddPlayerToMatchDialog::on_addAllPlayersButton_clicked()
{
for(int i = 0; i < round->getRoundListOfPlayers().size(); i++){
std::shared_ptr<Player>p = round->getRoundListOfPlayers().at(i);
match->addPlayer(p);
}
printMatchPlayers();
}
void AddPlayerToMatchDialog::on_removeAllPlayersButton_clicked()
{
match->deleteAllPlayers();
printMatchPlayers();
}