Commit 81124665 authored by Pino Toscano's avatar Pino Toscano Committed by Albert Astals Cid
Browse files

Store division::p_name as translated

Because of that, keep using its untranslatedName as unique identifier
all around, fetching the division object from the map to get properties
of it (e.g. translated name, flag, capital, etc).
parent 62c837f1
......@@ -26,12 +26,13 @@ bool capitalDivisionAsker::nextBoxAskerQuestionHook(const QString &division, int
bool b;
if (isAnswer)
{
const QString divisionName = p_map -> getDivision(division) -> getName();
p_capital = p_map -> getDivisionCapital(division);
p_currentAnswer.setQuestion(i18nc("@item:intable column Question, %1 is capital name", "%1", p_capital));
p_currentAnswer.setCorrectAnswer(i18nc("@option:radio <City> is the capital of...", "%1", i18nc(p_map -> getFileName().toUtf8(), division.toUtf8())));
p_currentAnswer.setCorrectAnswer(i18nc("@option:radio <City> is the capital of...", "%1", divisionName));
setQuestion(i18nc("@title:group", p_map->getCapitalToDivisionQuestionPattern().toUtf8(), p_capital));
p_radioButtons[i] -> setText(i18nc("@option:radio <City> is the capital of...", "%1", i18nc(p_map -> getFileName().toUtf8(), division.toUtf8())));
p_radioButtons[i] -> setText(i18nc("@option:radio <City> is the capital of...", "%1", divisionName));
b = true;
}
else
......@@ -45,7 +46,8 @@ bool capitalDivisionAsker::nextBoxAskerQuestionHook(const QString &division, int
// Hedmark
if (p_map -> getDivisionCapital(division) != p_capital)
{
p_radioButtons[i] -> setText(i18nc("@option:radio <City> is the capital of...", "%1", i18nc(p_map -> getFileName().toUtf8(), division.toUtf8())));
const QString divisionName = p_map -> getDivision(division) -> getName();
p_radioButtons[i] -> setText(i18nc("@option:radio <City> is the capital of...", "%1", divisionName));
b = true;
}
else b = false;
......
......@@ -27,9 +27,9 @@ bool divisionCapitalAsker::nextBoxAskerQuestionHook(const QString &division, int
bool b;
if (isAnswer)
{
QString divisionName = i18nc(p_map -> getFileName().toUtf8(), division.toUtf8());
const QString divisionName = p_map -> getDivision(division) -> getName();
setQuestion(i18nc("@title:group", p_map->getDivisionToCapitalQuestionPattern().toUtf8(), divisionName));
p_currentAnswer.setQuestion(i18nc("@item:intable column Question, %1 is region name", "%1", i18nc(p_map -> getFileName().toUtf8(), division.toUtf8())));
p_currentAnswer.setQuestion(i18nc("@item:intable column Question, %1 is region name", "%1", divisionName));
p_capital = p_map -> getDivisionCapital(division);
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));
......
......@@ -28,10 +28,10 @@ bool divisionFlagAsker::nextBoxAskerQuestionHook(const QString &division, int i,
QIcon icon(p_map -> getDivisionFlagFile(division));
if (isAnswer)
{
QString divisionName = i18nc(p_map -> getFileName().toUtf8(), division.toUtf8());
const QString divisionName = p_map -> getDivision(division) -> getName();
setQuestion(i18nc("@title:group", "The flag of %1 is...", divisionName));
p_currentAnswer.setCorrectAnswer(icon.pixmap(QSize(60, 40)));
p_currentAnswer.setQuestion(i18nc("@item:intable column Question, %1 is region name", "%1", i18nc(p_map -> getFileName().toUtf8(), division.toUtf8())));
p_currentAnswer.setQuestion(i18nc("@item:intable column Question, %1 is region name", "%1", divisionName));
}
else
{
......
......@@ -18,6 +18,7 @@
#include <qradiobutton.h>
#include "map.h"
#include "division.h"
class flagWidget : public QWidget
{
......@@ -46,24 +47,25 @@ flagDivisionAsker::flagDivisionAsker(QWidget *parent, KGmap *m, QWidget *w, uint
bool flagDivisionAsker::nextBoxAskerQuestionHook(const QString &division, int i, bool isAnswer)
{
const class division *vDivision = p_map -> getDivision(division);
if (isAnswer)
{
// we put the flag image
QImage image(p_map -> getDivisionFlagFile(division));
QImage image(vDivision -> getFlagFile());
p_flag -> img = image;
p_flag -> setMinimumSize(image.size());
p_flag -> update();
p_currentAnswer.setQuestion(QPixmap::fromImage(image.scaled(image.width()/5, image.height()/5, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)));
p_currentAnswer.setCorrectAnswer(i18nc("@option:radio This flag belongs to:", "%1", i18nc(p_map -> getFileName().toUtf8(), division.toUtf8())));
p_currentAnswer.setCorrectAnswer(i18nc("@option:radio This flag belongs to:", "%1", vDivision -> getName()));
}
else
{
// There are some maps like the Pacific one where two divisions have the same flag
QImage image(p_map -> getDivisionFlagFile(division));
QImage image(vDivision -> getFlagFile());
if (p_flag -> img == image) return false;
}
p_radioButtons[i] -> setText(i18nc("@option:radio This flag belongs to:", "%1", i18nc(p_map -> getFileName().toUtf8(), division.toUtf8())));
p_radioButtons[i] -> setText(i18nc("@option:radio This flag belongs to:", "%1", vDivision -> getName()));
return true;
}
......
......@@ -34,8 +34,8 @@ KGmap::~KGmap()
bool KGmap::addDivision(division *d)
{
bool b;
if ( ( getDivision(d -> getName()) == NULL && getDivision(d -> getRGB()) == NULL ) ||
( getDivision(d -> getName()) != NULL && getDivision(d -> getRGB()) == NULL && !d->canAsk(division::eClick) && !getDivision(d -> getName())->canAsk(division::eClick) ) )
if ( ( getDivision(d -> getUntranslatedName()) == NULL && getDivision(d -> getRGB()) == NULL ) ||
( getDivision(d -> getUntranslatedName()) != NULL && getDivision(d -> getRGB()) == NULL && !d->canAsk(division::eClick) && !getDivision(d -> getUntranslatedName())->canAsk(division::eClick) ) )
{
p_divisions.append(d);
b = true;
......@@ -167,7 +167,7 @@ QString KGmap::getRandomDivision(division::askMode am) const
QList<division*> aux;
int i = (int)((float)p_divisions.size() * KRandom::random() / (RAND_MAX + 1.0));
if (!p_divisions[i] -> canAsk(am)) return getRandomDivision(am);
else return p_divisions[i] -> getName();
else return p_divisions[i] -> getUntranslatedName();
}
QString KGmap::getWhatIs(QRgb c, bool all) const
......@@ -177,8 +177,8 @@ QString KGmap::getWhatIs(QRgb c, bool all) const
if (d == NULL) return QStringLiteral("nothing");
else
{
if (all) return d -> getName();
else if (d -> canAsk(division::eClick)) return d -> getName();
if (all) return d -> getUntranslatedName();
else if (d -> canAsk(division::eClick)) return d -> getUntranslatedName();
else return QLatin1String("");
}
}
......@@ -214,7 +214,7 @@ division *KGmap::getDivision(const QString &divisionName) const
{
foreach (division* div, p_divisions)
{
if (div->getName() == divisionName) return div;
if (div->getUntranslatedName() == divisionName) return div;
}
return NULL;
}
......
......@@ -56,10 +56,9 @@ class KGmap
QString getCapitalToDivisionTitle() const;
QString getDivisionToCapitalTitle() const;
division *getDivision(QRgb c) const;
division *getDivision(const QString &divisionName) const;
private:
division *getDivision(const QString &divisionName) const;
QList<division*> p_divisions;
QString p_name, p_file, p_mapFile;
......
......@@ -145,15 +145,16 @@ void mapAsker::handleMapClick(QRgb c, const QPoint &p)
}
else if (!p_asker)
{
QString flagFile = p_map -> getDivisionFlagFile(aux);
if (p_map -> getDivisionCanAsk(aux, division::eCapital)) cap = p_map -> getDivisionCapital(aux);
const division *vDivision = p_map -> getDivision(aux);
QString flagFile = vDivision -> getFlagFile();
if (vDivision -> canAsk(division::eCapital)) cap = vDivision -> getCapital();
if (!cap.isEmpty()) cap = i18nc("@item Capital name in map popup", "%1", cap);
QString wikiLink (guessWikipediaDomain());
wikiLink.append(i18nc(p_map -> getFileName().toUtf8(), aux.toUtf8()));
if (!p_map -> getDivisionCanAsk(aux, division::eClick)) wikiLink = QLatin1String("");
wikiLink.append(vDivision -> getName ());
if (!vDivision -> canAsk(division::eClick)) wikiLink = QLatin1String("");
aux = i18nc("@item Region name in map popup", "%1", i18nc(p_map -> getFileName().toUtf8(), aux.toUtf8()));
aux = i18nc("@item Region name in map popup", "%1", vDivision -> getName ());
if (!flagFile.isEmpty()) p_popupManager.show(aux, wikiLink, cap, p, flagFile);
else if (!cap.isEmpty()) p_popupManager.show(aux, wikiLink, cap , p);
......@@ -179,7 +180,7 @@ void mapAsker::handleMapClick(QRgb c, const QPoint &p)
{
vDivision = p_map->getDivision(vColorRgb);
}
vDivisionName = i18nc(p_map -> getFileName().toUtf8(), vDivision->getName().toUtf8());
vDivisionName = vDivision -> getName();
vAnswer.append(vDivisionName);
p_currentAnswer.setAnswer(vAnswer);
questionAnswered(aux == correctDivision);
......@@ -189,9 +190,9 @@ void mapAsker::handleMapClick(QRgb c, const QPoint &p)
void mapAsker::nextQuestionHook(const QString &division)
{
QString divisionName = i18nc(p_map -> getFileName().toUtf8(), division.toUtf8());
const QString divisionName = p_map -> getDivision(division) -> getName();
p_next -> setText(i18nc("@info:status", "Please click on:<br/><b>%1</b>", divisionName));
p_currentAnswer.setQuestion(i18nc("@item:intable column Question, %1 is region name", "%1", i18nc(p_map -> getFileName().toUtf8(), division.toUtf8())));
p_currentAnswer.setQuestion(i18nc("@item:intable column Question, %1 is region name", "%1", divisionName));
p_next -> show();
QRgb c = p_map -> getColor(division).rgb();
p_currentAnswer.setCorrectAnswer(QColor(c));
......
......@@ -108,7 +108,7 @@ KGmap *mapReader::parseMap(const QString &path)
// division name
kgdiv -> setUntranslatedName( getElementString(QStringLiteral("name"), divisionTag, Mandatory) );
kgdiv -> setName( kgdiv -> getUntranslatedName() );
kgdiv -> setName(i18nc(ctxt, kgdiv -> getUntranslatedName().toUtf8()));
// division capital
QString capital = getElementString(QStringLiteral("capital"), divisionTag, Optional);
......
......@@ -186,10 +186,10 @@ void placeAsker::handleMapClick(QRgb c, const QPoint & , const QPointF &mapPoint
void placeAsker::nextQuestionHook(const QString &division)
{
QString divisionName = i18nc(p_map -> getFileName().toUtf8(), division.toUtf8());
const QString divisionName = p_map -> getDivision(division) -> getName();
p_next -> setText(i18nc("@info:status", "Please place in the map:<br/><b>%1</b>", divisionName));
p_next -> show();
p_currentAnswer.setQuestion(i18nc("@item:intable column Question, %1 is region name", "%1", i18nc(p_map -> getFileName().toUtf8(), division.toUtf8())));
p_currentAnswer.setQuestion(i18nc("@item:intable column Question, %1 is region name", "%1", divisionName));
QColor color = p_map -> getColor(division);
p_currentRgb = color.rgb();
p_currentAnswer.setCorrectAnswer(color);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment