diff --git a/keduvocdocument/CMakeLists.txt b/keduvocdocument/CMakeLists.txt index 8ea9bc0..3ccde2c 100644 --- a/keduvocdocument/CMakeLists.txt +++ b/keduvocdocument/CMakeLists.txt @@ -1,212 +1,215 @@ 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 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 ) 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 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/keduvocsynonymwidget.cpp b/keduvocdocument/keduvocsynonymwidget.cpp new file mode 100644 index 0000000..b898413 --- /dev/null +++ b/keduvocdocument/keduvocsynonymwidget.cpp @@ -0,0 +1,198 @@ +/*************************************************************************** + Copyright 2008 Frederik Gladhorn + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "keduvocsynonymwidget.h" + +#include "ui_keduvocsynonymwidget.h" + +#include +#include +#include + +#include +#include +#include + +using namespace Editor; + +class KEduVocSynonymWidget::Private +{ +public: + Private( SynonymWidgetType type ); + + KEduVocDocument *m_doc; + // the one that was selected before + KEduVocTranslation* m_lastTranslation; + // the one the user clicked on latest + KEduVocTranslation* m_currentTranslation; + QStringListModel * m_listModel; + SynonymWidgetType m_type; + Ui::KEduVocSynonymWidget * m_ui; +}; + +KEduVocSynonymWidget::Private::Private( SynonymWidgetType type ) +{ + m_doc = 0; + m_type = type; + m_currentTranslation = 0; + m_lastTranslation = 0; + m_ui = new Ui::KEduVocSynonymWidget(); +} + +KEduVocSynonymWidget::KEduVocSynonymWidget( SynonymWidgetType type, QWidget *parent ) + : QWidget( parent ) + , d( new Private( type ) ) +{ + d->m_ui->setupUi( this ); + + connect( d->m_ui->synonymButton, &QPushButton::clicked, this, &KEduVocSynonymWidget::togglePair ); + d->m_listModel = new QStringListModel( this ); + d->m_ui->listView->setModel( d->m_listModel ); + + updateList(); +} + +KEduVocSynonymWidget::~KEduVocSynonymWidget() +{ + delete d; +} + +void KEduVocSynonymWidget::setDocument( KEduVocDocument *doc ) +{ + d->m_doc = doc; +} + +void KEduVocSynonymWidget::setTranslation( KEduVocExpression * entry, int translation ) +{ + // ignore zeros + if( entry ) { + d->m_lastTranslation = d->m_currentTranslation; + d->m_currentTranslation = entry->translation( translation ); + updateList(); + } else { + // better play save, the entry most likely has been deleted. + d->m_lastTranslation = 0; + d->m_currentTranslation = 0; + updateList(); + } +} + +void KEduVocSynonymWidget::updateList() +{ + // clear the list + d->m_listModel->removeRows( 0, d->m_listModel->rowCount() ); + + // set the button text + if( !( d->m_lastTranslation && d->m_currentTranslation ) ) { + d->m_ui->synonymButton->setEnabled( false ); + d->m_ui->synonymButton->setText( i18n( "Select Synonyms" ) ); + } else { + d->m_ui->synonymButton->setEnabled( true ); + switch( d->m_type ) { + case Synonym: + if( d->m_currentTranslation->synonyms().contains( d->m_lastTranslation ) ) { + d->m_ui->synonymButton->setText( i18n( "%1 and %2 are not Synonyms", d->m_currentTranslation->text(), d->m_lastTranslation->text() ) ); + } else { + d->m_ui->synonymButton->setText( i18n( "%1 and %2 are Synonyms", d->m_currentTranslation->text(), d->m_lastTranslation->text() ) ); + } + break; + case Antonym: + if( d->m_currentTranslation->antonyms().contains( d->m_lastTranslation ) ) { + d->m_ui->synonymButton->setText( i18n( "%1 and %2 are not Antonyms", d->m_currentTranslation->text(), d->m_lastTranslation->text() ) ); + } else { + d->m_ui->synonymButton->setText( i18n( "%1 and %2 are Antonyms", d->m_currentTranslation->text(), d->m_lastTranslation->text() ) ); + } + break; + case FalseFriend: + if( d->m_currentTranslation->falseFriends().contains( d->m_lastTranslation ) ) { + d->m_ui->synonymButton->setText( i18n( "%1 and %2 are not False Friends", d->m_currentTranslation->text(), d->m_lastTranslation->text() ) ); + } else { + d->m_ui->synonymButton->setText( i18n( "%1 and %2 are False Friends", d->m_currentTranslation->text(), d->m_lastTranslation->text() ) ); + } + break; + } + } + + if( d->m_currentTranslation ) { + switch( d->m_type ) { + case Synonym: + d->m_ui->synonymLabel->setText( i18nc( "Title for a list of synonyms for a word", "Synonyms of %1:", d->m_currentTranslation->text() ) ); + break; + case Antonym: + d->m_ui->synonymLabel->setText( i18nc( "Title for a list of antonyms (opposites) for a word", "Antonyms of %1:", d->m_currentTranslation->text() ) ); + break; + case FalseFriend: + d->m_ui->synonymLabel->setText( i18nc( "Title for a list of false friend (things that sound similar but have different meanings) for a word", "False Friends of %1:", d->m_currentTranslation->text() ) ); + break; + } + + // load list of synonyms/antonyms/ffs + QList< KEduVocTranslation* > list; + switch( d->m_type ) { + case Synonym: + list = d->m_currentTranslation->synonyms(); + break; + case Antonym: + list = d->m_currentTranslation->antonyms(); + break; + case FalseFriend: + list = d->m_currentTranslation->falseFriends(); + break; + } + foreach( KEduVocTranslation * translation, list ) { + int row = d->m_listModel->rowCount(); + d->m_listModel->insertRow( row ); + d->m_listModel->setData( d->m_listModel->index( row ), translation->text() ); + } + } else { + d->m_ui->synonymLabel->clear(); + } +} + +void KEduVocSynonymWidget::togglePair() +{ + // pair them up + switch( d->m_type ) { + case Synonym: + if( d->m_currentTranslation->synonyms().contains( d->m_lastTranslation ) ) { + d->m_currentTranslation->removeSynonym( d->m_lastTranslation ); + d->m_lastTranslation->removeSynonym( d->m_currentTranslation ); + } else { + d->m_currentTranslation->addSynonym( d->m_lastTranslation ); + d->m_lastTranslation->addSynonym( d->m_currentTranslation ); + } + break; + case Antonym: + if( d->m_currentTranslation->antonyms().contains( d->m_lastTranslation ) ) { + d->m_currentTranslation->removeAntonym( d->m_lastTranslation ); + d->m_lastTranslation->removeAntonym( d->m_currentTranslation ); + } else { + d->m_currentTranslation->addAntonym( d->m_lastTranslation ); + d->m_lastTranslation->addAntonym( d->m_currentTranslation ); + } + break; + case FalseFriend: + if( d->m_currentTranslation->falseFriends().contains( d->m_lastTranslation ) ) { + d->m_currentTranslation->removeFalseFriend( d->m_lastTranslation ); + d->m_lastTranslation->removeFalseFriend( d->m_currentTranslation ); + } else { + d->m_currentTranslation->addFalseFriend( d->m_lastTranslation ); + d->m_lastTranslation->addFalseFriend( d->m_currentTranslation ); + } + break; + } + + d->m_doc->setModified( true ); + + updateList(); +} diff --git a/keduvocdocument/keduvocsynonymwidget.h b/keduvocdocument/keduvocsynonymwidget.h new file mode 100644 index 0000000..1e8b0ef --- /dev/null +++ b/keduvocdocument/keduvocsynonymwidget.h @@ -0,0 +1,61 @@ +/*************************************************************************** + Copyright 2008 Frederik Gladhorn + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 KEDUVOCSYNONYMWIDGET_H +#define KEDUVOCSYNONYMWIDGET_H + +#include +#include + +#include + +class KEduVocExpression; +class KEduVocTranslation; +class KEduVocDocument; +class QStringListModel; + +namespace Editor +{ + +class KEDUVOCDOCUMENT_EXPORT KEduVocSynonymWidget : public QWidget +{ + Q_OBJECT +public: + enum SynonymWidgetType { + Synonym, + Antonym, + FalseFriend + }; + + explicit KEduVocSynonymWidget( SynonymWidgetType type, QWidget *parent = 0 ); + ~KEduVocSynonymWidget(); + +public slots: + /** + * Register the document inside the widget so that it can be marked as modified. + * @param doc + */ + void setDocument( KEduVocDocument *doc ); + + void setTranslation( KEduVocExpression* entry, int translation ); + +private slots: + void togglePair(); + void updateList(); + +private: + class Private; + Private * const d; +}; +} +#endif diff --git a/keduvocdocument/keduvocsynonymwidget.ui b/keduvocdocument/keduvocsynonymwidget.ui new file mode 100644 index 0000000..d5966e5 --- /dev/null +++ b/keduvocdocument/keduvocsynonymwidget.ui @@ -0,0 +1,34 @@ + + KEduVocSynonymWidget + + + + 0 + 0 + 297 + 196 + + + + + + + Synonyms + + + + + + + + + + Synonym + + + + + + + +