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

parley

CommonEntryPage.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002 
00003                        edit common properties
00004 
00005     -----------------------------------------------------------------------
00006 
00007     begin         : Mon Jun 28 21:02:16 1999
00008 
00009     copyright     : (C) 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
00010                     (C) 2005-2007 Peter Hedlund <peter.hedlund@kdemail.net>
00011                     (C) 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
00012 
00013     -----------------------------------------------------------------------
00014 
00015  ***************************************************************************/
00016 
00017 /***************************************************************************
00018  *                                                                         *
00019  *   This program is free software; you can redistribute it and/or modify  *
00020  *   it under the terms of the GNU General Public License as published by  *
00021  *   the Free Software Foundation; either version 2 of the License, or     *
00022  *   (at your option) any later version.                                   *
00023  *                                                                         *
00024  ***************************************************************************/
00025 
00026 #include "CommonEntryPage.h"
00027 
00028 #include <QLineEdit>
00029 #include <QLabel>
00030 #include <QComboBox>
00031 #include <QCheckBox>
00032 #include <QGroupBox>
00033 #include <QPixmap>
00034 
00035 #include <kdebug.h>
00036 #include <klocale.h>
00037 #include <kicon.h>
00038 #include <kdialog.h>
00039 
00040 #include "practice/testentrymanager.h"
00041 #include "docprop-dialogs/UsageOptPage.h"
00042 #include "docprop-dialogs/TypeOptPage.h"
00043 
00044 #include "PhoneticEntryPage.h"
00045 #include "EntryDlg.h"
00046 
00047 CommonEntryPage::CommonEntryPage(KEduVocDocument *doc, QWidget *parent) : QWidget(parent), m_doc(doc)
00048 {
00049     setupUi(this);
00050 
00051     m_wordTypes = m_doc->wordTypes();
00052 
00053     // subdialogs
00054     connect(b_usageDlg, SIGNAL(clicked()), SLOT(invokeUsageDlg()));
00055     connect(b_pronDlg, SIGNAL(clicked()), SLOT(invokePronDlg()));
00056     connect(b_TypeDlg, SIGNAL(clicked()), SLOT(invokeTypeDlg()));
00057 
00058     // in general only the modified state interests us.
00059     connect(usage_box, SIGNAL(itemSelectionChanged()), this, SLOT(slotDataChanged()));
00060     // to update the usage label
00061     connect(usage_box, SIGNAL(itemSelectionChanged()), this, SLOT(slotUsageChanged()));
00062     connect(lesson_box, SIGNAL(activated(int)), SLOT(slotDataChanged(int)));
00063     connect(subtype_box, SIGNAL(activated(int)), SLOT(slotDataChanged(int)));
00064     connect(c_active, SIGNAL(stateChanged(int)), SLOT(slotDataChanged(int)));
00065     connect(pronounce_line, SIGNAL(textChanged(const QString&)), SLOT(slotDataChanged(const QString&)));
00066     connect(expr_line, SIGNAL(textChanged(const QString&)), SLOT(slotDataChanged(const QString&)));
00067 
00068     connect(type_box, SIGNAL(activated(int)), SLOT(slotDataChanged(int)));
00069     // type is tricky - need to update subtype
00070     connect(type_box, SIGNAL(activated(const QString&)), SLOT(slotTypeBoxChanged(const QString&)));
00071 
00072 
00073     usage_label->setTitle(i18nc("Usage (area) of an Expression", "&Usage Labels"));
00074     pronounce_line->setFont(Prefs::iPAFont());
00075 
00076     QIcon list_pm = KIcon("list");
00077 
00078     b_TypeDlg->setIcon(list_pm);
00079     b_usageDlg->setIcon(list_pm);
00080 
00081     QIcon pron_pm = KIcon("character-set");
00082     b_pronDlg->setIcon(pron_pm);
00083 
00084     subDialog = 0;
00085 
00086     m_currentTranslation = -1;
00087 }
00088 
00089 
00090 void CommonEntryPage::setData(const QList<int>& entries, int currentTranslation)
00091 {
00092     m_currentTranslation = currentTranslation;
00093     m_entries = entries;
00094 
00095     bool editSingleEntry = (m_entries.count() == 1);
00096     //disable fields that cannot be changed for multiple, enable them if only one entry is edited
00097     expr_line->setEnabled(editSingleEntry);
00098     pronounce_line->setEnabled(editSingleEntry);
00099 
00100     KEduVocExpression *firstEntry = m_doc->entry(m_entries.value(0));
00101     // set these to the first entry, check if that's ok later
00102     setLessonBox(firstEntry->lesson());
00103     setUsageSelection(firstEntry->translation(m_currentTranslation).usages().values());
00104 
00105     c_active->setChecked(firstEntry->isActive());
00106 
00107     updateMainTypeBoxContents();
00108 
00109 
00110     QString mainType =
00111         m_doc->entry(m_entries.value(0))->
00112             translation(m_currentTranslation).type();
00113     QString subType =
00114         m_doc->entry(m_entries.value(0))->
00115             translation(m_currentTranslation).subType();
00116 
00117     type_box->setCurrentIndex( type_box->findText( mainType ) );
00118     slotTypeBoxChanged( mainType );
00119     subtype_box->setCurrentIndex( subtype_box->findText( subType ) );
00120 
00121     if (editSingleEntry) {
00122         c_active->setTristate(false);
00123         // these can only be edited in single mode
00124         expr_line->setText(m_doc->entry(m_entries.value(0))->translation(m_currentTranslation).text());
00125 
00126         pronounce_line->setText(m_doc->entry(m_entries.value(0))->translation(m_currentTranslation).pronunciation());
00127 
00128     } else { // edit more than one entry
00129         c_active->setTristate(true);
00130         expr_line->setText("");
00131         pronounce_line->setText("");
00132 
00133         // fill enabled fields if equal for all edited entries, otherwise empty.
00134         foreach ( int entry, m_entries) {
00135             KEduVocExpression *currentEntry = m_doc->entry(entry);
00136             if ( firstEntry->lesson() != currentEntry->lesson() ) {
00137                 lesson_box->setCurrentIndex(-1);
00138             }
00139 
00141             if ( firstEntry->translation(m_currentTranslation).type()
00142                     != currentEntry->translation(m_currentTranslation).type()) {
00143                 type_box->setCurrentIndex(-1);
00144                 subtype_box->setCurrentIndex(-1);
00145             }
00146             if ( firstEntry->translation(m_currentTranslation).usages()
00147                     != currentEntry->translation(m_currentTranslation).usages()) {
00148                 setUsageSelection(QStringList());
00149                 m_usageIsModified = false;
00150             }
00151             if ( firstEntry->isActive() != currentEntry->isActive() ) {
00152                 kDebug() << "Setting active box to PartiallyChecked.";
00153                 c_active->setCheckState(Qt::PartiallyChecked);
00154             }
00155         } // foreach
00156     } // edit more than one entry
00157 
00158     m_usageIsModified = false;
00159 }
00160 
00161 
00162 void CommonEntryPage::setLessonBox(int lesson)
00163 {
00164     lesson_box->clear();
00166     lesson_box->addItems(m_doc->lessonNames());
00167     lesson_box->setCurrentIndex(lesson);
00168 }
00169 
00170 
00171 void CommonEntryPage::setUsageSelection(const QStringList& usageList)
00172 {
00173     usage_box->clear();
00174     QStringList docUsages = m_doc->usages(); //KVTUsage::getRelation();
00175 
00176     for (int i = 0; i < (int) docUsages.size(); i++) {
00177         usage_box->addItem(docUsages.value(i));
00178         if ( usageList.contains(docUsages.value(i))) {
00179             usage_box->setCurrentRow(i);
00180         }
00181     }
00182     slotUsageChanged();
00183 }
00184 
00185 
00186 void CommonEntryPage::slotUsageChanged()
00187 {
00188     QString s;
00189 
00190     for (int i = 0; i < usage_box->count(); i++) {
00191         if (usage_box->item(i)->isSelected()) {
00192             if (!s.isEmpty()) {
00193                 s.append('\n');
00194             }
00195             s += usage_box->item(i)->text();
00196         }
00197     }
00198     usage_line->setText(s);
00199     m_usageIsModified = true;
00200 }
00201 
00202 
00203 void CommonEntryPage::slotTypeBoxChanged(const QString &mainType)
00204 {
00205     subtype_box->clear();
00206     subtype_box->addItems( m_wordTypes.subTypeNameList(mainType) );
00207 kDebug() << "fill subType box" << mainType;
00208     subtype_box->setCurrentIndex(-1);
00209 
00210     emit signalTypeSelected( mainType );
00211 }
00212 
00213 
00214 void CommonEntryPage::phoneticSelected(const QChar& c)
00215 {
00216     pronounce_line->setText( pronounce_line->text() += c );
00217     emit sigModified();
00218 }
00219 
00220 
00221 void CommonEntryPage::invokePronDlg()
00222 {
00223     PhoneticEntryPage * phoneticDlg = new PhoneticEntryPage(Prefs::iPAFont(), this);
00224     connect(phoneticDlg, SIGNAL(charSelected(const QChar&)), SLOT(phoneticSelected(const QChar&)));
00225     phoneticDlg->show();
00226 }
00227 
00228 
00229 void CommonEntryPage::invokeUsageDlg()
00230 {
00231 
00232     QStringList usages;
00233     for (int i = 0; i < usage_box->count(); i++) {
00234         if (usage_box->item(i)->isSelected()) {
00235             usages.append(usage_box->item(i)->text());
00236         }
00237     }
00238 
00239     KDialog *subDialog= new KDialog(b_usageDlg);
00240     subDialog->setCaption(i18nc("usage (area) of an expression", "Edit User-Defined Usage Labels"));
00241     subDialog->setButtons(KDialog::Ok|KDialog::Cancel);
00242 
00243     subDialog->setDefaultButton(KDialog::Ok);
00244 
00245     connect(subDialog, SIGNAL(finished()), this, SLOT(slotSubDialogClosed()));
00246 
00247     UsageOptPage *usageOptPage = new UsageOptPage(m_doc, this);
00248     subDialog->setMainWidget(usageOptPage);
00249 
00250     if (subDialog->exec() == KDialog::Accepted) {
00251         usageOptPage->accept();
00252         setUsageSelection( usages );
00253     }
00254 }
00255 
00256 
00257 void CommonEntryPage::invokeTypeDlg()
00258 {
00259     KDialog *subDialog = new KDialog(b_TypeDlg);
00260     subDialog->setCaption(i18n("Edit User Defined Types"));
00261     subDialog->setButtons(KDialog::Ok|KDialog::Cancel);
00262 
00263     subDialog->setDefaultButton(KDialog::Ok);
00264 
00265     connect(subDialog, SIGNAL(finished()), this, SLOT(slotSubDialogClosed()));
00266 
00267     WordTypeOptionPage *typeOptPage = new WordTypeOptionPage(m_doc, this);
00268     subDialog->setMainWidget(typeOptPage);
00269 
00270     if (subDialog->exec() == KDialog::Accepted) {
00271         updateMainTypeBoxContents();
00272     }
00273 }
00274 
00275 
00276 void CommonEntryPage::slotSubDialogClosed()
00277 {
00278     if (subDialog) {
00279         disconnect(subDialog, SIGNAL(finished()), this, SLOT(slotSubDialogClosed()));
00280         subDialog->deleteLater();
00281         subDialog = 0;
00282     }
00283 }
00284 
00285 void CommonEntryPage::commitData()
00286 {
00287     if ( m_entries.count() == 1 ) {
00288     // these things are only changed when editing a single entry
00289         KEduVocExpression *expr = m_doc->entry(m_entries.value(0));
00290         if (m_currentTranslation >= 0) {
00291             expr->translation(m_currentTranslation).setText( expr_line->text() );
00292             expr->translation(m_currentTranslation).setPronunciation( pronounce_line->text() );
00293         }
00294     }
00295 
00296     // things that are changed for multiple or single entries
00297 
00298     foreach(int entry, m_entries) {
00299         kDebug() << "Changing multiple entries - entry: " << entry;
00300         KEduVocExpression *expr = m_doc->entry(entry);
00301 
00302         // modified because it can be different for multiple entries and will only be saved if the user changes it. if partially checked no entry will be changed.
00303         if ( c_active->checkState() != Qt::PartiallyChecked ) {
00304             expr->setActive( c_active->checkState() == Qt::Checked );
00305         }
00306         if ( lesson_box->currentIndex() != -1 ) {
00307             //m_tableModel->setData(m_tableModel->index(index.m_entries.value(0)(), 0), getLesson(), Qt::EditRole);
00308             expr->setLesson( lesson_box->currentIndex() );
00309         }
00310 
00311         if (m_currentTranslation >= 0) {
00312             if (m_usageIsModified) {
00313                 QSet<QString> usages;
00314                 for (int i = 0; i < usage_box->count(); i++) {
00315                     if (usage_box->item(i)->isSelected()) {
00316                         usages.insert(usage_box->item(i)->text());
00317                     }
00318                 }
00319                 expr->translation(m_currentTranslation).setUsages( usages );
00320             }
00321             if ( type_box->currentIndex() != -1 ) {
00322                 QString type = type_box->currentText();
00323                 // set the type
00324                 expr->translation(m_currentTranslation).setType( type_box->currentText() );
00325                 expr->translation(m_currentTranslation).setSubType( subtype_box->currentText() );
00326                 // also set the same type for the other translations
00327                 foreach (int j, expr->translationIndices()) {
00328                     if (expr->translation(j).type().isEmpty())
00329                         expr->translation(j).setType( type );
00331                 }
00332             } // type
00333         }
00334     }
00335     m_usageIsModified = false;
00336 }
00337 
00338 void CommonEntryPage::slotDataChanged()
00339 {
00340     emit sigModified();
00341 }
00342 
00343 void CommonEntryPage::slotDataChanged(int )
00344 {
00345     emit sigModified();
00346 }
00347 
00348 void CommonEntryPage::slotDataChanged(const QString& )
00349 {
00350     emit sigModified();
00351 }
00352 
00353 void CommonEntryPage::updateMainTypeBoxContents()
00354 {
00355     type_box->clear();
00356     type_box->addItems( m_wordTypes.typeNameList() );
00357 }
00358 
00359 
00360 #include "CommonEntryPage.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