divisioncapitalasker.cpp 2.89 KB
Newer Older
1
2
/***************************************************************************
 *   Copyright (C) 2004 by Albert Astals Cid                               *
3
 *   aacid@kde.org                                                         *
4
5
6
7
8
9
10
 *                                                                         *
 *   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.                                   *
 ***************************************************************************/

Albert Astals Cid's avatar
Albert Astals Cid committed
11
12
#include "divisioncapitalasker.h"

David Gil's avatar
David Gil committed
13
#include <klocalizedstring.h>
14
#include <krandom.h>
15
16
17
18
19

#include <qradiobutton.h>
 
#include "map.h"

Albert Astals Cid's avatar
Albert Astals Cid committed
20
divisionCapitalAsker::divisionCapitalAsker(QWidget *parent, KGmap *m, QWidget *w, uint count) : boxAsker(parent, m, w, count)
21
22
23
24
{
	init();
}

25
bool divisionCapitalAsker::nextBoxAskerQuestionHook(const QString &division, int i, bool isAnswer)
26
{
27
	bool b;
Albert Astals Cid's avatar
Albert Astals Cid committed
28
29
	if (isAnswer)
	{
30
		QString divisionName = i18nc(p_map -> getFileName().toUtf8(), division.toUtf8());
31
		setQuestion(i18nc("@title:group", p_map->getDivisionToCapitalQuestionPattern().toUtf8(), divisionName));
Chusslove Illich's avatar
Chusslove Illich committed
32
		p_currentAnswer.setQuestion(i18nc("@item:intable column Question, %1 is region name", "%1", i18nc(p_map -> getFileName().toUtf8(), division.toUtf8())));
33
		p_capital = p_map -> getDivisionCapital(division);
34
35
		p_currentAnswer.setCorrectAnswer(i18nc("@option:radio The capital of <Region> is...", "%1", p_capital));
		p_radioButtons[i] -> setText(i18nc("@option:radio The capital of <Region> is...", "%1", p_capital));
36
		b = true;
37
38
39
40
41
42
43
44
45
46
		
		QStringList falseCapitals = p_map -> getDivisionFalseCapitals(division);
		int index = 0;
		while (!falseCapitals.isEmpty() && index < 4)
		{
			if (index != i)
			{
				int random = (int)((float)falseCapitals.size() * KRandom::random() / (RAND_MAX + 1.0));
				QString falseCapital = falseCapitals.at(random);
				falseCapitals.removeAt(random);
47
				p_radioButtons[index] -> setText(i18nc("@option:radio The capital of <Region> is...", "%1", i18nc(p_map -> getFileName().toUtf8(), falseCapital.toUtf8())));
48
49
50
			}
			++index;
		}
Albert Astals Cid's avatar
Albert Astals Cid committed
51
	}
52
53
54
55
56
57
58
59
60
61
62
63
64
	else
	{
		QString capital;
		capital = p_map -> getDivisionCapital(division);
		// There are crazy countries like Norway where two different divisions
		// have the same capital, avoid asking
		// The capital of Akershus is ...
		// Oslo (true)
		// Oslo (true)
		// Lillehammer
		// Moss
		if (capital != p_capital)
		{
65
			p_radioButtons[i] -> setText(i18nc("@option:radio The capital of <Region> is...", "%1", capital));
66
67
68
69
70
			b = true;
		}
		else b = false;
	}
	return b;
Albert Astals Cid's avatar
Albert Astals Cid committed
71
72
73
74
}

void divisionCapitalAsker::setAnswerHook(int userSays)
{
75
	p_currentAnswer.setAnswer(p_radioButtons[userSays] -> text());
Albert Astals Cid's avatar
Albert Astals Cid committed
76
77
78
79
}

QString divisionCapitalAsker::getQuestionHook() const
{
80
	return p_map->getDivisionToCapitalTitle();
81
}