diff --git a/src/config/ConfigDialog.cpp b/src/config/ConfigDialog.cpp index cd4a7cb5..a5583aa1 100644 --- a/src/config/ConfigDialog.cpp +++ b/src/config/ConfigDialog.cpp @@ -1,90 +1,91 @@ /* This file is part of the KDE project * Copyright (C) 2019 Dag Andersen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ConfigDialog.h" #include "ConfigProjectPanel.h" #include "ConfigWorkVacationPanel.h" #include "kpttaskdefaultpanel.h" #include "kptworkpackageconfigpanel.h" #include "kptcolorsconfigpanel.h" #include "ConfigDocumentationPanel.h" #include "ConfigTaskModulesPanel.h" #include "ConfigProjectTemplatesPanel.h" #include #include #include #include #include #include #include #include using namespace KPlato; ConfigDialog::ConfigDialog(QWidget *parent, const QString& name, KConfigSkeleton *config ) : KConfigDialog( parent, name, config ) { m_pages << addPage(new ConfigProjectPanel(), i18n("Project Defaults"), koIconName("calligraplan") ); m_pages << addPage(new ConfigWorkVacationPanel(), i18n("Work & Vacation"), koIconName("view-calendar") ); m_pages << addPage(new TaskDefaultPanel(), i18n("Task Defaults"), koIconName("view-task") ); m_pages << addPage(new ColorsConfigPanel(), i18n("Task Colors"), koIconName("fill-color") ); ConfigTaskModulesPanel *page = new ConfigTaskModulesPanel(); m_pages << addPage(page, i18n("Task Modules"), koIconName("calligraplanwork") ); connect(page, &ConfigTaskModulesPanel::settingsChanged, this, &ConfigDialog::updateButtons); connect(this, &ConfigDialog::updateWidgetsSettings, page, &ConfigTaskModulesPanel::updateSettings); connect(this, &ConfigDialog::updateWidgetsData, page, &ConfigTaskModulesPanel::updateWidgets); m_pages << addPage(new WorkPackageConfigPanel(), i18n("Work Package"), koIconName("calligraplanwork") ); m_pages << addPage(new ConfigDocumentationPanel(), i18n("Documentation"), koIconName("documents") ); ConfigProjectTemplatesPanel *p = new ConfigProjectTemplatesPanel(); m_pages << addPage(p, i18n("Project Templates"), koIconName("calligraplan")); connect(p, &ConfigProjectTemplatesPanel::settingsChanged, this, &ConfigDialog::updateButtons); connect(this, &ConfigDialog::updateWidgetsSettings, p, &ConfigProjectTemplatesPanel::updateSettings); connect(this, &ConfigDialog::updateWidgetsData, p, &ConfigProjectTemplatesPanel::updateWidgets); } void ConfigDialog::updateSettings() { emit updateWidgetsSettings(); new Help(KPlatoSettings::contextPath(), KPlatoSettings::contextLanguage()); KPlatoSettings::self()->save(); + emit settingsUpdated(); } void ConfigDialog::updateWidgets() { emit updateWidgetsData(); } bool ConfigDialog::hasChanged() { QWidget *w = currentPage()->widget()->findChild("ConfigWidget"); return w ? w->property("hasChanged").toBool() : false; } void ConfigDialog::showHelp() { Help::invoke("Configure_Plan"); } diff --git a/src/config/ConfigDialog.h b/src/config/ConfigDialog.h index fd37ffe3..9c6c3bae 100644 --- a/src/config/ConfigDialog.h +++ b/src/config/ConfigDialog.h @@ -1,59 +1,60 @@ /* This file is part of the KDE project * Copyright (C) 2019 Dag Andersen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef CONFIGDIALOG_H #define CONFIGDIALOG_H #include #include class KConfigSkeleton; namespace KPlato { class PLAN_EXPORT ConfigDialog : public KConfigDialog { Q_OBJECT public: ConfigDialog( QWidget *parent, const QString &name, KConfigSkeleton *config ); Q_SIGNALS: void updateWidgetsData(); void updateWidgetsSettings(); - + void settingsUpdated(); + protected Q_SLOTS: void updateSettings() override; void updateWidgets() override; void showHelp() override; protected: bool hasChanged() override; private: QList m_pages; }; } //KPlato namespace #endif diff --git a/src/kptpart.cpp b/src/kptpart.cpp index 222eda4b..11d51b2d 100644 --- a/src/kptpart.cpp +++ b/src/kptpart.cpp @@ -1,252 +1,255 @@ /* This file is part of the KDE project Copyright (C) 2012 C. Boemann This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ // clazy:excludeall=qstring-arg #include "kptpart.h" #include "config/ConfigDialog.h" #include "kptview.h" #include "kptmaindocument.h" #include "kptfactory.h" #include "welcome/WelcomeView.h" #include "kpthtmlview.h" #include "Help.h" #include "calligraplansettings.h" #include "kptdebug.h" #include #include #include #include #include #include #include #include #include #include using namespace KPlato; Part::Part(QObject *parent) : KoPart(Factory::global(), parent) , startUpWidget(0) { setTemplatesResourcePath(QLatin1String("calligraplan/templates/")); new Help(KPlatoSettings::contextPath(), KPlatoSettings::contextLanguage()); } Part::~Part() { } void Part::setDocument(KPlato::MainDocument *document) { KoPart::setDocument(document); m_document = document; } KoView *Part::createViewInstance(KoDocument *document, QWidget *parent) { // synchronize view selector View *view = dynamic_cast(views().value(0)); /*FIXME if (view && m_context) { QDomDocument doc = m_context->save(view); m_context->setContent(doc.toString()); }*/ view = new View(this, qobject_cast(document), parent); // connect(view, SIGNAL(destroyed()), this, SLOT(slotViewDestroyed())); // connect(document, SIGNAL(viewListItemAdded(const ViewListItem*,const ViewListItem*,int)), view, SLOT(addViewListItem(const ViewListItem*,const ViewListItem*,int))); // connect(document, SIGNAL(viewListItemRemoved(const ViewListItem*)), view, SLOT(removeViewListItem(const ViewListItem*))); return view; } KoMainWindow *Part::createMainWindow() { KoMainWindow *w = new KoMainWindow(PLAN_MIME_TYPE, componentData()); QAction *handbookAction = w->action("help_contents"); if (handbookAction) { // we do not want to use khelpcenter as we do not install docs disconnect(handbookAction, 0, 0, 0); connect(handbookAction, &QAction::triggered, this, &Part::slotHelpContents); } return w; } void Part::slotHelpContents() { QDesktopServices::openUrl(QUrl::fromUserInput(KPlatoSettings::documentationPath())); } void Part::showStartUpWidget(KoMainWindow *parent) { m_toolbarVisible = parent->factory()->container("mainToolBar", parent)->isVisible(); if (m_toolbarVisible) { parent->factory()->container("mainToolBar", parent)->hide(); } if (startUpWidget) { startUpWidget->show(); } else { createStarUpWidget(parent); parent->setCentralWidget(startUpWidget); } parent->setPartToOpen(this); } void Part::slotOpenTemplate(const QUrl &url) { openTemplate(url); } void Part::openTemplate(const QUrl &url) { debugPlan<<"Open shared resources template:"<setLoadingTemplate(true); m_document->setLoadingSharedResourcesTemplate(url.fileName() == "SharedResources.plant"); KoPart::openTemplate(url); m_document->setLoadingTemplate(false); } bool Part::openProjectTemplate(const QUrl &url) { QApplication::setOverrideCursor(Qt::BusyCursor); m_document->setLoadingTemplate(true); bool ok = m_document->loadNativeFormat(url.path()); m_document->setModified(false); m_document->undoStack()->clear(); if (ok) { m_document->resetURL(); m_document->setEmpty(); } else { m_document->showLoadingErrorDialog(); m_document->initEmpty(); } m_document->setLoadingTemplate(false); QApplication::restoreOverrideCursor(); return ok; } void Part::openTaskModule(const QUrl &url) { Part *part = new Part(0); MainDocument *doc = new MainDocument(part); part->setDocument(doc); doc->setIsTaskModule(true); mainWindows().first()->openDocument(part, url); } void Part::createStarUpWidget(KoMainWindow *parent) { startUpWidget = new QStackedWidget(parent); startUpWidget->addWidget(createWelcomeView(parent)); startUpWidget->addWidget(createIntroductionView()); } void Part::finish() { mainWindows().first()->setRootDocument(document(), this); if (m_toolbarVisible) { KoPart::mainWindows().first()->factory()->container("mainToolBar", mainWindows().first())->show(); } } QWidget *Part::createWelcomeView(KoMainWindow *mw) { MainDocument *doc = static_cast(document()); WelcomeView *v = new WelcomeView(this, doc, startUpWidget); v->setProject(&(doc->getProject())); KSharedConfigPtr configPtr = Factory::global().config(); KRecentFilesAction recent("x", 0); recent.loadEntries(configPtr->group("RecentFiles")); v->setRecentFiles(recent.actions()); connect(v, &WelcomeView::loadSharedResources, doc, &MainDocument::insertResourcesFile); connect(v, &WelcomeView::recentProject, mw, &KoMainWindow::slotFileOpenRecent); connect(v, &WelcomeView::showIntroduction, this, &Part::slotShowIntroduction); connect(v, &WelcomeView::projectCreated, doc, &MainDocument::slotProjectCreated); connect(v, &WelcomeView::finished, this, &Part::finish); connect(v, &WelcomeView::openTemplate, this, &Part::slotOpenTemplate); return v; } void Part::slotShowIntroduction() { startUpWidget->setCurrentIndex(1); slotOpenUrlRequest(static_cast(startUpWidget->currentWidget()), QUrl("about:plan/main")); } void Part::slotOpenUrlRequest( HtmlView *v, const QUrl &url ) { debugPlan<setCurrentIndex(0); return; } if ( url.url().startsWith( QLatin1String( "about:plan" ) ) ) { MainDocument *doc = static_cast(document()); doc->aboutPage().generatePage( v->htmlPart(), url ); return; } } if ( url.scheme() == QLatin1String("help") ) { KHelpClient::invokeHelp( "", url.fileName() ); return; } // try to open the url debugPlan<htmlPart().setJScriptEnabled(false); v->htmlPart().setJavaEnabled(false); v->htmlPart().setMetaRefreshEnabled(false); v->htmlPart().setPluginsEnabled(false); slotOpenUrlRequest( v, QUrl( "about:plan/main" ) ); connect( v, &KPlato::HtmlView::openUrlRequest, this, &KPlato::Part::slotOpenUrlRequest ); return v; } void Part::configure(KoMainWindow *mw) { //debugPlan; if( KConfigDialog::showDialog("Plan Settings")) { return; } ConfigDialog *dialog = new ConfigDialog(mw, "Plan Settings", KPlatoSettings::self()); dialog->open(); + if (startUpWidget) { + QObject::connect(dialog, &ConfigDialog::settingsUpdated, static_cast(startUpWidget->widget(0)), &WelcomeView::setProjectTemplatesModel); + } } diff --git a/src/welcome/WelcomeView.h b/src/welcome/WelcomeView.h index d38e68d1..ab685265 100644 --- a/src/welcome/WelcomeView.h +++ b/src/welcome/WelcomeView.h @@ -1,107 +1,106 @@ /* This file is part of the KDE project Copyright (C) 2017 Dag Andersen This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef WELCOMEVIEW_H #define WELCOMEVIEW_H #include "plan_export.h" #include "kptviewbase.h" #include "ui_WelcomeView.h" #include "kptmainprojectdialog.h" #include class KoDocument; class QUrl; class QItemSelecteion; namespace KPlato { class RecentFilesModel; class PLAN_EXPORT WelcomeView : public ViewBase { Q_OBJECT public: WelcomeView(KoPart *part, KoDocument *doc, QWidget *parent); ~WelcomeView() override; void setRecentFiles(const QList &actions); void setupGui(); void updateReadWrite(bool readwrite) override; KoPrintJob *createPrintJob() override; - void setProjectTemplatesModel(); - Project *project() const override; public Q_SLOTS: /// Activate/deactivate the gui void setGuiActive(bool activate) override; + void setProjectTemplatesModel(); Q_SIGNALS: void newProject(); void openProject(); void recentProject(const QUrl &file, KoPart *part); void showIntroduction(); void selectDefaultView(); void loadSharedResources(const QUrl &url, const QUrl &projects); void openExistingFile(const QUrl &url); void projectCreated(); void finished(); void openTemplate(QUrl); protected: void updateActionsEnabled( bool on = true); private Q_SLOTS: void slotContextMenuRequested(const QModelIndex &index, const QPoint& pos); void slotRecentFileSelected(const QModelIndex &idx); void slotEnableActions(bool on); void slotNewProject(); void slotOpenProject(); void slotLoadSharedResources(const QString &file, const QUrl &projects, bool loadProjectsAtStartup); void slotOpenProjectTemplate(const QModelIndex &idx); void slotProjectEditFinished(int result); void slotOpenFileFinished(int result); void slotCreateResourceFile(); private: Ui::WelcomeView ui; RecentFilesModel *m_model; QPointer m_projectdialog; QPointer m_filedialog; }; } //KPlato namespace #endif