1 /* This file is part of the KDE project
2 Copyright (C) 2012 C. Boemann <cbo@kogmbh.com>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "KPrPart.h"
21
22 #include "KPrView.h"
23 #include "KPrDocument.h"
24 #include "KPrFactory.h"
25
26 #include <KoComponentData.h>
27 #include <KoPACanvasItem.h>
28 #include <KoCanvasBase.h>
29 #include <KoShapeRegistry.h>
30 #include <KoShapeManager.h>
31 #include "KPrShapeManagerDisplayMasterStrategy.h"
32 #include "KPrPageSelectStrategyActive.h"
33
34 #include <kmessagebox.h>
35
KPrPart(QObject * parent)36 KPrPart::KPrPart(QObject *parent)
37 : KoPart(KPrFactory::componentData(), parent)
38 {
39 setTemplatesResourcePath(QLatin1String("calligrastage/templates/"));
40 }
41
~KPrPart()42 KPrPart::~KPrPart()
43 {
44 }
45
setDocument(KPrDocument * document)46 void KPrPart::setDocument(KPrDocument *document)
47 {
48 KoPart::setDocument(document);
49 m_document = document;
50 }
51
createViewInstance(KoDocument * document,QWidget * parent)52 KoView * KPrPart::createViewInstance(KoDocument *document, QWidget *parent)
53 {
54 KPrView *view = new KPrView(this, qobject_cast<KPrDocument*>(document), parent);
55 connect(document, SIGNAL(replaceActivePage(KoPAPageBase*,KoPAPageBase*)), view, SLOT(replaceActivePage(KoPAPageBase*,KoPAPageBase*)));
56 return view;
57 }
58
createCanvasItem(KoDocument * document)59 QGraphicsItem *KPrPart::createCanvasItem(KoDocument *document)
60 {
61 KoPACanvasItem *canvasItem = new KoPACanvasItem(qobject_cast<KoPADocument*>(document));
62 canvasItem->masterShapeManager()->setPaintingStrategy(new KPrShapeManagerDisplayMasterStrategy(canvasItem->masterShapeManager(),
63 new KPrPageSelectStrategyActive(canvasItem)));
64 return canvasItem;
65 }
66
createMainWindow()67 KoMainWindow *KPrPart::createMainWindow()
68 {
69 return new KoMainWindow(STAGE_MIME_TYPE, componentData());
70 }
71
showStartUpWidget(KoMainWindow * parent,bool alwaysShow)72 void KPrPart::showStartUpWidget(KoMainWindow *parent, bool alwaysShow)
73 {
74 // Go through all (optional) plugins we require and quit if necessary
75 bool error = false;
76 KoShapeFactoryBase *factory;
77
78 factory = KoShapeRegistry::instance()->value("TextShapeID");
79 if (!factory) {
80 m_errorMessage = i18n("Can not find needed text component, Calligra Stage will quit now.");
81 error = true;
82 }
83 factory = KoShapeRegistry::instance()->value("PictureShape");
84 if (!factory) {
85 m_errorMessage = i18n("Can not find needed picture component, Calligra Stage will quit now.");
86 error = true;
87 }
88
89 if (error) {
90 QTimer::singleShot(0, this, SLOT(showErrorAndDie()));
91 } else {
92 KoPart::showStartUpWidget(parent, alwaysShow);
93 }
94 }
95
showErrorAndDie()96 void KPrPart::showErrorAndDie()
97 {
98 KMessageBox::error(0, m_errorMessage, i18n( "Installation Error"));
99 // This means "the environment is incorrect" on Windows
100 // FIXME: Is this uniform on all platforms?
101 QCoreApplication::exit(10);
102 }
103
104