diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7e72cb8d..338d6727 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,199 +1,199 @@ include_directories( ${parley_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/collection ${CMAKE_CURRENT_SOURCE_DIR}/editor # FIXME: Remove when moving the rest of the files in vocabulary/ ) # installation of kconfig files .kcfg containing app settings add_subdirectory( settings ) set(parley_LIB_SRCS parleyactions.cpp parleydocument.cpp parleymainwindow.cpp utils.cpp collection/collection.cpp collection/testentry.cpp collection/entryfilter.cpp collection/entryfilterdialog.cpp collection/vocabularymimedata.cpp collection/containermimedata.cpp #collection/readonlycontainermodel.cpp #collection/containermodel.cpp - collection/lessonmodel.cpp + #collection/lessonmodel.cpp #collection/vocabularymodel.cpp collection/vocabularyfilter.cpp collection/wordclassmodel.cpp collection/containerview.cpp editor/editor.cpp editor/vocabularycolumnsdialog.cpp editor/lessonview.cpp editor/vocabularydelegate.cpp editor/vocabularyheaderview.cpp editor/vocabularyview.cpp editor/wordtypeview.cpp editor/audiowidget.cpp editor/browserwidget.cpp editor/comparisonwidget.cpp editor/inflectionwidget.cpp editor/conjugationwidget.cpp editor/declensionwidget.cpp editor/imagechooserwidget.cpp editor/multiplechoicewidget.cpp editor/summarywordwidget.cpp editor/synonymwidget.cpp editor/latexwidget.cpp practice/abstractwidget.cpp practice/sessionmanagerbase.cpp practice/sessionmanagercontinuous.cpp practice/sessionmanagerfixed.cpp practice/abstractfrontend.cpp practice/abstractbackendmode.cpp practice/practicestatemachine.cpp practice/comparisonbackendmode.cpp practice/comparisonmodewidget.cpp practice/conjugationbackendmode.cpp practice/conjugationmodewidget.cpp practice/guifrontend.cpp practice/writtenpracticewidget.cpp practice/writtenpracticevalidator.cpp practice/writtenbackendmode.cpp practice/examplesentencebackendmode.cpp practice/flashcardmodewidget.cpp practice/flashcardbackendmode.cpp practice/multiplechoicemodewidget.cpp practice/multiplechoicebackendmode.cpp practice/genderbackendmode.cpp practice/mixedlettersmodewidget.cpp practice/imagewidget.cpp practice/practicemainwindow.cpp practice/practicesummarycomponent.cpp practice/boxeswidget.cpp practice/audiobutton.cpp practice/summarybarwidget.cpp practice/themedbackgroundrenderer.cpp practice/imagecache.cpp practice/statustoggle.cpp practice/statustogglebutton.cpp practice/latexrenderer.cpp practice/configure/configurepracticedialog.cpp practice/configure/generalpracticeoptions.cpp practice/configure/blockoptions.cpp practice/configure/thresholdoptions.cpp practice/configure/specificpracticeoptions.cpp scripts/scriptdialog.cpp scripts/scriptmanager.cpp scripts/scripting/parley.cpp scripts/scripting/document.cpp scripts/scripting/lesson.cpp scripts/scripting/expression.cpp scripts/scripting/translation.cpp scripts/scripting/text.cpp scripts/scripting/container.cpp scripts/scripting/identifier.cpp scripts/script.cpp scripts/translator.cpp settings/generaloptions.cpp settings/parleyprefs.cpp settings/viewoptions.cpp settings/documentproperties.cpp settings/languageproperties.cpp settings/languagepropertiespage.cpp settings/kgametheme/kgametheme.cpp settings/kgametheme/kgamethemeselector.cpp statistics/conjugationoptions.cpp statistics/lessonstatisticsview.cpp statistics/statisticsmodel.cpp statistics/statisticsmainwindow.cpp statistics/statisticslegendwidget.cpp dashboard/dashboard.cpp dashboard/buttondelegate.cpp dashboard/gradereferencewidget.cpp dashboard/barwidget.cpp dashboard/collectionwidget.cpp ) ki18n_wrap_ui(parley_LIB_SRCS collection/entryfilterdialog.ui editor/multiplechoicewidget.ui editor/comparisonwidget.ui editor/conjugationwidget.ui editor/declensionwidget.ui editor/imagechooserwidget.ui editor/audiowidget.ui editor/synonymwidget.ui editor/browserwidget.ui editor/summarywordwidget.ui editor/latexwidget.ui practice/practicesummarywidget.ui practice/practice_mainwindow.ui practice/practice_widget_comparison.ui practice/practice_widget_conjugation.ui practice/practice_widget_flashcard.ui practice/practice_widget_multiplechoice.ui practice/practice_widget_written.ui practice/configure/generalpracticeoptions.ui practice/configure/blockoptions.ui practice/configure/thresholdoptions.ui practice/configure/specificpracticeoptions.ui settings/optionlistform.ui settings/viewoptionsbase.ui settings/generaloptionsbase.ui settings/languagepropertiespage.ui settings/documentproperties.ui settings/kgametheme/kgamethemeselector.ui statistics/statisticsmainwindow.ui dashboard/dashboard.ui ) kconfig_add_kcfg_files(parley_LIB_SRCS settings/prefs.kcfgc settings/documentsettings.kcfgc settings/languagesettings.kcfgc ) qt5_add_dbus_adaptor(parley_LIB_SRCS editor/org.kde.parley.xml editor/editor.h Editor::EditorWindow) #### XSLT Support #### # to transform the document xml to html or other if(HAVE_LIBXSLT) set(parley_LIB_SRCS ${parley_LIB_SRCS} exportdialog.cpp ) ki18n_wrap_ui(parley_LIB_SRCS exportdialog.ui ) endif(HAVE_LIBXSLT) #### End XSLT Support #### # This library is used both by parley itself and the unit tests. add_library(parley_LIB STATIC ${parley_LIB_SRCS}) set(parley_SRCS main.cpp) add_executable(parley ${parley_SRCS}) target_link_libraries(parley parley_LIB ${parley_LINK_LIBS}) target_link_libraries(parley_LIB ${parley_LINK_LIBS}) ########### install files ############### install(TARGETS parley ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} ) # desktop files appear in the menus install( PROGRAMS org.kde.parley.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) # hot new stuff config install( FILES parley.knsrc parley-themes.knsrc DESTINATION ${KDE_INSTALL_CONFDIR} ) # UI files - define menus and toolbars # @todo frameworks find a definitive locations for files and then use KXMLGUI_INSTALL_DIR install( FILES parleyui.rc DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/parley ) #install( FILES editor/editorui.rc DESTINATION ${KDE_INSTALL_DATADIR}/parley ) install( FILES editor/editorui.rc DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/parley ) install( FILES dashboard/dashboardui.rc DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/parley ) # install( FILES statistics/statisticsui.rc DESTINATION ${KDE_INSTALL_DATADIR}/parley ) # install( FILES practice/practiceui.rc DESTINATION ${KDE_INSTALL_DATADIR}/parley ) # install( FILES practice/practicesummaryui.rc DESTINATION ${KDE_INSTALL_DATADIR}/parley ) install( FILES statistics/statisticsui.rc DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/parley ) install( FILES practice/practiceui.rc DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/parley ) install( FILES practice/practicesummaryui.rc DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/parley ) diff --git a/src/editor/editor.cpp b/src/editor/editor.cpp index f5de16a2..4940d8eb 100644 --- a/src/editor/editor.cpp +++ b/src/editor/editor.cpp @@ -1,524 +1,524 @@ /*************************************************************************** Copyright 1999-2001 Ewald Arnold Copyright 2004-2007 Peter Hedlund Copyright 2007-2009 Frederik Gladhorn Copyright 2008 Daniel Laidig ***************************************************************************/ /*************************************************************************** * * * 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 "editor.h" #include // Qt models on top of the KEduVocDocument -#include "lessonmodel.h" #include "vocabularyfilter.h" #include "wordclassmodel.h" // Views #include "vocabularyview.h" #include "containerview.h" #include "lessonview.h" #include "wordtypeview.h" #include "multiplechoicewidget.h" #include "comparisonwidget.h" #include "inflectionwidget.h" #include "imagechooserwidget.h" #include "audiowidget.h" #include "browserwidget.h" #include "synonymwidget.h" #include "summarywordwidget.h" #include "latexwidget.h" #include "settings/parleyprefs.h" #include "prefs.h" #include "scripts/scriptdialog.h" #include "scripts/translator.h" #include "parleyactions.h" #include "parleyadaptor.h" //KEduVoc #include #include +#include #include #include #include #include #include #include #include #include #include #include using namespace Editor; EditorWindow::EditorWindow(ParleyMainWindow* parent) : KXmlGuiWindow(parent), m_mainWindow(parent) { // KXmlGui setXMLFile(QStringLiteral("editorui.rc")); setObjectName(QStringLiteral("Editor")); setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea); setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea); setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea); initView(); initModel(); initDockWidgets(); initActions(); KConfigGroup cfg(KSharedConfig::openConfig(QStringLiteral("parleyrc")), objectName()); applyMainWindowSettings(cfg); connect(parent->parleyDocument(), &ParleyDocument::documentChanged, this, &EditorWindow::updateDocument); connect(parent->parleyDocument(), &ParleyDocument::languagesChanged, this, &EditorWindow::slotLanguagesChanged); connect(parent->parleyDocument(), SIGNAL(statesNeedSaving()), this, SLOT(saveState())); connect(parent, &ParleyMainWindow::preferencesChanged, this, &EditorWindow::applyPrefs); QTimer::singleShot(0, this, &EditorWindow::initScripts); } EditorWindow::~EditorWindow() { saveState(); KConfigGroup cfg(KSharedConfig::openConfig(QStringLiteral("parleyrc")), objectName()); saveMainWindowSettings(cfg); } void EditorWindow::updateDocument(KEduVocDocument *doc) { m_vocabularyView->setDocument(doc); m_vocabularyModel->setDocument(doc); m_lessonModel->setDocument(doc); m_wordTypeModel->setDocument(doc); m_summaryWordWidget->slotDocumentChanged(doc); m_inflectionWidget->setDocument(doc); m_comparisonWidget->setDocument(doc); m_synonymWidget->setDocument(doc); m_antonymWidget->setDocument(doc); m_falseFriendWidget->setDocument(doc); if (!m_mainWindow->parleyDocument()->document()) { return; } if (!doc) { return; } // expand the root items m_lessonView->expandToDepth(0); m_wordTypeView->expandToDepth(0); connect(m_vocabularyView->selectionModel(), &QItemSelectionModel::selectionChanged, m_summaryWordWidget, &SummaryWordWidget::slotSelectionChanged); connect(m_vocabularyView->selectionModel(), &QItemSelectionModel::selectionChanged, m_latexWidget, &LatexWidget::slotSelectionChanged); m_spellCheckMenu->menu()->clear(); for (int i = 0; i < doc->identifierCount(); ++i) { QAction* languageSpellCheck = new QAction(doc->identifier(i).name(), m_spellCheckMenu->menu()); m_spellCheckMenu->menu()->addAction(languageSpellCheck); connect(languageSpellCheck, &QAction::triggered, this, [=] {m_vocabularyView->checkSpelling(i);}); } } void EditorWindow::initDockWidgets() { // Lesson dockwidget QDockWidget *lessonDockWidget = new QDockWidget(i18n("Units"), this); lessonDockWidget->setObjectName(QStringLiteral("LessonDock")); m_lessonView = new LessonView(this); lessonDockWidget->setWidget(m_lessonView); addDockWidget(Qt::LeftDockWidgetArea, lessonDockWidget); m_dockWidgets.append(lessonDockWidget); actionCollection()->addAction(QStringLiteral("show_units_dock"), lessonDockWidget->toggleViewAction()); - m_lessonModel = new LessonModel(this); + m_lessonModel = new KEduVocLessonModel(this); m_lessonView->setModel(m_lessonModel); m_lessonView->setToolTip(i18n("Right click to add, delete, or rename units. \n" "With the checkboxes you can select which units you want to practice. \n" "Only checked units [x] will be asked in the practice!")); connect(m_lessonView, &LessonView::selectedLessonChanged, m_vocabularyModel, &VocabularyModel::setLesson); connect(m_lessonView, &LessonView::signalShowContainer, m_vocabularyModel, &VocabularyModel::showContainer); connect(m_vocabularyView, &VocabularyView::translationChanged, m_lessonView, &LessonView::setTranslation); // Word classes dock widget QDockWidget* wordTypeDockWidget = new QDockWidget(i18n("Word Types"), this); wordTypeDockWidget->setObjectName(QStringLiteral("WordTypeDock")); m_wordTypeView = new WordTypeView(this); wordTypeDockWidget->setWidget(m_wordTypeView); addDockWidget(Qt::LeftDockWidgetArea, wordTypeDockWidget); m_dockWidgets.append(wordTypeDockWidget); m_wordTypeModel = new WordClassModel(this); wordTypeDockWidget->setVisible(false); actionCollection()->addAction(QStringLiteral("show_wordtype_dock"), wordTypeDockWidget->toggleViewAction()); ///@todo test, should be fixed with the lesson one though ///@todo remove before release // new ModelTest(m_wordTypeModel, this); m_wordTypeView->setModel(m_wordTypeModel); connect(m_vocabularyView, &VocabularyView::translationChanged, m_wordTypeView, &WordTypeView::setTranslation); // Inflections QDockWidget *inflectionDock = new QDockWidget(i18n("Inflection (verbs, adjectives, nouns)"), this); inflectionDock->setObjectName(QStringLiteral("InflectionDock")); m_inflectionWidget = new InflectionWidget(this); QScrollArea *inflectionScrollArea = new QScrollArea(this); inflectionScrollArea->setWidgetResizable(true); inflectionScrollArea->setWidget(m_inflectionWidget); inflectionDock->setWidget(inflectionScrollArea); addDockWidget(Qt::RightDockWidgetArea, inflectionDock); m_dockWidgets.append(inflectionDock); actionCollection()->addAction(QStringLiteral("show_inflection_dock"), inflectionDock->toggleViewAction()); connect(m_mainWindow->parleyDocument(), &ParleyDocument::documentChanged, m_inflectionWidget, &InflectionWidget::setDocument); connect(m_vocabularyView, &VocabularyView::translationChanged, m_inflectionWidget, &InflectionWidget::setTranslation); // Comparison forms QDockWidget *comparisonDock = new QDockWidget(i18n("Comparison forms"), this); comparisonDock->setObjectName(QStringLiteral("ComparisonDock")); m_comparisonWidget = new ComparisonWidget(this); QScrollArea *comparisonScrollArea = new QScrollArea(this); comparisonScrollArea->setWidgetResizable(true); comparisonScrollArea->setWidget(m_comparisonWidget); comparisonDock->setWidget(comparisonScrollArea); addDockWidget(Qt::RightDockWidgetArea, comparisonDock); m_dockWidgets.append(comparisonDock); actionCollection()->addAction(QStringLiteral("show_comparison_dock"), comparisonDock->toggleViewAction()); comparisonDock->setVisible(false); connect(m_vocabularyView, &VocabularyView::translationChanged, m_comparisonWidget, &ComparisonWidget::setTranslation); tabifyDockWidget(comparisonDock,inflectionDock); // Multiple choice QDockWidget *multipleChoiceDock = new QDockWidget(i18n("Multiple Choice"), this); multipleChoiceDock->setObjectName(QStringLiteral("MultipleChoiceDock")); MultipleChoiceWidget *multipleChoiceWidget = new MultipleChoiceWidget(this); QScrollArea *multipleChoiceScrollArea = new QScrollArea(this); multipleChoiceScrollArea->setWidgetResizable(true); multipleChoiceScrollArea->setWidget(multipleChoiceWidget); multipleChoiceDock->setWidget(multipleChoiceScrollArea); addDockWidget(Qt::RightDockWidgetArea, multipleChoiceDock); m_dockWidgets.append(multipleChoiceDock); actionCollection()->addAction(QStringLiteral("show_multiplechoice_dock"), multipleChoiceDock->toggleViewAction()); multipleChoiceDock->setVisible(false); connect(m_vocabularyView, &VocabularyView::translationChanged, multipleChoiceWidget, &MultipleChoiceWidget::setTranslation); // Synonym (and the same for antonym and false friends) QDockWidget *synonymDock = new QDockWidget(i18n("Synonyms"), this); synonymDock->setObjectName(QStringLiteral("SynonymDock")); m_synonymWidget = new SynonymWidget(SynonymWidget::Synonym, this); QScrollArea *synonymScrollArea = new QScrollArea(this); synonymScrollArea->setWidgetResizable(true); synonymScrollArea->setWidget(m_synonymWidget); synonymDock->setWidget(synonymScrollArea); addDockWidget(Qt::RightDockWidgetArea, synonymDock); m_dockWidgets.append(synonymDock); actionCollection()->addAction(QStringLiteral("show_synonym_dock"), synonymDock->toggleViewAction()); synonymDock->setVisible(false); connect(m_vocabularyView, &VocabularyView::translationChanged, m_synonymWidget, &SynonymWidget::setTranslation); QDockWidget *antonymDock = new QDockWidget(i18n("Antonyms"), this); antonymDock->setObjectName(QStringLiteral("AntonymDock")); m_antonymWidget = new SynonymWidget(SynonymWidget::Antonym, this); QScrollArea *antonymScrollArea = new QScrollArea(this); antonymScrollArea->setWidgetResizable(true); antonymScrollArea->setWidget(m_antonymWidget); antonymDock->setWidget(antonymScrollArea); addDockWidget(Qt::RightDockWidgetArea, antonymDock); m_dockWidgets.append(antonymDock); actionCollection()->addAction(QStringLiteral("show_antonym_dock"), antonymDock->toggleViewAction()); antonymDock->setVisible(false); connect(m_vocabularyView, &VocabularyView::translationChanged, m_antonymWidget, &SynonymWidget::setTranslation); tabifyDockWidget(synonymDock,antonymDock); QDockWidget *falseFriendDock = new QDockWidget(i18n("False Friends"), this); falseFriendDock->setObjectName(QStringLiteral("FalseFriendDock")); m_falseFriendWidget = new SynonymWidget(SynonymWidget::FalseFriend, this); QScrollArea *falseFriendScrollArea = new QScrollArea(this); falseFriendScrollArea->setWidgetResizable(true); falseFriendScrollArea->setWidget(m_falseFriendWidget); falseFriendDock->setWidget(falseFriendScrollArea); addDockWidget(Qt::RightDockWidgetArea, falseFriendDock); m_dockWidgets.append(falseFriendDock); actionCollection()->addAction(QStringLiteral("show_falsefriend_dock"), falseFriendDock->toggleViewAction()); falseFriendDock->setVisible(false); connect(m_vocabularyView, &VocabularyView::translationChanged, m_falseFriendWidget, &SynonymWidget::setTranslation); tabifyDockWidget(antonymDock,falseFriendDock); // Pronunciation symbols - Use KCharSelect QDockWidget *charSelectDock = new QDockWidget(i18n("Phonetic Symbols"), this); charSelectDock->setObjectName(QStringLiteral("IPADock")); KCharSelect *charSelectWidget = new KCharSelect(this, 0, KCharSelect::SearchLine | KCharSelect::BlockCombos | KCharSelect::CharacterTable); charSelectWidget->setCurrentChar(0x0250); QScrollArea *charSelectScrollArea = new QScrollArea(this); charSelectScrollArea->setWidgetResizable(true); charSelectScrollArea->setWidget(charSelectWidget); charSelectDock->setWidget(charSelectScrollArea); addDockWidget(Qt::BottomDockWidgetArea, charSelectDock); m_dockWidgets.append(charSelectDock); actionCollection()->addAction(QStringLiteral("show_pronunciation_dock"), charSelectDock->toggleViewAction()); charSelectDock->setVisible(false); connect(charSelectWidget, &KCharSelect::charSelected, m_vocabularyView, &VocabularyView::appendChar); // Image QDockWidget *imageDock = new QDockWidget(i18n("Image"), this); imageDock->setObjectName(QStringLiteral("ImageDock")); ImageChooserWidget *imageChooserWidget = new ImageChooserWidget(this); QScrollArea *imageScrollArea = new QScrollArea(this); imageScrollArea->setWidgetResizable(true); imageScrollArea->setWidget(imageChooserWidget); imageDock->setWidget(imageScrollArea); addDockWidget(Qt::RightDockWidgetArea, imageDock); m_dockWidgets.append(imageDock); actionCollection()->addAction(QStringLiteral("show_image_dock"), imageDock->toggleViewAction()); imageDock->setVisible(false); connect(m_vocabularyView, &VocabularyView::translationChanged, imageChooserWidget, &ImageChooserWidget::setTranslation); tabifyDockWidget(multipleChoiceDock,imageDock); // Summary word QDockWidget *summaryDock = new QDockWidget(i18n("Summary"), this); summaryDock->setObjectName(QStringLiteral("SummaryDock")); m_summaryWordWidget = new SummaryWordWidget(m_vocabularyFilter, m_mainWindow->parleyDocument()->document(), this); QScrollArea *summaryScrollArea = new QScrollArea(this); summaryScrollArea->setWidgetResizable(true); summaryScrollArea->setWidget(m_summaryWordWidget); summaryDock->setWidget(summaryScrollArea); addDockWidget(Qt::BottomDockWidgetArea, summaryDock); actionCollection()->addAction(QStringLiteral("show_summary_dock"), summaryDock->toggleViewAction()); summaryDock->setVisible(false); m_dockWidgets.append(summaryDock); connect(m_vocabularyView, &VocabularyView::translationChanged, m_summaryWordWidget, &SummaryWordWidget::setTranslation); // Sound QDockWidget *audioDock = new QDockWidget(i18n("Sound"), this); audioDock->setObjectName(QStringLiteral("AudioDock")); AudioWidget *audioWidget = new AudioWidget(this); QScrollArea *audioScrollArea = new QScrollArea(this); audioScrollArea->setWidgetResizable(true); audioScrollArea->setWidget(audioWidget); audioDock->setWidget(audioScrollArea); addDockWidget(Qt::RightDockWidgetArea, audioDock); m_dockWidgets.append(audioDock); actionCollection()->addAction(QStringLiteral("show_audio_dock"), audioDock->toggleViewAction()); audioDock->setVisible(false); connect(m_vocabularyView, &VocabularyView::translationChanged, audioWidget, &AudioWidget::setTranslation); tabifyDockWidget(imageDock,audioDock); // browser QDockWidget *browserDock = new QDockWidget(i18n("Internet"), this); browserDock->setObjectName(QStringLiteral("BrowserDock")); BrowserWidget *htmlPart = new BrowserWidget(browserDock); QScrollArea *browserScrollArea = new QScrollArea(this); browserScrollArea->setWidgetResizable(true); browserScrollArea->setWidget(htmlPart); browserDock->setWidget(browserScrollArea); addDockWidget(Qt::BottomDockWidgetArea, browserDock); m_dockWidgets.append(browserDock); actionCollection()->addAction(QStringLiteral("show_browser_dock"), browserDock->toggleViewAction()); browserDock->setVisible(false); connect(m_vocabularyView, &VocabularyView::translationChanged, htmlPart, &BrowserWidget::setTranslation); tabifyDockWidget(summaryDock,browserDock); // LaTeX QDockWidget *latexDock = new QDockWidget(i18n("LaTeX"), this); latexDock->setObjectName(QStringLiteral("LatexDock")); m_latexWidget = new LatexWidget(m_vocabularyFilter, m_mainWindow->parleyDocument()->document(), this); QScrollArea *latexScrollArea = new QScrollArea(this); latexScrollArea->setWidgetResizable(true); latexScrollArea->setWidget(m_latexWidget); latexDock->setWidget(latexScrollArea); addDockWidget(Qt::RightDockWidgetArea, latexDock); actionCollection()->addAction(QStringLiteral("show_latex_dock"), latexDock->toggleViewAction()); latexDock->setVisible(false); m_dockWidgets.append(latexDock); connect(m_vocabularyView, &VocabularyView::translationChanged, m_latexWidget, &LatexWidget::setTranslation); tabifyDockWidget(audioDock,latexDock); // Grades // QDockWidget *gradeDock = new QDockWidget(i18n("Grade"), this); // gradeDock->setObjectName("gradeDock"); // QLabel *gradeWidget = new QLabel("grade placeholder", this); // gradeDock->setWidget(gradeWidget); // addDockWidget(Qt::RightDockWidgetArea, gradeDock); // connect(this, SIGNAL(signalSetData(KEduVocTranslation*)), m_declensionWidget, SLOT(setTranslation(KEduVocTranslation*))); } void EditorWindow::initActions() { ParleyActions::create(ParleyActions::RemoveGrades, this, SLOT(removeGrades()), actionCollection()); m_spellCheckMenu = ParleyActions::create(ParleyActions::CheckSpelling, 0, "", actionCollection()); m_spellCheckMenu->setMenu(new QMenu(this)); ParleyActions::create(ParleyActions::ToggleShowSublessons, m_vocabularyModel, SLOT(showEntriesOfSubcontainers(bool)), actionCollection()); ParleyActions::create(ParleyActions::AutomaticTranslation, m_vocabularyModel, SLOT(automaticTranslation(bool)), actionCollection()); ParleyActions::create(ParleyActions::StartPractice, m_mainWindow, SLOT(showPracticeConfiguration()), actionCollection()); actionCollection()->action(QStringLiteral("practice_start"))->setText(i18n("Practice")); actionCollection()->action(QStringLiteral("practice_start"))->setToolTip(i18n("Practice")); ParleyActions::create(ParleyActions::ConfigurePractice, m_mainWindow, SLOT(configurePractice()), actionCollection()); ParleyActions::create(ParleyActions::ToggleSearchBar, this, SLOT(slotConfigShowSearch()), actionCollection()); ParleyActions::create(ParleyActions::SearchVocabulary, this, SLOT(startSearch()), actionCollection()); ParleyActions::create(ParleyActions::ShowScriptManager, this, SLOT(slotShowScriptManager()), actionCollection()); ParleyActions::create(ParleyActions::LanguagesProperties, m_mainWindow->parleyDocument(), SLOT(languageProperties()), actionCollection()); ParleyActions::createUploadAction(m_mainWindow->parleyDocument(), SLOT(uploadFile()), actionCollection()); new EditorWindowAdaptor(this); QDBusConnection dbus = QDBusConnection::sessionBus(); dbus.registerObject(QStringLiteral("/AddWithTranslation"), this); } void EditorWindow::addWordWithTranslation(const QStringList &w) { KEduVocExpression *kexpr = new KEduVocExpression(w); m_vocabularyModel->appendEntry(kexpr); } void EditorWindow::initModel() { m_vocabularyModel = new KEduVocVocabularyModel(Prefs::showSublessonentries(), this); m_vocabularyFilter = new VocabularyFilter(this); m_vocabularyFilter->setSourceModel(m_vocabularyModel); m_vocabularyView->setFilter(m_vocabularyFilter); // connect(m_mainWindow->parleyDocument(), SIGNAL(documentChanged(KEduVocDocument*)), m_vocabularyModel, SLOT(setDocument(KEduVocDocument*))); // connect(m_mainWindow->parleyDocument(), SIGNAL(documentChanged(KEduVocDocument*)), m_vocabularyView, SLOT(setDocument(KEduVocDocument*))); connect(m_searchLine, &QLineEdit::textChanged, m_vocabularyFilter, &VocabularyFilter::setSearchString); } /** * This initializes the main widgets and table. */ void EditorWindow::initView() { QWidget *mainWidget = new QWidget(this); setCentralWidget(mainWidget); QVBoxLayout *topLayout = new QVBoxLayout(mainWidget); m_searchLine = new QLineEdit(this); m_searchLine->show(); m_searchLine->setFocusPolicy(Qt::ClickFocus); m_searchLine->setClearButtonEnabled(true); m_searchLine->setPlaceholderText(i18n("Enter search terms here")); m_searchLine->setToolTip(i18n("Search your vocabulary")); QLabel *label = new QLabel(i18n("S&earch:"), this); label->setBuddy(m_searchLine); label->show(); m_searchWidget = new QWidget(this); QHBoxLayout* layout = new QHBoxLayout(m_searchWidget); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(label); layout->addWidget(m_searchLine); ///@todo centralWidget()-> delete layout QVBoxLayout * rightLayout = new QVBoxLayout(); rightLayout->setContentsMargins(0, 0, 0, 0); rightLayout->addWidget(m_searchWidget); m_searchWidget->setVisible(Prefs::showSearch()); m_vocabularyView = new VocabularyView(this); rightLayout->addWidget(m_vocabularyView, 1, 0); topLayout->addLayout(rightLayout); } void EditorWindow::slotConfigShowSearch() { m_searchWidget->setVisible(m_searchWidget->isHidden()); Prefs::setShowSearch(m_searchWidget->isVisible()); } void EditorWindow::startSearch() { m_searchWidget->setVisible(true); m_searchLine->setFocus(); } void EditorWindow::slotShowScriptManager() { ScriptDialog * dialog = new ScriptDialog(m_scriptManager); dialog->show(); } void EditorWindow::applyPrefs() { m_vocabularyView->reset(); } void EditorWindow::removeGrades() { m_mainWindow->parleyDocument()->document()->lesson()->resetGrades(-1, KEduVocContainer::Recursive); } void EditorWindow::initScripts() { m_scriptManager = new ScriptManager(this); m_vocabularyView->setTranslator(m_scriptManager->translator()); //Load scripts m_scriptManager->loadScripts(); } void EditorWindow::saveState() { m_vocabularyView->saveColumnVisibility(); } void EditorWindow::slotLanguagesChanged() { m_vocabularyModel->resetLanguages(); } diff --git a/src/editor/editor.h b/src/editor/editor.h index b5cb4670..a395ab97 100644 --- a/src/editor/editor.h +++ b/src/editor/editor.h @@ -1,166 +1,166 @@ /*************************************************************************** Copyright 1999-2001 Ewald Arnold Copyright 2004-2007 Peter Hedlund Copyright 2007-2009 Frederik Gladhorn Copyright 2008 Daniel Laidig ***************************************************************************/ /*************************************************************************** * * * 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 EDITOR_H #define EDITOR_H #include "parleydocument.h" #include "scripts/scripting/parley.h" #include #include class QLineEdit; class ScriptManager; ///@brief contains objects for the editor main window // Models around the Collection / KEduVocDocument -class LessonModel; +class KEduVocLessonModel; class KEduVocVocabularyModel; class VocabularyFilter; class WordClassModel; namespace Editor { class VocabularyView; class LessonView; class WordTypeView; class InflectionWidget; class ComparisonWidget; class SummaryWordWidget; class LatexWidget; class SynonymWidget; class EditorWindow : public KXmlGuiWindow { Q_OBJECT public: explicit EditorWindow(ParleyMainWindow* parent); ~EditorWindow(); /** * setup the action (menus etc) */ void initActions(); /** setup the main model*/ void initModel(); /** setup the main view*/ void initView(); void initDockWidgets(); /** This will look at the lesson list and also the combo box to determine what should be displayed in the table. */ void updateTableFilter(); public slots: /** * Load enabled scripts (from configuration parleyrc) */ void initScripts(); /** * Edit languages contained in the document. * This includes adding/removing languages, * editing articles, personal pronouns and tenses. */ void slotLanguagesChanged(); void slotConfigShowSearch(); /** * Display script manager (open a new window / or Settings window) */ void slotShowScriptManager(); void applyPrefs(); /** * Removes all grading information from the current document */ void removeGrades(); /** when closing the application, save the editor's state */ void saveState(); /** * Set the current doc (after creating a new one or opening a file) */ void updateDocument(KEduVocDocument *doc); /** * DBus method for adding words by external apps */ void addWordWithTranslation(const QStringList &w); private slots: /** Make the search bar visible and focus it */ void startSearch(); signals: void signalSetData(const QList& entries, int currentTranslation); private: ParleyMainWindow *m_mainWindow; QAction* m_vocabShowSearchBarAction; KEduVocVocabularyModel *m_vocabularyModel; VocabularyView *m_vocabularyView; VocabularyFilter *m_vocabularyFilter; QLineEdit *m_searchLine; QWidget *m_searchWidget; QAction *m_spellCheckMenu; /** Show a single conjugation and let the user edit it */ InflectionWidget *m_inflectionWidget; SummaryWordWidget *m_summaryWordWidget; ComparisonWidget *m_comparisonWidget; LatexWidget *m_latexWidget; SynonymWidget *m_synonymWidget; SynonymWidget *m_antonymWidget; SynonymWidget *m_falseFriendWidget; /// dock widgets to display lessons, word types, ... LessonView *m_lessonView; - LessonModel *m_lessonModel; + KEduVocLessonModel *m_lessonModel; WordClassModel *m_wordTypeModel; WordTypeView *m_wordTypeView; ScriptManager* m_scriptManager; ///stores all the translations of a vocabulary word Translator* m_translator; QList m_dockWidgets; QList m_dockWidgetVisibility; friend class ::ParleyDocument; friend class Scripting::Parley; friend class ::ScriptManager; }; } #endif // EDITOR_H diff --git a/src/editor/lessonview.cpp b/src/editor/lessonview.cpp index 3320eb65..b598a417 100644 --- a/src/editor/lessonview.cpp +++ b/src/editor/lessonview.cpp @@ -1,259 +1,259 @@ /*************************************************************************** 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 "lessonview.h" #include #include #include #include #include #include #include +#include #include "editor/editor.h" -#include "lessonmodel.h" #include "prefs.h" using namespace Editor; LessonView::LessonView(EditorWindow * parent) : ContainerView(parent) { QAction *actionNewLesson = new QAction(this); parent->actionCollection()->addAction(QStringLiteral("new_lesson"), actionNewLesson); actionNewLesson->setText(i18n("New Unit")); actionNewLesson->setIcon(QIcon::fromTheme(QStringLiteral("lesson-add"))); actionNewLesson->setWhatsThis(i18n("Add a new unit to your document")); actionNewLesson->setToolTip(actionNewLesson->whatsThis()); actionNewLesson->setStatusTip(actionNewLesson->whatsThis()); QAction *actionRenameLesson = new QAction(this); parent->actionCollection()->addAction(QStringLiteral("rename_lesson"), actionRenameLesson); actionRenameLesson->setText(i18n("Rename Unit")); actionRenameLesson->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename"))); // actionRenameLesson->setWhatsThis(i18n("Rename the selected unit")); actionRenameLesson->setToolTip(actionRenameLesson->whatsThis()); actionRenameLesson->setStatusTip(actionRenameLesson->whatsThis()); QAction *actionDeleteLesson = new QAction(this); parent->actionCollection()->addAction(QStringLiteral("delete_lesson"), actionDeleteLesson); actionDeleteLesson->setText(i18n("Delete Unit")); actionDeleteLesson->setIcon(QIcon::fromTheme(QStringLiteral("lesson-remove"))); actionDeleteLesson->setWhatsThis(i18n("Delete the selected unit.")); actionDeleteLesson->setToolTip(actionDeleteLesson->whatsThis()); actionDeleteLesson->setStatusTip(actionDeleteLesson->whatsThis()); QAction *actionSplitLesson = new QAction(this); parent->actionCollection()->addAction(QStringLiteral("split_lesson"), actionSplitLesson); actionSplitLesson->setText(i18n("Split Unit into Smaller Units")); actionSplitLesson->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy"))); /// @todo better icon actionSplitLesson->setWhatsThis(i18n("Make multiple smaller units out of one big unit.")); actionSplitLesson->setToolTip(actionSplitLesson->whatsThis()); actionSplitLesson->setStatusTip(actionSplitLesson->whatsThis()); QAction *actionRemoveGradesLesson = new QAction(this); parent->actionCollection()->addAction(QStringLiteral("remove_grades_lesson"), actionRemoveGradesLesson); actionRemoveGradesLesson->setText(i18n("Remove Confidence Levels")); actionRemoveGradesLesson->setIcon(QIcon::fromTheme(QStringLiteral("edit-clear"))); /// @todo better icon actionRemoveGradesLesson->setWhatsThis(i18n("Remove confidence levels from this unit.")); actionRemoveGradesLesson->setToolTip(actionRemoveGradesLesson->whatsThis()); actionRemoveGradesLesson->setStatusTip(actionRemoveGradesLesson->whatsThis()); QAction *actionRemoveGradesLessonChildren = new QAction(this); parent->actionCollection()->addAction(QStringLiteral("remove_grades_lesson_children"), actionRemoveGradesLessonChildren); actionRemoveGradesLessonChildren->setText(i18n("Remove Confidence Levels From This Unit And All Subunits")); actionRemoveGradesLessonChildren->setIcon(QIcon::fromTheme(QStringLiteral("edit-clear"))); actionRemoveGradesLessonChildren->setWhatsThis(i18n("Remove confidence levels from this unit and all subunits.")); actionRemoveGradesLessonChildren->setToolTip(actionRemoveGradesLessonChildren->whatsThis()); actionRemoveGradesLessonChildren->setStatusTip(actionRemoveGradesLessonChildren->whatsThis()); QAction *actionExpandAll = new QAction(this); parent->actionCollection()->addAction(QStringLiteral("expand_all_lesson_children"), actionExpandAll); actionExpandAll->setText(i18n("Expand Units and Subunits")); actionExpandAll->setIcon(QIcon::fromTheme(QStringLiteral("go-down-search"))); actionExpandAll->setWhatsThis(i18n("Expand all units and subunits.")); actionExpandAll->setToolTip(actionExpandAll->whatsThis()); actionExpandAll->setStatusTip(actionExpandAll->whatsThis()); QAction *actionCollapseAll = new QAction(this); parent->actionCollection()->addAction(QStringLiteral("collapse_all_lesson_children"), actionCollapseAll); actionCollapseAll->setText(i18n("Collapse All Units And Subunits")); actionCollapseAll->setIcon(QIcon::fromTheme(QStringLiteral("go-up-search"))); actionCollapseAll->setWhatsThis(i18n("Collapse all units and subunits.")); actionCollapseAll->setToolTip(actionCollapseAll->whatsThis()); actionCollapseAll->setStatusTip(actionCollapseAll->whatsThis()); connect(actionNewLesson, &QAction::triggered, this, &LessonView::slotCreateNewLesson); connect(actionRenameLesson, &QAction::triggered, this, &LessonView::slotRename); connect(actionDeleteLesson, &QAction::triggered, this, &LessonView::slotDeleteLesson); connect(actionSplitLesson, &QAction::triggered, this, &LessonView::slotSplitLesson); connect(actionRemoveGradesLesson, &QAction::triggered, this, &LessonView::slotRemoveGradesLesson); connect(actionRemoveGradesLessonChildren, &QAction::triggered, this, &LessonView::slotRemoveGradesLessonChildren); connect(actionExpandAll, &QAction::triggered, this, &LessonView::expandAllLesson); connect(actionCollapseAll, &QAction::triggered, this, &LessonView::collapseAllLesson); // right click menu for the lesson view: addAction(actionNewLesson); addAction(actionRenameLesson); addAction(actionDeleteLesson); QAction* separator = new QAction(this); separator->setSeparator(true); addAction(separator); addAction(actionRemoveGradesLesson); addAction(actionRemoveGradesLessonChildren); separator = new QAction(this); separator->setSeparator(true); addAction(separator); addAction(actionSplitLesson); addAction(actionExpandAll); addAction(actionCollapseAll); } void LessonView::currentChanged(const QModelIndex & current, const QModelIndex & previous) { QTreeView::currentChanged(current, previous); if (current.isValid()) { KEduVocLesson *container = static_cast(current.internalPointer()); if (container) { emit selectedLessonChanged(container); emit signalShowContainer(container); } } } void LessonView::selectionChanged(const QItemSelection & selected, const QItemSelection & deselected) { QTreeView::selectionChanged(selected, deselected); if (selected.count() == 0) { return; } KEduVocLesson *container = static_cast(selected.indexes().value(0).internalPointer()); if (container) { emit selectedLessonChanged(container); } } void LessonView::setTranslation(KEduVocExpression * entry, int translation) { Q_UNUSED(translation) if (entry == 0) { selectionModel()->clearSelection(); return; } QModelIndex index(m_model->index(entry->lesson())); selectionModel()->select(index, QItemSelectionModel::ClearAndSelect); scrollTo(index); } void LessonView::slotCreateNewLesson() { QModelIndex selectedIndex = selectionModel()->currentIndex(); if (!selectedIndex.isValid()) { selectedIndex = m_model->index(0, 0, QModelIndex()); } QModelIndex modelIndex = m_model->appendContainer(selectedIndex); scrollTo(modelIndex); selectionModel()->setCurrentIndex(modelIndex, QItemSelectionModel::ClearAndSelect); edit(modelIndex); // let the user type a new name for the lesson } void LessonView::slotDeleteLesson() { QModelIndex selectedIndex = selectionModel()->currentIndex(); if (selectedIndex.parent() == QModelIndex()) { KMessageBox::information(this, i18n("The root lesson cannot be deleted.")); return; } KEduVocLesson* lesson = static_cast(selectedIndex.internalPointer()); int count = lesson->entryCount(KEduVocLesson::Recursive); if (count == 0 || KMessageBox::warningYesNo(this, i18np("There is %1 word left in this unit. Do you want to delete it?", "There are %1 words left in this unit. Do you want to delete them?", count)) == KMessageBox::Yes) { m_model->deleteContainer(selectedIndex); } } void LessonView::slotSplitLesson() { if (!selectionModel()->currentIndex().isValid()) { return; } /** @todo A nicer dialog would be great. * Maybe with radio buttons to ask, if the entries should be in random order or as they come. */ bool ok = false; int numEntries = QInputDialog::getInt(this, i18n("Entries per Unit"), i18n("The unit will be split into smaller unit. How many entries in each unit do you want?"), Prefs::entriesPerLesson(), 1, 1000, 1, &ok); if (!ok) { return; } Prefs::setEntriesPerLesson(numEntries); - m_model->splitLesson(selectionModel()->currentIndex(), numEntries, LessonModel::Random); + m_model->splitLesson(selectionModel()->currentIndex(), numEntries, KEduVocLessonModel::Random); setExpanded(selectionModel()->currentIndex(), true); } void LessonView::slotRemoveGradesLesson() { QModelIndex selectedIndex = selectionModel()->currentIndex(); KEduVocLesson* lesson = static_cast(selectedIndex.internalPointer()); lesson->resetGrades(-1, KEduVocContainer::NotRecursive); emit signalShowContainer(lesson); } void LessonView::slotRemoveGradesLessonChildren() { QModelIndex selectedIndex = selectionModel()->currentIndex(); KEduVocLesson* lesson = static_cast(selectedIndex.internalPointer()); lesson->resetGrades(-1, KEduVocContainer::Recursive); emit signalShowContainer(lesson); } -void LessonView::setModel(LessonModel * model) +void LessonView::setModel(KEduVocLessonModel * model) { m_model = model; ContainerView::setModel(model); connect(model, &QAbstractItemModel::columnsInserted, this, &LessonView::columnsInserted); for (int i = 2; i < model->columnCount(QModelIndex()); i++) { setColumnHidden(i, true); } } void LessonView::columnsInserted() { for (int i = 2; i < m_model->columnCount(QModelIndex()); i++) { setColumnHidden(i, true); } } void LessonView::expandAllLesson() { expandAll(); } void LessonView::collapseAllLesson() { collapseAll(); } diff --git a/src/editor/lessonview.h b/src/editor/lessonview.h index 1832c14b..f6fcb72f 100644 --- a/src/editor/lessonview.h +++ b/src/editor/lessonview.h @@ -1,98 +1,99 @@ /*************************************************************************** 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 LESSONVIEW_H #define LESSONVIEW_H #include "containerview.h" -#include "lessonmodel.h" + +#include namespace Editor { class EditorWindow; /** * View for the lesson list. * @author Frederik Gladhorn */ class LessonView : public ContainerView { Q_OBJECT public: explicit LessonView(EditorWindow *parent); /** Set the model for the view. * @param model the model */ - virtual void setModel(LessonModel *model); + virtual void setModel(KEduVocLessonModel *model); signals: /** A lesson was selected */ void selectedLessonChanged(KEduVocLesson* lesson); /** Emitted when a new container is selected. Indicates the selected container. */ void signalShowContainer(KEduVocContainer* selected); /** Emitted when any of the checkboxes for the query change. */ void lessonsInPracticeChanged(); public slots: /** Append a lesson to the model and automatically set an edit up so the user can change "New unit" into something meaningful.*/ void slotCreateNewLesson(); /** Remove a lesson. Ask if it's not empty. */ void slotDeleteLesson(); /** Creates many small lessons with the contents of the original lesson. * @todo Let the user select if entries are taken by random or order. */ void slotSplitLesson(); /** Remove the grades for the selected lesson. */ void slotRemoveGradesLesson(); /** Remove the grades for the selected lesson and its children. */ void slotRemoveGradesLessonChildren(); /** * get notified of new columns only to hide them (grades not shown by default). */ void columnsInserted(); void setTranslation(KEduVocExpression* entry, int translationId); /** Expand all the lessons and its corresponding sub-lessons **/ void expandAllLesson(); /** Collapse all the lessons and its corresponding sub-lessons **/ void collapseAllLesson(); protected slots: void selectionChanged(const QItemSelection & selected, const QItemSelection & deselected) Q_DECL_OVERRIDE; void currentChanged(const QModelIndex & current, const QModelIndex & previous) Q_DECL_OVERRIDE; private: virtual void setModel(KEduVocContainerModel *model) Q_DECL_OVERRIDE { Q_UNUSED(model) } void setModel(QAbstractItemModel *model) Q_DECL_OVERRIDE { Q_UNUSED(model) } - LessonModel *m_model; + KEduVocLessonModel *m_model; }; } #endif diff --git a/src/editor/summarywordwidget.cpp b/src/editor/summarywordwidget.cpp index 137db601..ab74f2de 100644 --- a/src/editor/summarywordwidget.cpp +++ b/src/editor/summarywordwidget.cpp @@ -1,228 +1,228 @@ /*************************************************************************** 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 "summarywordwidget.h" #include "languagesettings.h" -#include "lessonmodel.h" #include "vocabularyfilter.h" #include "wordclassmodel.h" // Qt headers #include #include #include #include #include #include // KEduVocDocument #include #include #include #include #include +#include using namespace Editor; SummaryWordWidget::SummaryWordWidget(VocabularyFilter *model, KEduVocDocument *doc, QWidget *parent) : QWidget(parent) , m_doc(doc) , m_wordTypeModel(0) , m_wordTypeView(0) , m_entry(0) , m_translationId(0) { Q_ASSERT(model); Q_ASSERT(m_doc); m_model = model; setupUi(this); slotDocumentChanged(m_doc); m_mapper = new QDataWidgetMapper(this); m_mapper->setModel(model); m_mapper->setItemDelegate(new SummaryWordDelegate(this)); connect(wordTypeComboBox, QOverload::of(&KComboBox::currentTextChanged), this, &SummaryWordWidget::wordTypeSelected); } void SummaryWordWidget::setTranslation(KEduVocExpression *entry, int translation) { if (entry) { // we need to map the widgets relative to the translation (each translation has 9 columns) m_mapper->clearMapping(); m_mapper->addMapping(wordEntry, KEduVocVocabularyModel::EntryColumnsMAX * translation + KEduVocVocabularyModel::Translation); //m_mapper->addMapping(wordTypeComboBox, // VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::WordType); m_mapper->addMapping(pronunciationEntry, KEduVocVocabularyModel::EntryColumnsMAX * translation + KEduVocVocabularyModel::Pronunciation); m_mapper->addMapping(exampleEntry, KEduVocVocabularyModel::EntryColumnsMAX * translation + KEduVocVocabularyModel::Example); m_mapper->addMapping(paraphraseEntry, KEduVocVocabularyModel::EntryColumnsMAX * translation + KEduVocVocabularyModel::Paraphrase); m_mapper->addMapping(commentEntry, KEduVocVocabularyModel::EntryColumnsMAX * translation + KEduVocVocabularyModel::Comment); languageLabel->setText("" + m_doc->identifier(translation).name() + ""); lessonLabel->setText(entry->lesson()->name()); setCurrentWordType(entry, translation); } else { clear(); } m_entry = entry; m_translationId = translation; } void SummaryWordWidget::slotDocumentChanged(KEduVocDocument *doc) { m_doc = doc; if (!m_doc) { qDebug() << "Set invalid document"; delete m_wordTypeModel; m_wordTypeModel = 0; } else { delete m_wordTypeView; if (!m_wordTypeModel) { qDebug() << "Create word type model for summary view"; m_wordTypeModel = new WordClassModel(this); } m_wordTypeModel->setDocument(m_doc); m_wordTypeView = new QTreeView(this); m_wordTypeView->setModel(m_wordTypeModel); wordTypeComboBox->setModel(m_wordTypeModel); wordTypeComboBox->setView(m_wordTypeView); m_wordTypeView->setColumnHidden(1, true); m_wordTypeView->header()->setVisible(false); m_wordTypeView->setRootIsDecorated(true); m_wordTypeView->expandAll(); } } void SummaryWordWidget::slotSelectionChanged(const QItemSelection &itemSelected, const QItemSelection &itemDeselected) { Q_UNUSED(itemDeselected) if (itemSelected.indexes().size() >= 1) { // the selected index belongs to VocabularyFilter, when we need it from the vocabulary model QModelIndex index = m_model->index(itemSelected.indexes().at(0).row(), itemSelected.indexes().at(0).column()); 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 SummaryWordWidget::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 m_wordTypeView->setCurrentIndex(m_wordTypeModel->index(entry->translation(translation)->wordType())); } else { wordTypeComboBox->setCurrentIndex(-1); } } void SummaryWordWidget::clear() { qDebug() << "Clear summary widget"; languageLabel->setText(QString()); wordEntry->setText(QString()); // lessonComboBox->clear(); lessonLabel->setText(QString()); pronunciationEntry->setText(QString()); exampleEntry->setText(QString()); paraphraseEntry->setText(QString()); commentEntry->setText(QString()); } SummaryWordDelegate::SummaryWordDelegate(QObject *parent) : QItemDelegate(parent) { } void SummaryWordDelegate::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 SummaryWordWidget::wordTypeSelected(const QString& wordTypeName) { if (!m_doc || !m_entry) { return; } KEduVocContainer* container = m_doc->wordTypeContainer()->childContainer(wordTypeName); if (container) { KEduVocWordType *wordType = static_cast(container); if (wordType) { m_entry->translation(m_translationId)->setWordType(wordType); } } }