/***************************************************************************
                           scorekeeper.cpp
                           -------------------
    copyright            : (C) 2004 by Jos van den Oever
    email                : jos@vandenoever.info
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#include "scorekeeper.h"
#include <qlabel.h>

ScoreKeeper::ScoreKeeper(QWidget* parent, const char* name, Qt::WFlags f)
	: Q3VBox(parent, name, f) {
	questions = new QLabel(this);
	questions->setBackgroundOrigin(QWidget::WindowOrigin);
	points = new QLabel(this);
	points->setBackgroundOrigin(QWidget::WindowOrigin);
	int alignment = Qt::AlignHCenter | Qt::AlignVCenter
		| Qt::SingleLine | Qt::ExpandTabs;
	points->setAlignment(alignment);
	questions->setAlignment(alignment);
	reset();
}
// return the number of questions answered
int
ScoreKeeper::getQuestions() const {
	return numquestions;
}
int
ScoreKeeper::getPoints() const {
	return numpoints;
}
void
ScoreKeeper::setNumQuestions(int q) {
	hasmaxquestions = true;
	maxquestions = q;
	updateLabels();
}
void
ScoreKeeper::setMaxNumPoints(int p) {
	hasmaxpoints = true;
	maxpoints = p;
	updateLabels();
}
int
ScoreKeeper::getNumQuestions() const {
	return maxquestions;
}
int
ScoreKeeper::getMaxNumPoints() const {
	return maxpoints;
}
void
ScoreKeeper::addPoints(short i) {
	numpoints += i;
	updateLabels();
}
void
ScoreKeeper::nextQuestion() {
	numquestions++;
	updateLabels();
}
void
ScoreKeeper::reset() {
	numpoints = 0;
	maxpoints = 0;
	hasmaxpoints = false;
	numquestions = 0;
	maxquestions = 0;
	hasmaxquestions = 0;
	updateLabels();
}
void
ScoreKeeper::updateLabels() {
	QString ps(tr("Score: "));
	ps += QString::number(numpoints);
	if (hasmaxpoints) {
		ps += " / " + QString::number(maxpoints);
	}
	points->setText(ps);
	QString qs(tr("Question: "));
	qs += QString::number(numquestions);
	if (hasmaxquestions) {
		qs += " / " + QString::number(maxquestions);
	}
	questions->setText(qs);
}
