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-2013 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 Casper Boemann <cbr@boemann.dk> 0024 * Copyright (C) 2006-2007 Thorsten Zachmann <t.zachmann@zagge.de> 0025 * Copyright (C) 2007 Matthias Kretz <kretz@kde.org> 0026 * Copyright (C) 2012 Yue Liu <yue.liu@mail.com> 0027 * 0028 * This library is free software; you can redistribute it and/or 0029 * modify it under the terms of the GNU Library General Public 0030 * License as published by the Free Software Foundation; either 0031 * version 2 of the License, or (at your option) any later version. 0032 * 0033 * This library is distributed in the hope that it will be useful, 0034 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0035 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0036 * Library General Public License for more details. 0037 * 0038 * You should have received a copy of the GNU Library General Public License 0039 * along with this library; see the file COPYING.LIB. If not, write to 0040 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0041 * Boston, MA 02110-1301, USA. 0042 */ 0043 0044 #include "KarbonDocument.h" 0045 #include "KarbonPart.h" 0046 #include "KarbonFactory.h" 0047 #include "KarbonView.h" 0048 #include "KarbonUiDebug.h" 0049 0050 #include <KoImageCollection.h> 0051 #include <KoText.h> 0052 #include <KoSelection.h> 0053 #include <KoStyleManager.h> 0054 #include <KoTextSharedLoadingData.h> 0055 #include <KoOdfStylesReader.h> 0056 #include <KoOdfLoadingContext.h> 0057 #include <KoOdfReadStore.h> 0058 #include <KoOdfWriteStore.h> 0059 #include <KoShapeSavingContext.h> 0060 #include <KoShapeLoadingContext.h> 0061 #include <KoGridData.h> 0062 #include <KoGuidesData.h> 0063 #include <KoPageLayout.h> 0064 #include <KoXmlWriter.h> 0065 #include <KoXmlNS.h> 0066 #include <KoGenStyles.h> 0067 #include <KoOasisSettings.h> 0068 #include <KoMainWindow.h> 0069 #include <KoCanvasController.h> 0070 #include <KoToolManager.h> 0071 #include <KoShapeManager.h> 0072 #include <KoShapeLayer.h> 0073 #include <KoShapeRegistry.h> 0074 #include <KoCanvasResourceManager.h> 0075 #include <KoDocumentResourceManager.h> 0076 #include <KoEmbeddedDocumentSaver.h> 0077 #include <KoStoreDevice.h> 0078 #include <KoStore.h> 0079 #include <KoUnit.h> 0080 #include <KoShapePainter.h> 0081 #include <SvgShapeFactory.h> 0082 0083 #include <kconfig.h> 0084 #include <kconfiggroup.h> 0085 #include <klocalizedstring.h> 0086 #include <kundo2stack.h> 0087 0088 #include <QLocale> 0089 #include <QRectF> 0090 #include <QPainter> 0091 0092 // Make sure an appropriate DTD is available in www/calligra/DTD if changing this value 0093 // static const char * CURRENT_DTD_VERSION = "1.2"; 0094 0095 class Q_DECL_HIDDEN KarbonDocument::Private 0096 { 0097 public: 0098 Private() 0099 : showStatusBar(true), 0100 merge(false), 0101 maxRecentFiles(10) 0102 {} 0103 0104 // KarbonDocument document; ///< store non-visual doc info 0105 0106 bool showStatusBar; ///< enable/disable status bar in attached view(s) 0107 bool merge; 0108 uint maxRecentFiles; ///< max. number of files shown in open recent menu item 0109 }; 0110 0111 0112 KarbonDocument::KarbonDocument(KarbonPart* part) 0113 : KoPADocument(part) 0114 , d(new Private()) 0115 { 0116 Q_ASSERT(part); 0117 0118 initConfig(); 0119 0120 SvgShapeFactory::addToRegistry(); 0121 0122 // set as default paper 0123 KoPageLayout pl = pageLayout(); 0124 pl.format = KoPageFormat::defaultFormat(); 0125 pl.orientation = KoPageFormat::Portrait; 0126 pl.width = MM_TO_POINT(KoPageFormat::width(pl.format, pl.orientation)); 0127 pl.height = MM_TO_POINT(KoPageFormat::height(pl.format, pl.orientation)); 0128 setPageLayout(pl); 0129 } 0130 0131 KarbonDocument::~KarbonDocument() 0132 { 0133 delete d; 0134 } 0135 0136 void KarbonDocument::slotDocumentRestored() 0137 { 0138 setModified(false); 0139 } 0140 0141 bool KarbonDocument::showStatusBar() const 0142 { 0143 return d->showStatusBar; 0144 } 0145 0146 void KarbonDocument::setShowStatusBar(bool b) 0147 { 0148 d->showStatusBar = b; 0149 } 0150 0151 uint KarbonDocument::maxRecentFiles() const 0152 { 0153 return d->maxRecentFiles; 0154 } 0155 0156 void KarbonDocument::reorganizeGUI() 0157 { 0158 foreach(KoView* view, documentPart()->views()) { 0159 KarbonView * kv = qobject_cast<KarbonView*>(view); 0160 if (kv) { 0161 kv->reorganizeGUI(); 0162 } 0163 } 0164 } 0165 0166 void KarbonDocument::initConfig() 0167 { 0168 KSharedConfigPtr config = KarbonFactory::karbonConfig(); 0169 0170 // disable grid by default 0171 gridData().setShowGrid(false); 0172 0173 if (config->hasGroup("Interface")) { 0174 KConfigGroup interfaceGroup = config->group("Interface"); 0175 setAutoSave(interfaceGroup.readEntry("AutoSave", defaultAutoSave() / 60) * 60); 0176 d->maxRecentFiles = interfaceGroup.readEntry("NbRecentFile", 10); 0177 setShowStatusBar(interfaceGroup.readEntry("ShowStatusBar" , true)); 0178 setBackupFile(interfaceGroup.readEntry("BackupFile", true)); 0179 } 0180 int undos = 30; 0181 0182 QString defaultUnitSymbol = 0183 QLatin1String((QLocale().measurementSystem() == QLocale::ImperialSystem)?"in":"cm"); 0184 0185 if (config->hasGroup("Misc")) { 0186 KConfigGroup miscGroup = config->group("Misc"); 0187 undos = miscGroup.readEntry("UndoRedo", -1); 0188 defaultUnitSymbol = miscGroup.readEntry("Units", defaultUnitSymbol); 0189 } 0190 undoStack()->setUndoLimit(undos); 0191 setUnit(KoUnit::fromSymbol(defaultUnitSymbol)); 0192 0193 } 0194 0195 bool KarbonDocument::mergeNativeFormat(const QString &file) 0196 { 0197 d->merge = true; 0198 bool result = loadNativeFormat(file); 0199 if (!result) 0200 showLoadingErrorDialog(); 0201 d->merge = false; 0202 return result; 0203 } 0204 0205 KoOdf::DocumentType KarbonDocument::documentType() const 0206 { 0207 return KoOdf::Graphics; 0208 } 0209 0210 const char * KarbonDocument::odfTagName(bool withNamespace) 0211 { 0212 return withNamespace ? "office:drawing": "drawing"; 0213 }