Warning, file /office/calligra/libs/flake/KoPathShapeFactory.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2006 Thomas Zander <zander@kde.org> 0003 * Copyright (C) 2011 Thorsten Zachmann <zachmann@kde.org> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 #include "KoPathShapeFactory.h" 0021 #include "KoPathShape.h" 0022 #include "KoShapeStroke.h" 0023 #include "KoImageCollection.h" 0024 #include "KoMarkerCollection.h" 0025 #include "KoDocumentResourceManager.h" 0026 #include "KoShapeLoadingContext.h" 0027 #include <KoIcon.h> 0028 0029 #include <klocalizedstring.h> 0030 0031 #include <KoXmlReader.h> 0032 #include <KoXmlNS.h> 0033 0034 KoPathShapeFactory::KoPathShapeFactory(const QStringList&) 0035 : KoShapeFactoryBase(KoPathShapeId, i18n("Simple path shape")) 0036 { 0037 setToolTip(i18n("A simple path shape")); 0038 setIconName(koIconName("pathshape")); 0039 QStringList elementNames; 0040 elementNames << "path" << "line" << "polyline" << "polygon"; 0041 setXmlElementNames(KoXmlNS::draw, elementNames); 0042 setLoadingPriority(0); 0043 } 0044 0045 KoShape *KoPathShapeFactory::createDefaultShape(KoDocumentResourceManager *) const 0046 { 0047 KoPathShape* path = new KoPathShape(); 0048 path->moveTo(QPointF(0, 50)); 0049 path->curveTo(QPointF(0, 120), QPointF(50, 120), QPointF(50, 50)); 0050 path->curveTo(QPointF(50, -20), QPointF(100, -20), QPointF(100, 50)); 0051 path->normalize(); 0052 path->setStroke(new KoShapeStroke(1.0)); 0053 return path; 0054 } 0055 0056 bool KoPathShapeFactory::supports(const KoXmlElement & e, KoShapeLoadingContext &context) const 0057 { 0058 Q_UNUSED(context); 0059 if (e.namespaceURI() == KoXmlNS::draw) { 0060 if (e.localName() == "path") 0061 return true; 0062 if (e.localName() == "line") 0063 return true; 0064 if (e.localName() == "polyline") 0065 return true; 0066 if (e.localName() == "polygon") 0067 return true; 0068 } 0069 0070 return false; 0071 } 0072 0073 void KoPathShapeFactory::newDocumentResourceManager(KoDocumentResourceManager *manager) const 0074 { 0075 // as we need an image collection for the pattern background 0076 // we want to make sure that there is always an image collection 0077 // added to the data center map, in case the picture shape plugin 0078 // is not loaded 0079 if (manager->imageCollection() == 0) { 0080 KoImageCollection *imgCol = new KoImageCollection(manager); 0081 manager->setImageCollection(imgCol); 0082 } 0083 // we also need a MarkerCollection so add if it is not there yet 0084 if (!manager->hasResource(KoDocumentResourceManager::MarkerCollection)) { 0085 KoMarkerCollection *markerCollection = new KoMarkerCollection(manager); 0086 manager->setResource(KoDocumentResourceManager::MarkerCollection, qVariantFromValue(markerCollection)); 0087 } 0088 }