diff --git a/plan/kptpart.cpp b/plan/kptpart.cpp index e5ca9f51414..20836ac72fa 100644 --- a/plan/kptpart.cpp +++ b/plan/kptpart.cpp @@ -1,178 +1,183 @@ /* 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. */ #include "kptpart.h" #include "kptview.h" #include "kptmaindocument.h" #include "kptfactory.h" #include "welcome/WelcomeView.h" #include "kpthtmlview.h" #include #include #include #include #include #include #include #include #include Part::Part(QObject *parent) : KoPart(Factory::global(), parent) , startUpWidget(0) { setTemplatesResourcePath(QLatin1String("calligraplan/templates/")); } 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() { return new KoMainWindow(PLAN_MIME_TYPE, componentData()); } void Part::showStartUpWidget(KoMainWindow *parent, bool alwaysShow) { - parent->factory()->container("mainToolBar", parent)->hide(); + Q_UNUSED(alwaysShow); + + 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::openTemplate(const QUrl &url) { m_document->setLoadingTemplate(true); KoPart::openTemplate(url); m_document->setLoadingTemplate(false); } void Part::createStarUpWidget(KoMainWindow *parent) { startUpWidget = new QStackedWidget(parent); startUpWidget->addWidget(createWelcomeView(parent)); startUpWidget->addWidget(createIntroductionView()); } -void Part::deleteStartUpWidget() +void Part::finish() { - delete startUpWidget; - startUpWidget = 0; mainWindows().first()->setRootDocument(document(), this); - KoPart::mainWindows().first()->factory()->container("mainToolBar", mainWindows().first())->show(); + 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.items()); connect(v, SIGNAL(loadSharedResources(const QUrl&)), doc, SLOT(insertResourcesFile(const QUrl&))); connect(v, SIGNAL(recentProject(const QUrl&)), mw, SLOT(slotFileOpenRecent(const QUrl&))); connect(v, SIGNAL(showIntroduction()), this, SLOT(slotShowIntroduction())); - connect(v, SIGNAL(finished()), this, SLOT(deleteStartUpWidget())); + connect(v, SIGNAL(finished()), this, SLOT(finish())); 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, SIGNAL(openUrlRequest(HtmlView*,QUrl)), SLOT(slotOpenUrlRequest(HtmlView*,QUrl)) ); return v; } diff --git a/plan/kptpart.h b/plan/kptpart.h index d2abb243d97..fa6ce5b3b99 100644 --- a/plan/kptpart.h +++ b/plan/kptpart.h @@ -1,73 +1,75 @@ /* 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. */ #ifndef KPTPART_H #define KPTPART_H #include #include "kplato_export.h" +#include + class KoView; class QStackedWidget; /// The main namespace. namespace KPlato { class MainDocument; class HtmlView; class KPLATO_EXPORT Part : public KoPart { Q_OBJECT public: explicit Part(QObject *parent); virtual ~Part(); void setDocument(KPlato::MainDocument *document); /// reimplemented virtual KoView *createViewInstance(KoDocument *document, QWidget *parent); /// reimplemented virtual KoMainWindow *createMainWindow(); virtual void showStartUpWidget(KoMainWindow *parent, bool alwaysShow = false); protected Q_SLOTS: - void deleteStartUpWidget(); + void finish(); void slotShowIntroduction(); void slotOpenUrlRequest( HtmlView *v, const QUrl &url ); protected: virtual void openTemplate( const QUrl& url ); void createStarUpWidget(KoMainWindow *parent); QWidget *createWelcomeView(KoMainWindow *parent); QWidget *createIntroductionView(); private: KPlato::MainDocument *m_document; - - QStackedWidget *startUpWidget; + QPointer startUpWidget; + bool m_toolbarVisible; }; } //KPlato namespace #endif