QTfrontend/statsPage.cpp
author unc0rr
Fri, 09 Jan 2009 11:27:52 +0000
changeset 1622 8e0d62727f01
parent 1621 d1ded2532d3f
child 1623 d590e6da04da
permissions -rw-r--r--
Fully separate statistics code from main form code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1621
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
     1
/*
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2009 Andrey Korotaev <unC0Rr@gmail.com>
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
     4
 *
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
     8
 *
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    13
 *
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    17
 */
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    18
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    19
#include <QLabel>
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    20
#include <QGridLayout>
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    21
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    22
#include "statsPage.h"
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    23
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    24
PageGameStats::PageGameStats(QWidget* parent) : AbstractPage(parent)
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    25
{
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    26
	QFont * font14 = new QFont("MS Shell Dlg", 14);
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    27
	QGridLayout * pageLayout = new QGridLayout(this);
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    28
	pageLayout->setColumnStretch(0, 1);
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    29
	pageLayout->setColumnStretch(1, 1);
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    30
	pageLayout->setColumnStretch(2, 1);
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    31
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    32
	BtnBack = addButton(":/res/Exit.png", pageLayout, 1, 0, true);
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    33
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    34
	labelGameStats = new QLabel(this);
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    35
	labelGameStats->setTextFormat(Qt::RichText);
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    36
	pageLayout->addWidget(labelGameStats, 0, 0, 1, 3);
d1ded2532d3f - svn maintenance
unc0rr
parents:
diff changeset
    37
}
1622
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    38
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    39
void PageGameStats::AddStatText(const QString & msg)
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    40
{
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    41
	labelGameStats->setText(labelGameStats->text() + msg);
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    42
}
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    43
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    44
void PageGameStats::clear()
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    45
{
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    46
	labelGameStats->setText("");
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    47
}
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    48
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    49
void PageGameStats::GameStats(char type, const QString & info)
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    50
{
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    51
	switch(type) {
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    52
		case 'r' : {
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    53
			AddStatText(QString("<h1 align=\"center\">%1</h1>").arg(info));
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    54
			break;
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    55
		}
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    56
		case 'D' : {
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    57
			int i = info.indexOf(' ');
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    58
			QString message = tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> pts.</p>")
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    59
					.arg(info.mid(i + 1), info.left(i));
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    60
			AddStatText(message);
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    61
			break;
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    62
		}
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    63
		case 'k' : {
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    64
			int i = info.indexOf(' ');
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    65
			QString message = tr("<p>The best shot award was won by <b>%1</b> with <b>%2</b> kills.</p>")
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    66
					.arg(info.mid(i + 1), info.left(i));
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    67
			AddStatText(message);
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    68
			break;
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    69
		}
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    70
		case 'K' : {
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    71
			QString message = tr("<p>A total of <b>%1</b> Hedgehog(s) were killed during this round.</p>").arg(info);
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    72
			AddStatText(message);
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    73
			break;
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    74
		}
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    75
	}
8e0d62727f01 Fully separate statistics code from main form code
unc0rr
parents: 1621
diff changeset
    76
}