QTfrontend/statsPage.cpp
changeset 1625 37aae47943ce
parent 1623 d590e6da04da
child 1636 e528696f2177
equal deleted inserted replaced
1624:3cbf01d31e5c 1625:37aae47943ce
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    17  */
    17  */
    18 
    18 
    19 #include <QLabel>
    19 #include <QLabel>
    20 #include <QGridLayout>
    20 #include <QGridLayout>
       
    21 #include <QGraphicsScene>
       
    22 #include <QGraphicsView>
    21 
    23 
    22 #include "statsPage.h"
    24 #include "statsPage.h"
    23 
    25 
    24 PageGameStats::PageGameStats(QWidget* parent) : AbstractPage(parent)
    26 PageGameStats::PageGameStats(QWidget* parent) : AbstractPage(parent)
    25 {
    27 {
    27 	QGridLayout * pageLayout = new QGridLayout(this);
    29 	QGridLayout * pageLayout = new QGridLayout(this);
    28 	pageLayout->setColumnStretch(0, 1);
    30 	pageLayout->setColumnStretch(0, 1);
    29 	pageLayout->setColumnStretch(1, 1);
    31 	pageLayout->setColumnStretch(1, 1);
    30 	pageLayout->setColumnStretch(2, 1);
    32 	pageLayout->setColumnStretch(2, 1);
    31 
    33 
    32 	BtnBack = addButton(":/res/Exit.png", pageLayout, 1, 0, true);
    34 	BtnBack = addButton(":/res/Exit.png", pageLayout, 2, 0, true);
    33 
    35 
    34 	labelGameStats = new QLabel(this);
    36 	labelGameStats = new QLabel(this);
    35 	labelGameStats->setTextFormat(Qt::RichText);
    37 	labelGameStats->setTextFormat(Qt::RichText);
    36 	pageLayout->addWidget(labelGameStats, 0, 0, 1, 3);
    38 	pageLayout->addWidget(labelGameStats, 0, 0, 1, 3);
       
    39 
       
    40 	graphic = new QGraphicsView(this);
       
    41 	graphic->scale(1.0, -1.0);
       
    42 	pageLayout->addWidget(graphic, 1, 0, 1, 3);
    37 }
    43 }
    38 
    44 
    39 void PageGameStats::AddStatText(const QString & msg)
    45 void PageGameStats::AddStatText(const QString & msg)
    40 {
    46 {
    41 	labelGameStats->setText(labelGameStats->text() + msg);
    47 	labelGameStats->setText(labelGameStats->text() + msg);
    42 }
    48 }
    43 
    49 
    44 void PageGameStats::clear()
    50 void PageGameStats::clear()
    45 {
    51 {
    46 	labelGameStats->setText("");
    52 	labelGameStats->setText("");
       
    53 	healthPoints.clear();
       
    54 }
       
    55 
       
    56 void PageGameStats::renderStats()
       
    57 {
       
    58 	QGraphicsScene * scene = new QGraphicsScene();
       
    59 
       
    60 	QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin();
       
    61 	while (i != healthPoints.constEnd())
       
    62 	{
       
    63 		quint32 c = i.key();
       
    64 		QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255));
       
    65 		QVector<quint32> hps = i.value();
       
    66 
       
    67 		QPainterPath path;
       
    68 		if (hps.size())
       
    69 			path.moveTo(0, hps[0]);
       
    70 		
       
    71 		for(int t = 1; t < hps.size(); ++t)
       
    72 			path.lineTo(t, hps[t]);
       
    73 
       
    74 		scene->addPath(path, QPen(c));
       
    75 		++i;
       
    76 	}
       
    77 
       
    78 	graphic->setScene(scene);
       
    79 	graphic->fitInView(graphic->sceneRect());
    47 }
    80 }
    48 
    81 
    49 void PageGameStats::GameStats(char type, const QString & info)
    82 void PageGameStats::GameStats(char type, const QString & info)
    50 {
    83 {
    51 	switch(type) {
    84 	switch(type) {
    70 		case 'K' : {
   103 		case 'K' : {
    71 			QString message = tr("<p>A total of <b>%1</b> Hedgehog(s) were killed during this round.</p>").arg(info);
   104 			QString message = tr("<p>A total of <b>%1</b> Hedgehog(s) were killed during this round.</p>").arg(info);
    72 			AddStatText(message);
   105 			AddStatText(message);
    73 			break;
   106 			break;
    74 		}
   107 		}
       
   108 		case 'H' : {
       
   109 			int i = info.indexOf(' ');
       
   110 			quint32 clan = info.left(i).toInt();
       
   111 			quint32 hp = info.mid(i + 1).toUInt();
       
   112 			healthPoints[clan].append(hp);
       
   113 			break;
       
   114 		}
    75 	}
   115 	}
    76 }
   116 }