42 { |
42 { |
43 QGridLayout * pageLayout = new QGridLayout(); |
43 QGridLayout * pageLayout = new QGridLayout(); |
44 pageLayout->setSpacing(20); |
44 pageLayout->setSpacing(20); |
45 pageLayout->setColumnStretch(0, 1); |
45 pageLayout->setColumnStretch(0, 1); |
46 pageLayout->setColumnStretch(1, 1); |
46 pageLayout->setColumnStretch(1, 1); |
|
47 pageLayout->setRowStretch(0, 1); |
|
48 pageLayout->setRowStretch(1, 20); |
|
49 //pageLayout->setRowStretch(1, -1); this should work but there is unnecessary empty space betwin lines if used |
47 pageLayout->setContentsMargins(7, 7, 7, 0); |
50 pageLayout->setContentsMargins(7, 7, 7, 0); |
48 |
51 |
49 QGroupBox * gb = new QGroupBox(this); |
52 QGroupBox * gb = new QGroupBox(this); |
50 QVBoxLayout * gbl = new QVBoxLayout; |
53 QVBoxLayout * gbl = new QVBoxLayout; |
51 |
54 |
59 labelGameStats->setAlignment(Qt::AlignTop); |
62 labelGameStats->setAlignment(Qt::AlignTop); |
60 labelGameStats->setWordWrap(true); |
63 labelGameStats->setWordWrap(true); |
61 gbl->addWidget(l); |
64 gbl->addWidget(l); |
62 gbl->addWidget(labelGameStats); |
65 gbl->addWidget(labelGameStats); |
63 gb->setLayout(gbl); |
66 gb->setLayout(gbl); |
64 pageLayout->addWidget(gb, 1, 1, 1, 2); |
67 pageLayout->addWidget(gb, 1, 1); |
65 |
68 |
66 // graph |
69 // graph |
67 graphic = new FitGraphicsView(gb); |
70 graphic = new FitGraphicsView(gb); |
68 l = new QLabel(this); |
71 labelGraphTitle = new QLabel(this); |
69 l->setTextFormat(Qt::RichText); |
72 labelGraphTitle->setTextFormat(Qt::RichText); |
70 l->setText("<br><h1><img src=\":/res/StatsH.png\"> " + PageGameStats::tr("Health graph") + "</h1>"); |
73 labelGraphTitle->setText("<br><h1><img src=\":/res/StatsH.png\"> " + PageGameStats::tr("Health graph") + "</h1>"); |
71 l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
74 labelGraphTitle->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
72 gbl->addWidget(l); |
75 gbl->addWidget(labelGraphTitle); |
73 gbl->addWidget(graphic); |
76 gbl->addWidget(graphic); |
74 graphic->scale(1.0, -1.0); |
77 graphic->scale(1.0, -1.0); |
75 graphic->setBackgroundBrush(QBrush(Qt::black)); |
78 graphic->setBackgroundBrush(QBrush(Qt::black)); |
76 |
79 |
77 labelGameWin = new QLabel(this); |
80 labelGameWin = new QLabel(this); |
152 btnRestart->setVisible(visible); |
155 btnRestart->setVisible(visible); |
153 } |
156 } |
154 |
157 |
155 void PageGameStats::renderStats() |
158 void PageGameStats::renderStats() |
156 { |
159 { |
157 QGraphicsScene * scene = new QGraphicsScene(); |
160 graphic->show(); |
158 |
161 labelGraphTitle-> show(); |
159 QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin(); |
162 // if not health data sent |
160 while (i != healthPoints.constEnd()) |
163 if(healthPoints.size() == 0) { |
161 { |
164 labelGraphTitle->hide(); |
162 quint32 c = i.key(); |
165 graphic->hide(); |
163 //QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255)); |
166 } else { |
164 QVector<quint32> hps = i.value(); |
167 labelGraphTitle->setText("<br><h1><img src=\":/res/StatsH.png\"> " + PageGameStats::tr("Health graph") + "</h1>"); |
165 |
168 QGraphicsScene * scene = new QGraphicsScene(); |
166 QPainterPath path; |
169 |
167 if (hps.size()) |
170 QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin(); |
168 path.moveTo(0, hps[0]); |
171 while (i != healthPoints.constEnd()) |
169 |
172 { |
170 for(int t = 1; t < hps.size(); ++t) |
173 quint32 c = i.key(); |
171 path.lineTo(t, hps[t]); |
174 //QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255)); |
172 |
175 QVector<quint32> hps = i.value(); |
173 scene->addPath(path, QPen(c)); |
176 |
174 ++i; |
177 QPainterPath path; |
175 } |
178 if (hps.size()) |
176 |
179 path.moveTo(0, hps[0]); |
177 graphic->setScene(scene); |
180 |
178 graphic->fitInView(graphic->sceneRect()); |
181 for(int t = 1; t < hps.size(); ++t) |
|
182 path.lineTo(t, hps[t]); |
|
183 |
|
184 scene->addPath(path, QPen(c)); |
|
185 ++i; |
|
186 } |
|
187 |
|
188 graphic->setScene(scene); |
|
189 graphic->fitInView(graphic->sceneRect()); |
|
190 } |
179 } |
191 } |
180 |
192 |
181 void PageGameStats::GameStats(char type, const QString & info) |
193 void PageGameStats::GameStats(char type, const QString & info) |
182 { |
194 { |
183 switch(type) |
195 switch(type) |
213 { |
225 { |
214 int i = info.indexOf(' '); |
226 int i = info.indexOf(' '); |
215 quint32 clan = info.left(i).toInt(); |
227 quint32 clan = info.left(i).toInt(); |
216 quint32 hp = info.mid(i + 1).toUInt(); |
228 quint32 hp = info.mid(i + 1).toUInt(); |
217 healthPoints[clan].append(hp); |
229 healthPoints[clan].append(hp); |
|
230 break; |
|
231 } |
|
232 case 'g' : |
|
233 { |
|
234 // TODO: change default picture or add change pic capability |
|
235 labelGraphTitle->setText("<br><h1><img src=\":/res/StatsR.png\"> " + info + "</h1>"); |
218 break; |
236 break; |
219 } |
237 } |
220 case 'T': // local team stats |
238 case 'T': // local team stats |
221 { |
239 { |
222 //AddStatText("<p>local team: " + info + "</p>"); |
240 //AddStatText("<p>local team: " + info + "</p>"); |