diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a43446c4..a9a12c50 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/vocabularymodel.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/collection/vocabularyfilter.cpp b/src/collection/vocabularyfilter.cpp index 72902e37..fa8d5512 100644 --- a/src/collection/vocabularyfilter.cpp +++ b/src/collection/vocabularyfilter.cpp @@ -1,78 +1,78 @@ /*************************************************************************** Copyright 2007-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 "vocabularyfilter.h" -#include "vocabularymodel.h" +#include VocabularyFilter::VocabularyFilter(QObject *parent) : QSortFilterProxyModel(parent), m_model(0) { // do not use capitalization for searches setSortCaseSensitivity(Qt::CaseInsensitive); setFilterCaseSensitivity(Qt::CaseInsensitive); // sort locale aware: at least puts umlauts and accents in the right position. // Not sure about languages that are more different. // Also depends on the current locale. setSortLocaleAware(true); // eventually accept only one language if so desired... setFilterKeyColumn(-1); } QModelIndex VocabularyFilter::appendEntry(KEduVocExpression *expression) { if (!m_model) { return QModelIndex(); } return mapFromSource(m_model->appendEntry(expression)); } -void VocabularyFilter::setSourceModel(VocabularyModel * model) +void VocabularyFilter::setSourceModel(KEduVocVocabularyModel * model) { QSortFilterProxyModel::setSourceModel(model); m_model = model; } void VocabularyFilter::setSearchString(const QString & expression) { m_filterString = expression; invalidateFilter(); } bool VocabularyFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { if (m_filterString.isEmpty()) { return true; } int columns = m_model->columnCount(QModelIndex()); - for (int i = 0; i < columns; i += VocabularyModel::EntryColumnsMAX) { + for (int i = 0; i < columns; i += KEduVocVocabularyModel::EntryColumnsMAX) { QModelIndex index = sourceModel()->index(sourceRow, i, sourceParent); if (sourceModel()->data(index).toString().contains(m_filterString, Qt::CaseInsensitive)) { return true; } } return false; } KEduVocLesson * VocabularyFilter::lesson() { if (m_model) { return m_model->lesson(); } return 0; } diff --git a/src/collection/vocabularyfilter.h b/src/collection/vocabularyfilter.h index 3a668a3d..b51ad4db 100644 --- a/src/collection/vocabularyfilter.h +++ b/src/collection/vocabularyfilter.h @@ -1,53 +1,53 @@ /*************************************************************************** Copyright 2007-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 VOCABULARYFILTER_H #define VOCABULARYFILTER_H #include class KEduVocLesson; class KEduVocExpression; -class VocabularyModel; +class KEduVocVocabularyModel; class VocabularyFilter : public QSortFilterProxyModel { Q_OBJECT public: explicit VocabularyFilter(QObject *parent = 0); - void setSourceModel(VocabularyModel* model); + void setSourceModel(KEduVocVocabularyModel* model); QModelIndex appendEntry(KEduVocExpression *expression = 0); KEduVocLesson * lesson(); public slots: void setSearchString(const QString& expression); protected: bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_OVERRIDE; private: void setSourceModel(QAbstractItemModel *model) Q_DECL_OVERRIDE { Q_UNUSED(model) } - VocabularyModel * m_model; + KEduVocVocabularyModel * m_model; QString m_filterString; }; #endif diff --git a/src/editor/editor.cpp b/src/editor/editor.cpp index b355760f..e1e9df1d 100644 --- a/src/editor/editor.cpp +++ b/src/editor/editor.cpp @@ -1,521 +1,523 @@ /*************************************************************************** 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 "containermodel.h" #include "lessonmodel.h" -#include "vocabularymodel.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 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_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 VocabularyModel(this); + 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 ee545b47..b5cb4670 100644 --- a/src/editor/editor.h +++ b/src/editor/editor.h @@ -1,164 +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 VocabularyModel; +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; - VocabularyModel *m_vocabularyModel; + 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; 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/latexwidget.cpp b/src/editor/latexwidget.cpp index 274a1305..bdd40b7a 100644 --- a/src/editor/latexwidget.cpp +++ b/src/editor/latexwidget.cpp @@ -1,147 +1,148 @@ /*************************************************************************** Copyright 2010 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 "latexwidget.h" -#include "vocabularymodel.h" #include "vocabularyfilter.h" #include "practice/latexrenderer.h" +#include + #include #include using namespace Editor; LatexWidget::LatexWidget(VocabularyFilter *model, KEduVocDocument *doc, QWidget *parent) : QWidget(parent), m_translation(0), m_renderer(0) { m_doc = doc; m_model = model; setupUi(this); lineEdit->setPlaceholderText(i18n("Enter LaTeX code here.")); m_mapper = new QDataWidgetMapper(this); m_mapper->setModel(model); LatexDelegate *delegate = new LatexDelegate(this); delegate->setMathModeCheckBox(mathModeCheckBox); m_mapper->setItemDelegate(delegate); connect(mathModeCheckBox, &QCheckBox::stateChanged, this, &LatexWidget::checkBoxToggled); connect(lineEdit, &QLineEdit::editingFinished, this, &LatexWidget::updateLatex, Qt::QueuedConnection); } LatexWidget::~LatexWidget() { delete m_mapper; } void LatexWidget::setTranslation(KEduVocExpression *entry, int translation) { previewLabel->clear(); previewLabel->setMinimumSize(QSize(1, 1)); if (entry) { // we need to map the widgets relative to the translation (each translation has 9 columns) m_mapper->clearMapping(); m_mapper->addMapping(lineEdit, - VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::Translation); + KEduVocVocabularyModel::EntryColumnsMAX * translation + KEduVocVocabularyModel::Translation); m_translation = entry->translation(translation); updateLatex(); } } void LatexWidget::slotDocumentChanged(KEduVocDocument *doc) { m_doc = doc; } void LatexWidget::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 LatexWidget::checkBoxToggled() { // emulate editing of the line edit lineEdit->setFocus(); mathModeCheckBox->setFocus(); } void LatexWidget::updateLatex() { if (!m_translation) { return; } if (Practice::LatexRenderer::isLatex(m_translation->text())) { if (!m_renderer) { m_renderer = new Practice::LatexRenderer(this); m_renderer->setResultLabel(previewLabel); } m_renderer->renderLatex(m_translation->text()); } } LatexDelegate::LatexDelegate(QObject *parent) : QItemDelegate(parent), m_checkBox(0) { } void LatexDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { if (!index.isValid()) { return; } if (editor) { QLineEdit *entry = static_cast (editor); if (entry) { QString text = index.model()->data(index).toString(); if (text.startsWith(QLatin1String("$$")) && text.endsWith(QLatin1String("$$"))) { entry->setText(text.mid(2, text.count() - 4)); m_checkBox->setChecked(true); } else if (text.startsWith(QStringLiteral("§§")) && text.endsWith(QStringLiteral("§§"))) { entry->setText(text.mid(2, text.count() - 4)); m_checkBox->setChecked(false); } else { entry->setText(QString()); return; } } } } void LatexDelegate::setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const { if (!index.isValid()) { return; } if (editor) { QLineEdit *entry = static_cast (editor); if (entry) { QString text = entry->text(); if (m_checkBox->isChecked()) { model->setData(index, QString("$$" + text + "$$")); } else { model->setData(index, QString(QStringLiteral("§§") + text + QStringLiteral("§§"))); } } } } diff --git a/src/editor/summarywordwidget.cpp b/src/editor/summarywordwidget.cpp index 7728a85a..137db601 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 "vocabularymodel.h" #include "vocabularyfilter.h" #include "wordclassmodel.h" // Qt headers #include #include #include #include #include #include // KEduVocDocument #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, - VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::Translation); + KEduVocVocabularyModel::EntryColumnsMAX * translation + KEduVocVocabularyModel::Translation); //m_mapper->addMapping(wordTypeComboBox, // VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::WordType); m_mapper->addMapping(pronunciationEntry, - VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::Pronunciation); + KEduVocVocabularyModel::EntryColumnsMAX * translation + KEduVocVocabularyModel::Pronunciation); m_mapper->addMapping(exampleEntry, - VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::Example); + KEduVocVocabularyModel::EntryColumnsMAX * translation + KEduVocVocabularyModel::Example); m_mapper->addMapping(paraphraseEntry, - VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::Paraphrase); + KEduVocVocabularyModel::EntryColumnsMAX * translation + KEduVocVocabularyModel::Paraphrase); m_mapper->addMapping(commentEntry, - VocabularyModel::EntryColumnsMAX * translation + VocabularyModel::Comment); + 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 (VocabularyModel::columnType(index.column())) { - case VocabularyModel::WordClass: + switch (KEduVocVocabularyModel::columnType(index.column())) { + case KEduVocVocabularyModel::WordClass: break; - case VocabularyModel::Comment: - case VocabularyModel::Pronunciation: - case VocabularyModel::Translation: - case VocabularyModel::Example: - case VocabularyModel::Paraphrase: + 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); } } } diff --git a/src/editor/vocabularycolumnsdialog.cpp b/src/editor/vocabularycolumnsdialog.cpp index 3ff18269..59d0e890 100644 --- a/src/editor/vocabularycolumnsdialog.cpp +++ b/src/editor/vocabularycolumnsdialog.cpp @@ -1,153 +1,153 @@ /*************************************************************************** options to enable/disable columns for the languages ----------------------------------------------------------------------- copyright :(C) 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 "vocabularycolumnsdialog.h" // parley imports #include "documentsettings.h" -#include "vocabularymodel.h" // KDE imports #include +#include #include #include // Qt imports #include #include #include #include #include #include #include #include const int COLUMNS_LIMIT = 1; // columns for row using namespace Editor; VocabularyColumnsDialog::VocabularyColumnsDialog(KEduVocDocument *doc, QWidget *parent) : QDialog(parent), m_models() { QDialogButtonBox * button_dialog = new QDialogButtonBox; button_dialog->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel ); m_box = new QGridLayout(); m_doc = doc; m_settings = new DocumentSettings(m_doc->url().url()); setWindowTitle(i18n("Vocabulary Columns")); QWidget *main_widget = new QWidget(this); main_widget->setLayout(m_box); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget( main_widget ); layout->addWidget( button_dialog ); setLayout( layout ); connect(button_dialog, &QDialogButtonBox::accepted, this, &VocabularyColumnsDialog::accept); connect(button_dialog, &QDialogButtonBox::rejected, this, &VocabularyColumnsDialog::reject); KTitleWidget *titleWidget = new KTitleWidget(this); titleWidget->setText(i18n("Enable/Disable the columns for each language")); titleWidget->setPixmap(QIcon::fromTheme(QStringLiteral("view-file-columns")).pixmap(22, 22), KTitleWidget::ImageRight); m_box->addWidget(titleWidget, 0, 0, 1, 2); createLanguagesLayout(); } VocabularyColumnsDialog::~VocabularyColumnsDialog() { delete m_settings; } void VocabularyColumnsDialog::accept() { saveVisibleColumns(); QDialog::accept(); } void VocabularyColumnsDialog::createLanguagesLayout() { int row = 1; int column = 0; for (int i = 0; i < m_doc->identifierCount(); i++) { m_models [i] = new QStandardItemModel(this); QGroupBox *box = new QGroupBox(m_doc->identifier(i).name(), 0); QVBoxLayout *box_layout = new QVBoxLayout(0); m_box->addWidget(box, row, column); if (column < COLUMNS_LIMIT) { column ++; } else { row ++; column = 0; } box->setLayout(box_layout); addLanguage(i, box_layout); } } void VocabularyColumnsDialog::addLanguage(int i, QVBoxLayout *parent) { - for (int c = 1; c < VocabularyModel::EntryColumnsMAX; c++) { - QStandardItem *item_data = new QStandardItem(VocabularyModel::columnTitle(m_doc, i, c, /*addLocaleSuffix*/ false)); + for (int c = 1; c < KEduVocVocabularyModel::EntryColumnsMAX; c++) { + QStandardItem *item_data = new QStandardItem(KEduVocVocabularyModel::columnTitle(m_doc, i, c, /*addLocaleSuffix*/ false)); item_data->setData(QVariant(c - 1), VocabularyColumnsDialog::ColumnRole); item_data->setData(QVariant(i), VocabularyColumnsDialog::LanguageRole); item_data->setCheckable(true); item_data->setEditable(false); // check if the column is active if (m_settings->visibleColumns().size() >= (i * 8 + c)) { item_data->setCheckState(m_settings->visibleColumns().at(i * 8 + c) == 1 ? Qt::Checked : Qt::Unchecked); } m_models [i]->insertRow(c - 1, item_data); } QTreeView *treeView = new QTreeView(this); treeView->header()->hide(); treeView->setModel(m_models [i]); parent->addWidget(treeView); } void VocabularyColumnsDialog::saveVisibleColumns() { QList columns; for (int i = 0; i < m_doc->identifierCount(); i++) { // each model for every language columns << 1; for (int row = 0; row < m_models [i]->rowCount(); row++) { // the columns for one language int enabled = (m_models [i]->item(row)->checkState() == Qt::Checked) ? 1 : 0; columns << enabled; } } // i think that this is not the place for this m_settings->setVisibleColumns(columns); m_settings->save(); } diff --git a/src/editor/vocabularycolumnsdialog.h b/src/editor/vocabularycolumnsdialog.h index df5013f8..75531486 100644 --- a/src/editor/vocabularycolumnsdialog.h +++ b/src/editor/vocabularycolumnsdialog.h @@ -1,78 +1,79 @@ /*************************************************************************** options to enable/disable columns for the languages ----------------------------------------------------------------------- copyright :(C) 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 VOCABULARYCOLUMNSDIALOG_H #define VOCABULARYCOLUMNSDIALOG_H #include #include class DocumentSettings; class QGridLayout; class QStandardItem; class QStandardItemModel; class QVBoxLayout; class KEduVocDocument; +class KEduVocVocabularyModel; namespace Editor { /** * Show options to enable/disable the columns for each language of the current document */ class VocabularyColumnsDialog : public QDialog { Q_OBJECT public: enum Roles { ColumnRole = 0x12, LanguageRole = 0x18 }; VocabularyColumnsDialog(KEduVocDocument *doc, QWidget *parent); ~VocabularyColumnsDialog(); void accept() Q_DECL_OVERRIDE; private: /** * Initialize the gridlayout of the widget * with one treeview for each language showing the possible columns */ void createLanguagesLayout(); /** * Adds a language to the main gridlayout */ void addLanguage(int language, QVBoxLayout *parent); /** * Save the visible columns for each language in the document settings */ void saveVisibleColumns(); DocumentSettings *m_settings; QGridLayout *m_box; KEduVocDocument *m_doc; QMap m_models; }; } #endif diff --git a/src/editor/vocabularydelegate.cpp b/src/editor/vocabularydelegate.cpp index b2e0b9f2..fd8f40d3 100644 --- a/src/editor/vocabularydelegate.cpp +++ b/src/editor/vocabularydelegate.cpp @@ -1,372 +1,372 @@ /*************************************************************************** Copyright 2006, 2007 Peter Hedlund Copyright 2007 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 "vocabularydelegate.h" -#include "vocabularymodel.h" #include "vocabularyfilter.h" #include "prefs.h" #include "languagesettings.h" #include "readonlycontainermodel.h" #include #include +#include #include #include #include #include #include #include #include #include #include #include using namespace Editor; VocabularyDelegate::VocabularyDelegate(QObject *parent) : QItemDelegate(parent), m_doc(0), m_translator(0) { } QSet VocabularyDelegate::getTranslations(const QModelIndex & index) const { if (Prefs::automaticTranslation() == false) return QSet(); QSet translations; //translations of this column from all the other languages - int language = index.column() / VocabularyModel::EntryColumnsMAX; + int language = index.column() / KEduVocVocabularyModel::EntryColumnsMAX; QString toLanguage = m_doc->identifier(language).locale(); //iterate through all the Translation columns for (int i = 0; i < index.model()->columnCount(index.parent()); i ++) { - if (VocabularyModel::columnType(i) == VocabularyModel::Translation) { //translation column - QString fromLanguage = m_doc->identifier(VocabularyModel::translation(i)).locale(); + if (KEduVocVocabularyModel::columnType(i) == KEduVocVocabularyModel::Translation) { //translation column + QString fromLanguage = m_doc->identifier(KEduVocVocabularyModel::translation(i)).locale(); QString word = index.model()->index(index.row(), i, QModelIndex()).data().toString(); if (fromLanguage != toLanguage) { // qDebug() << fromLanguage << toLanguage << word; //get the word translations and add them to the translations set QSet * tr = m_translator->getTranslation(word, fromLanguage, toLanguage); if (tr) translations.unite(* (tr)); } } } return translations; } QWidget * VocabularyDelegate::createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const { Q_UNUSED(option); /// as long as it's unused if (!index.isValid()) { return 0; } - switch (VocabularyModel::columnType(index.column())) { - case VocabularyModel::WordClass: { + switch (KEduVocVocabularyModel::columnType(index.column())) { + case KEduVocVocabularyModel::WordClass: { if (!m_doc) return 0; KComboBox *wordTypeCombo = new KComboBox(parent); WordTypeBasicModel *basicWordTypeModel = new WordTypeBasicModel(parent); wordTypeCombo->setModel(basicWordTypeModel); QTreeView *view = new QTreeView(parent); view->setModel(basicWordTypeModel); wordTypeCombo->setView(view); view->header()->setVisible(false); view->setRootIsDecorated(true); basicWordTypeModel->setDocument(m_doc); view->expandAll(); qDebug() << "index data" << index.data().toString(); //view->setCurrentItem(); return wordTypeCombo; } - case VocabularyModel::Translation: + case KEduVocVocabularyModel::Translation: { if (!m_doc || !m_translator) return 0; - if (VocabularyModel::columnType(index.column()) == VocabularyModel::Translation) { + if (KEduVocVocabularyModel::columnType(index.column()) == KEduVocVocabularyModel::Translation) { //get the translations of this word (fetch only with the help of scripts, if enabled) QSet translations = getTranslations(index); //create combo box //if there is only one word and that is the suggestion word (in translations) then don't create the combobox if (!translations.isEmpty() && !(translations.size() == 1 && (*translations.begin()) == index.model()->data(index, Qt::DisplayRole).toString())) { KComboBox *translationCombo = new KComboBox(parent); translationCombo->setFrame(false); translationCombo->addItems(translations.toList()); translationCombo->setEditable(true); translationCombo->setFont(index.model()->data(index, Qt::FontRole).value()); translationCombo->setEditText(index.model()->data(index, Qt::DisplayRole).toString()); translationCombo->completionObject()->setItems(translations.toList()); return translationCombo; } } // no break - we fall back to a line edit if there are not multiple translations fetched onlin // fallthrough default: { QLineEdit *editor = new QLineEdit(parent); editor->setFrame(false); editor->setFont(index.model()->data(index, Qt::FontRole).value()); editor->setText(index.model()->data(index, Qt::DisplayRole).toString()); - QString locale = index.model()->data(index, VocabularyModel::LocaleRole).toString(); + QString locale = index.model()->data(index, KEduVocVocabularyModel::LocaleRole).toString(); if (!locale.isEmpty()) { LanguageSettings settings(locale); settings.load(); QString layout = settings.keyboardLayout(); if (!layout.isEmpty()) { QDBusInterface kxkb(QStringLiteral("org.kde.keyboard"), QStringLiteral("/Layouts"), QStringLiteral("org.kde.KeyboardLayouts")); if (kxkb.isValid()) { kxkb.call(QStringLiteral("setLayout"), layout); } } } return editor; } } } bool VocabularyDelegate::helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index) { Q_UNUSED(view); if (event->type() == QEvent::ToolTip) { QPainterPath audioPainterPath; QPainterPath imagePainterPath; audioPainterPath.addPolygon(audioPolygon(option)); imagePainterPath.addPolygon(imagePolygon(option)); int column = columnType(index.column()); if (audioPainterPath.contains(event->pos()) && hasAudio(index) && (column == Translation || column == Pronunciation)) { QToolTip::showText(event->globalPos(), i18n("Sound file selected: %1", audioUrl(index))); } else if (imagePainterPath.contains(event->pos()) && hasImage(index) && (column == Translation || column == Pronunciation)) { QToolTip::showText(event->globalPos(), i18n("Image file selected: %1", imageUrl(index))); } else { QToolTip::hideText(); event->ignore(); } return true; } return false; } QPolygon VocabularyDelegate::audioPolygon(const QStyleOptionViewItem &option) const { QRect rect = option.rect; QPolygon polygon; polygon << QPoint(rect.x() + rect.width() - 10, rect.y()); polygon << QPoint(rect.x() + rect.width(), rect.y()); polygon << QPoint(rect.x() + rect.width(), rect.y() + 10); return polygon; } QPolygon VocabularyDelegate::imagePolygon(const QStyleOptionViewItem &option) const { QRect rect = option.rect; QPolygon polygon; polygon << QPoint(rect.x() + rect.width() - 10, rect.y() + rect.height()); polygon << QPoint(rect.x() + rect.width(), rect.y() + rect.height()); polygon << QPoint(rect.x() + rect.width(), rect.y() + rect.height() - 10); return polygon; } bool VocabularyDelegate::hasAudio(const QModelIndex &index) const { return !audioUrl(index).isEmpty(); } bool VocabularyDelegate::hasImage(const QModelIndex &index) const { return !imageUrl(index).isEmpty(); } QString VocabularyDelegate::audioUrl(const QModelIndex &index) const { - QVariant audioVar = index.data(VocabularyModel::AudioRole); + QVariant audioVar = index.data(KEduVocVocabularyModel::AudioRole); QString audioUrl = audioVar.toString(); return audioUrl; } QString VocabularyDelegate::imageUrl(const QModelIndex &index) const { - QVariant imageVar = index.data(VocabularyModel::ImageRole); + QVariant imageVar = index.data(KEduVocVocabularyModel::ImageRole); QString imageUrl = imageVar.toString(); return imageUrl; } int VocabularyDelegate::columnType(int column) { return column % EntryColumnsMAX; } void VocabularyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QItemDelegate::paint(painter, option, index); painter->save(); int column = columnType(index.column()); if (hasAudio(index) == true && (column == Translation || column == Pronunciation)) { painter->setPen(QPen(Qt::red)); painter->setBrush(QBrush(Qt::red)); painter->drawPolygon(audioPolygon(option)); } if (hasImage(index) == true && (column == Translation || column == Pronunciation)) { painter->setPen(QPen(Qt::blue)); painter->setBrush(QBrush(Qt::blue)); painter->drawPolygon(imagePolygon(option)); } painter->restore(); } void VocabularyDelegate::setEditorData(QWidget * editor, const QModelIndex & index) const { if (!index.isValid()) { return; } - switch (VocabularyModel::columnType(index.column())) { - case (VocabularyModel::Translation) : { + switch (KEduVocVocabularyModel::columnType(index.column())) { + case (KEduVocVocabularyModel::Translation) : { QString value = index.model()->data(index, Qt::DisplayRole).toString(); KComboBox * translationCombo = qobject_cast (editor); if (translationCombo) { translationCombo->setEditText(value); if (value.isEmpty()) { // show the translations that were fetched as popup translationCombo->showPopup(); } break; } } // fallthrough default: { QString value = index.model()->data(index, Qt::DisplayRole).toString(); QLineEdit *lineEdit = qobject_cast (editor); if (lineEdit) { lineEdit->setText(value); } } } } void VocabularyDelegate::setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const { if (!index.isValid()) { return; } - switch (VocabularyModel::columnType(index.column())) { - case (VocabularyModel::WordClass) : { + switch (KEduVocVocabularyModel::columnType(index.column())) { + case (KEduVocVocabularyModel::WordClass) : { qDebug() << "word type editor"; KComboBox *combo = qobject_cast (editor); if (!combo) { return; } qDebug() << "combo" << combo->currentText(); QModelIndex comboIndex = combo->view()->currentIndex(); KEduVocWordType* wordType = static_cast(comboIndex.internalPointer()); // the root is the same as no word type if (wordType && wordType->parent() == 0) { wordType = 0; } VocabularyFilter *filter = qobject_cast (model); - VocabularyModel *vocModel = qobject_cast ((filter)->sourceModel()); + KEduVocVocabularyModel *vocModel = qobject_cast ((filter)->sourceModel()); Q_ASSERT(vocModel); - QVariant data = vocModel->data(filter->mapToSource(index), VocabularyModel::EntryRole); + QVariant data = vocModel->data(filter->mapToSource(index), KEduVocVocabularyModel::EntryRole); KEduVocExpression *expression = data.value(); Q_ASSERT(expression); - int translationId = VocabularyModel::translation(index.column()); + int translationId = KEduVocVocabularyModel::translation(index.column()); expression->translation(translationId)->setWordType(wordType); model->setData(index, combo->currentText()); break; } - case (VocabularyModel::Translation) : { + case (KEduVocVocabularyModel::Translation) : { QLineEdit *lineEdit = qobject_cast (editor); if (lineEdit) { model->setData(index, lineEdit->text()); } break; } default: { QLineEdit *lineEdit = qobject_cast (editor); if (lineEdit) { model->setData(index, lineEdit->text()); } } } } void VocabularyDelegate::setDocument(KEduVocDocument * doc) { m_doc = doc; } /* QPair< QString, QString > VocabularyDelegate::guessWordType(const QString & entry, int language) const { qDebug() << "guessing word type for: " << entry; QString article = entry.section(" ", 0, 0); if ( article.length() < entry.length() ) { if ( article == ->identifier(language).articles().article(KEduVocWordFlag::Singular| KEduVocWordFlag::Definite| KEduVocWordFlag::Masculine) ) { qDebug() << "Noun masculine"; return qMakePair(m_doc->wordTypes().specialTypeNoun(), m_doc->wordTypes().specialTypeNounMale()); } } return qMakePair(QString(), QString()); } */ VocabularyDelegate::WordTypeBasicModel::WordTypeBasicModel(QObject * parent) : ReadonlyContainerModel(KEduVocContainer::WordType, parent) { } KEduVocContainer * VocabularyDelegate::WordTypeBasicModel::rootContainer() const { if (!m_doc) { return 0; } return m_doc->wordTypeContainer(); } /** * Sets the member variable m_translator to a Translator object * @param translator Translator Object to be used for retrieving word translations */ void VocabularyDelegate::setTranslator(Translator* translator) { m_translator = translator; } diff --git a/src/editor/vocabularyview.cpp b/src/editor/vocabularyview.cpp index e330f00a..8cca6eb2 100644 --- a/src/editor/vocabularyview.cpp +++ b/src/editor/vocabularyview.cpp @@ -1,465 +1,465 @@ /*************************************************************************** Copyright 2006, 2007 Peter Hedlund Copyright 2007-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. * * * ***************************************************************************/ ///@file vocabularyview.cpp #include "vocabularyview.h" #include "vocabularyheaderview.h" -#include "vocabularymodel.h" #include "vocabularyfilter.h" #include "vocabularydelegate.h" #include "vocabularymimedata.h" #include "editor/editor.h" #include "prefs.h" #include "vocabularycolumnsdialog.h" #include "documentsettings.h" #include #include +#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace Editor; VocabularyView::VocabularyView(EditorWindow * parent) : QTableView(parent), m_model(0), m_doc(0), m_spellChecker(0), m_spellDialog(0) { installEventFilter(this); setHorizontalHeader(new VocabularyHeaderView(Qt::Horizontal, this)); horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); horizontalHeader()->setSectionsMovable(true); setEditTriggers(QAbstractItemView::AnyKeyPressed | QAbstractItemView::EditKeyPressed | QAbstractItemView::DoubleClicked); setSortingEnabled(true); setTabKeyNavigation(true); m_vocabularyDelegate = new VocabularyDelegate(this); setItemDelegate(m_vocabularyDelegate); setFrameStyle(QFrame::NoFrame); setAlternatingRowColors(true); // Enable context menus setContextMenuPolicy(Qt::ActionsContextMenu); horizontalHeader()->setContextMenuPolicy(Qt::ActionsContextMenu); setWordWrap(true); setDragEnabled(true); // smooth scrolling horizontally, otherwise it tries to jump from item to item. setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); m_appendEntryAction = new QAction(this); parent->actionCollection()->addAction(QStringLiteral("edit_append"), m_appendEntryAction); parent->actionCollection()->setDefaultShortcut( m_appendEntryAction, QKeySequence(Qt::Key_Insert)); m_appendEntryAction->setIcon(QIcon::fromTheme(QStringLiteral("list-add-card"))); m_appendEntryAction->setText(i18n("&Add New Entry")); connect(m_appendEntryAction, &QAction::triggered, this, &VocabularyView::appendEntry); m_appendEntryAction->setShortcut(QKeySequence(Qt::Key_Insert)); m_appendEntryAction->setWhatsThis(i18n("Append a new row to the vocabulary")); m_appendEntryAction->setToolTip(m_appendEntryAction->whatsThis()); m_appendEntryAction->setStatusTip(m_appendEntryAction->whatsThis()); addAction(m_appendEntryAction); m_deleteEntriesAction = new QAction(this); parent->actionCollection()->addAction(QStringLiteral("edit_remove_selected_area"), m_deleteEntriesAction); parent->actionCollection()->setDefaultShortcut( m_deleteEntriesAction, QKeySequence::Delete); m_deleteEntriesAction->setIcon(QIcon::fromTheme(QStringLiteral("list-remove-card"))); m_deleteEntriesAction->setText(i18n("&Delete Entry")); connect(m_deleteEntriesAction, &QAction::triggered, this, &VocabularyView::deleteSelectedEntries); m_deleteEntriesAction->setShortcut(QKeySequence::Delete); m_deleteEntriesAction->setWhatsThis(i18n("Delete the selected rows")); m_deleteEntriesAction->setToolTip(m_deleteEntriesAction->whatsThis()); m_deleteEntriesAction->setStatusTip(m_deleteEntriesAction->whatsThis()); addAction(m_deleteEntriesAction); QAction* separator = new QAction(this); separator->setSeparator(true); addAction(separator); m_copyAction = KStandardAction::copy(this, SLOT(slotEditCopy()), parent->actionCollection()); parent->actionCollection()->setDefaultShortcut( m_copyAction, QKeySequence::Copy); m_copyAction->setWhatsThis(i18n("Copy")); m_copyAction->setToolTip(m_copyAction->whatsThis()); m_copyAction->setStatusTip(m_copyAction->whatsThis()); addAction(m_copyAction); m_cutAction = KStandardAction::cut(this, SLOT(slotCutEntry()), parent->actionCollection()); parent->actionCollection()->setDefaultShortcut( m_cutAction, QKeySequence::Cut); m_cutAction->setWhatsThis(i18n("Cut")); m_cutAction->setToolTip(m_cutAction->whatsThis()); m_cutAction->setStatusTip(m_cutAction->whatsThis()); addAction(m_cutAction); m_pasteAction = KStandardAction::paste(this, SLOT(slotEditPaste()), parent->actionCollection()); parent->actionCollection()->setDefaultShortcut( m_pasteAction, QKeySequence::Paste); m_pasteAction->setWhatsThis(i18n("Paste")); m_pasteAction->setToolTip(m_pasteAction->whatsThis()); m_pasteAction->setStatusTip(m_pasteAction->whatsThis()); addAction(m_pasteAction); m_selectAllAction = KStandardAction::selectAll(this, SLOT(selectAll()), parent->actionCollection()); parent->actionCollection()->setDefaultShortcut( m_selectAllAction, QKeySequence::SelectAll); m_selectAllAction->setWhatsThis(i18n("Select all rows")); m_selectAllAction->setToolTip(m_selectAllAction->whatsThis()); m_selectAllAction->setStatusTip(m_selectAllAction->whatsThis()); m_clearSelectionAction = KStandardAction::deselect(this, SLOT(clearSelection()), parent->actionCollection()); parent->actionCollection()->setDefaultShortcut( m_clearSelectionAction, QKeySequence::Deselect); m_clearSelectionAction->setWhatsThis(i18n("Deselect all rows")); m_clearSelectionAction->setToolTip(m_clearSelectionAction->whatsThis()); m_clearSelectionAction->setStatusTip(m_clearSelectionAction->whatsThis()); // vocabulary columns dialog QAction *vocabularyColumnsDialogAction = new QAction(this); parent->actionCollection()->addAction(QStringLiteral("show_vocabulary_columns_dialog"), vocabularyColumnsDialogAction); vocabularyColumnsDialogAction->setIcon(QIcon::fromTheme(QStringLiteral("view-file-columns"))); vocabularyColumnsDialogAction->setText(i18n("Vocabulary Columns...")); vocabularyColumnsDialogAction->setWhatsThis(i18n("Toggle display of individual vocabulary columns")); vocabularyColumnsDialogAction->setToolTip(vocabularyColumnsDialogAction->whatsThis()); vocabularyColumnsDialogAction->setStatusTip(vocabularyColumnsDialogAction->whatsThis()); horizontalHeader()->addAction(vocabularyColumnsDialogAction); addAction(vocabularyColumnsDialogAction); connect(vocabularyColumnsDialogAction, &QAction::triggered, this, &VocabularyView::slotShowVocabularyColumnsDialog); } void VocabularyView::setFilter(VocabularyFilter * model) { QTableView::setModel(model); m_model = model; connect(selectionModel(), &QItemSelectionModel::currentChanged, this, &VocabularyView::slotCurrentChanged); connect(selectionModel(), &QItemSelectionModel::selectionChanged, this, &VocabularyView::slotSelectionChanged); slotSelectionChanged(QItemSelection(), QItemSelection()); } void VocabularyView::slotCurrentChanged(const QModelIndex & current, const QModelIndex & previous) { Q_UNUSED(previous); KEduVocExpression* entry = 0; if (current.isValid()) { - entry = model()->data(current, VocabularyModel::EntryRole).value(); + entry = model()->data(current, KEduVocVocabularyModel::EntryRole).value(); } - emit translationChanged(entry, VocabularyModel::translation(current.column())); + emit translationChanged(entry, KEduVocVocabularyModel::translation(current.column())); } void VocabularyView::reset() { QTableView::reset(); emit translationChanged(0, 0); QList visibleColumns; if (m_doc) { DocumentSettings ds(m_doc->url().url()); ds.load(); visibleColumns = ds.visibleColumns(); KConfig parleyConfig(QStringLiteral("parleyrc")); KConfigGroup documentGroup(&parleyConfig, "Document " + m_doc->url().url()); QByteArray state = documentGroup.readEntry("VocabularyColumns", QByteArray()); if (!horizontalHeader()->restoreState(state)) { resizeColumnsToContents(); } } horizontalHeader()->setSectionsMovable(true); for (int i = 0; i < model()->columnCount(QModelIndex()); i++) { if (i < visibleColumns.size()) { setColumnHidden(i, !visibleColumns.value(i)); } else { - if (VocabularyModel::columnType(i) != VocabularyModel::Translation) { + if (KEduVocVocabularyModel::columnType(i) != KEduVocVocabularyModel::Translation) { setColumnHidden(i, true); } } } } void VocabularyView::saveColumnVisibility() const { if (!m_doc) { return; } // Generate a QList for saving QList visibleList; for (int i = 0; i < m_model->columnCount(); ++i) { visibleList.append(static_cast(!isColumnHidden(i))); } DocumentSettings ds(m_doc->url().url()); ds.setVisibleColumns(visibleList); ds.save(); QByteArray saveState = horizontalHeader()->saveState(); KConfig parleyConfig(QStringLiteral("parleyrc")); KConfigGroup documentGroup(&parleyConfig, "Document " + m_doc->url().url()); documentGroup.writeEntry("VocabularyColumns", horizontalHeader()->saveState()); } void VocabularyView::appendEntry() { QModelIndex newIndex = m_model->appendEntry(); scrollTo(newIndex); selectionModel()->clear(); // otherwise proxy mapping gets screwed for some reason selectionModel()->select(newIndex, QItemSelectionModel::ClearAndSelect); selectionModel()->setCurrentIndex(newIndex, QItemSelectionModel::ClearAndSelect); edit(newIndex); } void VocabularyView::appendChar(const QChar &c) { const QModelIndex &index = selectionModel()->currentIndex(); m_model->setData(index, QString(m_model->data(index).toString() + c)); } void VocabularyView::deleteSelectedEntries(bool askConfirmation) { QSet rows; foreach(const QModelIndex & index, selectionModel()->selectedIndexes()) { rows.insert(index.row()); } bool del = true; if (askConfirmation) { del = KMessageBox::Continue == KMessageBox::warningContinueCancel(this, i18np("Do you really want to delete the selected entry?", "Do you really want to delete the selected %1 entries?", rows.count()), i18n("Delete"), KStandardGuiItem::del()); } if (del) { emit translationChanged(0, 0); while (!selectionModel()->selectedIndexes().isEmpty()) { m_model->removeRows(selectionModel()->selectedIndexes()[0].row(), 1, QModelIndex()); } } } void VocabularyView::slotEditCopy() { QModelIndexList sortedIndexes = selectionModel()->selectedIndexes(); std::sort(sortedIndexes.begin(), sortedIndexes.end()); QMimeData *mimeData = m_model->mimeData(sortedIndexes); QClipboard *clipboard = QApplication::clipboard(); clipboard->setMimeData(mimeData); } void VocabularyView::slotEditPaste() { QClipboard *clipboard = QApplication::clipboard(); const QMimeData *mimeData = clipboard->mimeData(); const VocabularyMimeData *vocMimeData = qobject_cast(mimeData); if (vocMimeData) { qDebug() << "Clipboard contains vocabulary mime data."; foreach(const VocabularyMimeData::MimeExpression & mimeEntry, vocMimeData->expressionList()) { KEduVocExpression *pasteExpression = new KEduVocExpression(mimeEntry.expression); m_model->appendEntry(pasteExpression); // find word type (create if not found) KEduVocWordType *type = m_doc->wordTypeContainer(); foreach(int translation, mimeEntry.wordTypes.keys()) { // append if needed foreach(const QString & typeName, mimeEntry.wordTypes.value(translation).wordType) { qDebug() << mimeEntry.wordTypes.value(translation).wordType; KEduVocContainer *childType = type->childContainer(typeName); if (!childType) { // the doc does not contain the right word type - create it childType = new KEduVocWordType(typeName); type->appendChildContainer(childType); } type = static_cast(childType); } pasteExpression->translation(translation)->setWordType(type); // check for special type stuff if (type->wordType() != mimeEntry.wordTypes.value(translation).grammarType) { if (type->wordType() == KEduVocWordFlag::NoInformation) { type->setWordType(mimeEntry.wordTypes.value(translation).grammarType); } } } } } else if (mimeData->hasText()) { qDebug() << "Clipboard contains text data."; // split at newline QStringList lines = clipboard->text().split('\n'); foreach(QString line, lines) { // split at tabs or semicolon: m_model->appendEntry(new KEduVocExpression(line.split(QRegExp(QStringLiteral("[\t;]")), QString::KeepEmptyParts))); } } } void VocabularyView::slotCutEntry() { slotEditCopy(); deleteSelectedEntries(false); } void VocabularyView::slotSelectionChanged(const QItemSelection &, const QItemSelection &) { bool hasSelection = selectionModel()->hasSelection(); m_deleteEntriesAction->setEnabled(hasSelection); m_clearSelectionAction->setEnabled(hasSelection); m_copyAction->setEnabled(hasSelection); m_cutAction->setEnabled(hasSelection); } void VocabularyView::setDocument(KEduVocDocument * doc) { m_doc = doc; m_vocabularyDelegate->setDocument(doc); QTimer::singleShot(0, this, SLOT(reset())); } /** * Set the translator to be used by the delegate * @param translator */ void VocabularyView::setTranslator(Translator* translator) { m_vocabularyDelegate->setTranslator(translator); } void VocabularyView::slotShowVocabularyColumnsDialog() { VocabularyColumnsDialog *dialog = new VocabularyColumnsDialog(m_doc, this); if (dialog->exec() == QDialog::Accepted) { reset(); } } void VocabularyView::checkSpelling(int language) { if (!m_model->rowCount()) { KMessageBox::information(this, i18n("Nothing to spell check.")); return; } if (!m_spellChecker) { m_spellChecker = new Sonnet::BackgroundChecker(this); m_spellDialog = new Sonnet::Dialog(m_spellChecker, this); connect(m_spellDialog, SIGNAL(done(QString)), this, SLOT(continueSpelling())); connect(m_spellDialog, &Sonnet::Dialog::misspelling, this, &VocabularyView::misspelling); connect(m_spellDialog, &Sonnet::Dialog::replace, this, &VocabularyView::spellingReplace); } - m_spellColumn = language * VocabularyModel::EntryColumnsMAX; + m_spellColumn = language * KEduVocVocabularyModel::EntryColumnsMAX; m_spellRow = -1; if (m_spellColumn < 0) { return; } QString locale = m_doc->identifier(language).locale(); LanguageSettings settings(locale); QString spellCode = settings.spellChecker().isEmpty() ? locale : settings.spellChecker(); m_spellChecker->changeLanguage(spellCode); if (!m_spellChecker->speller().isValid()) { qDebug() << "Invalid Language, popup here!"; KNotification::event(KNotification::Warning, i18nc("@title of a popup", "No Spell Checker Available"), i18nc("@popupmessage", "Either the language set up is incorrect or no spellchecker was installed for this locale: %1.", locale)); } m_spellDialog->show(); continueSpelling(); } void VocabularyView::continueSpelling() { qDebug() << "Check spelling: " << m_spellRow << m_spellColumn; ++m_spellRow; while (m_spellRow < m_model->rowCount()) { QModelIndex index = m_model->index(m_spellRow, m_spellColumn); qDebug() << " " << m_model->data(index).toString(); if (!m_model->data(index).toString().isEmpty()) { m_spellDialog->setBuffer(m_model->data(index).toString()); break; } else { ++m_spellRow; } } } void VocabularyView::selectIndex(const QModelIndex &newIndex) { selectionModel()->select(newIndex, QItemSelectionModel::ClearAndSelect); selectionModel()->setCurrentIndex(newIndex, QItemSelectionModel::ClearAndSelect); scrollTo(newIndex); } bool VocabularyView::eventFilter(QObject* obj, QEvent* event) { if (event->type() == QEvent::KeyPress && Prefs::smartAppend()) { QKeyEvent *keyEvent = static_cast(event); if (keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) { if (selectionModel()->currentIndex().row() == m_model->rowCount() - 1) { appendEntry(); } } } // standard event processing return QObject::eventFilter(obj, event); } void VocabularyView::misspelling(const QString & word, int start) { Q_UNUSED(word) Q_UNUSED(start) QModelIndex index = m_model->index(m_spellRow, m_spellColumn); selectIndex(index); } void VocabularyView::spellingReplace(const QString & oldWord, int start, const QString & newWord) { qDebug() << oldWord << start << newWord; QModelIndex index = m_model->index(m_spellRow, m_spellColumn); QString data = index.data().toString(); QString newData = data.replace(start, oldWord.length(), newWord); qDebug() << "Changing " << data << " to " << newData; m_model->setData(index, newData); } QModelIndexList VocabularyView::getSelectedIndexes() const { return selectionModel()->selectedIndexes(); } diff --git a/src/scripts/scripting/parley.cpp b/src/scripts/scripting/parley.cpp index 9cf84c5a..627ea711 100644 --- a/src/scripts/scripting/parley.cpp +++ b/src/scripts/scripting/parley.cpp @@ -1,152 +1,152 @@ /*************************************************************************** Copyright 2008 Avgoustinos Kadis ***************************************************************************/ /*************************************************************************** * * * 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 "parley.h" #include "editor/editor.h" -#include "vocabularymodel.h" +#include #include "vocabularyview.h" #include "../scriptmanager.h" #include "../translator.h" #include "document.h" #include "lesson.h" #include "expression.h" #include "translation.h" #include #include #include using namespace Editor; namespace Scripting { Parley::Parley(EditorWindow * editor) : QObject(), m_editor(editor) { m_translator = new Translator(this); //parameter has to be cause it's used by Translator to access callTranslateWord m_doc = new Document(m_editor->m_mainWindow->parleyDocument()->document()); } Parley::~Parley() { delete m_translator; delete m_doc; } void Parley::callTranslateWord(const QString & word, const QString& fromLanguage, const QString& toLanguage) { emit translationStarted(word, fromLanguage, toLanguage); emit translateWord(word, fromLanguage, toLanguage); emit translationFinished(word, fromLanguage, toLanguage); } void Parley::addTranslation(const QString &word, const QString &fromLanguage, const QString &toLanguage, const QString &translation) { if (m_translator) m_translator->addTranslation(word, fromLanguage, toLanguage, translation); } QStringList Parley::locales() { /// @todo Change it into a QMap property (Parley.languageCodes) return QLocale().uiLanguages(); } QString Parley::localeName(const QString &locale) { return QLocale( locale ).nativeLanguageName( ); } void Parley::open(const QString &filename) { QUrl url( QUrl::fromLocalFile(filename) ); qDebug() << url; m_editor->m_mainWindow->parleyDocument()->open(url); } QObject* Parley::activeLesson() { return new Lesson(m_editor->m_vocabularyModel->lesson()); } QVariantList Parley::selectedEntries() { QVariantList entries; //get selected indexes and active lesson QModelIndexList indexes = m_editor->m_vocabularyView->getSelectedIndexes(); //get the unique selected entries QSet kentries; foreach(const QModelIndex & index, indexes) { // qDebug() << index.row() << index.data(Qt::DisplayRole); - KEduVocExpression * expr = qvariant_cast (index.data(VocabularyModel::EntryRole)); + KEduVocExpression * expr = qvariant_cast (index.data(KEduVocVocabularyModel::EntryRole)); kentries << expr; } //convert them to Expression objects and add them to the QVariantList foreach(KEduVocExpression * expr, kentries) { // Expression entry(expr); // qDebug() << entry.translationTexts(); QObject * obj = new Expression(expr); entries << QVariant::fromValue(obj); } return entries; } QVariantList Parley::selectedTranslations() { QVariantList translations; //get selected indexes and active lesson QModelIndexList indexes = m_editor->m_vocabularyView->getSelectedIndexes(); //get the unique selected entries QSet ktranslations; // const QModelIndex &index; foreach(const QModelIndex & index, indexes) { - if (VocabularyModel::columnType(index.column()) == VocabularyModel::Translation) { - KEduVocExpression * expr = qvariant_cast (index.data(VocabularyModel::EntryRole)); - ktranslations << expr->translation(VocabularyModel::translation(index.column())); + if (KEduVocVocabularyModel::columnType(index.column()) == KEduVocVocabularyModel::Translation) { + KEduVocExpression * expr = qvariant_cast (index.data(KEduVocVocabularyModel::EntryRole)); + ktranslations << expr->translation(KEduVocVocabularyModel::translation(index.column())); } // qDebug() << index.row() << index.data(Qt::DisplayRole); } //convert them to Expression objects and add them to the QVariantList foreach(KEduVocTranslation * tr, ktranslations) { // Translation transltion(tr); // qDebug() << entry.translationTexts(); QObject * obj = new Translation(tr); translations << QVariant::fromValue(obj); } return translations; } QObject * Scripting::Parley::newAction(const QString & name, const QString& text) { //create new action QAction* action = new QAction(text, m_editor); m_editor->m_scriptManager->addScriptAction(name, action); return action; } }