added option to change stats graph title
authorPeriklis Ntanasis <pntanasis@gmail.com>
Sat, 08 Jun 2013 23:24:52 +0300
changeset 9175 dc3c0e44f7f3
parent 9174 d328fe17b195
child 9176 c21c88dca14c
added option to change stats graph title
QTfrontend/ui/page/pagegamestats.cpp
QTfrontend/ui/page/pagegamestats.h
hedgewars/uIO.pas
hedgewars/uTypes.pas
--- a/QTfrontend/ui/page/pagegamestats.cpp	Thu Jun 06 03:52:32 2013 +0300
+++ b/QTfrontend/ui/page/pagegamestats.cpp	Sat Jun 08 23:24:52 2013 +0300
@@ -44,6 +44,9 @@
     pageLayout->setSpacing(20);
     pageLayout->setColumnStretch(0, 1);
     pageLayout->setColumnStretch(1, 1);
+    pageLayout->setRowStretch(0, 1);    
+    pageLayout->setRowStretch(1, 20);
+    //pageLayout->setRowStretch(1, -1); this should work but there is unnecessary empty space betwin lines if used
     pageLayout->setContentsMargins(7, 7, 7, 0);
 
     QGroupBox * gb = new QGroupBox(this);
@@ -61,15 +64,15 @@
     gbl->addWidget(l);
     gbl->addWidget(labelGameStats);
     gb->setLayout(gbl);
-    pageLayout->addWidget(gb, 1, 1, 1, 2);
+    pageLayout->addWidget(gb, 1, 1);
 
     // graph
     graphic = new FitGraphicsView(gb);
-    l = new QLabel(this);
-    l->setTextFormat(Qt::RichText);
-    l->setText("<br><h1><img src=\":/res/StatsH.png\"> " + PageGameStats::tr("Health graph") + "</h1>");
-    l->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
-    gbl->addWidget(l);
+    labelGraphTitle = new QLabel(this);
+    labelGraphTitle->setTextFormat(Qt::RichText);
+    labelGraphTitle->setText("<br><h1><img src=\":/res/StatsH.png\"> " + PageGameStats::tr("Health graph") + "</h1>");
+    labelGraphTitle->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+    gbl->addWidget(labelGraphTitle);
     gbl->addWidget(graphic);
     graphic->scale(1.0, -1.0);
     graphic->setBackgroundBrush(QBrush(Qt::black));
@@ -154,28 +157,37 @@
 
 void PageGameStats::renderStats()
 {
-    QGraphicsScene * scene = new QGraphicsScene();
-
-    QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin();
-    while (i != healthPoints.constEnd())
-    {
-        quint32 c = i.key();
-        //QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255));
-        QVector<quint32> hps = i.value();
+	graphic->show();
+	labelGraphTitle-> show();
+	// if not health data sent
+	if(healthPoints.size() == 0) {
+		labelGraphTitle->hide();
+		graphic->hide();
+	} else {
+		labelGraphTitle->setText("<br><h1><img src=\":/res/StatsH.png\"> " + PageGameStats::tr("Health graph") + "</h1>");
+		QGraphicsScene * scene = new QGraphicsScene();
 
-        QPainterPath path;
-        if (hps.size())
-            path.moveTo(0, hps[0]);
+		QMap<quint32, QVector<quint32> >::const_iterator i = healthPoints.constBegin();
+		while (i != healthPoints.constEnd())
+		{
+			quint32 c = i.key();
+			//QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255));
+			QVector<quint32> hps = i.value();
 
-        for(int t = 1; t < hps.size(); ++t)
-            path.lineTo(t, hps[t]);
+			QPainterPath path;
+			if (hps.size())
+				path.moveTo(0, hps[0]);
 
-        scene->addPath(path, QPen(c));
-        ++i;
-    }
+			for(int t = 1; t < hps.size(); ++t)
+				path.lineTo(t, hps[t]);
 
-    graphic->setScene(scene);
-    graphic->fitInView(graphic->sceneRect());
+			scene->addPath(path, QPen(c));
+			++i;
+		}
+
+		graphic->setScene(scene);
+		graphic->fitInView(graphic->sceneRect());
+	}
 }
 
 void PageGameStats::GameStats(char type, const QString & info)
@@ -217,6 +229,12 @@
             healthPoints[clan].append(hp);
             break;
         }
+        case 'g' :
+        {
+			// TODO: change default picture or add change pic capability
+			labelGraphTitle->setText("<br><h1><img src=\":/res/StatsR.png\"> " + info + "</h1>");
+            break;
+        }
         case 'T':   // local team stats
         {
             //AddStatText("<p>local team: " + info + "</p>");
--- a/QTfrontend/ui/page/pagegamestats.h	Thu Jun 06 03:52:32 2013 +0300
+++ b/QTfrontend/ui/page/pagegamestats.h	Sat Jun 08 23:24:52 2013 +0300
@@ -49,6 +49,7 @@
         QLabel *labelGameStats;
         QLabel *labelGameWin;
         QLabel *labelGameRank;
+        QLabel *labelGraphTitle;
         FitGraphicsView * graphic;
 
     public slots:
--- a/hedgewars/uIO.pas	Thu Jun 06 03:52:32 2013 +0300
+++ b/hedgewars/uIO.pas	Sat Jun 08 23:24:52 2013 +0300
@@ -212,7 +212,7 @@
 end;
 
 procedure SendStat(sit: TStatInfoType; s: shortstring);
-const stc: array [TStatInfoType] of char = ('r', 'D', 'k', 'K', 'H', 'T', 'P', 's', 'S', 'B', 'c');
+const stc: array [TStatInfoType] of char = ('r', 'D', 'k', 'K', 'H', 'T', 'P', 's', 'S', 'B', 'c', 'g');
 var buf: shortstring;
 begin
 buf:= 'i' + stc[sit] + s;
--- a/hedgewars/uTypes.pas	Thu Jun 06 03:52:32 2013 +0300
+++ b/hedgewars/uTypes.pas	Sat Jun 08 23:24:52 2013 +0300
@@ -164,7 +164,7 @@
 
     TStatInfoType = (siGameResult, siMaxStepDamage, siMaxStepKills, siKilledHHs,
             siClanHealth, siTeamStats, siPlayerKills, siMaxTeamDamage,
-            siMaxTeamKills, siMaxTurnSkips, siCustomAchievement );
+            siMaxTeamKills, siMaxTurnSkips, siCustomAchievement, siGraphTitle);
 
     // Various "emote" animations a hedgehog can do
     TWave = (waveRollup, waveSad, waveWave, waveHurrah, waveLemonade, waveShrug, waveJuggle);