File indexing completed on 2024-05-12 16:36:44
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 "KPrPart.h" 0021 0022 #include "KPrView.h" 0023 #include "KPrDocument.h" 0024 #include "KPrFactory.h" 0025 0026 #include <KoComponentData.h> 0027 #include <KoPACanvasItem.h> 0028 #include <KoCanvasBase.h> 0029 #include <KoShapeRegistry.h> 0030 #include <KoShapeManager.h> 0031 #include "KPrShapeManagerDisplayMasterStrategy.h" 0032 #include "KPrPageSelectStrategyActive.h" 0033 0034 #include <kmessagebox.h> 0035 0036 KPrPart::KPrPart(QObject *parent) 0037 : KoPart(KPrFactory::componentData(), parent) 0038 { 0039 setTemplatesResourcePath(QLatin1String("calligrastage/templates/")); 0040 } 0041 0042 KPrPart::~KPrPart() 0043 { 0044 } 0045 0046 void KPrPart::setDocument(KPrDocument *document) 0047 { 0048 KoPart::setDocument(document); 0049 m_document = document; 0050 } 0051 0052 KoView * KPrPart::createViewInstance(KoDocument *document, QWidget *parent) 0053 { 0054 KPrView *view = new KPrView(this, qobject_cast<KPrDocument*>(document), parent); 0055 connect(document, SIGNAL(replaceActivePage(KoPAPageBase*,KoPAPageBase*)), view, SLOT(replaceActivePage(KoPAPageBase*,KoPAPageBase*))); 0056 return view; 0057 } 0058 0059 QGraphicsItem *KPrPart::createCanvasItem(KoDocument *document) 0060 { 0061 KoPACanvasItem *canvasItem = new KoPACanvasItem(qobject_cast<KoPADocument*>(document)); 0062 canvasItem->masterShapeManager()->setPaintingStrategy(new KPrShapeManagerDisplayMasterStrategy(canvasItem->masterShapeManager(), 0063 new KPrPageSelectStrategyActive(canvasItem))); 0064 return canvasItem; 0065 } 0066 0067 KoMainWindow *KPrPart::createMainWindow() 0068 { 0069 return new KoMainWindow(STAGE_MIME_TYPE, componentData()); 0070 } 0071 0072 void KPrPart::showStartUpWidget(KoMainWindow *parent, bool alwaysShow) 0073 { 0074 // Go through all (optional) plugins we require and quit if necessary 0075 bool error = false; 0076 KoShapeFactoryBase *factory; 0077 0078 factory = KoShapeRegistry::instance()->value("TextShapeID"); 0079 if (!factory) { 0080 m_errorMessage = i18n("Can not find needed text component, Calligra Stage will quit now."); 0081 error = true; 0082 } 0083 factory = KoShapeRegistry::instance()->value("PictureShape"); 0084 if (!factory) { 0085 m_errorMessage = i18n("Can not find needed picture component, Calligra Stage will quit now."); 0086 error = true; 0087 } 0088 0089 if (error) { 0090 QTimer::singleShot(0, this, SLOT(showErrorAndDie())); 0091 } else { 0092 KoPart::showStartUpWidget(parent, alwaysShow); 0093 } 0094 } 0095 0096 void KPrPart::showErrorAndDie() 0097 { 0098 KMessageBox::error(0, m_errorMessage, i18n( "Installation Error")); 0099 // This means "the environment is incorrect" on Windows 0100 // FIXME: Is this uniform on all platforms? 0101 QCoreApplication::exit(10); 0102 } 0103