forked from shervinkh/sgu-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
competitionview.cpp
143 lines (124 loc) · 3.89 KB
/
competitionview.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
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
#include "competitionview.h"
#include "competition.h"
#include "accountmanager.h"
#include "profileinfo.h"
#include "competitiondetail.h"
#include <QTableWidget>
#include <QTableWidgetItem>
#include <QHeaderView>
#include <QString>
#include <QSize>
#include <QProcess>
#include <QtGui>
CompetitionView::CompetitionView(QWidget *parent, AccountManager *am,
Competition *com) :
QTableWidget(parent)
{
this->am = am;
this->com = com;
setColumnCount(3);
setHorizontalHeaderItem(0, new QTableWidgetItem(tr("Target")));
setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Compared to")));
setHorizontalHeaderItem(2, new QTableWidgetItem(tr("Competition type")));
connect(this, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(handleDoubleClick(int,int)));
resizeColumnsToContents();
}
void CompetitionView::setData(const QList<CompetitionInfo> &in)
{
setRowCount(0);
setRowCount(in.size());
foreach (CompetitionInfo ci, in)
{
if (!ids.contains(ci) && com->hasNoti() )
{
QString name = am->infoOf(ci.target()).name();
QProcess::execute("notify-send", QStringList() << "--icon=info" << "--app-name='SGU Client'" << "SGU Client" << "You have some warnings about "+name);
}
}
ids.clear();
for (int i = 0; i < in.size(); i++)
setVerticalHeaderItem(i, new QTableWidgetItem(QString::number(i+1)));
bool hascrit = false;
for (int i = 0; i < in.size(); i++)
{
ids.append(in[i]);
bool critical = false;
if (in[i].type() == DiffAc || in[i].type() == MoreAc)
{
hascrit = true;
critical = true;
}
QString nam = am->infoOf(in[i].target()).name();
QTableWidgetItem *name = new QTableWidgetItem;
name->setText(nam);
name->setFlags(Qt::ItemIsEnabled);
if (critical)
{
name->setBackground(Qt::red);
name->setForeground(Qt::yellow);
}
else
{
name->setBackground(Qt::yellow);
name->setForeground(Qt::red);
}
setItem(i, 0, name);
QTableWidgetItem *compto = new QTableWidgetItem;
compto->setText(am->ownInfo().name());
compto->setFlags(Qt::ItemIsEnabled);
compto->setForeground(Qt::blue);
if (critical)
compto->setBackground(Qt::red);
else
compto->setBackground(Qt::yellow);
setItem(i, 1, compto);
QTableWidgetItem *compt = new QTableWidgetItem;
compt->setText(reason(in[i].type()));
compt->setFlags(Qt::ItemIsEnabled);
if (critical)
compt->setBackground(Qt::red);
else
compt->setBackground(Qt::yellow);
setItem(i, 2, compt);
}
if (hascrit && com->hasNoti() )
QProcess::execute("notify-send", QStringList() << "--icon=error" << "--app-name='SGU Client'" << "SGU Client" << "You have some critical warnings!");
resizeColumnsToContents();
}
QSize CompetitionView::sizeHint() const
{
return QSize(750, 500);
}
QString CompetitionView::reason(CompetitionType T) const
{
if (T == MoreAc)
return "Target has more accepts than you.";
else if (T == NearAc)
return "Target is reaching you.";
else if (T == DiffAc)
return "Target has some accepts that you don't have.";
else
return "Target tried to solve problems that you haven't accepted.";
}
void CompetitionView::handleDoubleClick(int row, int col)
{
if (col == 2)
{
CompetitionDetail cd(am, ids[row], reason(ids[row].type()), this);
if (cd.isValid())
cd.exec();
}
else if (col == 1)
{
ProfileInfo pi(this, am, am->ID());
if (pi.isValid())
pi.exec();
}
else if (col == 0)
{
QString pid = ids[row].target();
ProfileInfo pi(this, am, pid);
if (pi.isValid())
pi.exec();
}
}