File indexing completed on 2024-05-12 16:30:48

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2001-2002 Lennart Kudling <kudling@kde.org>
0003  * Copyright (C) 2001-2007 Rob Buis <buis@kde.org>
0004  * Copyright (C) 2002-2006 Laurent Montel <montel@kde.org>
0005  * Copyright (C) 2002 Werner Trobin <trobin@kde.org>
0006  * Copyright (C) 2002-2006 David Faure <faure@kde.org>
0007  * Copyright (C) 2002 Stephan Kulow <coolo@kde.org>
0008  * Copyright (C) 2002 Benoit Vautrin <benoit.vautrin@free.fr>
0009  * Copyright (C) 2003 Thomas Nagy <tnagyemail-mail@yahoo.fr>
0010  * Copyright (C) 2003,2006 Dirk Mueller <mueller@kde.org>
0011  * Copyright (C) 2004 Brad Hards <bradh@frogmouth.net>
0012  * Copyright (C) 2004-2006 Peter Simonsson <psn@linux.se>
0013  * Copyright (C) 2004-2005 Fredrik Edemar <f_edemar@linux.se>
0014  * Copyright (C) 2005-2006 Tim Beaulen <tbscope@gmail.com>
0015  * Copyright (C) 2005 Sven Langkamp <sven.langkamp@gmail.com>
0016  * Copyright (C) 2005-2007 Jan Hambrecht <jaham@gmx.net>
0017  * Copyright (C) 2005-2007 Thomas Zander <zander@kde.org>
0018  * Copyright (C) 2005-2006 Inge Wallin <inge@lysator.liu.se>
0019  * Copyright (C) 2005 Johannes Schaub <johannes.schaub@kdemail.net>
0020  * Copyright (C) 2006 Gabor Lehel <illissius@gmail.com>
0021  * Copyright (C) 2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0022  * Copyright (C) 2006 Jaison Lee <lee.jaison@gmail.com>
0023  * Copyright (C) 2006,2012 C. Boemann <cbo@boemann.dk>
0024  * Copyright (C) 2006-2007 Thorsten Zachmann <t.zachmann@zagge.de>
0025  * Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
0026  *
0027  * This library is free software; you can redistribute it and/or
0028  * modify it under the terms of the GNU Library General Public
0029  * License as published by the Free Software Foundation; either
0030  * version 2 of the License, or (at your option) any later version.
0031  *
0032  * This library is distributed in the hope that it will be useful,
0033  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0034  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0035  * Library General Public License for more details.
0036  *
0037  * You should have received a copy of the GNU Library General Public License
0038  * along with this library; see the file COPYING.LIB.  If not, write to
0039  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0040  * Boston, MA 02110-1301, USA.
0041 */
0042 
0043 #include "KarbonPart.h"
0044 
0045 #include "KarbonView.h"
0046 #include "ProxyView.h"
0047 #include "KarbonDocument.h"
0048 #include "KarbonFactory.h"
0049 #include "KarbonPaletteBarWidget.h"
0050 
0051 #include <KoCanvasResourceManager.h>
0052 #include <KoCanvasBase.h>
0053 #include <KoComponentData.h>
0054 
0055 #include <kconfiggroup.h>
0056 
0057 #include <QVBoxLayout>
0058 
0059 KarbonPart::KarbonPart(QObject *parent)
0060     : KoPart(KarbonFactory::global(), parent)
0061 {
0062     setTemplatesResourcePath(QLatin1String("karbon/templates/"));
0063 }
0064 
0065 KarbonPart::~KarbonPart()
0066 {
0067 }
0068 
0069 KoView * KarbonPart::createViewInstance(KoDocument *_document, QWidget *parent)
0070 {
0071     KarbonDocument *doc = qobject_cast<KarbonDocument*>(_document);
0072     ProxyView *view = new ProxyView(this, doc, parent);
0073 
0074     KarbonView *result = new KarbonView(this, doc, view);
0075     view->view = result;
0076 
0077     // Add the color bar below the karbon view (the reason for the ProxyView)
0078     QVBoxLayout *layout = new QVBoxLayout(view);
0079     layout->setMargin(0);
0080     layout->setSpacing(0);
0081     layout->addWidget(result);
0082     layout->addWidget(result->colorBar());
0083 
0084     connect(doc, SIGNAL(replaceActivePage(KoPAPageBase*,KoPAPageBase*)), result, SLOT(replaceActivePage(KoPAPageBase*,KoPAPageBase*)));
0085 
0086     return view;
0087 }
0088 
0089 KoMainWindow *KarbonPart::createMainWindow()
0090 {
0091     return new KoMainWindow(KARBON_MIME_TYPE, componentData());
0092 }
0093 
0094 void KarbonPart::openTemplate(const QUrl& url)
0095 {
0096     KoPart::openTemplate(url);
0097 
0098     // explicitly set the output mimetype to our native mimetype
0099     // so that autosaving works for not yet saved templates as well
0100     if (document()->outputMimeType().isEmpty()) {
0101         document()->setOutputMimeType("application/vnd.oasis.opendocument.graphics");
0102     }
0103 }