parley
documentproperties.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "documentproperties.h"
00027
00028 #include "parleydocument.h"
00029
00030 #include <keduvocdocument.h>
00031 #include <KDebug>
00032 #include <KLineEdit>
00033
00034 #include <QTextEdit>
00035 #include <QLabel>
00036
00037
00038 DocumentProperties::DocumentProperties(KEduVocDocument * doc, bool languageSetup, QWidget* parent)
00039 :QWidget(parent), m_doc(doc), m_showLanguages(languageSetup)
00040 {
00041 setupUi(this);
00042
00043 titleLineEdit->setText(doc->title());
00044 authorLineEdit->setText(doc->author());
00045 contactLineEdit->setText(doc->authorContact());
00046 licenseComboBox->setEditText(doc->license());
00047 commentTextEdit->setText(doc->documentComment());
00048 categoryComboBox->setEditText(doc->category());
00049
00050 if (languageSetup) {
00051 prepareLanguageSelection();
00052 } else {
00053 languageGroupBox->setVisible(false);
00054 }
00055 }
00056
00057 void DocumentProperties::prepareLanguageSelection()
00058 {
00059 QStringList codes = KGlobal::locale()->allLanguagesList();
00060 QStringList languageNames;
00061 foreach (const QString &code, codes){
00062 languageNames.append( KGlobal::locale()->languageCodeToName(code) );
00063 }
00064 languageNames.sort();
00065
00066 firstLanguageComboBox->addItems(languageNames);
00067 firstLanguageComboBox->completionObject()->insertItems(languageNames);
00068 firstLanguageComboBox->completionObject()->setIgnoreCase(true);
00069 secondLanguageComboBox->addItems(languageNames);
00070 secondLanguageComboBox->completionObject()->insertItems(languageNames);
00071 secondLanguageComboBox->completionObject()->setIgnoreCase(true);
00072
00073 languageGroupBox->setVisible(true);
00074 }
00075
00076 void DocumentProperties::accept()
00077 {
00078 ParleyDocument::instance()->setTitle(titleLineEdit->text());
00079 m_doc->setAuthor(authorLineEdit->text());
00080 m_doc->setAuthorContact(contactLineEdit->text());
00081 m_doc->setLicense(licenseComboBox->currentText());
00082 m_doc->setDocumentComment(commentTextEdit->toPlainText());
00083 m_doc->setCategory(categoryComboBox->currentText());
00084
00085 if (m_showLanguages) {
00086 acceptLanguageConfiguration();
00087 }
00088 }
00089
00090 void DocumentProperties::acceptLanguageConfiguration()
00091 {
00092 QString firstLanguage = firstLanguageComboBox->currentText();
00093 QString firstLocale;
00094 QString secondLanguage = secondLanguageComboBox->currentText();
00095 QString secondLocale;
00096
00097
00098 foreach ( const QString &code, KGlobal::locale()->allLanguagesList() ) {
00099 if ( firstLanguage == KGlobal::locale()->languageCodeToName(code) ) {
00100 firstLocale = code;
00101 }
00102 if ( secondLanguage == KGlobal::locale()->languageCodeToName(code) ) {
00103 secondLocale = code;
00104 }
00105 }
00106
00107 m_doc->identifier(0).setLocale(firstLocale);
00108 m_doc->identifier(0).setName(firstLanguage);
00109 m_doc->identifier(1).setLocale(secondLocale);
00110 m_doc->identifier(1).setName(secondLanguage);
00111 }
00112
00113 #include "documentproperties.moc"