• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdeedu
  • Sitemap
  • Contact Us
 

parley

ArtQueryDlg.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002 
00003                      query dialog for articles
00004 
00005     -----------------------------------------------------------------------
00006 
00007     begin         : Fri Dec 3 18:28:18 1999
00008 
00009     copyright     : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
00010                     (C) 2004-2007 Peter Hedlund <peter.hedlund@kdemail.net>
00011 
00012     -----------------------------------------------------------------------
00013 
00014  ***************************************************************************
00015 
00016  ***************************************************************************
00017  *                                                                         *
00018  *   This program is free software; you can redistribute it and/or modify  *
00019  *   it under the terms of the GNU General Public License as published by  *
00020  *   the Free Software Foundation; either version 2 of the License, or     *
00021  *   (at your option) any later version.                                   *
00022  *                                                                         *
00023  ***************************************************************************/
00024 
00025 #include "ArtQueryDlg.h"
00026 
00027 #include "kvttablemodel.h"
00028 #include <keduvocwordtype.h>
00029 #include <KLocale>
00030 #include <QTimer>
00031 #include <QRadioButton>
00032 #include <QLabel>
00033 #include <QPushButton>
00034 #include <QButtonGroup>
00035 
00036 ArtQueryDlg::ArtQueryDlg(KEduVocDocument *doc, QWidget *parent) : PracticeDialog(i18nc("@title:window", "Article Training"), doc, parent)
00037 {
00038     mw = new Ui::ArtQueryDlgForm();
00039     mw->setupUi(mainWidget());
00040 
00041     mw->stopPracticeButton->setIcon( KIcon("process-stop") );
00042     mw->editEntryButton->setIcon( KIcon("document-properties") );
00043     mw->know_it->setIcon(KIcon("go-next"));
00044     mw->dont_know->setIcon(KIcon("go-next"));
00045 
00046     connect(mw->stopPracticeButton, SIGNAL(clicked()), SLOT(close()));
00047     connect(mw->editEntryButton, SIGNAL(clicked()), SLOT(editEntry()));
00048 
00049     articles = m_doc->identifier(Prefs::solutionLanguage()).article();
00050 
00051     connect(mw->dont_know, SIGNAL(clicked()), SLOT(skipUnknown()()));
00052     connect(mw->know_it, SIGNAL(clicked()), SLOT(skipKnown()));
00053     connect(mw->show_all, SIGNAL(clicked()), SLOT(showSolution()));
00054 
00055     connect(mw->maleRadio, SIGNAL(clicked()), SLOT(verifyClicked()));
00056     connect(mw->femaleRadio, SIGNAL(clicked()), SLOT(verifyClicked()));
00057     connect(mw->neutralRadio, SIGNAL(clicked()), SLOT(verifyClicked()));
00058 
00059     mw->dont_know->setShortcut(QKeySequence(Qt::Key_Escape));
00060 
00061     mw->countbar->setFormat("%v/%m");
00062     mw->timebar->setFormat("%v");
00063 
00064     mw->know_it->setVisible(Prefs::skipKnownEnabled());
00065     mw->imageGraphicsView->setVisible(false);
00066 
00067     KConfigGroup cg(KGlobal::config(), "ArtQueryDlg");
00068     restoreDialogSize(cg);
00069 }
00070 
00071 
00072 ArtQueryDlg::~ArtQueryDlg()
00073 {
00074     KConfigGroup cg(KGlobal::config(), "ArtQueryDlg");
00075     KDialog::saveDialogSize(cg);
00076 }
00077 
00078 
00079 void ArtQueryDlg::setEntry(TestEntry* entry)
00080 {
00081     PracticeDialog::setEntry(entry);
00082 
00083     mw->timebar->setVisible(Prefs::practiceTimeout());
00084     mw->timelabel->setVisible(Prefs::practiceTimeout());
00085     mw->show_all->setDefault(true);
00086 
00087     QString def, indef;
00088 
00089     KEduVocArticle::ArticleNumber singular = KEduVocArticle::Singular;
00090     KEduVocArticle::ArticleDefiniteness definite = KEduVocArticle::Definite;
00091     KEduVocArticle::ArticleDefiniteness indefinite = KEduVocArticle::Indefinite;
00092     KEduVocArticle::ArticleGender male = KEduVocArticle::Masculine;
00093     KEduVocArticle::ArticleGender female = KEduVocArticle::Feminine;
00094     KEduVocArticle::ArticleGender neutral = KEduVocArticle::Neutral;
00095 
00096     // set the word (possibly without the article)
00097     QString noun = m_entry->exp->translation(Prefs::solutionLanguage()).text();
00098     // strip the article
00100     int pos;
00101     foreach(QString word, noun.split(QRegExp("\\W"), QString::SkipEmptyParts) ) {
00102         if (articles.isArticle(word)) {
00103             while ((pos = noun.indexOf(word)) >= 0) {
00104                 noun.remove(pos, word.length());
00105             }
00106         }
00107     }
00108 //     QString firstPart = noun.substring(
00109 //     if (articles.isArticle(firstPart)){
00110         //remove
00111 //     }
00112 
00113     mw->orgField->setText(noun);
00114     mw->progCount->setText(QString::number(entry->statisticCount()));
00115 
00116 
00117     // set the choices
00118     if(articles.isEmpty()) {
00119         mw->maleRadio->setText(i18nc("@label the gender of the word: male", "&male"));
00120         mw->femaleRadio->setText(i18nc("@label the gender of the word: female", "&female"));
00121         mw->neutralRadio->setText(i18nc("@label the gender of the word: neutral", "&neutral"));
00122     } else {
00123         def = articles.article( singular, definite, male );
00124         indef = articles.article( singular, indefinite, male );
00125         bool male = !(def.isEmpty() && indef.isEmpty());
00126         QString article;
00127         if((!def.isEmpty()) && (!indef.isEmpty())) {
00128             article = def + " / " + indef;
00129         } else {
00130             article = def + indef;
00131         }
00132         mw->maleRadio->setText(i18nc("@label the gender of the word: male", "&male:\t") + article);
00133 
00134         def = articles.article( singular, definite, female );
00135         indef = articles.article( singular, indefinite, female );
00136         bool female = !(def.isEmpty() && indef.isEmpty());
00137         if((!def.isEmpty()) && (!indef.isEmpty())) {
00138             article = def + " / " + indef;
00139         } else {
00140             article = def + indef;
00141         }
00142         mw->femaleRadio->setText(i18nc("@label the gender of the word: female", "&female:\t") + article);
00143 
00144         def = articles.article( singular, definite, neutral );
00145         indef = articles.article( singular, indefinite, neutral );
00146         bool neutral = !(def.isEmpty() && indef.isEmpty());
00147         if((!def.isEmpty()) && (!indef.isEmpty())) {
00148             article = def + " / " + indef;
00149         } else {
00150             article = def + indef;
00151         }
00152         if (!neutral && male && female) {
00153             mw->neutralRadio->setVisible(false);
00154         } else {
00155             mw->neutralRadio->setText(i18nc("@label the gender of the word: neutral", "&neutral:\t") + article);
00156             mw->neutralRadio->setVisible(true);
00157         }
00158     }
00159 
00160     setWidgetStyle(mw->maleRadio);
00161     setWidgetStyle(mw->femaleRadio);
00162     setWidgetStyle(mw->neutralRadio);
00163 
00164     // As long as the buttons are AutoExclusive we cannot uncheck all.
00165     mw->maleRadio->setChecked(true);
00166     mw->maleRadio->setAutoExclusive ( false );
00167     mw->maleRadio->setChecked(false);
00168     mw->maleRadio->setAutoExclusive ( true );
00169 
00170     mw->dont_know->setFocus();
00171 
00172     imageShowFromEntry( mw->imageGraphicsView, entry );
00173 }
00174 
00175 
00176 void ArtQueryDlg::showSolution()
00177 {
00178     setWidgetStyle(mw->maleRadio);
00179     setWidgetStyle(mw->femaleRadio);
00180     setWidgetStyle(mw->neutralRadio);
00181 
00182     QString specialSubType = m_doc->wordTypes().specialSubType(m_entry->exp->translation(Prefs::solutionLanguage()).type(), m_entry->exp->translation(Prefs::solutionLanguage()).subType());
00183 
00184     if (specialSubType == m_doc->wordTypes().specialTypeNounMale()) {
00185         mw->maleRadio->setChecked(true);
00186         setWidgetStyle(mw->maleRadio, PositiveResult);
00187     } else if (specialSubType == m_doc->wordTypes().specialTypeNounFemale()) {
00188         mw->femaleRadio->setChecked(true);
00189         setWidgetStyle(mw->femaleRadio, PositiveResult);
00190     } else if (specialSubType == m_doc->wordTypes().specialTypeNounNeutral()) {
00191         mw->neutralRadio->setChecked(true);
00192         setWidgetStyle(mw->neutralRadio, PositiveResult);
00193     }
00194     mw->dont_know->setDefault(true);
00195     setAnswerTainted();
00196 }
00197 
00198 
00199 void ArtQueryDlg::verifyClicked()
00200 {
00201     QString specialSubType = m_doc->wordTypes().specialSubType(m_entry->exp->translation(Prefs::solutionLanguage()).type(), m_entry->exp->translation(Prefs::solutionLanguage()).subType());
00202 
00203     bool correct = false;
00204 
00205     if (specialSubType ==  m_doc->wordTypes().specialTypeNounMale()) {
00206         if ( mw->maleRadio->isChecked() ) {
00207             setWidgetStyle(mw->maleRadio, PositiveResult);
00208             correct = true;
00209         } else {
00210             setWidgetStyle(mw->maleRadio, NegativeResult);
00211         }
00212     }
00213     if (specialSubType == m_doc->wordTypes().specialTypeNounFemale()) {
00214         if ( mw->femaleRadio->isChecked() ) {
00215             setWidgetStyle(mw->femaleRadio, PositiveResult);
00216             correct = true;
00217         } else {
00218             setWidgetStyle(mw->femaleRadio, NegativeResult);
00219         }
00220     }
00221     if (specialSubType == m_doc->wordTypes().specialTypeNounNeutral()) {
00222         if ( mw->neutralRadio->isChecked() ) {
00223             setWidgetStyle(mw->neutralRadio, PositiveResult);
00224             correct = true;
00225         } else {
00226             setWidgetStyle(mw->neutralRadio, NegativeResult);
00227         }
00228     }
00229 
00230     if (correct) {
00231         resultCorrect();
00232         emit showSolutionFinished();
00233     } else {
00234         mw->dont_know->setDefault(true);
00235     }
00236 }
00237 
00238 
00239 void ArtQueryDlg::setProgressCounter(int current, int total)
00240 {
00241     mw->countbar->setMaximum(total);
00242     mw->countbar->setValue(current);
00243 }
00244 
00245 
00246 #include "ArtQueryDlg.moc"
00247 
00248 

parley

Skip menu "parley"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeedu

Skip menu "kdeedu"
  • kalzium
  • kanagram
  • kig
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  •   docs
  •   src
  • parley
Generated for kdeedu by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal