QTfrontend/ui/page/pagegamestats.cpp
changeset 9175 dc3c0e44f7f3
parent 9172 72bfa6a3e8e2
child 9177 d5e98b81e135
--- 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>");