27 |
27 |
28 } |
28 } |
29 |
29 |
30 void FitGraphicsView::resizeEvent(QResizeEvent * event) |
30 void FitGraphicsView::resizeEvent(QResizeEvent * event) |
31 { |
31 { |
32 fitInView(sceneRect()); |
32 fitInView(sceneRect()); |
33 } |
33 } |
34 |
34 |
35 PageGameStats::PageGameStats(QWidget* parent) : AbstractPage(parent) |
35 PageGameStats::PageGameStats(QWidget* parent) : AbstractPage(parent) |
36 { |
36 { |
37 QGridLayout * pageLayout = new QGridLayout(this); |
37 QGridLayout * pageLayout = new QGridLayout(this); |
38 pageLayout->setColumnStretch(0, 1); |
38 pageLayout->setColumnStretch(0, 1); |
39 pageLayout->setColumnStretch(1, 1); |
39 pageLayout->setColumnStretch(1, 1); |
40 pageLayout->setColumnStretch(2, 1); |
40 pageLayout->setColumnStretch(2, 1); |
41 |
41 |
42 BtnBack = addButton(":/res/Exit.png", pageLayout, 2, 0, true); |
42 BtnBack = addButton(":/res/Exit.png", pageLayout, 2, 0, true); |
43 |
43 |
44 labelGameStats = new QLabel(this); |
44 labelGameStats = new QLabel(this); |
45 labelGameStats->setTextFormat(Qt::RichText); |
45 labelGameStats->setTextFormat(Qt::RichText); |
46 pageLayout->addWidget(labelGameStats, 0, 0, 1, 3); |
46 pageLayout->addWidget(labelGameStats, 0, 0, 1, 3); |
47 |
47 |
48 graphic = new FitGraphicsView(this); |
48 graphic = new FitGraphicsView(this); |
49 graphic->scale(1.0, -1.0); |
49 graphic->scale(1.0, -1.0); |
50 graphic->setBackgroundBrush(QBrush(Qt::black)); |
50 graphic->setBackgroundBrush(QBrush(Qt::black)); |
51 pageLayout->addWidget(graphic, 1, 0, 1, 3); |
51 pageLayout->addWidget(graphic, 1, 0, 1, 3); |
52 } |
52 } |
53 |
53 |
54 void PageGameStats::AddStatText(const QString & msg) |
54 void PageGameStats::AddStatText(const QString & msg) |
55 { |
55 { |
56 labelGameStats->setText(labelGameStats->text() + msg); |
56 labelGameStats->setText(labelGameStats->text() + msg); |
57 } |
57 } |
58 |
58 |
59 void PageGameStats::clear() |
59 void PageGameStats::clear() |
60 { |
60 { |
61 labelGameStats->setText(""); |
61 labelGameStats->setText(""); |
62 healthPoints.clear(); |
62 healthPoints.clear(); |
63 } |
63 } |
64 |
64 |
65 void PageGameStats::renderStats() |
65 void PageGameStats::renderStats() |
66 { |
66 { |
67 QGraphicsScene * scene = new QGraphicsScene(); |
67 QGraphicsScene * scene = new QGraphicsScene(); |
68 |
68 |
69 QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin(); |
69 QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin(); |
70 while (i != healthPoints.constEnd()) |
70 while (i != healthPoints.constEnd()) |
71 { |
71 { |
72 quint32 c = i.key(); |
72 quint32 c = i.key(); |
73 QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255)); |
73 QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255)); |
74 QVector<quint32> hps = i.value(); |
74 QVector<quint32> hps = i.value(); |
75 |
75 |
76 QPainterPath path; |
76 QPainterPath path; |
77 if (hps.size()) |
77 if (hps.size()) |
78 path.moveTo(0, hps[0]); |
78 path.moveTo(0, hps[0]); |
79 |
79 |
80 for(int t = 1; t < hps.size(); ++t) |
80 for(int t = 1; t < hps.size(); ++t) |
81 path.lineTo(t, hps[t]); |
81 path.lineTo(t, hps[t]); |
82 |
82 |
83 scene->addPath(path, QPen(c)); |
83 scene->addPath(path, QPen(c)); |
84 ++i; |
84 ++i; |
85 } |
85 } |
86 |
86 |
87 graphic->setScene(scene); |
87 graphic->setScene(scene); |
88 graphic->fitInView(graphic->sceneRect()); |
88 graphic->fitInView(graphic->sceneRect()); |
89 } |
89 } |
90 |
90 |
91 void PageGameStats::GameStats(char type, const QString & info) |
91 void PageGameStats::GameStats(char type, const QString & info) |
92 { |
92 { |
93 switch(type) { |
93 switch(type) { |
94 case 'r' : { |
94 case 'r' : { |
95 AddStatText(QString("<h1 align=\"center\">%1</h1>").arg(info)); |
95 AddStatText(QString("<h1 align=\"center\">%1</h1>").arg(info)); |
96 break; |
96 break; |
97 } |
97 } |
98 case 'D' : { |
98 case 'D' : { |
99 int i = info.indexOf(' '); |
99 int i = info.indexOf(' '); |
100 QString message = PageGameStats::tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> pts.</p>") |
100 QString message = PageGameStats::tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> pts.</p>") |
101 .arg(info.mid(i + 1), info.left(i)); |
101 .arg(info.mid(i + 1), info.left(i)); |
102 AddStatText(message); |
102 AddStatText(message); |
103 break; |
103 break; |
104 } |
104 } |
105 case 'k' : { |
105 case 'k' : { |
106 int i = info.indexOf(' '); |
106 int i = info.indexOf(' '); |
107 int num = info.left(i).toInt(); |
107 int num = info.left(i).toInt(); |
108 QString message = PageGameStats::tr("<p>The best killer is <b>%1</b> with <b>%2</b> kills in a turn.</p>", "", num) |
108 QString message = PageGameStats::tr("<p>The best killer is <b>%1</b> with <b>%2</b> kills in a turn.</p>", "", num) |
109 .arg(info.mid(i + 1), info.left(i)); |
109 .arg(info.mid(i + 1), info.left(i)); |
110 AddStatText(message); |
110 AddStatText(message); |
111 break; |
111 break; |
112 } |
112 } |
113 case 'K' : { |
113 case 'K' : { |
114 int num = info.toInt(); |
114 int num = info.toInt(); |
115 QString message = PageGameStats::tr("<p>A total of <b>%1</b> hedgehog(s) were killed during this round.</p>", "", num).arg(num); |
115 QString message = PageGameStats::tr("<p>A total of <b>%1</b> hedgehog(s) were killed during this round.</p>", "", num).arg(num); |
116 AddStatText(message); |
116 AddStatText(message); |
117 break; |
117 break; |
118 } |
118 } |
119 case 'H' : { |
119 case 'H' : { |
120 int i = info.indexOf(' '); |
120 int i = info.indexOf(' '); |
121 quint32 clan = info.left(i).toInt(); |
121 quint32 clan = info.left(i).toInt(); |
122 quint32 hp = info.mid(i + 1).toUInt(); |
122 quint32 hp = info.mid(i + 1).toUInt(); |
123 healthPoints[clan].append(hp); |
123 healthPoints[clan].append(hp); |
124 break; |
124 break; |
125 } |
125 } |
126 } |
126 } |
127 } |
127 } |