forked from Rescator7/Hearts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctable.cpp
110 lines (87 loc) · 2.25 KB
/
ctable.cpp
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
#ifdef ONLINE_PLAY
#include "ctable.h"
#include "define.h"
#include "ui_ctable.h"
CTable::CTable(QWidget *parent) :
QWidget(parent),
ui(new Ui::CTable)
{
ui->setupUi(this);
ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
setWindowTitle(tr("Tables list"));
setAttribute( Qt::WA_QuitOnClose, false );
}
CTable::~CTable()
{
delete ui;
}
void CTable::AddRow(QString id, QString flags)
{
int rowc = ui->tableWidget->rowCount();
ui->tableWidget->insertRow(rowc);
QTableWidgetItem *item_id = new QTableWidgetItem(id);
ui->tableWidget->setItem(rowc, 0, item_id);
QString s;
int i = flags.toInt();
if (i & QUEEN_SPADE_f) s += "Q ";
if (i & PERFECT_100_f) s += "P ";
if (i & OMNIBUS_f) s += "O ";
if (i & NO_TRICK_BONUS_f) s += "T ";
if (i & NEW_MOON_f) s += "M ";
if (!(i & NO_DRAW_f)) s += "D";
QTableWidgetItem *item_flags = new QTableWidgetItem(s);
ui->tableWidget->setItem(rowc, 1, item_flags);
for (int i=0; i<4; i++) {
QTableWidgetItem *empty_item = new QTableWidgetItem("");
ui->tableWidget->setItem(rowc, i+2, empty_item);
}
}
void CTable::Empty()
{
ui->tableWidget->setRowCount(0);
}
void CTable::RemoveRow(QString id)
{
int rowc = ui->tableWidget->rowCount();
for (int i=0; i<rowc; i++) {
if (ui->tableWidget->item(i, 0)->text() == id) {
ui->tableWidget->removeRow(i); // by removing a row, the index changes, don't forget to break.
break;
}
}
}
void CTable::SetPlayer(QString id, QString name, QString chair)
{
int rowc = ui->tableWidget->rowCount();
int c = 0;
if (chair == "n") c = 2;
else
if (chair == "s") c = 3;
else
if (chair == "w") c = 4;
else
if (chair == "e") c = 5;
if (!c) return;
for (int i=0; i<rowc; i++) {
if (ui->tableWidget->item(i, 0)->text() == id) {
ui->tableWidget->item(i, c)->setText(name);
}
}
}
void CTable::on_tableWidget_cellDoubleClicked(int row, int column)
{
int id = ui->tableWidget->item(row, 0)->text().toInt();
char chair = ' ';
switch (column) {
case 2: chair = 'n'; break;
case 3: chair = 's'; break;
case 4: chair = 'w'; break;
case 5: chair = 'e'; break;
}
emit clicked(id, chair);
}
void CTable::Translate()
{
ui->retranslateUi(this);
}
#endif // ONLINE_PLAY