summaryrefslogtreecommitdiffstats
path: root/kgeography/src/askwidget.cpp
blob: 3a5fade6cf171b4de17eec4518f759fb6b3e22e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/***************************************************************************
 *   Copyright (C) 2004-2005 by Albert Astals Cid                          *
 *   tsdgeos@terra.es                                                      *
 *                                                                         *
 *   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 <klocale.h>
#include <kmessagebox.h>

#include <tqlabel.h>

#include "askwidget.h"
#include "map.h"

askWidget::askWidget(TQWidget *tqparent, KGmap *m, TQWidget *w, uint count, bool showLabel) : TQWidget(tqparent), p_map(m), p_count(count)
{
	if (showLabel)
	{
		p_answers = new TQLabel(w);
		p_answers -> tqsetAlignment(AlignTop | AlignHCenter);
		resetAnswers();
		p_answers -> show();
	}
	else p_answers = 0;
}

askWidget::~askWidget()
{
	delete p_answers;
}

int askWidget::correctAnswers() const
{
	return p_correctAnswers;
}

TQValueVector<userAnswer> askWidget::userAnswers() const
{
	return p_userAnswers;
}

void askWidget::setMovement(bool)
{
}

void askWidget::setZoom(bool)
{
}

void askWidget::setOriginalZoom()
{
}

void askWidget::clearAsked()
{
	p_asked.clear();
}

TQString askWidget::lastDivisionAsked()
{
	return p_asked.last();
}

void askWidget::nextQuestion()
{
	TQString aux;
	
	if (p_asked.count() < p_count)
	{
		aux = p_map -> getRandomDivision(isClickOnDivision());
		while (p_asked.find(aux) != p_asked.end()) aux = p_map -> getRandomDivision(isClickOnDivision());
		p_asked << aux;
		nextQuestionHook(aux);
	}
	else emit questionsEnded();
}

void askWidget::questionAnswered(bool wasCorrect)
{
	p_currentAnswer.setAnswerCorrect(wasCorrect);
	p_userAnswers.append(p_currentAnswer);
	
	if (wasCorrect) p_correctAnswers++;
	else p_incorrectAnswers++;
	updateLabel();
}

void askWidget::resetAnswers()
{
	p_correctAnswers = 0;
	p_incorrectAnswers = 0;
	updateLabel();
}

void askWidget::updateLabel()
{
	p_answers -> setText(i18n("Correct answers: %1/%2").tqarg(p_correctAnswers).tqarg(p_correctAnswers + p_incorrectAnswers));
}

#include "askwidget.moc"