version++
[impuzzle] / src / statisticsdialog.cpp
1 /*
2   Image Puzzle - A set your pieces straight game
3   Copyright (C) 2009  Timo Härkönen
4
5   This program is free software: you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation, either version 3 of the License, or
8   (at your option) any later version.
9
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14
15   You should have received a copy of the GNU General Public License
16   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include "statisticsdialog.h"
20 #include "statistics.h"
21
22 #include <QVBoxLayout>
23 #include <QHBoxLayout>
24 #include <QLabel>
25 #include <QPushButton>
26
27 StatisticsDialog::StatisticsDialog(QWidget *parent) :
28         QDialog(parent)
29 {
30     setModal(true);
31     setWindowTitle(tr("Statistics"));
32
33     resetButton_ = new QPushButton(tr("Reset"));
34     doneButton_ = new QPushButton(tr("Close"));
35
36     buttonLayout_ = new QHBoxLayout;
37     buttonLayout_->addStretch();
38     buttonLayout_->addWidget(resetButton_);
39     buttonLayout_->addWidget(doneButton_);
40
41     label_ = new QLabel;
42
43     updateContent();
44
45     mainLayout_ = new QVBoxLayout;
46     mainLayout_->addWidget(label_);
47     mainLayout_->addLayout(buttonLayout_);
48
49     setLayout(mainLayout_);
50
51     connect(resetButton_, SIGNAL(clicked()), this, SLOT(resetClicked()));
52     connect(doneButton_, SIGNAL(clicked()), this, SLOT(close()));
53 }
54
55 void StatisticsDialog::updateContent()
56 {
57     QString txt = QString("\tEasy\tHard\nGames\t%1\t%5\nBest\t%2\t%6\nAvg\t%3\t%7\nWorst\t%4\t%8\n")
58     .arg(QString::number(Statistics::instance()->gameCount(Statistics::easyDifficulty)))
59     .arg(QString::number(Statistics::instance()->minMoves(Statistics::easyDifficulty)))
60     .arg(QString::number(Statistics::instance()->averageMoves(Statistics::easyDifficulty)))
61     .arg(QString::number(Statistics::instance()->maxMoves(Statistics::easyDifficulty)))
62     .arg(QString::number(Statistics::instance()->gameCount(Statistics::hardDifficulty)))
63     .arg(QString::number(Statistics::instance()->minMoves(Statistics::hardDifficulty)))
64     .arg(QString::number(Statistics::instance()->averageMoves(Statistics::hardDifficulty)))
65     .arg(QString::number(Statistics::instance()->maxMoves(Statistics::hardDifficulty)));
66
67     label_->setText(txt);
68 }
69
70 void StatisticsDialog::resetClicked()
71 {
72     Statistics::instance()->resetStatistics();
73     updateContent();
74 }