• Skip to content
  • Skip to link menu
KDE 4.4 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 #include "ui_multiplechoiceoptionswidget.h"
00026 #include "ui_flashcardsoptionswidget.h"
00027 
00028 #include "languagesettings.h"
00029 #include "documentsettings.h"
00030 #include "prefs.h"
00031 
00032 #include <keduvocdocument.h>
00033 
00034 #include <KStandardDirs>
00035 #include <KLocale>
00036 #include <QStackedLayout>
00037 #include <QLabel>
00038 #include <QtDBus>
00039 
00044 ConfigurePracticeWidget::ConfigurePracticeWidget(KEduVocDocument* doc, QWidget * parent)
00045     : QWidget(parent)
00046 {
00047     m_doc = doc;
00048     m_bilingual = true;
00049 
00050     setupUi(this);
00051 
00052     for ( int i = 0; i < m_doc->identifierCount(); i++ ) {
00053         LanguageSettings currentSettings(m_doc->identifier(i).locale());
00054         currentSettings.readConfig();
00055         QString icon = currentSettings.icon();
00056         if (icon.isEmpty()) {
00057             icon = QString("set-language");
00058         }
00059         LanguageFromList->addItem( new QListWidgetItem( KIcon(icon), m_doc->identifier(i).name() ) );
00060     }
00061 
00062     OptionsGroupBox->setEnabled( false );
00063     m_optionsStackedLayout = new QStackedLayout(OptionsGroupBox);
00064     OptionsGroupBox->setLayout(m_optionsStackedLayout);
00065 
00066     // the widgets have to be inserted in order of the enum because insert appends if the index is too great
00067     m_optionsStackedLayout->insertWidget(Empty, new QLabel(i18n("No options"), OptionsGroupBox));
00068 
00069     // add the written practice ui to the stacked widget
00070     QWidget* writtenContainer = new QWidget(OptionsGroupBox);
00071     Ui::WrittenPracticeOptionsWidget writtenPracticeUi;
00072     writtenPracticeUi.setupUi(writtenContainer);
00073     m_optionsStackedLayout->insertWidget(WrittenPractice, writtenContainer);
00074 
00075     // add the muliple choice practice ui to the stacked widget
00076     QWidget* multipleChoiceContainer = new QWidget(OptionsGroupBox);
00077     Ui::MultipleChoiceOptionsWidget multipleChoiceUi;
00078     multipleChoiceUi.setupUi(multipleChoiceContainer);
00079     m_optionsStackedLayout->insertWidget(MultipleChoice, multipleChoiceContainer);
00080 
00081     // add the conjugation ui to the stacked widget
00082     QWidget* conjugationContainer = new QWidget(OptionsGroupBox);
00083     m_conjugationUi.setupUi(conjugationContainer);
00084     m_optionsStackedLayout->insertWidget(Conjugation, conjugationContainer);
00085 
00086     // add the comparison ui to the stacked widget
00087     QWidget* comparisonContainer = new QWidget(OptionsGroupBox);
00088     Ui::ComparisonOptionsWidget comparisonUi;
00089     comparisonUi.setupUi(comparisonContainer);
00090     m_optionsStackedLayout->insertWidget(Comparison, comparisonContainer);
00091 
00092     // add the flashcard ui
00093     QWidget* flashcardsContainer = new QWidget(OptionsGroupBox);
00094     Ui::FlashCardsOptionsWidget flashcardsUi;
00095     flashcardsUi.setupUi(flashcardsContainer);
00096     m_optionsStackedLayout->insertWidget(FlashCards, flashcardsContainer);
00097 
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(LanguageFromList, SIGNAL(currentRowChanged(int)), SLOT(fromLanguageSelected(int)));
00105     LanguageFromList->setCurrentRow(Prefs::questionLanguage());
00106 
00107     setupTenses();
00108 
00109     connect(AntonymRadio, SIGNAL(toggled(bool)), SLOT(otherRadioToggled(bool)));
00110     connect(ArticleRadio, SIGNAL(toggled(bool)), SLOT(otherRadioToggled(bool)));
00111     connect(ExampleRadio, SIGNAL(toggled(bool)), SLOT(otherRadioToggled(bool)));
00112     connect(MixedLettersRadio, SIGNAL(toggled(bool)), SLOT(otherRadioToggled(bool)));
00113     connect(MultipleChoiceRadio, SIGNAL(toggled(bool)), SLOT(otherRadioToggled(bool)));
00114     connect(ParaphraseRadio, SIGNAL(toggled(bool)), SLOT(otherRadioToggled(bool)));
00115     connect(SynonymRadio, SIGNAL(toggled(bool)), SLOT(otherRadioToggled(bool)));
00116 
00117 //    connect(FlashCardsRadio, SIGNAL(toggled(bool)), SLOT(flashCardsRadioToggled(bool)));
00118     connect(WrittenRadio, SIGNAL(toggled(bool)), SLOT(writtenRadioToggled(bool)));
00119     connect(ComparisonRadio, SIGNAL(toggled(bool)), SLOT(comparisonRadioToggled(bool)));
00120     connect(ConjugationRadio, SIGNAL(toggled(bool)), SLOT(conjugationRadioToggled(bool)));
00121     connect(MultipleChoiceRadio, SIGNAL(toggled(bool)), SLOT(multipleChoiceRadioToggled(bool)));
00122 
00123 
00124     // mono/bilingual - practice effects one/two languages - change the language selection accordingly
00125     connect(WrittenRadio, SIGNAL(toggled(bool)), SLOT(bilingualPracticeSelected(bool)));
00126     connect(MixedLettersRadio, SIGNAL(toggled(bool)), SLOT(bilingualPracticeSelected(bool)));
00127     connect(MultipleChoiceRadio, SIGNAL(toggled(bool)), SLOT(bilingualPracticeSelected(bool)));
00128 //    connect(FlashCardsRadio, SIGNAL(toggled(bool)), SLOT(bilingualPracticeSelected(bool)));
00129 
00130 
00131     connect(ArticleRadio, SIGNAL(toggled(bool)), SLOT(monolingualPracticeSelected(bool)));
00132     connect(ExampleRadio, SIGNAL(toggled(bool)), SLOT(monolingualPracticeSelected(bool)));
00133     connect(ParaphraseRadio, SIGNAL(toggled(bool)), SLOT(monolingualPracticeSelected(bool)));
00134     connect(SynonymRadio, SIGNAL(toggled(bool)), SLOT(monolingualPracticeSelected(bool)));
00135     connect(AntonymRadio, SIGNAL(toggled(bool)), SLOT(monolingualPracticeSelected(bool)));
00136     connect(ComparisonRadio, SIGNAL(toggled(bool)), SLOT(monolingualPracticeSelected(bool)));
00137     connect(ConjugationRadio, SIGNAL(toggled(bool)), SLOT(monolingualPracticeSelected(bool)));
00138 }
00139 
00140 
00141 void ConfigurePracticeWidget::updateSettings()
00142 {
00143     Prefs::setQuestionLanguage(LanguageFromList->currentRow());
00144     if (m_bilingual) {
00145         Prefs::setSolutionLanguage(LanguageToList->currentItem()->data(Qt::UserRole).toInt());
00146     } else {
00147         Prefs::setSolutionLanguage(LanguageFromList->currentRow());
00148     }
00149 
00150     QTreeWidgetItem* parentItem = m_conjugationUi.tenseSelectionTreeWidget->invisibleRootItem();
00151     QStringList activeTenses;
00152     for ( int i = 0; i < parentItem->childCount(); i++ ) {
00153         QTreeWidgetItem* tenseItem = parentItem->child(i);
00154         if ( tenseItem->checkState(0) == Qt::Checked ) {
00155             activeTenses.append(tenseItem->text(0));
00156         }
00157     }
00158 
00159     DocumentSettings documentSettings(m_doc->url().url());
00160     documentSettings.setConjugationTenses(activeTenses);
00161     documentSettings.writeConfig();
00162 }
00163 
00164 void ConfigurePracticeWidget::fromLanguageSelected(int identifierFromIndex)
00165 {
00166     LanguageToList->clear();
00167     for ( int i = 0; i < m_doc->identifierCount(); i++ ) {
00168         if ( i != identifierFromIndex ) {
00169 
00170             LanguageSettings currentSettings(m_doc->identifier(i).locale());
00171             currentSettings.readConfig();
00172             QString icon = currentSettings.icon();
00173             if (icon.isEmpty()) {
00174                 icon = QString("set-language");
00175             }
00176             LanguageToList->addItem( new QListWidgetItem( KIcon(icon), m_doc->identifier(i).name() ) );
00177 
00178             LanguageToList->item(LanguageToList->count()-1)->setData(Qt::UserRole, i);
00179             if ( i == Prefs::solutionLanguage() ) {
00180                 LanguageToList->setCurrentRow(i);
00181             }
00182         }
00183     }
00184     if ( LanguageToList->currentRow() < 0 ) {
00185         LanguageToList->setCurrentRow(0);
00186     }
00187     setupTenses();
00188 }
00189 
00190 void ConfigurePracticeWidget::updateWidgets()
00191 {
00192     LanguageFromList->setCurrentRow(Prefs::questionLanguage());
00193 }
00194 
00195 bool ConfigurePracticeWidget::hasChanged()
00196 {
00197     kDebug()<< "ConfigurePracticeWidget::hasChanged()";
00198     int toRow = LanguageToList->currentRow();
00199     if ( toRow <= LanguageFromList->currentRow() ) {
00200         toRow++;
00201     }
00202     if (LanguageFromList->currentRow() == Prefs::questionLanguage() &&
00203         toRow == Prefs::solutionLanguage())
00204         return false;
00205 
00206     return true;
00207 
00209 }
00210 
00211 bool ConfigurePracticeWidget::isDefault()
00212 {
00214     return true;
00215 //         LanguageFromList->currentRow() == 0 &&
00216 //         LanguageToList->currentRow() == 1;
00217 }
00218 
00219 void ConfigurePracticeWidget::writtenRadioToggled(bool checked)
00220 {
00221     if ( checked ) {
00222         OptionsGroupBox->setEnabled(true);
00223         m_optionsStackedLayout->setCurrentIndex(WrittenPractice);
00224     }
00225 }
00226 
00227 
00228 void ConfigurePracticeWidget::multipleChoiceRadioToggled(bool checked)
00229 {
00230     if ( checked ) {
00231         OptionsGroupBox->setEnabled(true);
00232         m_optionsStackedLayout->setCurrentIndex(MultipleChoice);
00233     }
00234 }
00235 
00236 
00237 void ConfigurePracticeWidget::comparisonRadioToggled(bool checked)
00238 {
00239     if ( checked ) {
00240         OptionsGroupBox->setEnabled(true);
00241         m_optionsStackedLayout->setCurrentIndex(Comparison);
00242     }
00243 }
00244 
00245 void ConfigurePracticeWidget::conjugationRadioToggled(bool checked)
00246 {
00247     if ( checked ) {
00248         OptionsGroupBox->setEnabled(true);
00249         m_optionsStackedLayout->setCurrentIndex(Conjugation);
00250     }
00251 }
00252 
00253 
00254 void ConfigurePracticeWidget::flashCardsRadioToggled(bool checked)
00255 {
00256     if ( checked ) {
00257         OptionsGroupBox->setEnabled(true);
00258         m_optionsStackedLayout->setCurrentIndex(FlashCards);
00259     }
00260 }
00261 
00262 void ConfigurePracticeWidget::otherRadioToggled(bool checked)
00263 {
00264     if ( checked ) {
00265         OptionsGroupBox->setEnabled(false);
00266         m_optionsStackedLayout->setCurrentIndex(Empty);
00267     }
00268 }
00269 
00270 void ConfigurePracticeWidget::setupTenses()
00271 {
00272     int index = LanguageFromList->currentRow();
00273     if (index < 0) {
00274         index = 0;
00275     }
00276 
00277     QTreeWidget *tenseListWidget = m_conjugationUi.tenseSelectionTreeWidget;
00278     tenseListWidget->clear();
00279 
00280     // stack widget - select the right index
00281     if ( m_doc->identifier(index).tenseList().isEmpty() ) {
00282         // help message
00283         m_conjugationUi.conjugationStack->setCurrentIndex(1);
00284         return;
00285     }
00286 
00287     // the tense list
00288     m_conjugationUi.conjugationStack->setCurrentIndex(0);
00289 
00290     DocumentSettings currentSettings(m_doc->url().url() + QString::number(index));
00291     currentSettings.readConfig();
00292     QStringList activeTenses = currentSettings.conjugationTenses();
00293     QTreeWidgetItem* tenseItem;
00294 
00295     foreach ( const QString &tenseName, m_doc->identifier(index).tenseList() ) {
00296         tenseItem = new QTreeWidgetItem(tenseListWidget);
00297         tenseItem->setText(0, tenseName);
00298         if ( activeTenses.contains( tenseName ) ) {
00299             tenseItem->setCheckState(0, Qt::Checked);
00300         } else {
00301             tenseItem->setCheckState(0, Qt::Unchecked);
00302         }
00303         tenseItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
00304         tenseListWidget->addTopLevelItem( tenseItem );
00305     }
00307 }
00308 
00309 void ConfigurePracticeWidget::monolingualPracticeSelected(bool selected)
00310 {
00311     if (selected) {
00312         LanguageToList->setEnabled(false);
00313         m_bilingual = false;
00314     }
00315 }
00316 
00317 void ConfigurePracticeWidget::bilingualPracticeSelected(bool selected)
00318 {
00319     if (selected) {
00320         LanguageToList->setEnabled(true);
00321         m_bilingual = true;
00322     }
00323 }
00324 
00325 #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"
  •     lib
  • kalzium
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  •   stepcore
Generated for kdeedu by doxygen 1.5.9-20090814
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