capitaldivisionasker.cpp 2.31 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 "capitaldivisionasker.h"

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

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

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

24
bool capitalDivisionAsker::nextBoxAskerQuestionHook(const QString &division, int i, bool isAnswer)
25
{
26
	bool b;
Albert Astals Cid's avatar
Albert Astals Cid committed
27
28
	if (isAnswer)
	{
29
		const QString divisionName = p_map -> getDivision(division) -> getName();
30
		p_capital = p_map -> getDivisionCapital(division);
31
		p_currentAnswer.setQuestion(i18nc("@item:intable column Question, %1 is capital name", "%1", p_capital));
32
		p_currentAnswer.setCorrectAnswer(i18nc("@option:radio <City> is the capital of...", "%1", divisionName));
Albert Astals Cid's avatar
Albert Astals Cid committed
33

34
		setQuestion(p_map->getCapitalToDivisionQuestionPattern().subs(p_capital).toString());
35
		p_radioButtons[i] -> setText(i18nc("@option:radio <City> is the capital of...", "%1", divisionName));
36
		b = true;
Albert Astals Cid's avatar
Albert Astals Cid committed
37
	}
38
39
40
41
42
43
44
45
46
47
48
	else
	{
		// There are crazy countries like Norway where two different divisions
		// have the same capital, avoid asking
		// Oslo is the capital of ...
		// Oslo (true)
		// Akershus (true)
		// Buskerud
		// Hedmark
		if (p_map -> getDivisionCapital(division) != p_capital)
		{
49
50
			const QString divisionName = p_map -> getDivision(division) -> getName();
			p_radioButtons[i] -> setText(i18nc("@option:radio <City> is the capital of...", "%1", divisionName));
51
52
53
54
55
			b = true;
		}
		else b = false;
	}
	return b;
Albert Astals Cid's avatar
Albert Astals Cid committed
56
57
58
59
}

void capitalDivisionAsker::setAnswerHook(int userSays)
{
60
	p_currentAnswer.setAnswer(p_radioButtons[userSays] -> text());
Albert Astals Cid's avatar
Albert Astals Cid committed
61
62
63
64
}

QString capitalDivisionAsker::getQuestionHook() const
{
65
	return p_map->getCapitalToDivisionTitle();
66
}