1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
|
/***************************************************************************
Vocabulary Expression Translation for KDE Edu
-----------------------------------------------------------------------
Copyright 2007-2010 Frederik Gladhorn <gladhorn@kde.org>
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include "keduvoctranslation.h"
#include "keduvocdeclension.h"
#include "keduvocwordtype.h"
#include "keduvocleitnerbox.h"
#include "kvtml2defs.h"
#include "keduvockvtml2writer.h"
#include <QtCore/QMap>
class KEduVocTranslation::KEduVocTranslationPrivate
{
public:
KEduVocTranslationPrivate(KEduVocExpression* parent);
~KEduVocTranslationPrivate();
KEduVocExpression* m_entry;
/// Type of a word noun, verb, adjective etc
KEduVocWordType* m_wordType;
/// Leitner box of the translation.
KEduVocLeitnerBox* m_leitnerBox;
/// A comment giving additional information.
QString m_comment;
/// A hint, to make guessing the word easier.
QString m_hint;
/// Paraphrase
QString m_paraphrase;
/// An example
QString m_example;
/// Pronunciation
QString m_pronunciation;
/// Image url
QUrl m_imageUrl;
/// Sound url
QUrl m_soundUrl;
/// When creating multiple choice tests, these are possible answers. (otherwise other words are added randomly)
QStringList m_multipleChoice;
/// Conjugations of a word (I go, you go, he goes... boring in english)
QMap <QString, KEduVocConjugation> m_conjugations;
/// The comparison forms of adjectives and adverbs: (fast), faster, fastest
KEduVocText* m_comparative;
KEduVocText* m_superlative;
/// The grade of an article. The text part should not be used.
KEduVocText* m_articleGrade;
KEduVocDeclension* m_declension;
// connections to other translations
/// Synonyms for a word: sick and ill, student and pupil
QList< KEduVocTranslation* > m_synonyms;
/// An antonym - the opposite: hot - cold
QList< KEduVocTranslation* > m_antonyms;
/// List of false friends
QList< KEduVocTranslation* > m_falseFriends;
};
KEduVocTranslation::KEduVocTranslationPrivate::KEduVocTranslationPrivate(KEduVocExpression* parent)
{
m_entry = parent;
m_wordType = 0;
m_leitnerBox = 0;
m_declension = 0;
m_comparative = 0;
m_superlative = 0;
m_articleGrade = 0;
}
KEduVocTranslation::KEduVocTranslationPrivate::~KEduVocTranslationPrivate()
{
delete m_declension;
}
KEduVocTranslation::KEduVocTranslation(KEduVocExpression* entry) : d( new KEduVocTranslationPrivate(entry) )
{
}
KEduVocTranslation::KEduVocTranslation(KEduVocExpression* entry, const QString &translation ) : d( new KEduVocTranslationPrivate(entry) )
{
setText(translation.simplified());
}
KEduVocTranslation::KEduVocTranslation( const KEduVocTranslation &other )
: KEduVocText(other),
// set the entry to 0, the translation will be put into a copied entry by the expression copy constructor
d( new KEduVocTranslationPrivate(0) )
{
// beter no word type copy as this is pointer copying
// will not work as this is not added to the word type container!
// d->m_wordType = other.d->m_wordType;
// d->m_leitnerBox = translation.d->m_leitnerBox;
d->m_comment = other.d->m_comment;
d->m_paraphrase = other.d->m_paraphrase;
d->m_example = other.d->m_example;
d->m_pronunciation = other.d->m_pronunciation;
d->m_conjugations = other.d->m_conjugations;
d->m_comparative = other.d->m_comparative;
d->m_superlative = other.d->m_superlative;
d->m_multipleChoice = other.d->m_multipleChoice;
d->m_imageUrl = other.d->m_imageUrl;
d->m_soundUrl = other.d->m_soundUrl;
// no copies of the following for now. we don't know enough to also add this as synonym/etc
// d->m_synonyms = other.d->m_synonyms;
// d->m_antonyms = other.d->m_antonyms;
// d->m_falseFriends = other.d->m_falseFriends;
if (other.d->m_declension) {
d->m_declension = new KEduVocDeclension(*other.d->m_declension);
}
}
KEduVocTranslation::~KEduVocTranslation()
{
setWordType(0);
setLeitnerBox(0);
foreach (KEduVocTranslation *synonym, d->m_synonyms) {
synonym->removeSynonym(this);
}
foreach (KEduVocTranslation *antonym, d->m_antonyms) {
antonym->removeAntonym(this);
}
foreach (KEduVocTranslation *falseFriend, d->m_falseFriends) {
falseFriend->removeFalseFriend(this);
}
delete d;
}
bool KEduVocTranslation::operator == ( const KEduVocTranslation & translation ) const
{
return KEduVocText::operator==(translation) &&
d->m_wordType == translation.d->m_wordType &&
d->m_leitnerBox == translation.d->m_leitnerBox &&
d->m_comment == translation.d->m_comment &&
d->m_paraphrase == translation.d->m_paraphrase &&
d->m_example == translation.d->m_example &&
d->m_pronunciation == translation.d->m_pronunciation &&
d->m_imageUrl == translation.d->m_imageUrl &&
d->m_soundUrl == translation.d->m_soundUrl &&
d->m_comparative == translation.d->m_comparative &&
d->m_superlative == translation.d->m_superlative &&
d->m_multipleChoice == translation.d->m_multipleChoice &&
d->m_synonyms == translation.d->m_synonyms &&
d->m_antonyms == translation.d->m_antonyms &&
d->m_falseFriends == translation.d->m_falseFriends &&
d->m_conjugations == translation.d->m_conjugations;
/// @todo check and include declensions d->m_declension == translation.d->m_declension;
}
KEduVocTranslation & KEduVocTranslation::operator = ( const KEduVocTranslation & translation )
{
KEduVocText::operator=(translation);
d->m_entry = translation.d->m_entry;
// d->m_wordType = translation.d->m_wordType;
// d->m_leitnerBox = translation.d->m_leitnerBox;
d->m_comment = translation.d->m_comment;
d->m_paraphrase = translation.d->m_paraphrase;
d->m_example = translation.d->m_example;
d->m_pronunciation = translation.d->m_pronunciation;
d->m_imageUrl = translation.d->m_imageUrl;
d->m_soundUrl = translation.d->m_soundUrl;
d->m_comparative = translation.d->m_comparative;
d->m_superlative = translation.d->m_superlative;
d->m_multipleChoice = translation.d->m_multipleChoice;
d->m_falseFriends = translation.d->m_falseFriends;
d->m_synonyms = translation.d->m_synonyms;
d->m_antonyms = translation.d->m_antonyms;
d->m_conjugations = translation.d->m_conjugations;
if (translation.d->m_declension) {
d->m_declension = new KEduVocDeclension(*translation.d->m_declension);
}
return *this;
}
QString KEduVocTranslation::comment() const
{
return d->m_comment;
}
void KEduVocTranslation::setComment( const QString & expr )
{
d->m_comment = expr.simplified();
}
void KEduVocTranslation::addFalseFriend( KEduVocTranslation* falseFriend )
{
d->m_falseFriends.append(falseFriend);
}
void KEduVocTranslation::removeFalseFriend(KEduVocTranslation * falseFriend)
{
d->m_falseFriends.removeAt(d->m_falseFriends.indexOf(falseFriend));
}
QList< KEduVocTranslation* > KEduVocTranslation::falseFriends() const
{
return d->m_falseFriends;
}
void KEduVocTranslation::addSynonym( KEduVocTranslation* synonym )
{
d->m_synonyms.append(synonym);
}
void KEduVocTranslation::removeSynonym(KEduVocTranslation * synonym)
{
d->m_synonyms.removeAt(d->m_synonyms.indexOf(synonym));
}
QList<KEduVocTranslation*> KEduVocTranslation::synonyms() const
{
return d->m_synonyms;
}
void KEduVocTranslation::addAntonym( KEduVocTranslation* antonym )
{
d->m_antonyms.append(antonym);
}
QList<KEduVocTranslation*> KEduVocTranslation::antonyms() const
{
return d->m_antonyms;
}
void KEduVocTranslation::removeAntonym(KEduVocTranslation * antonym)
{
d->m_antonyms.removeAt(d->m_antonyms.indexOf(antonym));
}
void KEduVocTranslation::setExample( const QString & expr )
{
d->m_example = expr.simplified();
}
QString KEduVocTranslation::example() const
{
return d->m_example;
}
void KEduVocTranslation::setParaphrase( const QString & expr )
{
d->m_paraphrase = expr.simplified();
}
QString KEduVocTranslation::paraphrase() const
{
return d->m_paraphrase;
}
void KEduVocTranslation::setConjugation( const QString& tense, const KEduVocConjugation& con )
{
d->m_conjugations[tense] = con;
}
KEduVocConjugation& KEduVocTranslation::conjugation(const QString &tense)
{
return d->m_conjugations[tense];
}
KEduVocConjugation KEduVocTranslation::getConjugation(const QString &tense) const
{
if (d->m_conjugations.contains(tense)) {
return d->m_conjugations[tense];
}
return KEduVocConjugation();
}
QStringList& KEduVocTranslation::multipleChoice()
{
return d->m_multipleChoice;
}
QStringList KEduVocTranslation::getMultipleChoice() const
{
return d->m_multipleChoice;
}
void KEduVocTranslation::setMultipleChoice(const QStringList &choices)
{
d->m_multipleChoice = choices;
}
QString KEduVocTranslation::pronunciation() const
{
return d->m_pronunciation;
}
void KEduVocTranslation::setPronunciation( const QString & expr )
{
d->m_pronunciation = expr.simplified();
}
QStringList KEduVocTranslation::conjugationTenses() const
{
return d->m_conjugations.keys();
}
QMap< QString, KEduVocConjugation > KEduVocTranslation::conjugations() const
{
return d->m_conjugations;
}
void KEduVocTranslation::setConjugations(const QMap< QString, KEduVocConjugation > & conjugations)
{
d->m_conjugations = conjugations;
}
/** get the sound url for this translation if it exists */
QUrl KEduVocTranslation::soundUrl()
{
return d->m_soundUrl;
}
/** set the sound url for this translation
* @param url url of the sound file */
void KEduVocTranslation::setSoundUrl(const QUrl &url)
{
d->m_soundUrl = url;
}
/** get the image url for this translation if it exists */
QUrl KEduVocTranslation::imageUrl()
{
return d->m_imageUrl;
}
/** set the image url for this translation
* @param url url of the image
*/
void KEduVocTranslation::setImageUrl(const QUrl &url)
{
d->m_imageUrl = url;
}
KEduVocWordType * KEduVocTranslation::wordType() const
{
if (d) {
return d->m_wordType;
} else {
return 0;
}
}
void KEduVocTranslation::setWordType(KEduVocWordType * wordType)
{
if ( d->m_wordType ) {
d->m_wordType->removeTranslation(this);
}
if ( wordType ) {
wordType->addTranslation(this);
}
d->m_wordType = wordType;
}
KEduVocLeitnerBox * KEduVocTranslation::leitnerBox() const
{
return d->m_leitnerBox;
}
void KEduVocTranslation::setLeitnerBox(KEduVocLeitnerBox * leitnerBox)
{
if ( d->m_leitnerBox ) {
d->m_leitnerBox->removeTranslation(this);
}
if ( leitnerBox ) {
leitnerBox->addTranslation(this);
}
d->m_leitnerBox = leitnerBox;
}
KEduVocExpression * KEduVocTranslation::entry()
{
return d->m_entry;
}
QString KEduVocTranslation::comparative() const
{
if (d->m_comparative) {
return d->m_comparative->text();
}
return QString();
}
void KEduVocTranslation::setComparative(const QString & comparative)
{
if (!d->m_comparative) {
d->m_comparative = new KEduVocText(comparative);
} else {
d->m_comparative->setText(comparative);
}
}
QString KEduVocTranslation::superlative() const
{
if (d->m_superlative) {
return d->m_superlative->text();
}
return QString();
}
void KEduVocTranslation::setSuperlative(const QString & superlative)
{
if (!d->m_superlative) {
d->m_superlative = new KEduVocText(superlative);
} else {
d->m_superlative->setText(superlative);
}
}
KEduVocText KEduVocTranslation::comparativeForm() const
{
if (!d->m_comparative) {
return KEduVocText();
}
KEduVocText t(*(d->m_comparative));
return t;
}
void KEduVocTranslation::setComparativeForm(const KEduVocText& comparative)
{
if (!d->m_comparative) {
d->m_comparative = new KEduVocText();
}
*(d->m_comparative) = comparative;
}
KEduVocText KEduVocTranslation::superlativeForm() const
{
if (!d->m_superlative) {
return KEduVocText();
}
KEduVocText t(*d->m_superlative);
return t;
}
void KEduVocTranslation::setSuperlativeForm(const KEduVocText& superlative)
{
if (!d->m_superlative) {
d->m_superlative = new KEduVocText();
}
*d->m_superlative = superlative;
}
KEduVocText KEduVocTranslation::article() const
{
if (!d->m_articleGrade) {
return KEduVocText();
}
KEduVocText t(*d->m_articleGrade);
return t;
}
void KEduVocTranslation::setArticle(const KEduVocText& article)
{
if (!d->m_articleGrade) {
d->m_articleGrade = new KEduVocText();
}
*d->m_articleGrade = article;
}
KEduVocDeclension * KEduVocTranslation::declension()
{
return d->m_declension;
}
void KEduVocTranslation::setDeclension(KEduVocDeclension * declension)
{
// remove the old declension object
delete d->m_declension;
d->m_declension = declension;
}
void KEduVocTranslation::toKVTML2(QDomElement & parent)
{
// text and grade
KEduVocText::toKVTML2(parent);
// declension
if (d->m_declension) {
d->m_declension->toKVTML2(parent);
}
// conjugation
foreach ( const QString &tense, conjugationTenses() ) {
QDomElement conjugationElement = parent.ownerDocument().createElement( KVTML_CONJUGATION );
getConjugation(tense).toKVTML2(conjugationElement, tense);
if (conjugationElement.hasChildNodes()) {
parent.appendChild( conjugationElement );
}
}
// <comment>
KEduVocKvtml2Writer::appendTextElement( parent, KVTML_COMMENT, comment() );
// <pronunciation>
KEduVocKvtml2Writer::appendTextElement( parent, KVTML_PRONUNCIATION, pronunciation() );
// <example>
KEduVocKvtml2Writer::appendTextElement( parent, KVTML_EXAMPLE, example() );
// <paraphrase>
KEduVocKvtml2Writer::appendTextElement( parent, KVTML_PARAPHRASE, paraphrase() );
///@todo synonyms, antonyms
///@todo false friends
}
void KEduVocTranslation::fromKVTML2(QDomElement & parent)
{
KEduVocText::fromKVTML2(parent);
setDeclension(KEduVocDeclension::fromKVTML2(parent));
setComment( parent.firstChildElement( KVTML_COMMENT ).text() );
setPronunciation( parent.firstChildElement( KVTML_PRONUNCIATION ).text() );
//<example></example>
setExample( parent.firstChildElement( KVTML_EXAMPLE ).text() );
//<paraphrase></paraphrase>
setParaphrase( parent.firstChildElement( KVTML_PARAPHRASE ).text() );
// conjugations
QDomElement conjugationElement = parent.firstChildElement( KVTML_CONJUGATION );
while ( !conjugationElement.isNull() ) {
QDomElement tenseElement = conjugationElement.firstChildElement( KVTML_TENSE );
QString tense = tenseElement.text();
KEduVocConjugation *conjugation = KEduVocConjugation::fromKVTML2(conjugationElement);
setConjugation(tense, *conjugation);
delete conjugation;
conjugationElement = conjugationElement.nextSiblingElement( KVTML_CONJUGATION );
}
///@todo synonyms, antonym
///@todo false friends
}
void KEduVocTranslation::setEntry(KEduVocExpression * entry)
{
d->m_entry = entry;
}
|