00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00067 m_optionsStackedLayout->insertWidget(Empty, new QLabel(i18n("No options"), OptionsGroupBox));
00068
00069
00070 QWidget* writtenContainer = new QWidget(OptionsGroupBox);
00071 Ui::WrittenPracticeOptionsWidget writtenPracticeUi;
00072 writtenPracticeUi.setupUi(writtenContainer);
00073 m_optionsStackedLayout->insertWidget(WrittenPractice, writtenContainer);
00074
00075
00076 QWidget* multipleChoiceContainer = new QWidget(OptionsGroupBox);
00077 Ui::MultipleChoiceOptionsWidget multipleChoiceUi;
00078 multipleChoiceUi.setupUi(multipleChoiceContainer);
00079 m_optionsStackedLayout->insertWidget(MultipleChoice, multipleChoiceContainer);
00080
00081
00082 QWidget* conjugationContainer = new QWidget(OptionsGroupBox);
00083 m_conjugationUi.setupUi(conjugationContainer);
00084 m_optionsStackedLayout->insertWidget(Conjugation, conjugationContainer);
00085
00086
00087 QWidget* comparisonContainer = new QWidget(OptionsGroupBox);
00088 Ui::ComparisonOptionsWidget comparisonUi;
00089 comparisonUi.setupUi(comparisonContainer);
00090 m_optionsStackedLayout->insertWidget(Comparison, comparisonContainer);
00091
00092
00093 QWidget* flashcardsContainer = new QWidget(OptionsGroupBox);
00094 Ui::FlashCardsOptionsWidget flashcardsUi;
00095 flashcardsUi.setupUi(flashcardsContainer);
00096 m_optionsStackedLayout->insertWidget(FlashCards, flashcardsContainer);
00097
00098
00099
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
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
00216
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
00274 QTreeWidget *tenseListWidget = m_conjugationUi.tenseSelectionTreeWidget;
00275 tenseListWidget->clear();
00276
00277
00278 if ( m_doc->identifier(index).tenseList().isEmpty() ) {
00279
00280 m_conjugationUi.conjugationStack->setCurrentIndex(1);
00281 return;
00282 }
00283
00284
00285 m_conjugationUi.conjugationStack->setCurrentIndex(0);
00286
00287 DocumentSettings currentSettings(m_doc->url().url() + QString::number(index));
00288 currentSettings.readConfig();
00289 QStringList activeTenses = currentSettings.conjugationTenses();
00290 QTreeWidgetItem* tenseItem;
00291
00292 foreach ( const QString &tenseName, m_doc->identifier(index).tenseList() ) {
00293 tenseItem = new QTreeWidgetItem(tenseListWidget);
00294 tenseItem->setText(0, tenseName);
00295 if ( activeTenses.contains( tenseName ) ) {
00296 tenseItem->setCheckState(0, Qt::Checked);
00297 } else {
00298 tenseItem->setCheckState(0, Qt::Unchecked);
00299 }
00300 tenseItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
00301 tenseListWidget->addTopLevelItem( tenseItem );
00302 }
00304 }
00305
00306 void ConfigurePracticeWidget::monolingualPracticeSelected(bool selected)
00307 {
00308 if (selected) {
00309 LanguageToList->setEnabled(false);
00310 m_bilingual = false;
00311 }
00312 }
00313
00314 void ConfigurePracticeWidget::bilingualPracticeSelected(bool selected)
00315 {
00316 if (selected) {
00317 LanguageToList->setEnabled(true);
00318 m_bilingual = true;
00319 }
00320 }
00321
00322 #include "configurepracticewidget.moc"