libs/flake

KoPathShapeFactory.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002  * Copyright (C) 2006 Thomas Zander <zander@kde.org>
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this library; see the file COPYING.LIB.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019 #include "KoPathShapeFactory.h"
00020 #include "KoPathShape.h"
00021 #include "KoLineBorder.h"
00022 #include "KoImageCollection.h"
00023 
00024 #include <klocale.h>
00025 
00026 #include <KoXmlReader.h>
00027 #include <KoXmlNS.h>
00028 
00029 KoPathShapeFactory::KoPathShapeFactory(QObject *parent, const QStringList&)
00030         : KoShapeFactory(parent, KoPathShapeId, i18n("Simple path shape"))
00031 {
00032     setToolTip(i18n("A simple path shape"));
00033     setIcon("pathshape");
00034     QStringList elementNames;
00035     elementNames << "path" << "line" << "polyline" << "polygon";
00036     setOdfElementNames(KoXmlNS::draw, elementNames);
00037     setLoadingPriority(0);
00038 }
00039 
00040 KoShape * KoPathShapeFactory::createDefaultShape() const
00041 {
00042     KoPathShape* path = new KoPathShape();
00043     path->moveTo(QPointF(0, 50));
00044     path->curveTo(QPointF(0, 120), QPointF(50, 120), QPointF(50, 50));
00045     path->curveTo(QPointF(50, -20), QPointF(100, -20), QPointF(100, 50));
00046     path->normalize();
00047     path->setBorder(new KoLineBorder(1.0));
00048     return path;
00049 }
00050 
00051 KoShape * KoPathShapeFactory::createShape(const KoProperties * params) const
00052 {
00053     Q_UNUSED(params);
00054     return createDefaultShape();
00055 }
00056 
00057 bool KoPathShapeFactory::supports(const KoXmlElement & e) const
00058 {
00059     if (e.localName() == "path" && e.namespaceURI() == KoXmlNS::draw)
00060         return true;
00061     if (e.localName() == "line" && e.namespaceURI() == KoXmlNS::draw)
00062         return true;
00063     if (e.localName() == "polyline" && e.namespaceURI() == KoXmlNS::draw)
00064         return true;
00065     if (e.localName() == "polygon" && e.namespaceURI() == KoXmlNS::draw)
00066         return true;
00067 
00068     return false;
00069 }
00070 
00071 void KoPathShapeFactory::populateDataCenterMap(QMap<QString, KoDataCenter *>   & dataCenterMap)
00072 {
00073     // as we need an image collection for the pattern background
00074     // we want to make sure that there is always an image collection
00075     // added to the data center map, in case the picture shape plugin
00076     // is not loaded
00077     if (! dataCenterMap.contains("ImageCollection")) {
00078         KoImageCollection *imgCol = new KoImageCollection();
00079         dataCenterMap["ImageCollection"] = imgCol;
00080     }
00081 }