File indexing completed on 2024-05-12 15:56:44

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2006 Thomas Zander <zander@kde.org>
0003  * SPDX-FileCopyrightText: 2011 Thorsten Zachmann <zachmann@kde.org>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.0-or-later
0006  */
0007 #include "KoPathShapeFactory.h"
0008 #include "KoPathShape.h"
0009 #include "KoShapeStroke.h"
0010 #include "KoMarkerCollection.h"
0011 #include "KoDocumentResourceManager.h"
0012 #include "KoShapeLoadingContext.h"
0013 #include <KoIcon.h>
0014 #include "KoInsets.h"
0015 
0016 #include <klocalizedstring.h>
0017 
0018 #include <KoXmlNS.h>
0019 
0020 #include "kis_pointer_utils.h"
0021 
0022 KoPathShapeFactory::KoPathShapeFactory(const QStringList&)
0023         : KoShapeFactoryBase(KoPathShapeId, i18n("Simple path shape"))
0024 {
0025     setToolTip(i18n("A simple path shape"));
0026     setIconName(koIconNameCStr("pathshape"));
0027     QStringList elementNames;
0028     elementNames << "path" << "line" << "polyline" << "polygon";
0029     setXmlElementNames(KoXmlNS::draw, elementNames);
0030     setLoadingPriority(0);
0031 }
0032 
0033 KoShape *KoPathShapeFactory::createDefaultShape(KoDocumentResourceManager *) const
0034 {
0035     KoPathShape* path = new KoPathShape();
0036     path->moveTo(QPointF(0, 50));
0037     path->curveTo(QPointF(0, 120), QPointF(50, 120), QPointF(50, 50));
0038     path->curveTo(QPointF(50, -20), QPointF(100, -20), QPointF(100, 50));
0039     path->normalize();
0040     path->setStroke(toQShared(new KoShapeStroke(1.0)));
0041     return path;
0042 }
0043 
0044 bool KoPathShapeFactory::supports(const QDomElement & e, KoShapeLoadingContext &context) const
0045 {
0046     Q_UNUSED(context);
0047     if (e.namespaceURI() == KoXmlNS::draw) {
0048         if (e.localName() == "path")
0049             return true;
0050         if (e.localName() == "line")
0051             return true;
0052         if (e.localName() == "polyline")
0053             return true;
0054         if (e.localName() == "polygon")
0055             return true;
0056     }
0057 
0058     return false;
0059 }
0060 
0061 void KoPathShapeFactory::newDocumentResourceManager(KoDocumentResourceManager *manager) const
0062 {
0063     // we also need a MarkerCollection so add if it is not there yet
0064     if (!manager->hasResource(KoDocumentResourceManager::MarkerCollection)) {
0065         KoMarkerCollection *markerCollection = new KoMarkerCollection(manager);
0066         manager->setResource(KoDocumentResourceManager::MarkerCollection, QVariant::fromValue(markerCollection));
0067     }
0068 }