diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8a372aa8..2f5867c5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,160 +1,160 @@ 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 - editor/editor.cpp + #editor/editor.cpp #editor/browserwidget.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/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/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 settings/generaloptions.cpp settings/parleyprefs.cpp settings/viewoptions.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/conjugationwidget.ui #editor/browserwidget.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/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) +#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/parleymainwindow.cpp b/src/parleymainwindow.cpp index 84df9bf1..ecb40232 100644 --- a/src/parleymainwindow.cpp +++ b/src/parleymainwindow.cpp @@ -1,572 +1,637 @@ /*************************************************************************** main part of parley ----------------------------------------------------------------------- begin : Thu Mar 11 20:50:53 MET 1999 copyright : (C) 1999-2001 Ewald Arnold (C) 2004-2007 Peter Hedlund (C) 2007-2008 Frederik Gladhorn (C) 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 "parleymainwindow.h" #include -#include "editor/editor.h" #include "statistics/statisticsmainwindow.h" #include "settings/parleyprefs.h" #include "practice/guifrontend.h" #include "practice/practicesummarycomponent.h" #include "practice/configure/configurepracticedialog.h" #include "parleyactions.h" #include "languagesettings.h" +#include "documentsettings.h" + #include "prefs.h" #include "dashboard/dashboard.h" #include #include #include #include #include #include #include #include #include #include +#include #include using namespace Editor; ParleyMainWindow* ParleyMainWindow::s_instance = 0; ParleyMainWindow* ParleyMainWindow::instance() { return s_instance; } ParleyMainWindow::ParleyMainWindow(const QUrl& filename) : KXmlGuiWindow(0) , m_currentComponent(NoComponent) , m_currentComponentWindow(0) + , m_editor(0) , m_sessionManager(this) { s_instance = this; // initialize KEduVocEditorDocument m_document = new KEduVocEditorDocument( this ); connect( m_document, &KEduVocEditorDocument::documentChanged, this, &ParleyMainWindow::documentUpdated ); connect( m_document, &KEduVocEditorDocument::languageSettingsChanged, this, &ParleyMainWindow::loadLanguageSettings ); connect( m_document, &KEduVocEditorDocument::editorFontChanged, this, &ParleyMainWindow::loadEditorFont ); connect( m_document, &KEduVocEditorDocument::practiceFontChanged, this, &ParleyMainWindow::loadPracticeFont ); connect( m_document, &KEduVocEditorDocument::keyboardLayoutChanged, this, &ParleyMainWindow::loadKeyboardLayout ); connect( m_document, &KEduVocEditorDocument::spellCheckerChanged, this, &ParleyMainWindow::loadSpellChecker ); connect( m_document, &KEduVocEditorDocument::storeEditorFont, this, &ParleyMainWindow::saveEditorFont ); connect( m_document, &KEduVocEditorDocument::storePracticeFont, this, &ParleyMainWindow::savePracticeFont ); connect( m_document, &KEduVocEditorDocument::storeKeyboardLayout, this, &ParleyMainWindow::saveKeyboardLayout ); connect( m_document, &KEduVocEditorDocument::storeSpellChecker, this, &ParleyMainWindow::saveSpellChecker ); connect( m_document, &KEduVocEditorDocument::saveSettings, this, &ParleyMainWindow::storeSettings ); connect( m_document, &KEduVocEditorDocument::autoBackupChanged, this, &ParleyMainWindow::loadAutoBackup ); connect( m_document, &KEduVocEditorDocument::showEditor, this, &ParleyMainWindow::loadEditor ); connect( m_document, &KEduVocEditorDocument::checkBoxChanged, this, &ParleyMainWindow::setCheckBox ); connect( m_document, &KEduVocEditorDocument::showPracticeConfiguration, this, &ParleyMainWindow::loadPracticeConfiguration ); connect( m_document, &KEduVocEditorDocument::separatorChanged, this, &ParleyMainWindow::loadSeparator ); connect( m_document, &KEduVocEditorDocument::recentFileChanged, this, &ParleyMainWindow::loadRecentFile ); connect( m_document, &KEduVocEditorDocument::prefsSelfSave, this, &ParleyMainWindow::selfSave ); connect( m_document, &KEduVocEditorDocument::autoSaveChanged, this, &ParleyMainWindow::loadAutoSave ); connect( m_document, &KEduVocEditorDocument::queryCloseChanged, this, &ParleyMainWindow::loadQueryClose ); connect( m_document, &KEduVocEditorDocument::updateRecentFilesModel, this, &ParleyMainWindow::updateRecentFiles ); connect( m_document, &KEduVocEditorDocument::backupTimeChanged, this, &ParleyMainWindow::loadBackupTime ); setCentralWidget(new QWidget()); centralWidget()->setLayout(new QHBoxLayout()); centralWidget()->layout()->setContentsMargins(0, 0, 0, 0); initActions(); bool startWithDashboard = false; setupGUI(ToolBar | Keys | Create); ///@todo frameworks KXMLGui warnings if (!filename.isEmpty()) { m_document->open(filename); } else { bool openLastFile = Prefs::autoOpenLast(); if (openLastFile && m_recentFilesAction->actions().count() > 0 && m_recentFilesAction->action(m_recentFilesAction->actions().count() - 1)->isEnabled()) { m_recentFilesAction->action(m_recentFilesAction->actions().count() - 1)->trigger(); } else { startWithDashboard = true; } } // save position of dock windows etc setAutoSaveSettings(); if (startWithDashboard) { showDashboard(); } else { showEditor(); } connect(this, &ParleyMainWindow::preferencesChanged, this, &ParleyMainWindow::slotApplyPreferences); menuBar()->show(); // finally show tip-of-day (if the user wants it) //QTimer::singleShot( 0, this, SLOT(startupTipOfDay()) ); } ParleyMainWindow::~ParleyMainWindow() { guiFactory()->removeClient(m_currentComponentWindow); centralWidget()->layout()->removeWidget(m_currentComponentWindow); delete m_currentComponentWindow; delete m_document; } void ParleyMainWindow::loadLanguageSettings( QString locale ) { LanguageSettings settings( locale ); settings.load(); } void ParleyMainWindow::loadEditorFont( QString locale, KEduVocLanguagePropertiesPage* page ) { LanguageSettings settings( locale ); settings.load(); page->setEditorFont( settings.editorFont() ); } void ParleyMainWindow::loadPracticeFont( QString locale, KEduVocLanguagePropertiesPage* page ) { LanguageSettings settings( locale ); settings.load(); page->setPracticeFont( settings.practiceFont() ); } void ParleyMainWindow::loadKeyboardLayout( QString locale, KEduVocLanguagePropertiesPage* page ) { LanguageSettings settings( locale ); settings.load(); page->setKeyboardLayout( settings.keyboardLayout() ); } void ParleyMainWindow::loadSpellChecker( QString locale, KEduVocLanguagePropertiesPage* page ) { LanguageSettings settings( locale ); settings.load(); page->setSpellChecker( settings.spellChecker() ); } void ParleyMainWindow::saveEditorFont( QString locale, QFont font ) { LanguageSettings settings( locale ); settings.load(); settings.setEditorFont( font ); } void ParleyMainWindow::savePracticeFont( QString locale, QFont font ) { LanguageSettings settings( locale ); settings.load(); settings.setPracticeFont( font ); } void ParleyMainWindow::saveKeyboardLayout( QString locale, QString keyboardLayout ) { LanguageSettings settings( locale ); settings.load(); settings.setKeyboardLayout( keyboardLayout ); } void ParleyMainWindow::saveSpellChecker( QString locale, QString spellChecker ) { LanguageSettings settings( locale ); settings.load(); settings.setSpellChecker( spellChecker ); } void ParleyMainWindow::storeSettings( QString locale ) { LanguageSettings settings( locale ); settings.load(); settings.save(); } void ParleyMainWindow::loadAutoBackup() { m_document->setAutoBackup( Prefs::autoBackup() ); } void ParleyMainWindow::loadEditor() { showEditor(); } void ParleyMainWindow::setCheckBox( QCheckBox* box ) { box->setChecked( currentComponent() != EditorComponent ); } void ParleyMainWindow::loadPracticeConfiguration() { showPracticeConfiguration(); } void ParleyMainWindow::loadSeparator() { m_document->setSeparator( Prefs::separator() ); } void ParleyMainWindow::loadRecentFile( const QUrl& url, QString title ) { addRecentFile( url, title ); } void ParleyMainWindow::selfSave() { Prefs::self()->save(); } void ParleyMainWindow::loadAutoSave() { m_document->setAutoSave( Prefs::autoSave() ); } void ParleyMainWindow::loadQueryClose() { m_document->setQueryClose( queryClose() ); } void ParleyMainWindow::updateRecentFiles() { updateRecentFilesModel(); } void ParleyMainWindow::loadBackupTime() { m_document->setBackupTime( Prefs::backupTime() ); } +void ParleyMainWindow::changeVisibleColumns( KEduVocDocument *doc ) +{ + DocumentSettings ds( doc->url().url() ); + ds.load(); + QList vc = ds.visibleColumns(); + m_editor->setVisibleColumns( vc ); +} + +void ParleyMainWindow::storeAutomaticTranslation( bool v ) +{ + Prefs::setAutomaticTranslation( v ); +} + +void ParleyMainWindow::changeEntriesPerLesson() +{ + m_editor->setEntriesPerLesson( Prefs::entriesPerLesson() ); +} + +void ParleyMainWindow::changeSubLessonEntries() +{ + m_editor->setSubLessonEntries( Prefs::showSublessonentries() ); +} + +void ParleyMainWindow::setAutomaticTranslation() +{ + m_editor->saveAutomaticTranslation( Prefs::automaticTranslation() ); +} + +void ParleyMainWindow::setShowSearch() +{ + m_editor->setShowSearch( Prefs::showSearch() ); +} + +void ParleyMainWindow::setSpellChecker( QString locale ) +{ + LanguageSettings settings(locale); + m_editor->setSpellChecker( settings.spellChecker() ); +} + +void ParleyMainWindow::storeShowSearch( bool v ) +{ + Prefs::setShowSearch( v ); +} + +void ParleyMainWindow::setSeparator() +{ + m_editor->setSeparator( Prefs::separator() ); +} + + void ParleyMainWindow::addRecentFile(const QUrl &url, const QString &name) { m_recentFilesAction->addUrl(url, name); m_recentFilesAction->saveEntries(KSharedConfig::openConfig()->group("Recent Files")); } void ParleyMainWindow::removeRecentFile(const QUrl &url) { m_recentFilesAction->removeUrl(url); m_recentFilesAction->saveEntries(KSharedConfig::openConfig()->group("Recent Files")); } void ParleyMainWindow::documentUpdated(KEduVocDocument *doc) { if (doc != nullptr) { connect(doc, &KEduVocDocument::docModified, this, &ParleyMainWindow::slotUpdateWindowCaption); connect(doc, &KEduVocDocument::destroyed, this, &ParleyMainWindow::slotUpdateWindowCaption); slotUpdateWindowCaption(); } } void ParleyMainWindow::updateRecentFilesModel() { emit recentFilesChanged(); } void ParleyMainWindow::saveOptions() { Prefs::self()->save(); } void ParleyMainWindow::slotUpdateWindowCaption() { QString title; bool modified = false; if (m_document->document()) { title = i18nc("Title and a modified status indicator. [*] is exact and will be shown only when document is modified" , "%1 [*]",m_document->document()->title()); modified = m_document->document()->isModified(); if (title == i18n("Untitled")) { title = QStringLiteral("[*]"); } } setCaption(title, modified); } void ParleyMainWindow::slotGeneralOptions() { ParleyPrefs* dialog = new ParleyPrefs(m_document->document(), this, QStringLiteral("settings"), Prefs::self()); connect(dialog, &ParleyPrefs::settingsChanged, this, &ParleyMainWindow::preferencesChanged); dialog->show(); } void ParleyMainWindow::slotApplyPreferences() { m_document->enableAutoBackup((m_currentComponent != DashboardComponent) && Prefs::autoBackup()); } void ParleyMainWindow::slotCloseDocument() { if (!queryClose()) { return; } showDashboard(); m_document->close(); } void ParleyMainWindow::configurePractice() { ConfigurePracticeDialog configurePracticeDialog(m_document->document(), this, QStringLiteral("practice settings"), Prefs::self()); configurePracticeDialog.exec(); } void ParleyMainWindow::startPractice() { if (Prefs::learningLanguage() == Prefs::knownLanguage()) { KMessageBox::sorry(this, i18n("You cannot start to practice when the known language is the same as the language to learn."), i18n("Select languages")); return; } qDebug() <<"Starting Switch Practice"; switchComponent(PracticeComponent); qDebug() <<"Finished Switch Practice"; } void ParleyMainWindow::practiceFinished() { switchComponent(m_componentBeforePractice); } bool ParleyMainWindow::queryClose() { if (m_document->queryClose()) { Prefs::self()->save(); return true; } return false; } QSize ParleyMainWindow::sizeHint() const { return QSize(800, 600).expandedTo(KXmlGuiWindow::minimumSizeHint()); } void ParleyMainWindow::tipOfDay() { KTipDialog::showTip(this, QStringLiteral("parley/tips"), true); } void ParleyMainWindow::startupTipOfDay() { KTipDialog::showTip(this, QStringLiteral("parley/tips")); } void ParleyMainWindow::slotFileNew() { m_document->slotFileNew(); slotUpdateWindowCaption(); } void ParleyMainWindow::initActions() { ParleyActions::create(ParleyActions::FileNew, this, SLOT(slotFileNew()), actionCollection()); ParleyActions::create(ParleyActions::FileOpen, m_document, SLOT(slotFileOpen()), actionCollection()); ParleyActions::createDownloadAction(m_document, SLOT(slotGHNS()), actionCollection()); ParleyActions::create(ParleyActions::FileOpenDownloaded, m_document, SLOT(openGHNS()), actionCollection()); m_recentFilesAction = ParleyActions::createRecentFilesAction( m_document, SLOT(slotFileOpenRecent(QUrl)), actionCollection()); m_recentFilesAction->loadEntries(KSharedConfig::openConfig()->group("Recent Files")); ParleyActions::create(ParleyActions::FileSave, m_document, SLOT(save()), actionCollection()); ParleyActions::create(ParleyActions::FileSaveAs, m_document, SLOT(saveAs()), actionCollection()); #ifdef HAVE_LIBXSLT ParleyActions::create(ParleyActions::FileExport, m_document, SLOT(exportDialog()), actionCollection()); #endif ParleyActions::create(ParleyActions::FileProperties, m_document, SLOT(documentProperties()), actionCollection()); ParleyActions::create(ParleyActions::FileClose, this, SLOT(slotCloseDocument()), actionCollection()); ParleyActions::create(ParleyActions::FileQuit, this, SLOT(close()), actionCollection()); ParleyActions::create(ParleyActions::Preferences, this, SLOT(slotGeneralOptions()), actionCollection()); actionCollection()->addAction(KStandardAction::TipofDay, QStringLiteral("help_tipofday"), this, SLOT(tipOfDay())); } void ParleyMainWindow::showDashboard() { switchComponent(DashboardComponent); } void ParleyMainWindow::showEditor() { switchComponent(EditorComponent); } void ParleyMainWindow::showPracticeConfiguration() { switchComponent(ConfigurePracticeComponent); } void ParleyMainWindow::showPractice() { switchComponent(PracticeComponent); } void ParleyMainWindow::showPracticeSummary() { switchComponent(PracticeSummary); } void ParleyMainWindow::switchComponent(Component component) { if (component == PracticeComponent) { StatisticsMainWindow *statisticsWidget = qobject_cast(m_currentComponentWindow); if (statisticsWidget) { statisticsWidget->syncConfig(); } // Don't start a practice when there are no words to practice. // This has to be checked before deleting the old component. m_sessionManager.setDocument(m_document->document()); if (!m_sessionManager.allEntryCount()) { return; } } // Remove and delete the old component window if there is one active. if (m_currentComponentWindow) { guiFactory()->removeClient(m_currentComponentWindow); centralWidget()->layout()->removeWidget(m_currentComponentWindow); m_currentComponentWindow->deleteLater(); } switch (component) { case DashboardComponent: { Dashboard *dashboard = new Dashboard(this); m_currentComponentWindow = dashboard; showDocumentActions(true, false); //dashboard->updateRecentFilesModel(); break; } case ConfigurePracticeComponent: { StatisticsMainWindow *statisticsWidget = new StatisticsMainWindow(m_document->document(), this); m_currentComponentWindow = statisticsWidget; showDocumentActions(true, true); break; } case EditorComponent: { - EditorWindow *editor = new EditorWindow(this); - m_currentComponentWindow = editor; + m_editor = new KEduVocEditorWindow( this, this->parleyDocument() ); + + // signal-slot connections between Parley mainwindow and KEduVocEditor + + connect( m_editor, &KEduVocEditorWindow::visibleColumnsChanged, this, &ParleyMainWindow::changeVisibleColumns ); + connect( m_editor, &KEduVocEditorWindow::saveAutomaticTranslation, this, &ParleyMainWindow::storeAutomaticTranslation ); + connect( m_editor, &KEduVocEditorWindow::entriesPerLessonChanged, this, &ParleyMainWindow::changeEntriesPerLesson ); + connect( m_editor, &KEduVocEditorWindow::subLessonEntriesChanged, this, &ParleyMainWindow::changeSubLessonEntries ); + connect( m_editor, &KEduVocEditorWindow::automaticTranslationChanged, this, &ParleyMainWindow::setAutomaticTranslation ); + connect( m_editor, &KEduVocEditorWindow::showSearchChanged, this, &ParleyMainWindow::setShowSearch ); + connect( m_editor, &KEduVocEditorWindow::spellCheckerChanged, this, &ParleyMainWindow::setSpellChecker ); + connect( m_editor, &KEduVocEditorWindow::saveShowSearch, this, &ParleyMainWindow::storeShowSearch ); + connect( m_editor, &KEduVocEditorWindow::separatorChanged, this, &ParleyMainWindow::setSeparator ); + m_currentComponentWindow = m_editor; showDocumentActions(true, true); - editor->updateDocument(m_document->document()); + m_editor->updateDocument(m_document->document()); break; } case PracticeComponent: { ///@todo trust the dirty bit m_document->document()->setModified(true); Practice::PracticeMainWindow *practiceWindow = new Practice::PracticeMainWindow(&m_sessionManager, this); connect(practiceWindow, &Practice::PracticeMainWindow::stopPractice, this, &ParleyMainWindow::showPracticeSummary); m_currentComponentWindow = practiceWindow; qDebug() <<" Practice Slotted up"; showDocumentActions(false, false); practiceWindow->startPractice(); qDebug() <<" Practice Slotted up2"; break; } case PracticeSummary: { Practice::PracticeSummaryComponent* summary = new Practice::PracticeSummaryComponent(&m_sessionManager, this); m_currentComponentWindow = summary; showDocumentActions(true, true); break; } default: break; } //qDebug() << "new component" << m_currentComponentWindow; guiFactory()->addClient(m_currentComponentWindow); centralWidget()->layout()->addWidget(m_currentComponentWindow); m_currentComponentWindow->show(); switch (component) { case DashboardComponent: { setVisibleToolbar(QString()); break; } case ConfigurePracticeComponent: { setVisibleToolbar(QStringLiteral("statisticsToolBar")); break; } case EditorComponent: { setVisibleToolbar(QStringLiteral("editorToolBar")); break; } case PracticeComponent: { setVisibleToolbar(QStringLiteral("practiceToolBar")); break; } case PracticeSummary: { setVisibleToolbar(QStringLiteral("practiceSummaryToolBar")); break; } default: break; } m_currentComponent = component; setupToolbarMenuActions(); } void ParleyMainWindow::showDocumentActions(bool open, bool edit) { actionCollection()->action(QStringLiteral("file_new"))->setVisible(open); actionCollection()->action(QStringLiteral("file_open"))->setVisible(open); actionCollection()->action(QStringLiteral("file_open_recent"))->setVisible(open); actionCollection()->action(QStringLiteral("file_ghns"))->setVisible(open); actionCollection()->action(QStringLiteral("file_open_downloaded"))->setVisible(open); actionCollection()->action(QStringLiteral("file_save"))->setVisible(edit); actionCollection()->action(QStringLiteral("file_save_as"))->setVisible(edit); actionCollection()->action(QStringLiteral("file_close"))->setVisible(edit); #ifdef HAVE_LIBXSLT actionCollection()->action("file_export")->setVisible(edit); #endif actionCollection()->action(QStringLiteral("file_properties"))->setVisible(edit); actionCollection()->action(QStringLiteral("file_close"))->setVisible(edit); } void ParleyMainWindow::setVisibleToolbar(const QString& name) { Q_FOREACH(KToolBar * toolbar, toolBars()) { if (toolbar && toolbar->objectName() == name) { toolbar->show(); } else if (toolbar) { toolbar->hide(); } } } KEduVocEditorDocument* ParleyMainWindow::parleyDocument() { return m_document; } ParleyMainWindow::Component ParleyMainWindow::currentComponent() { return m_currentComponent; } diff --git a/src/parleymainwindow.h b/src/parleymainwindow.h index aca53349..7ba42b33 100644 --- a/src/parleymainwindow.h +++ b/src/parleymainwindow.h @@ -1,194 +1,210 @@ /*************************************************************************** main part of Parley ----------------------------------------------------------------------- begin : Thu Mar 11 20:50:53 MET 1999 copyright : (C) 1999-2001 Ewald Arnold (C) 2004-2007 Peter Hedlund (C) 2007-2008 Frederik Gladhorn (C) 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 PARLEYMAINWINDOW_H #define PARLEYMAINWINDOW_H -#include "keduvoceditordocument.h" +#include +#include #include #include "practice/sessionmanagercontinuous.h" #include "practice/sessionmanagerfixed.h" #include +using namespace Editor; class KRecentFilesAction; #if 0 class Dashboard; class StatisticsMainWindow; class KEduVocScriptManager; class ParleyPracticeMainWindow; #endif class ParleyMainWindow : public KXmlGuiWindow { Q_OBJECT public: static ParleyMainWindow * instance(); ~ParleyMainWindow(); /** enum for the different components that can be displayed */ enum Component { NoComponent, DashboardComponent, EditorComponent, ConfigurePracticeComponent, PracticeComponent, PracticeSummary }; /** * setup the action (menus etc) */ void initActions(); /** add a new entry to the list of recent files */ void addRecentFile(const QUrl &url, const QString &name); /** save the app-specific options on slotAppExit or by an Options dialog */ void saveOptions(); /** This will look at the lesson list and also the combo box to determine what should be displayed in the table. */ void updateTableFilter(); /** update the list of recent files in the dashboard */ void updateRecentFilesModel(); /** * Return the KEduVocEditorDocument member object * @return member m_document */ KEduVocEditorDocument* parleyDocument(); Component currentComponent(); public slots: /** Updates connections when the KEduVocEditorDocument pointer is changed to @p doc **/ void documentUpdated(KEduVocDocument *doc); /** Opens a dialog for a new collection. **/ void slotFileNew(); /** Update the title bar of the main window with the current document */ void slotUpdateWindowCaption(); /** When quitting, ask for confirmation if the doc has not been saved */ bool queryClose() Q_DECL_OVERRIDE; /** remove an entry from the list of recent files */ void removeRecentFile(const QUrl &url); QSize sizeHint() const Q_DECL_OVERRIDE; /** set up options */ void slotGeneralOptions(); void slotApplyPreferences(); void slotCloseDocument(); void configurePractice(); void startPractice(); void showPracticeSummary(); void practiceFinished(); /** * Show the tip of the day (force it to be shown) */ void tipOfDay(); /** * Show the tip of the day - the startup version that can be disabled */ void startupTipOfDay(); void showDashboard(); void showEditor(); void showPractice(); void showPracticeConfiguration(); void switchComponent(Component component); /** * Shows or hides actions that are only relevant when a document is opened */ void showDocumentActions(bool open, bool edit); void setVisibleToolbar(const QString& name); void loadLanguageSettings( QString locale ); void loadEditorFont( QString locale, KEduVocLanguagePropertiesPage* page ); void loadPracticeFont( QString locale, KEduVocLanguagePropertiesPage* page ); void loadKeyboardLayout( QString locale, KEduVocLanguagePropertiesPage* page ); void loadSpellChecker( QString locale, KEduVocLanguagePropertiesPage* page ); void saveEditorFont( QString locale, QFont font ); void savePracticeFont( QString locale, QFont font ); void saveKeyboardLayout( QString locale, QString keyboardLayout ); void saveSpellChecker( QString locale, QString spellChecker ); void storeSettings( QString locale ); void loadAutoBackup(); void loadEditor(); void setCheckBox( QCheckBox* box ); void loadPracticeConfiguration(); void loadSeparator(); void loadRecentFile( const QUrl& url, QString title ); void selfSave(); void loadAutoSave(); void loadQueryClose(); void updateRecentFiles(); void loadBackupTime(); + // KEduVocEditorWindow slots + void changeVisibleColumns( KEduVocDocument *doc ); + void storeAutomaticTranslation( bool v ); + void changeEntriesPerLesson(); + void changeSubLessonEntries(); + void setAutomaticTranslation(); + void setShowSearch(); + void setSpellChecker( QString locale ); + void storeShowSearch( bool v ); + void setSeparator(); + signals: void recentFilesChanged(); void preferencesChanged(); private: ParleyMainWindow(const QUrl &filename = QUrl()); static ParleyMainWindow *s_instance; Component m_currentComponent; KXmlGuiWindow *m_currentComponentWindow; KRecentFilesAction *m_recentFilesAction; /** m_document is the current vocabulary document. */ KEduVocEditorDocument *m_document; + /** m_editor is the editor mainwindow */ + KEduVocEditorWindow *m_editor; + Component m_componentBeforePractice; //Practice::SessionManagerContinuous m_sessionManager; Practice::SessionManagerFixed m_sessionManager; friend int main(int argc, char* argv[]); }; #endif // PARLEYMAINWINDOW_H