File indexing completed on 2024-04-14 03:40:30
0001 /*************************************************************************** 0002 * Copyright (C) 2004 by Albert Astals Cid * 0003 * aacid@kde.org * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ***************************************************************************/ 0010 0011 #include "divisioncapitalasker.h" 0012 0013 #include <KLocalizedString> 0014 0015 #include <QRadioButton> 0016 #include <QRandomGenerator> 0017 0018 #include "map.h" 0019 0020 divisionCapitalAsker::divisionCapitalAsker(QWidget *parent, KGmap *m, QWidget *w, uint count) : boxAsker(parent, m, w, count) 0021 { 0022 init(); 0023 } 0024 0025 bool divisionCapitalAsker::nextBoxAskerQuestionHook(const division *div, int i, bool isAnswer) 0026 { 0027 bool b; 0028 if (isAnswer) 0029 { 0030 const QString divisionName = div -> getName(); 0031 setQuestion(p_map->getDivisionToCapitalQuestionPattern().subs(divisionName).toString()); 0032 p_currentAnswer.setQuestion(i18nc("@item:intable column Question, %1 is region name", "%1", divisionName)); 0033 p_capital = div -> getCapital(); 0034 p_currentAnswer.setCorrectAnswer(i18nc("@option:radio The capital of <Region> is...", "%1", p_capital)); 0035 p_radioButtons[i] -> setText(i18nc("@option:radio The capital of <Region> is...", "%1", p_capital)); 0036 b = true; 0037 0038 QStringList falseCapitals = div -> getFalseCapitals(); 0039 int index = 0; 0040 while (!falseCapitals.isEmpty() && index < 4) 0041 { 0042 if (index != i) 0043 { 0044 const int random = QRandomGenerator::global()->bounded(falseCapitals.size()); 0045 QString falseCapital = falseCapitals.at(random); 0046 falseCapitals.removeAt(random); 0047 p_radioButtons[index] -> setText(i18nc("@option:radio The capital of <Region> is...", "%1", falseCapital)); 0048 } 0049 ++index; 0050 } 0051 } 0052 else 0053 { 0054 QString capital; 0055 capital = div -> getCapital(); 0056 // There are crazy countries like Norway where two different divisions 0057 // have the same capital, avoid asking 0058 // The capital of Akershus is ... 0059 // Oslo (true) 0060 // Oslo (true) 0061 // Lillehammer 0062 // Moss 0063 if (capital != p_capital) 0064 { 0065 p_radioButtons[i] -> setText(i18nc("@option:radio The capital of <Region> is...", "%1", capital)); 0066 b = true; 0067 } 0068 else b = false; 0069 } 0070 return b; 0071 } 0072 0073 void divisionCapitalAsker::setAnswerHook(int userSays) 0074 { 0075 p_currentAnswer.setAnswer(p_radioButtons[userSays] -> text()); 0076 } 0077 0078 QString divisionCapitalAsker::getQuestionHook() const 0079 { 0080 return p_map->getDivisionToCapitalTitle(); 0081 }