diff --git a/keduvocdocument/CMakeLists.txt b/keduvocdocument/CMakeLists.txt index 3ccde2c..4c7aa8e 100644 --- a/keduvocdocument/CMakeLists.txt +++ b/keduvocdocument/CMakeLists.txt @@ -1,215 +1,218 @@ if (BUILD_TESTING) add_subdirectory(autotests) add_subdirectory(tests) endif() ########### next target ############### include(ECMSetupVersion) ecm_setup_version(5.0.0 VARIABLE_PREFIX KDEEDU VERSION_HEADER "${CMAKE_BINARY_DIR}/keduvocdocument/keduvocdocument_version.h" PACKAGE_VERSION_FILE "${CMAKE_BINARY_DIR}/KEduVocDocumentVersion.cmake") include_directories( ${CMAKE_CURRENT_BINARY_DIR} ) set(keduvocdocument_LIB_SRCS keduvocdocument.cpp keduvocidentifier.cpp keduvocexpression.cpp keduvoctranslation.cpp keduvoccontainer.cpp keduvoclesson.cpp keduvocleitnerbox.cpp keduvoctext.cpp keduvocarticle.cpp keduvocconjugation.cpp keduvocpersonalpronoun.cpp keduvocdeclension.cpp keduvocwordtype.cpp keduvockvtmlcompability.cpp keduvockvtml2writer.cpp keduvoccsvwriter.cpp keduvoccontainermodel.cpp keduvoclessonmodel.cpp keduvocreadonlycontainermodel.cpp keduvocvocabularymodel.cpp keduvocwordclassmodel.cpp keduvoccontainermimedata.cpp keduvocvocabularymimedata.cpp keduvocvocabularyfilter.cpp keduvoctranslator.cpp keduvocvocabularydelegate.cpp keduvocvocabularyheaderview.cpp keduvocvocabularycolumnsdialog.cpp keduvoccontainerview.cpp keduvocvocabularyview.cpp keduvocwordtypeview.cpp keduvoclessonview.cpp keduvocaudiowidget.cpp keduvocmultiplechoicewidget.cpp keduvoccomparisonwidget.cpp keduvocdeclensionwidget.cpp keduvocconjugationwidget.cpp keduvocinflectionwidget.cpp keduvocimagewidget.cpp keduvocimagechooserwidget.cpp keduvocsynonymwidget.cpp + keduvocsummarywordwidget.cpp readerwriters/dummyreader.cpp readerwriters/failedreader.cpp readerwriters/keduvockvtmlreader.cpp readerwriters/keduvockvtml2reader.cpp readerwriters/keduvoccsvreader.cpp readerwriters/keduvocpaukerreader.cpp readerwriters/keduvocvokabelnreader.cpp readerwriters/keduvocwqlreader.cpp readerwriters/keduvocxdxfreader.cpp readerwriters/readermanager.cpp sharedkvtmlfiles.cpp ) ki18n_wrap_ui(keduvocdocument_LIB_SRCS keduvocaudiowidget.ui keduvocmultiplechoicewidget.ui keduvoccomparisonwidget.ui keduvocdeclensionwidget.ui keduvocconjugationwidget.ui keduvocimagechooserwidget.ui keduvocsynonymwidget.ui + keduvocsummarywordwidget.ui ) include(ECMGenerateHeaders) ecm_generate_headers( KdeEdu_HEADERS HEADER_NAMES KEduVocDocument KEduVocIdentifier KEduVocExpression KEduVocText KEduVocArticle KEduVocConjugation KEduVocLesson KEduVocLeitnerBox KEduVocContainer KEduVocWordFlags KEduVocMultipleChoice KEduVocTranslation KEduVocWordtype KEduVocPersonalPronoun SharedKVTMLFiles KEduVocDeclension KEduVocKVTML2Writer KEduVocContainerModel KEduVocLessonModel KEduVocReadOnlyContainerModel KEduVocVocabularyModel KEduVocWordClassModel KEduVocContainerMimeData KEduVocVocabularyMimeData KEduVocVocabularyFilter KEduVocTranslator KEduVocVocabularyDelegate KEduVocVocabularyHeaderView KEduVocVocabularyColumnsDialog KEduVocContainerView KEduVocVocabularyView KEduVocWordTypeView KEduVocLessonView KEduVocAudioWidget KEduVocMultipleChoiceWidget KEduVocComparisonWidget KEduVocDeclensionWidget KEduVocConjugationWidget KEduVocInflectionWidget KEduVocImageWidget KEduVocImageChooserWidget KEduVocSynonymWidget + KEduVocSummaryWordWidget REQUIRED_HEADERS KdeEdu_HEADERS ) add_library(KEduVocDocument SHARED ${keduvocdocument_LIB_SRCS}) generate_export_header(KEduVocDocument BASE_NAME KEduVocDocument) # vHanda: Add library alias? target_link_libraries(KEduVocDocument PUBLIC Qt5::Xml Qt5::Gui Qt5::Core Qt5::Widgets Qt5::DBus Qt5::Multimedia PRIVATE KF5::I18n KF5::KIOCore KF5::KIOFileWidgets KF5::KIOWidgets KF5::KIONTLM KF5::Archive KF5::Completion KF5::WidgetsAddons KF5::SonnetCore KF5::SonnetUi KF5::Notifications KF5::XmlGui ) # vHanda: Add Export Name? set_target_properties(KEduVocDocument PROPERTIES VERSION ${KDEEDU_VERSION_STRING} SOVERSION ${KDEEDU_SOVERSION} ) target_include_directories(KEduVocDocument INTERFACE "$") #Library for non-api unittests add_library(keduvocdocument_static STATIC ${keduvocdocument_LIB_SRCS}) set_target_properties(keduvocdocument_static PROPERTIES COMPILE_FLAGS -DKEDUVOCDOCUMENT_STATIC_DEFINE) target_link_libraries(keduvocdocument_static PUBLIC KF5::KIOCore Qt5::Xml Qt5::Core Qt5::Gui Qt5::Widgets Qt5::DBus Qt5::Multimedia PRIVATE KF5::I18n KF5::KIOCore KF5::KIOFileWidgets KF5::KIOWidgets KF5::KIONTLM KF5::Archive KF5::Completion KF5::WidgetsAddons KF5::SonnetCore KF5::SonnetUi KF5::Notifications KF5::XmlGui ) # if we want to set our own version instead of following kde generic #set(LIB_KEDUVOCDOCUMENT_VERSION "5.0.0") #set(LIB_KEDUVOCDOCUMENT_SOVERSION "5") #set_target_properties(keduvocdocument # PROPERTIES VERSION ${LIB_KEDUVOCDOCUMENT_VERSION} # SOVERSION ${LIB_KEDUVOCDOCUMENT_SOVERSION} #) install(TARGETS KEduVocDocument EXPORT LibKEduVocDocumentTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) ########### install files ############### install(FILES ${CMAKE_CURRENT_BINARY_DIR}/keduvocdocument_export.h ${KdeEdu_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/libkeduvocdocument COMPONENT Devel ) diff --git a/keduvocdocument/keduvocsummarywordwidget.cpp b/keduvocdocument/keduvocsummarywordwidget.cpp new file mode 100644 index 0000000..f6f5387 --- /dev/null +++ b/keduvocdocument/keduvocsummarywordwidget.cpp @@ -0,0 +1,253 @@ +/*************************************************************************** + + Copyright 2007 Frederik Gladhorn + Copyright 2008 Javier Goday + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "keduvocsummarywordwidget.h" + +#include "ui_keduvocsummarywordwidget.h" + +// Qt headers +#include +#include +#include +#include +#include +#include +#include +#include + +// KEduVocDocument +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Editor; + +class KEduVocSummaryWordWidget::Private +{ +public: + Private( KEduVocVocabularyFilter *model, KEduVocDocument *doc ); + + KEduVocVocabularyFilter *m_model; + KEduVocDocument *m_doc; + QDataWidgetMapper *m_mapper; + KEduVocWordClassModel *m_wordTypeModel; + QTreeView *m_wordTypeView; + KEduVocExpression *m_entry; + int m_translationId; + Ui::KEduVocSummaryWordWidget * m_ui; +}; + +KEduVocSummaryWordWidget::Private::Private( KEduVocVocabularyFilter *model, KEduVocDocument *doc ) +{ + m_doc = doc; + m_wordTypeModel = 0; + m_wordTypeView = 0; + m_entry = 0; + m_translationId = 0; + m_ui = new Ui::KEduVocSummaryWordWidget(); + Q_ASSERT( model ); + Q_ASSERT( m_doc ); + m_model = model; +} + +KEduVocSummaryWordWidget::KEduVocSummaryWordWidget( KEduVocVocabularyFilter *model, KEduVocDocument *doc, QWidget *parent ) + : QWidget(parent) + , d( new Private( model, doc ) ) +{ + d->m_ui->setupUi(this); + slotDocumentChanged( d->m_doc ); + + d->m_mapper = new QDataWidgetMapper( this ); + d->m_mapper->setModel( model ); + d->m_mapper->setItemDelegate( new KEduVocSummaryWordDelegate( this ) ); + + connect( d->m_ui->wordTypeComboBox, static_cast( &KComboBox::currentIndexChanged ), this, &KEduVocSummaryWordWidget::wordTypeSelected ); +} + +KEduVocSummaryWordWidget::~KEduVocSummaryWordWidget() +{ + delete d; +} + +void KEduVocSummaryWordWidget::setTranslation( KEduVocExpression *entry, int translation ) +{ + if( entry ) { + // we need to map the widgets relative to the translation (each translation has 9 columns) + d->m_mapper->clearMapping(); + + d->m_mapper->addMapping( d->m_ui->wordEntry, + KEduVocVocabularyModel::EntryColumnsMAX * translation + KEduVocVocabularyModel::Translation ); + //m_mapper->addMapping(wordTypeComboBox, + // VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::WordType); + d->m_mapper->addMapping( d->m_ui->pronunciationEntry, + KEduVocVocabularyModel::EntryColumnsMAX * translation + KEduVocVocabularyModel::Pronunciation ); + d->m_mapper->addMapping( d->m_ui->exampleEntry, + KEduVocVocabularyModel::EntryColumnsMAX * translation + KEduVocVocabularyModel::Example ); + d->m_mapper->addMapping( d->m_ui->paraphraseEntry, + KEduVocVocabularyModel::EntryColumnsMAX * translation + KEduVocVocabularyModel::Paraphrase ); + d->m_mapper->addMapping( d->m_ui->commentEntry, + KEduVocVocabularyModel::EntryColumnsMAX * translation + KEduVocVocabularyModel::Comment ); + + d->m_ui->languageLabel->setText( "" + d->m_doc->identifier( translation ).name() + "" ); + d->m_ui->lessonLabel->setText( entry->lesson()->name() ); + + setCurrentWordType( entry, translation ); + } else { + clear(); + } + + d->m_entry = entry; + d->m_translationId = translation; +} + +void KEduVocSummaryWordWidget::slotDocumentChanged( KEduVocDocument *doc ) +{ + d->m_doc = doc; + if( !d->m_doc ) { + qDebug() << "Set invalid document"; + delete d->m_wordTypeModel; + d->m_wordTypeModel = 0; + } else { + delete d->m_wordTypeView; + if (!d->m_wordTypeModel) { + qDebug() << "Create word type model for summary view"; + d->m_wordTypeModel = new KEduVocWordClassModel( this ); + } + d->m_wordTypeModel->setDocument( d->m_doc ); + d->m_wordTypeView = new QTreeView( this ); + d->m_wordTypeView->setModel( d->m_wordTypeModel ); + d->m_ui->wordTypeComboBox->setModel( d->m_wordTypeModel ); + d->m_ui->wordTypeComboBox->setView( d->m_wordTypeView ); + + d->m_wordTypeView->setColumnHidden( 1, true ); + d->m_wordTypeView->header()->setVisible( false ); + d->m_wordTypeView->setRootIsDecorated( true ); + d->m_wordTypeView->expandAll(); + } +} + + +void KEduVocSummaryWordWidget::slotSelectionChanged( const QItemSelection &itemSelected, + const QItemSelection &itemDeselected ) +{ + Q_UNUSED( itemDeselected ) + + if( itemSelected.indexes().size() >= 1 ) { + // the selected index belongs to KEduVocVocabularyFilter, when we need it from the vocabulary model + QModelIndex index = d->m_model->index( itemSelected.indexes().at( 0 ).row(), + itemSelected.indexes().at( 0 ).column() ); + d->m_mapper->setCurrentModelIndex( index ); + } +} + +/* +void SummaryWordWidget::populateLessonList(KEduVocExpression *entry) +{ + lessonComboBox->clear(); + + LessonModel *basicLessonModel = new LessonModel(this); + lessonComboBox->setModel(basicLessonModel); + QTreeView *view = new QTreeView(this); + + view->setModel(basicLessonModel); + lessonComboBox->setView(view); + + basicLessonModel->setDocument(m_doc); + + view->header()->setVisible(false); + view->setRootIsDecorated(true); + view->expandAll(); + + view->setCurrentIndex(basicLessonModel->index(entry->lesson())); +} +*/ + +void KEduVocSummaryWordWidget::setCurrentWordType( KEduVocExpression *entry, int translation ) +{ + if( entry && entry->translation( translation )->wordType() ) { + qDebug() << "Set current word type: " << entry->translation( translation )->wordType()->name(); + // select the right word type + d->m_wordTypeView->setCurrentIndex( d->m_wordTypeModel->index( entry->translation( translation )->wordType() ) ); + } else { + d->m_ui->wordTypeComboBox->setCurrentIndex( -1 ); + } +} + +void KEduVocSummaryWordWidget::clear() +{ + qDebug() << "Clear summary widget"; + + d->m_ui->languageLabel->setText( QString() ); + d->m_ui->wordEntry->setText( QString() ); + + // lessonComboBox->clear(); + d->m_ui->lessonLabel->setText( QString() ); + + d->m_ui->pronunciationEntry->setText( QString() ); + d->m_ui->exampleEntry->setText( QString() ); + d->m_ui->paraphraseEntry->setText( QString() ); + d->m_ui->commentEntry->setText( QString() ); +} + +KEduVocSummaryWordDelegate::KEduVocSummaryWordDelegate( QObject *parent ) + : QItemDelegate( parent ) +{ +} + +void KEduVocSummaryWordDelegate::setEditorData( QWidget *editor, const QModelIndex &index ) const +{ + if( !index.isValid() ) { + return; + } + + if( editor ) { + switch( KEduVocVocabularyModel::columnType( index.column() ) ) { + case KEduVocVocabularyModel::WordClass: + break; + + case KEduVocVocabularyModel::Comment: + case KEduVocVocabularyModel::Pronunciation: + case KEduVocVocabularyModel::Translation: + case KEduVocVocabularyModel::Example: + case KEduVocVocabularyModel::Paraphrase: + + QLineEdit *entry = static_cast ( editor ); + if( entry ) { + entry->setText( index.model()->data( index ).toString() ); + } + break; + } + } +} + +void KEduVocSummaryWordWidget::wordTypeSelected( const QString& wordTypeName ) +{ + if( !d->m_doc || !d->m_entry ) { + return; + } + + KEduVocContainer* container = d->m_doc->wordTypeContainer()->childContainer( wordTypeName ); + if( container ) { + KEduVocWordType *wordType = static_cast ( container ); + if( wordType ) { + d->m_entry->translation( d->m_translationId )->setWordType( wordType ); + } + } +} diff --git a/keduvocdocument/keduvocsummarywordwidget.h b/keduvocdocument/keduvocsummarywordwidget.h new file mode 100644 index 0000000..cfca43a --- /dev/null +++ b/keduvocdocument/keduvocsummarywordwidget.h @@ -0,0 +1,104 @@ +/*************************************************************************** + + Copyright 2007 Frederik Gladhorn + Copyright 2008 Javier Goday + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +#ifndef KEDUVOCSUMMARYWORDWIDGET_H +#define KEDUVOCSUMMARYWORDWIDGET_H + +#include +#include + +#include + +class QTreeView; +class QDataWidgetMapper; +class QItemSelection; +class QModelIndex; + +class KEduVocContainer; +class KEduVocDocument; +class KEduVocExpression; +class KEduVocVocabularyFilter; +class KEduVocWordClassModel; + +namespace Editor +{ + +/** +* Represents the overview of a KEduVocExpression +* Shows the language word +* the lesson + the word type + pronunciation + example + paraphrase + comment +*/ +class KEDUVOCDOCUMENT_EXPORT KEduVocSummaryWordWidget : public QWidget +{ + Q_OBJECT + +public: + KEduVocSummaryWordWidget( KEduVocVocabularyFilter *model, KEduVocDocument *doc, QWidget *parent = 0 ); + ~KEduVocSummaryWordWidget(); + +public slots: + /** + * Sets the selected word (KEduVocExpression) from the vocabularyView + */ + void setTranslation( KEduVocExpression *entry, int translation ); + + /** + * Called when a KEduVocDocument change happened + */ + void slotDocumentChanged( KEduVocDocument *doc ); + + /** + * Called when the selection changed in the vocabulary view + */ + void slotSelectionChanged( const QItemSelection &, const QItemSelection & ); + + void wordTypeSelected( const QString& wordTypeName ); + +private: + /** + * Clears the form and the comboboxes + */ + void clear(); + + /** + * Fill the lesson combobox with the available lessons of the KEduVocDocument + + void populateLessonList(KEduVocExpression *entry); + */ + /** + * Fill the word types list with the available word types of the KEduVocDocument + */ + void setCurrentWordType( KEduVocExpression *entry, int translation ); + +private: + class Private; + Private * const d; +}; + +class KEduVocSummaryWordDelegate : public QItemDelegate +{ + Q_OBJECT +public: + KEduVocSummaryWordDelegate( QObject *parent = 0 ); + + void setEditorData( QWidget *editor, const QModelIndex &index ) const; +}; +} + +#endif diff --git a/keduvocdocument/keduvocsummarywordwidget.ui b/keduvocdocument/keduvocsummarywordwidget.ui new file mode 100644 index 0000000..8479f38 --- /dev/null +++ b/keduvocdocument/keduvocsummarywordwidget.ui @@ -0,0 +1,137 @@ + + KEduVocSummaryWordWidget + + + + 0 + 0 + 411 + 236 + + + + + + + Language + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + wordEntry + + + + + + + + + + Lesson + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Word type + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + wordTypeComboBox + + + + + + + Pronunciation + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + pronunciationEntry + + + + + + + + + + Example + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + exampleEntry + + + + + + + + + + Paraphrase + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + paraphraseEntry + + + + + + + + + + Comment + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + commentEntry + + + + + + + + + + + + + + + + + + + + + KComboBox + QComboBox +
kcombobox.h
+
+
+ + +