diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 192fd27b..cf975c72 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,187 +1,186 @@ 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/containerview.cpp editor/editor.cpp editor/lessonview.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 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/containerview.cpp b/src/collection/containerview.cpp deleted file mode 100644 index 8e063440..00000000 --- a/src/collection/containerview.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/*************************************************************************** - - 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. * - * * - ***************************************************************************/ - -// Own -#include "containerview.h" - -// Qt -#include - -// KEduVoc -#include - - -ContainerView::ContainerView(QWidget *parent) : QTreeView(parent) -{ - header()->setStretchLastSection(false); - header()->setVisible(false); - - setAlternatingRowColors(true); - - // show the actions added by addAction() as right click menu. - setContextMenuPolicy(Qt::ActionsContextMenu); - - setDragEnabled(true); - setAcceptDrops(true); - setDropIndicatorShown(true); - setDragDropMode(QAbstractItemView::DragDrop); -} - -void ContainerView::setModel(KEduVocContainerModel *model) -{ - QTreeView::setModel(model); - m_model = model; - - header()->setSectionResizeMode(0, QHeaderView::Stretch); - header()->setSectionResizeMode(1, QHeaderView::ResizeToContents); -} - -void ContainerView::slotRename() -{ - edit(selectionModel()->currentIndex()); -} diff --git a/src/collection/containerview.h b/src/collection/containerview.h deleted file mode 100644 index eaf7f4cf..00000000 --- a/src/collection/containerview.h +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************** - - 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. * - * * - ***************************************************************************/ - -#ifndef CONTAINERVIEW_H -#define CONTAINERVIEW_H - -#include - -class KEduVocContainer; - -class KEduVocContainerModel; - - -/** - * View for containers (KEduVocContainer). - * @author Frederik Gladhorn - */ -class ContainerView : public QTreeView -{ - Q_OBJECT -public: - /** Set up the lesson list widget. - * Also creates the menu to manipulate the lessons. - * @param parent parent widget */ - explicit ContainerView(QWidget *parent = 0); - /** Set the model for the view. - * @param model the model */ - virtual void setModel(KEduVocContainerModel *model); - -public slots: - /** let the user type a new name for the container */ - void slotRename(); - -protected: - /** ContainerModel for this view. */ - KEduVocContainerModel *m_model; - -private: - // intentionally hide this to make sure a proper model is passed - void setModel(QAbstractItemModel *model) Q_DECL_OVERRIDE { - Q_UNUSED(model) - } -}; - - -#endif diff --git a/src/editor/editor.cpp b/src/editor/editor.cpp index 718c90b1..7012d461 100644 --- a/src/editor/editor.cpp +++ b/src/editor/editor.cpp @@ -1,529 +1,530 @@ /*************************************************************************** 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 // 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 "parleymainwindow.h" #include "settings/parleyprefs.h" #include "prefs.h" #include "scripts/scriptdialog.h" #include "parleyactions.h" #include "parleyadaptor.h" //KEduVoc #include #include #include #include #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::setAutomaticTranslation(bool v) { Prefs::setAutomaticTranslation(v); } 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 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 KEduVocWordClassModel(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(setRecursive(bool)), actionCollection()); ParleyActions::create(ParleyActions::AutomaticTranslation, this, SLOT(setAutomaticTranslation(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 KEduVocVocabularyFilter(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/lessonview.cpp b/src/editor/lessonview.cpp index b598a417..9373ffd1 100644 --- a/src/editor/lessonview.cpp +++ b/src/editor/lessonview.cpp @@ -1,259 +1,260 @@ /*************************************************************************** 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 "prefs.h" using namespace Editor; -LessonView::LessonView(EditorWindow * parent) : ContainerView(parent) +LessonView::LessonView(EditorWindow * parent) + : KEduVocContainerView(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, 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(KEduVocLessonModel * model) { m_model = model; - ContainerView::setModel(model); + KEduVocContainerView::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 f6fcb72f..12a3d594 100644 --- a/src/editor/lessonview.h +++ b/src/editor/lessonview.h @@ -1,99 +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 #include namespace Editor { class EditorWindow; /** * View for the lesson list. * @author Frederik Gladhorn */ -class LessonView : public ContainerView +class LessonView : public KEduVocContainerView { Q_OBJECT public: explicit LessonView(EditorWindow *parent); /** Set the model for the view. * @param model the 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) } KEduVocLessonModel *m_model; }; } #endif diff --git a/src/editor/wordtypeview.cpp b/src/editor/wordtypeview.cpp index 9bae70b9..54b8cb95 100644 --- a/src/editor/wordtypeview.cpp +++ b/src/editor/wordtypeview.cpp @@ -1,328 +1,329 @@ /*************************************************************************** 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 "wordtypeview.h" #include #include #include #include #include #include #include #include #include +#include #include "editor/editor.h" -#include "containerview.h" using namespace Editor; -WordTypeView::WordTypeView(EditorWindow* parent) : ContainerView(parent) +WordTypeView::WordTypeView( EditorWindow* parent ) + : KEduVocContainerView(parent) { setContextMenuPolicy(Qt::DefaultContextMenu); m_actionNewWordType = new QAction(this); m_actionNewWordType->setText(i18n("New")); m_actionNewWordType->setIcon(QIcon::fromTheme(QStringLiteral("lesson-add"))); m_actionNewWordType->setWhatsThis(i18n("Add a new word type to your document")); m_actionNewWordType->setToolTip(m_actionNewWordType->whatsThis()); m_actionNewWordType->setStatusTip(m_actionNewWordType->whatsThis()); m_actionNewWordType->setStatusTip(m_actionNewWordType->whatsThis()); m_actionRenameWordType = new QAction(this); m_actionRenameWordType->setText(i18n("Rename")); m_actionRenameWordType->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename"))); m_actionRenameWordType->setWhatsThis(i18n("Rename the selected word type")); m_actionRenameWordType->setToolTip(m_actionRenameWordType->whatsThis()); m_actionRenameWordType->setStatusTip(m_actionRenameWordType->whatsThis()); m_actionRenameWordType->setStatusTip(m_actionRenameWordType->whatsThis()); m_actionDeleteWordType = new QAction(this); m_actionDeleteWordType->setText(i18n("Delete Word Type")); m_actionDeleteWordType->setIcon(QIcon::fromTheme(QStringLiteral("lesson-remove"))); m_actionDeleteWordType->setWhatsThis(i18n("Delete the selected word type.")); m_actionDeleteWordType->setToolTip(m_actionDeleteWordType->whatsThis()); m_actionDeleteWordType->setStatusTip(m_actionDeleteWordType->whatsThis()); m_actionDeleteWordType->setStatusTip(m_actionDeleteWordType->whatsThis()); m_actionSpecialTypeMenu = new KSelectAction(this); m_actionSpecialTypeMenu->setText(i18nc("Let the user select what grammatical meaning is connected to a word type (nouns have gender, verbs conjugations etc)", "Grammar")); //actionSplitWordType->setIcon(QIcon::fromTheme("")); /// @todo better icon m_actionSpecialTypeMenu->setWhatsThis(i18n("To let Parley know the grammatical meaning of a word type.")); m_actionSpecialTypeMenu->setToolTip(m_actionSpecialTypeMenu->whatsThis()); m_actionSpecialTypeMenu->setStatusTip(m_actionSpecialTypeMenu->whatsThis()); m_actionSpecialTypeMenu->setStatusTip(m_actionSpecialTypeMenu->whatsThis()); m_nounAction = new QAction(this); m_nounAction->setText(i18n("Noun")); m_nounAction->setCheckable(true); m_nounAction->setWhatsThis(i18n("This word type folder contains nouns.")); m_nounAction->setToolTip(m_nounAction->whatsThis()); m_nounAction->setStatusTip(m_nounAction->whatsThis()); m_nounAction->setStatusTip(m_nounAction->whatsThis()); m_nounMaleAction = new QAction(this); m_nounMaleAction->setText(i18n("Masculine Noun")); m_nounMaleAction->setCheckable(true); m_nounMaleAction->setWhatsThis(i18n("This word type folder contains masculine nouns.")); m_nounMaleAction->setToolTip(m_nounMaleAction->whatsThis()); m_nounMaleAction->setStatusTip(m_nounMaleAction->whatsThis()); m_nounMaleAction->setStatusTip(m_nounMaleAction->whatsThis()); m_nounFemaleAction = new QAction(this); m_nounFemaleAction->setText(i18n("Feminine Noun")); m_nounFemaleAction->setCheckable(true); m_nounFemaleAction->setWhatsThis(i18n("This word type folder contains feminine nouns.")); m_nounFemaleAction->setToolTip(m_nounFemaleAction->whatsThis()); m_nounFemaleAction->setStatusTip(m_nounFemaleAction->whatsThis()); m_nounFemaleAction->setStatusTip(m_nounFemaleAction->whatsThis()); m_nounNeutralAction = new QAction(this); m_nounNeutralAction->setText(i18n("Neuter Noun")); m_nounNeutralAction->setCheckable(true); m_nounNeutralAction->setWhatsThis(i18n("This word type folder contains neuter nouns.")); m_nounNeutralAction->setToolTip(m_nounNeutralAction->whatsThis()); m_nounNeutralAction->setStatusTip(m_nounNeutralAction->whatsThis()); m_nounNeutralAction->setStatusTip(m_nounNeutralAction->whatsThis()); m_adjectiveAction = new QAction(this); m_adjectiveAction->setText(i18n("Adjective")); m_adjectiveAction->setCheckable(true); m_adjectiveAction->setWhatsThis(i18n("This word type folder contains adjectives.")); m_adjectiveAction->setToolTip(m_adjectiveAction->whatsThis()); m_adjectiveAction->setStatusTip(m_adjectiveAction->whatsThis()); m_adjectiveAction->setStatusTip(m_adjectiveAction->whatsThis()); m_adverbAction = new QAction(this); m_adverbAction->setText(i18n("Adverb")); m_adverbAction->setCheckable(true); m_adverbAction->setWhatsThis(i18n("This word type folder contains adverbs.")); m_adverbAction->setToolTip(m_adverbAction->whatsThis()); m_adverbAction->setStatusTip(m_adverbAction->whatsThis()); m_adverbAction->setStatusTip(m_adverbAction->whatsThis()); m_verbAction = new QAction(this); m_verbAction->setText(i18n("Verb")); m_verbAction->setCheckable(true); m_verbAction->setWhatsThis(i18n("This word type folder contains verbs.")); m_verbAction->setToolTip(m_verbAction->whatsThis()); m_verbAction->setStatusTip(m_verbAction->whatsThis()); m_verbAction->setStatusTip(m_verbAction->whatsThis()); m_conjunctionAction = new QAction(this); m_conjunctionAction->setText(i18n("Conjunction")); m_conjunctionAction->setCheckable(true); m_conjunctionAction->setWhatsThis(i18n("This word type folder contains conjunctions.")); m_conjunctionAction->setToolTip(m_conjunctionAction->whatsThis()); m_conjunctionAction->setStatusTip(m_conjunctionAction->whatsThis()); m_conjunctionAction->setStatusTip(m_conjunctionAction->whatsThis()); m_noneAction = new QAction(this); m_noneAction->setText(i18n("No Special Type")); m_noneAction->setCheckable(true); m_noneAction->setChecked(true); m_noneAction->setWhatsThis(i18n("This word type folder contains no word type with special meaning.")); m_noneAction->setToolTip(m_noneAction->whatsThis()); m_noneAction->setStatusTip(m_noneAction->whatsThis()); m_noneAction->setStatusTip(m_noneAction->whatsThis()); QAction* separator = new QAction(this); separator->setSeparator(true); m_actionSpecialTypeMenu->addAction(m_noneAction); m_actionSpecialTypeMenu->addAction(separator); m_actionSpecialTypeMenu->addAction(m_nounAction); m_actionSpecialTypeMenu->addAction(m_nounMaleAction); m_actionSpecialTypeMenu->addAction(m_nounFemaleAction); m_actionSpecialTypeMenu->addAction(m_nounNeutralAction); m_actionSpecialTypeMenu->addAction(m_adjectiveAction); m_actionSpecialTypeMenu->addAction(m_adverbAction); m_actionSpecialTypeMenu->addAction(m_verbAction); m_actionSpecialTypeMenu->addAction(m_conjunctionAction); connect(m_actionNewWordType, &QAction::triggered, this, &WordTypeView::slotCreateNewWordType); connect(m_actionRenameWordType, &QAction::triggered, this, &WordTypeView::slotRename); connect(m_actionDeleteWordType, &QAction::triggered, this, &WordTypeView::slotDeleteWordType); // right click menu for the WordType view: addAction(m_actionNewWordType); addAction(m_actionRenameWordType); addAction(m_actionDeleteWordType); separator = new QAction(this); separator->setSeparator(true); addAction(separator); separator = new QAction(this); separator->setSeparator(true); addAction(separator); addAction(m_actionSpecialTypeMenu); connect(m_noneAction, &QAction::triggered, this, &WordTypeView::setWordTypeNone); connect(m_nounAction, &QAction::triggered, this, &WordTypeView::setWordTypeNoun); connect(m_nounMaleAction, &QAction::triggered, this, &WordTypeView::setWordTypeNounMale); connect(m_nounFemaleAction, &QAction::triggered, this, &WordTypeView::setWordTypeNounFemale); connect(m_nounNeutralAction, &QAction::triggered, this, &WordTypeView::setWordTypeNounNeutral); connect(m_adjectiveAction, &QAction::triggered, this, &WordTypeView::setWordTypeAdjective); connect(m_adverbAction, &QAction::triggered, this, &WordTypeView::setWordTypeAdverb); connect(m_verbAction, &QAction::triggered, this, &WordTypeView::setWordTypeVerb); connect(m_conjunctionAction, &QAction::triggered, this, &WordTypeView::setWordTypeConjunction); } void WordTypeView::setTranslation(KEduVocExpression * entry, int translation) { if (entry == 0) { return; } // attempt to find the container to select - QModelIndex index(m_model->index(entry->translation(translation)->wordType())); + QModelIndex index(model()->index(entry->translation(translation)->wordType())); scrollTo(index); selectionModel()->select(index, QItemSelectionModel::ClearAndSelect); } void WordTypeView::slotCreateNewWordType() { QModelIndex selectedIndex = selectionModel()->currentIndex(); if (!selectedIndex.isValid()) { - selectedIndex = m_model->index(0, 0, QModelIndex()); + selectedIndex = model()->index(0, 0, QModelIndex()); } - QModelIndex modelIndex = m_model->appendContainer(selectedIndex); + QModelIndex modelIndex = model()->appendContainer(selectedIndex); scrollTo(modelIndex); selectionModel()->setCurrentIndex(modelIndex, QItemSelectionModel::ClearAndSelect); edit(modelIndex); // let the user type a new name for the WordType } void WordTypeView::slotDeleteWordType() { QModelIndex selectedIndex = selectionModel()->currentIndex(); if (selectedIndex.parent() == QModelIndex()) { KMessageBox::information(this, i18n("The root word type cannot be deleted.")); return; } KEduVocWordType* WordType = static_cast(selectedIndex.internalPointer()); int count = WordType->entryCount(); if (count == 0 || KMessageBox::warningYesNo(this, i18np("There is a word left with this word type. It will lose its type. Continue?", "There are %1 words left with this word type. They will lose their word type. Continue?", count)) == KMessageBox::Yes) { - m_model->deleteContainer(selectedIndex); + model()->deleteContainer(selectedIndex); } } void WordTypeView::contextMenuEvent(QContextMenuEvent * event) { // check for the root element: QModelIndex selectedIndex = selectionModel()->currentIndex(); m_actionRenameWordType->setEnabled(selectedIndex.parent() != QModelIndex()); m_actionDeleteWordType->setEnabled(selectedIndex.parent() != QModelIndex()); m_actionSpecialTypeMenu->setEnabled(selectedIndex.parent() != QModelIndex()); if (selectedIndex.isValid()) { KEduVocWordFlags t = (static_cast(selectionModel()->currentIndex().internalPointer())->wordType()); if (!t) m_noneAction->setChecked(true); else if (t.testFlag(KEduVocWordFlag::Noun) && t.testFlag(KEduVocWordFlag::Masculine)) m_nounMaleAction->setChecked(true); else if (t.testFlag(KEduVocWordFlag::Noun) && t.testFlag(KEduVocWordFlag::Feminine)) m_nounFemaleAction->setChecked(true); else if (t.testFlag(KEduVocWordFlag::Noun) && t.testFlag(KEduVocWordFlag::Neuter)) m_nounNeutralAction->setChecked(true); else if (t.testFlag(KEduVocWordFlag::Noun)) m_nounAction->setChecked(true); else if (t.testFlag(KEduVocWordFlag::Adjective)) m_adjectiveAction->setChecked(true); else if (t.testFlag(KEduVocWordFlag::Adverb)) m_adverbAction->setChecked(true); else if (t.testFlag(KEduVocWordFlag::Verb)) m_verbAction->setChecked(true); else if (t.testFlag(KEduVocWordFlag::Conjunction)) m_conjunctionAction->setChecked(true); } QMenu::exec(actions(), event->globalPos()); } void WordTypeView::setWordTypeNone() { KEduVocWordType* wordType = static_cast(selectionModel()->currentIndex().internalPointer()); wordType->setWordType(KEduVocWordFlag::NoInformation); } void WordTypeView::setWordTypeNoun() { KEduVocWordType* wordType = static_cast(selectionModel()->currentIndex().internalPointer()); wordType->setWordType(KEduVocWordFlag::Noun); } void WordTypeView::setWordTypeNounMale() { KEduVocWordType* wordType = static_cast(selectionModel()->currentIndex().internalPointer()); wordType->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Masculine); } void WordTypeView::setWordTypeNounFemale() { KEduVocWordType* wordType = static_cast(selectionModel()->currentIndex().internalPointer()); wordType->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Feminine); } void WordTypeView::setWordTypeNounNeutral() { KEduVocWordType* wordType = static_cast(selectionModel()->currentIndex().internalPointer()); wordType->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Neuter); } void WordTypeView::setWordTypeAdjective() { KEduVocWordType* wordType = static_cast(selectionModel()->currentIndex().internalPointer()); wordType->setWordType(KEduVocWordFlag::Adjective); } void WordTypeView::setWordTypeAdverb() { KEduVocWordType* wordType = static_cast(selectionModel()->currentIndex().internalPointer()); wordType->setWordType(KEduVocWordFlag::Adverb); } void WordTypeView::setWordTypeVerb() { KEduVocWordType* wordType = static_cast(selectionModel()->currentIndex().internalPointer()); wordType->setWordType(KEduVocWordFlag::Verb); } void WordTypeView::setWordTypeConjunction() { KEduVocWordType* wordType = static_cast(selectionModel()->currentIndex().internalPointer()); wordType->setWordType(KEduVocWordFlag::Conjunction); } diff --git a/src/editor/wordtypeview.h b/src/editor/wordtypeview.h index 0fddec2b..f0ff41cd 100644 --- a/src/editor/wordtypeview.h +++ b/src/editor/wordtypeview.h @@ -1,81 +1,81 @@ /*************************************************************************** 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 WORDTYPEVIEW_H #define WORDTYPEVIEW_H -#include "containerview.h" +#include class QAction; class KSelectAction; class KEduVocWordType; class KEduVocExpression; namespace Editor { class EditorWindow; -class WordTypeView : public ContainerView +class WordTypeView : public KEduVocContainerView { Q_OBJECT public: explicit WordTypeView(EditorWindow *parent); public slots: /** Append a word type to the model and automatically set an edit up so the user can change "New lesson" into something meaningful.*/ void slotCreateNewWordType(); /** Remove a word type. */ void slotDeleteWordType(); void setTranslation(KEduVocExpression* entry, int translationId); signals: void selectedWordTypeChanged(KEduVocWordType* wordType); protected: void contextMenuEvent(QContextMenuEvent * event) Q_DECL_OVERRIDE; private slots: void setWordTypeNone(); void setWordTypeNoun(); void setWordTypeNounMale(); void setWordTypeNounFemale(); void setWordTypeNounNeutral(); void setWordTypeAdjective(); void setWordTypeAdverb(); void setWordTypeVerb(); void setWordTypeConjunction(); private: QAction *m_actionNewWordType; QAction *m_actionDeleteWordType; QAction *m_actionRenameWordType; KSelectAction *m_actionSpecialTypeMenu; QAction *m_noneAction; QAction *m_separator; QAction *m_nounAction; QAction *m_nounMaleAction; QAction *m_nounFemaleAction; QAction *m_nounNeutralAction; QAction *m_adjectiveAction; QAction *m_adverbAction; QAction *m_verbAction; QAction *m_conjunctionAction; }; } #endif diff --git a/src/statistics/lessonstatisticsview.cpp b/src/statistics/lessonstatisticsview.cpp index 31f8f04b..2db0419f 100644 --- a/src/statistics/lessonstatisticsview.cpp +++ b/src/statistics/lessonstatisticsview.cpp @@ -1,254 +1,254 @@ /*************************************************************************** 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. * * * ***************************************************************************/ // Own #include "lessonstatisticsview.h" // Qt #include #include #include #include // KDE #include #include #include #include #include // Parley #include "statisticslegendwidget.h" #include "statisticsmodel.h" #include "keduvoclesson.h" #include "utils.h" #include "documentsettings.h" // GradeDelegate shows the graphic colored bar in the statistics, // showing how far the student has come on the way to enlightenment. class GradeDelegate: public QItemDelegate { public: GradeDelegate(QObject *parent = 0) : QItemDelegate(parent) { } void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE { QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, 0); // empty lesson? If so, paint nothing. if (!index.data(StatisticsModel::TotalCount).toInt()) { return; } // Draw the colored bar. KEduVocContainer *container = index.data(StatisticsModel::Container) .value(); QStringList activeConjugationTenses = index.data(StatisticsModel::ActiveConjugationTenses) .toStringList(); WordCount wordCount; wordCount.fillFromContainerForPracticeMode( *container, index.column() - KEduVocContainerModel::FirstDataColumn, activeConjugationTenses ); ConfidenceColors colors(ConfidenceColors::ProgressiveColorScheme); paintColorBar(*painter, option.rect, wordCount, colors); // in utils // Draw the text telling the percentage on top of the bar. painter->drawText(option.rect, Qt::AlignCenter, QStringLiteral("%1%").arg(index.data(StatisticsModel::TotalPercent).toInt())); } }; // ---------------------------------------------------------------- LessonStatisticsView::LessonStatisticsView(QWidget *parent) - : ContainerView(parent) + : KEduVocContainerView(parent) { header()->setVisible(true); header()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignBottom); header()->setSectionsMovable( true ); // inherits context menu policy - so action will show up in right click menu QAction *removeGradesAction = new QAction(this); removeGradesAction->setText(i18n("Remove confidence levels from this unit")); removeGradesAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-clear"))); removeGradesAction->setWhatsThis(i18n("Remove confidence levels from this unit")); removeGradesAction->setToolTip(removeGradesAction->whatsThis()); removeGradesAction->setStatusTip(removeGradesAction->whatsThis()); connect(removeGradesAction, &QAction::triggered, this, &LessonStatisticsView::removeGrades); addAction(removeGradesAction); QAction *removeGradesChildrenAction = new QAction(this); removeGradesChildrenAction->setText(i18n("Remove confidence levels from this unit and all sub-units")); removeGradesChildrenAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-clear"))); removeGradesChildrenAction->setWhatsThis(i18n("Remove confidence level from this unit and all sub-units")); removeGradesChildrenAction->setToolTip(removeGradesChildrenAction->whatsThis()); removeGradesChildrenAction->setStatusTip(removeGradesChildrenAction->whatsThis()); connect(removeGradesChildrenAction, &QAction::triggered, this, &LessonStatisticsView::removeGradesChildren); addAction(removeGradesChildrenAction); connect(header(), &QHeaderView::geometriesChanged, this, &LessonStatisticsView::adjustColumnWidths); connect(header(), &QHeaderView::sectionResized, this, &LessonStatisticsView::sectionResized); } LessonStatisticsView::~LessonStatisticsView() { saveExpandedStatus(); } void LessonStatisticsView::setModel(KEduVocContainerModel *model) { - ContainerView::setModel(model); + KEduVocContainerView::setModel(model); GradeDelegate *delegate = new GradeDelegate(this); for (int i = KEduVocContainerModel::FirstDataColumn; i < model->columnCount(QModelIndex()); i++) { setItemDelegateForColumn(i, delegate); } adjustColumnWidths(); } void LessonStatisticsView::resizeEvent(QResizeEvent *event) { adjustColumnWidths(); - ContainerView::resizeEvent(event); + KEduVocContainerView::resizeEvent(event); } void LessonStatisticsView::sectionResized(int index, int /*oldSize*/, int /*newSize*/) { if (index < KEduVocContainerModel::FirstDataColumn) { adjustColumnWidths(); } } void LessonStatisticsView::adjustColumnWidths() { int firstWidth = columnWidth(0) + columnWidth(1); int totalWidth = viewport()->width() - firstWidth; int columnCount = model()->columnCount(QModelIndex()); int visibleColumns = 0; for (int i = KEduVocContainerModel::FirstDataColumn; i < columnCount; ++i) { if (!isColumnHidden(i)) visibleColumns++; } int columnWidth = visibleColumns > 0 ? totalWidth / visibleColumns : 150; for (int i = KEduVocContainerModel::FirstDataColumn; i < model()->columnCount(QModelIndex()); i++) { setColumnWidth(i, columnWidth); } // header()->resizeSections(QHeaderView::ResizeToContents); header()->setSectionResizeMode(QHeaderView::Interactive); header()->setStretchLastSection(true); } void LessonStatisticsView::removeGrades() { QModelIndex selectedIndex = selectionModel()->currentIndex(); KEduVocLesson *lesson = static_cast(selectedIndex.internalPointer()); lesson->resetGrades(-1, KEduVocContainer::NotRecursive); } void LessonStatisticsView::removeGradesChildren() { QModelIndex selectedIndex = selectionModel()->currentIndex(); KEduVocLesson *lesson = static_cast(selectedIndex.internalPointer()); lesson->resetGrades(-1, KEduVocContainer::Recursive); } void LessonStatisticsView::saveExpandedStatus() const { auto statisticsModel = qobject_cast(model()); Q_ASSERT(statisticsModel != nullptr); QStringList collapsedItems; getCollapsedItems(collapsedItems, statisticsModel->index(0, 0, QModelIndex()), QString()); const KEduVocDocument *doc = statisticsModel->document(); if (doc != nullptr) { DocumentSettings documentSettings(doc->url().url()); documentSettings.setCollapsedStatisticsViewItems(collapsedItems); documentSettings.save(); } } void LessonStatisticsView::getCollapsedItems(QStringList &collapsedItems, const QModelIndex &item, QString name) const { if (!item.isValid()) { return; } int rowCount = model()->rowCount(item); if (rowCount > 0) { // Item has children and therefore expandable name += item.data().toString(); if (!isExpanded(item)) { collapsedItems << name; } for (int row = 0; row < rowCount; ++row) { getCollapsedItems(collapsedItems, model()->index(row, 0, item), name + '/'); } } } void LessonStatisticsView::restoreExpandedStatus() { auto statisticsModel = qobject_cast(model()); Q_ASSERT(statisticsModel != nullptr); const KEduVocDocument *doc = statisticsModel->document(); if (doc != nullptr) { DocumentSettings documentSettings(doc->url().url()); documentSettings.load(); QStringList collapsedItems = documentSettings.collapsedStatisticsViewItems(); setCollapsedItems(collapsedItems, statisticsModel->index(0, 0, QModelIndex()), QString()); } } void LessonStatisticsView::setCollapsedItems(const QStringList &collapsedItems, const QModelIndex &item, QString name) { if (!item.isValid()) { return; } int rowCount = model()->rowCount(item); if (rowCount > 0) { // Item has children and therefore expandable name += item.data().toString(); if (collapsedItems.contains(name)) { collapse(item); } else { expand(item); } for (int row = 0; row < rowCount; ++row) { setCollapsedItems(collapsedItems, model()->index(row, 0, item), name + '/'); } } } diff --git a/src/statistics/lessonstatisticsview.h b/src/statistics/lessonstatisticsview.h index 73b56fcd..0181aeeb 100644 --- a/src/statistics/lessonstatisticsview.h +++ b/src/statistics/lessonstatisticsview.h @@ -1,57 +1,57 @@ /*************************************************************************** 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 LESSONSTATISTICSVIEW_H #define LESSONSTATISTICSVIEW_H -#include "containerview.h" +#include /** * View for the lesson list. * @author Frederik Gladhorn */ -class LessonStatisticsView : public ContainerView +class LessonStatisticsView : public KEduVocContainerView { Q_OBJECT public: explicit LessonStatisticsView(QWidget *parent); ~LessonStatisticsView(); void setModel(KEduVocContainerModel *model) Q_DECL_OVERRIDE; void saveExpandedStatus() const; void restoreExpandedStatus(); public Q_SLOTS: void adjustColumnWidths(); protected: void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; private Q_SLOTS: void removeGrades(); void removeGradesChildren(); void sectionResized(int index, int /*oldSize*/, int /*newSize*/); private: void setModel(QAbstractItemModel *model) Q_DECL_OVERRIDE { Q_UNUSED(model) } void getCollapsedItems(QStringList &collapsedItems, const QModelIndex &item, QString name) const; void setCollapsedItems(const QStringList &collapsedItems, const QModelIndex &item, QString name); }; #endif