File indexing completed on 2024-05-12 16:35:46

0001 /* This file is part of the KDE project
0002    Copyright (C) 2012 C. Boemann <cbo@kogmbh.com>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include "Part.h"
0021 
0022 #include "Factory.h"
0023 #include "View.h"
0024 #include "Doc.h"
0025 #include "CanvasItem.h"
0026 #include "Map.h"
0027 #include "LoadingInfo.h"
0028 
0029 #include "ui/Selection.h"
0030 
0031 #include <KoCanvasBase.h>
0032 #include <KoSelection.h>
0033 #include <KoToolManager.h>
0034 #include <KoInteractionTool.h>
0035 #include <KoComponentData.h>
0036 
0037 using namespace Calligra::Sheets;
0038 
0039 Part::Part(QObject *parent)
0040     : KoPart(Factory::global(), parent)
0041 {
0042     setTemplatesResourcePath(QLatin1String("calligrasheets/templates/"));
0043 }
0044 
0045 Part::~Part()
0046 {
0047 }
0048 
0049 void Part::setDocument(Doc *document)
0050 {
0051     KoPart::setDocument(document);
0052     m_document = document;
0053 }
0054 
0055 KoView* Part::createViewInstance(KoDocument *document, QWidget* parent)
0056 {
0057     View *view = new View(this, parent, qobject_cast<Sheets::Doc*>(document));
0058     // If we don't have this here, the next call will die horribly
0059     KoToolManager::instance()->addController(view->canvasController());
0060     // explicit switch tool to be sure that the list of option-widgets (CellToolOptionWidget
0061     // as returned by KoToolBase::optionWidgets) is updated to prevent crashes like bug 278896.
0062     KoToolManager::instance()->switchToolRequested(KoInteractionTool_ID);
0063     // We need to set the active sheet, otherwise we will break various other bits of the API
0064     // which expect your view to actually be ready for interaction after being created (e.g.
0065     // printing)
0066     view->setActiveSheet(qobject_cast<Sheets::Doc*>(document)->map()->sheet(0));
0067     return view;
0068 }
0069 
0070 QGraphicsItem *Part::createCanvasItem(KoDocument *document)
0071 {
0072     return new CanvasItem(qobject_cast<Sheets::Doc*>(document));
0073 }
0074 
0075 KoMainWindow *Part::createMainWindow()
0076 {
0077     return new KoMainWindow(SHEETS_MIME_TYPE, componentData());
0078 }
0079 
0080 void Part::openTemplate(const QUrl& url)
0081 {
0082     m_document->map()->loadingInfo()->setLoadTemplate(true);
0083     KoPart::openTemplate(url);
0084     m_document->map()->deleteLoadingInfo();
0085     m_document->initConfig();
0086 }
0087 
0088 void Part::addView(KoView *_view, KoDocument *document)
0089 {
0090     KoPart::addView(_view, document);
0091     foreach(KoView* view, views()) {
0092         static_cast<View*>(view)->selection()->emitCloseEditor(true);
0093     }
0094 }
0095