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

parley

configurepracticewidget.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002 
00003     -----------------------------------------------------------------------
00004 
00005     copyright     : (C) 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
00006 
00007     -----------------------------------------------------------------------
00008 
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *   This program is free software; you can redistribute it and/or modify  *
00014  *   it under the terms of the GNU General Public License as published by  *
00015  *   the Free Software Foundation; either version 2 of the License, or     *
00016  *   (at your option) any later version.                                   *
00017  *                                                                         *
00018  ***************************************************************************/
00019 
00020 #include "configurepracticewidget.h"
00021 
00022 #include "ui_comparisonoptionswidget.h"
00023 #include "ui_conjugationoptionswidget.h"
00024 #include "ui_writtenpracticeoptionswidget.h"
00025 
00026 #include "languagesettings.h"
00027 #include "documentsettings.h"
00028 #include "prefs.h"
00029 
00030 #include <keduvocdocument.h>
00031 
00032 #include <KStandardDirs>
00033 #include <KLocale>
00034 #include <QStackedLayout>
00035 #include <QLabel>
00036 #include <QtDBus>
00037 
00042 ConfigurePracticeWidget::ConfigurePracticeWidget(KEduVocDocument* doc, QWidget * parent)
00043     : QWidget(parent)
00044 {
00045     m_doc = doc;
00046     m_bilingual = true;
00047 
00048     setupUi(this);
00049 
00050     for ( int i = 0; i < m_doc->identifierCount(); i++ ) {
00051         LanguageSettings currentSettings(m_doc->identifier(i).locale());
00052         currentSettings.readConfig();
00053         QString icon = currentSettings.icon();
00054         if (icon.isEmpty()) {
00055             icon = QString("preferences-desktop-locale");
00056         }
00057         LanguageFromList->addItem( new QListWidgetItem( KIcon(icon), m_doc->identifier(i).name() ) );
00058     }
00059 
00060     connect(LanguageFromList, SIGNAL(currentRowChanged(int)), SLOT(fromLanguageSelected(int)));
00061     LanguageFromList->setCurrentRow(Prefs::questionLanguage());
00062 
00063     OptionsGroupBox->setEnabled( false );
00064     m_optionsStackedLayout = new QStackedLayout(OptionsGroupBox);
00065     OptionsGroupBox->setLayout(m_optionsStackedLayout);
00066 
00067     // the widgets have to be inserted in order of the enum because insert appends if the index is too great
00068     m_optionsStackedLayout->insertWidget(Empty, new QLabel(i18n("No options"), OptionsGroupBox));
00069 
00070     // add the written practice ui to the stacked widget
00071     QWidget* writtenContainer = new QWidget(OptionsGroupBox);
00072     Ui::WrittenPracticeOptionsWidget writtenPracticeUi;
00073     writtenPracticeUi.setupUi(writtenContainer);
00074     m_optionsStackedLayout->insertWidget(WrittenPractice, writtenContainer);
00075 
00076     // add the conjugation ui to the stacked widget
00077     if ( !m_doc->tenseDescriptions().isEmpty() ) {
00078         QWidget* conjugationContainer = new QWidget(OptionsGroupBox);
00079         Ui::ConjugationOptionsWidget conjugationUi;
00080         conjugationUi.setupUi(conjugationContainer);
00081         m_optionsStackedLayout->insertWidget(Conjugation, conjugationContainer);
00082         m_tenseListWidget = conjugationUi.tenseSelectionTreeWidget;
00083         setupTenses();
00084     } else {
00085         m_tenseListWidget = 0;
00086         QLabel* tenseHint = new QLabel(OptionsGroupBox);
00087         tenseHint->setText(i18n("To practice conjugations set up tenses in the \"Edit\" -> \"Grammar\" options and add the conjugation forms to your vocabulary."));
00088         tenseHint->setWordWrap(true);
00089         m_optionsStackedLayout->insertWidget(Conjugation, tenseHint);
00090     }
00091 
00092 
00093     // add the comparison ui to the stacked widget
00094     QWidget* comparisonContainer = new QWidget(OptionsGroupBox);
00095     Ui::ComparisonOptionsWidget comparisonUi;
00096     comparisonUi.setupUi(comparisonContainer);
00097     m_optionsStackedLayout->insertWidget(Comparison, comparisonContainer);
00098 
00099     // this is preset in the ui. thus the button is not toggled when setting up
00100     if ( WrittenRadio->isChecked() ) {
00101         writtenRadioToggled(true);
00102     }
00103 
00104     connect(AntonymRadio, SIGNAL(toggled(bool)), SLOT(otherRadioToggled(bool)));
00105     connect(ArticleRadio, SIGNAL(toggled(bool)), SLOT(otherRadioToggled(bool)));
00106     connect(ExampleRadio, SIGNAL(toggled(bool)), SLOT(otherRadioToggled(bool)));
00107     connect(MixedLettersRadio, SIGNAL(toggled(bool)), SLOT(otherRadioToggled(bool)));
00108     connect(MultipleChoiceRadio, SIGNAL(toggled(bool)), SLOT(otherRadioToggled(bool)));
00109     connect(ParaphraseRadio, SIGNAL(toggled(bool)), SLOT(otherRadioToggled(bool)));
00110     connect(SynonymRadio, SIGNAL(toggled(bool)), SLOT(otherRadioToggled(bool)));
00111 
00112     connect(WrittenRadio, SIGNAL(toggled(bool)), SLOT(writtenRadioToggled(bool)));
00113     connect(ComparisonRadio, SIGNAL(toggled(bool)), SLOT(comparisonRadioToggled(bool)));
00114     connect(ConjugationRadio, SIGNAL(toggled(bool)), SLOT(conjugationRadioToggled(bool)));
00115 
00116 
00117     // mono/bilingual - practice effects one/two languages - change the language selection accordingly
00118     connect(AntonymRadio, SIGNAL(toggled(bool)), SLOT(bilingualPracticeSelected(bool)));
00119     connect(WrittenRadio, SIGNAL(toggled(bool)), SLOT(bilingualPracticeSelected(bool)));
00120     connect(MixedLettersRadio, SIGNAL(toggled(bool)), SLOT(bilingualPracticeSelected(bool)));
00121     connect(MultipleChoiceRadio, SIGNAL(toggled(bool)), SLOT(bilingualPracticeSelected(bool)));
00122 
00123     connect(ArticleRadio, SIGNAL(toggled(bool)), SLOT(monolingualPracticeSelected(bool)));
00124     connect(ExampleRadio, SIGNAL(toggled(bool)), SLOT(monolingualPracticeSelected(bool)));
00125     connect(ParaphraseRadio, SIGNAL(toggled(bool)), SLOT(monolingualPracticeSelected(bool)));
00126     connect(SynonymRadio, SIGNAL(toggled(bool)), SLOT(monolingualPracticeSelected(bool)));
00127     connect(ComparisonRadio, SIGNAL(toggled(bool)), SLOT(monolingualPracticeSelected(bool)));
00128     connect(ConjugationRadio, SIGNAL(toggled(bool)), SLOT(monolingualPracticeSelected(bool)));
00129 }
00130 
00131 
00132 void ConfigurePracticeWidget::updateSettings()
00133 {
00134     Prefs::setQuestionLanguage(LanguageFromList->currentRow());
00135     if (m_bilingual) {
00136         Prefs::setSolutionLanguage(LanguageToList->currentItem()->data(Qt::UserRole).toInt());
00137     } else {
00138         Prefs::setSolutionLanguage(LanguageFromList->currentRow());
00139     }
00140 
00141     if ( m_tenseListWidget ) {
00142         QTreeWidgetItem* parentItem = m_tenseListWidget->invisibleRootItem();
00143         QStringList activeTenses;
00144         for ( int i = 0; i < parentItem->childCount(); i++ ) {
00145             QTreeWidgetItem* tenseItem = parentItem->child(i);
00146             if ( tenseItem->checkState(0) == Qt::Checked ) {
00147                 activeTenses.append(tenseItem->text(0));
00148             }
00149         }
00150 
00151         DocumentSettings documentSettings(m_doc->url().url());
00152         documentSettings.setConjugationTenses(activeTenses);
00153         documentSettings.writeConfig();
00154     }
00155 }
00156 
00157 void ConfigurePracticeWidget::fromLanguageSelected(int identifierFromIndex)
00158 {
00159     LanguageToList->clear();
00160     for ( int i = 0; i < m_doc->identifierCount(); i++ ) {
00161         if ( i != identifierFromIndex ) {
00162 
00163             LanguageSettings currentSettings(m_doc->identifier(i).locale());
00164             currentSettings.readConfig();
00165             QString icon = currentSettings.icon();
00166             if (icon.isEmpty()) {
00167                 icon = QString("preferences-desktop-locale");
00168             }
00169             LanguageToList->addItem( new QListWidgetItem( KIcon(icon), m_doc->identifier(i).name() ) );
00170 
00171             LanguageToList->item(LanguageToList->count()-1)->setData(Qt::UserRole, i);
00172             if ( i == Prefs::solutionLanguage() ) {
00173                 LanguageToList->setCurrentRow(i);
00174             }
00175         }
00176     }
00177     if ( LanguageToList->currentRow() < 0 ) {
00178         LanguageToList->setCurrentRow(0);
00179     }
00180 }
00181 
00182 void ConfigurePracticeWidget::updateWidgets()
00183 {
00184     LanguageFromList->setCurrentRow(Prefs::questionLanguage());
00185 }
00186 
00187 bool ConfigurePracticeWidget::hasChanged()
00188 {
00189     kDebug()<< "ConfigurePracticeWidget::hasChanged()";
00190     int toRow = LanguageToList->currentRow();
00191     if ( toRow <= LanguageFromList->currentRow() ) {
00192         toRow++;
00193     }
00195     return false;
00196         //LanguageFromList->currentRow() == Prefs::questionLanguage() &&
00197         //    toRow == Prefs::solutionLanguage();
00198 
00200 }
00201 
00202 bool ConfigurePracticeWidget::isDefault()
00203 {
00205     return true;
00206 //         LanguageFromList->currentRow() == 0 &&
00207 //         LanguageToList->currentRow() == 1;
00208 }
00209 
00210 void ConfigurePracticeWidget::writtenRadioToggled(bool checked)
00211 {
00212     if ( checked ) {
00213         OptionsGroupBox->setEnabled(true);
00214         m_optionsStackedLayout->setCurrentIndex(WrittenPractice);
00215     }
00216 }
00217 
00218 void ConfigurePracticeWidget::comparisonRadioToggled(bool checked)
00219 {
00220     if ( checked ) {
00221         OptionsGroupBox->setEnabled(true);
00222         m_optionsStackedLayout->setCurrentIndex(Comparison);
00223     }
00224 }
00225 
00226 void ConfigurePracticeWidget::conjugationRadioToggled(bool checked)
00227 {
00228     if ( checked ) {
00229         OptionsGroupBox->setEnabled(true);
00230         m_optionsStackedLayout->setCurrentIndex(Conjugation);
00231     }
00232 }
00233 
00234 void ConfigurePracticeWidget::otherRadioToggled(bool checked)
00235 {
00236     if ( checked ) {
00237         OptionsGroupBox->setEnabled(false);
00238         m_optionsStackedLayout->setCurrentIndex(Empty);
00239     }
00240 }
00241 
00242 void ConfigurePracticeWidget::setupTenses()
00243 {
00244     DocumentSettings currentSettings(m_doc->url().url());
00245     currentSettings.readConfig();
00246     QStringList activeTenses = currentSettings.conjugationTenses();
00247     QTreeWidgetItem* tenseItem;
00248 
00249     foreach ( QString tenseName, m_doc->tenseDescriptions() ) {
00250         tenseItem = new QTreeWidgetItem(m_tenseListWidget);
00251         tenseItem->setText(0, tenseName);
00252         if ( activeTenses.contains( tenseName ) ) {
00253             tenseItem->setCheckState(0, Qt::Checked);
00254         } else {
00255             tenseItem->setCheckState(0, Qt::Unchecked);
00256         }
00257         tenseItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
00258         m_tenseListWidget->addTopLevelItem( tenseItem );
00259     }
00261 }
00262 
00263 void ConfigurePracticeWidget::monolingualPracticeSelected(bool selected)
00264 {
00265     if (selected) {
00266         LanguageToList->setEnabled(false);
00267         m_bilingual = false;
00268     }
00269 }
00270 
00271 void ConfigurePracticeWidget::bilingualPracticeSelected(bool selected)
00272 {
00273     if (selected) {
00274         LanguageToList->setEnabled(true);
00275         m_bilingual = true;
00276     }
00277 }
00278 
00279 #include "configurepracticewidget.moc"

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