1 /***************************************************************************
2  *   Copyright (C) 2004 by Albert Astals Cid                               *
3  *   aacid@kde.org                                                         *
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 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  ***************************************************************************/
10 
11 #include "divisionflagasker.h"
12 
13 #include <KLocalizedString>
14 
15 #include <QImage>
16 #include <QRadioButton>
17 
18 #include "map.h"
19 
divisionFlagAsker(QWidget * parent,KGmap * m,QWidget * w,uint count)20 divisionFlagAsker::divisionFlagAsker(QWidget *parent, KGmap *m, QWidget *w, uint count) : boxAsker(parent, m, w, count)
21 {
22 	init();
23 }
24 
nextBoxAskerQuestionHook(const division * div,int i,bool isAnswer)25 bool divisionFlagAsker::nextBoxAskerQuestionHook(const division *div, int i, bool isAnswer)
26 {
27 	QSize pixmapSize(60, 40);
28 	QIcon icon(div -> getFlagFile());
29 	if (isAnswer)
30 	{
31 		const QString divisionName = div -> getName();
32 		setQuestion(i18nc("@title:group", "The flag of %1 is...", divisionName));
33 		p_currentAnswer.setCorrectAnswer(icon.pixmap(QSize(60, 40)));
34 		p_currentAnswer.setQuestion(i18nc("@item:intable column Question, %1 is region name", "%1", divisionName));
35 	}
36 	else
37 	{
38 		// There are some maps like the Pacific one where two divisions have the same flag
39 		if (icon.pixmap(pixmapSize).toImage() == p_radioButtons[p_position]->icon().pixmap(pixmapSize).toImage()) return false;
40 	}
41 	p_radioButtons[i] -> setIcon(icon);
42 	p_radioButtons[i] -> show();
43 	p_radioButtons[i] -> setIconSize(pixmapSize);
44 	return true;
45 }
46 
setAnswerHook(int userSays)47 void divisionFlagAsker::setAnswerHook(int userSays)
48 {
49 	QIcon i = p_radioButtons[userSays] -> icon();
50 	p_currentAnswer.setAnswer(i.pixmap(QSize(60, 40)));
51 }
52 
getQuestionHook() const53 QString divisionFlagAsker::getQuestionHook() const
54 {
55 	QString divisionType = p_map->getDivisionsString();
56 	return i18nc("@title", "Flag of %1", divisionType);
57 }
58