1
/* This file is part of the KDE project
2
* Copyright (C) 2006-2007 Jan Hambrecht <jaham@gmx.net>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public License
15
* along with this library; see the file COPYING.LIB. If not, write to
16
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
20
#include "star/KoStarShapeFactory.h"
21
#include "star/KoStarShape.h"
22
#include "star/StarShapeConfigWidget.h"
24
#include <KoShapeFactory.h>
25
#include <KoLineBorder.h>
26
#include <KoProperties.h>
28
#include <KoXmlReader.h>
29
#include <KoColorBackground.h>
33
KoStarShapeFactory::KoStarShapeFactory( QObject *parent )
34
: KoShapeFactory( parent, KoStarShapeId, i18n( "A star shape" ) )
36
setToolTip( i18n( "A star" ) );
38
QStringList elementNames;
39
elementNames << "regular-polygon" << "custom-shape";
40
setOdfElementNames(KoXmlNS::draw, elementNames);
41
setLoadingPriority( 5 );
45
t.templateId = "star";
46
t.name = i18n("Star");
47
t.family = "geometric";
48
t.toolTip = i18n("A star");
49
t.icon = "star-shape";
50
KoProperties *props = new KoProperties();
51
props->setProperty( "corners", 5 );
53
v.setValue( QColor( Qt::yellow ) );
54
props->setProperty( "background", v );
59
t.templateId = "flower";
60
t.name = i18n("Flower");
62
t.toolTip = i18n("A flower");
63
t.icon = "flower-shape";
64
props = new KoProperties();
65
props->setProperty( "corners", 5 );
66
props->setProperty( "baseRadius", 10.0 );
67
props->setProperty( "tipRadius", 50.0 );
68
props->setProperty( "baseRoundness", 0.0 );
69
props->setProperty( "tipRoundness", 40.0 );
70
v.setValue( QColor( Qt::magenta ) );
71
props->setProperty( "background", v );
76
t.templateId = "pentagon";
77
t.name = i18n("Pentagon");
78
t.family = "geometric";
79
t.toolTip = i18n("A pentagon");
80
t.icon = "pentagon-shape";
81
props = new KoProperties();
82
props->setProperty( "corners", 5 );
83
props->setProperty( "convex", true );
84
props->setProperty( "tipRadius", 50.0 );
85
props->setProperty( "tipRoundness", 0.0 );
86
v.setValue( QColor( Qt::blue ) );
87
props->setProperty( "background", v );
92
t.templateId = "hexagon";
93
t.name = i18n("Hexagon");
94
t.family = "geometric";
95
t.toolTip = i18n("A hexagon");
96
t.icon = "hexagon-shape";
97
props = new KoProperties();
98
props->setProperty( "corners", 6 );
99
props->setProperty( "convex", true );
100
props->setProperty( "tipRadius", 50.0 );
101
props->setProperty( "tipRoundness", 0.0 );
102
v.setValue( QColor( Qt::blue ) );
103
props->setProperty( "background", v );
104
t.properties = props;
108
KoShape * KoStarShapeFactory::createDefaultShape() const
110
KoStarShape *star = new KoStarShape();
112
star->setBorder( new KoLineBorder( 1.0 ) );
113
star->setShapeId( KoPathShapeId );
118
KoShape * KoStarShapeFactory::createShape( const KoProperties * params ) const
120
KoStarShape *star = new KoStarShape();
124
star->setCornerCount( params->intProperty("corners", 5 ) );
125
star->setConvex( params->boolProperty( "convex", false ) );
126
star->setBaseRadius( params->doubleProperty( "baseRadius", 25.0 ) );
127
star->setTipRadius( params->doubleProperty( "tipRadius", 50.0 ) );
128
star->setBaseRoundness( params->doubleProperty( "baseRoundness", 0.0 ) );
129
star->setTipRoundness( params->doubleProperty( "tipRoundness", 0.0 ) );
130
star->setBorder( new KoLineBorder( 1.0 ) );
131
star->setShapeId( KoPathShapeId );
133
if( params->property( "background", v ) )
134
star->setBackground( new KoColorBackground( v.value<QColor>() ) );
139
bool KoStarShapeFactory::supports(const KoXmlElement & e) const
141
if ( e.localName() == "regular-polygon" && e.namespaceURI() == KoXmlNS::draw )
143
if ( e.localName() == "custom-shape" && e.namespaceURI() == KoXmlNS::draw )
149
QList<KoShapeConfigWidgetBase*> KoStarShapeFactory::createShapeOptionPanels()
151
QList<KoShapeConfigWidgetBase*> panels;
152
panels.append( new StarShapeConfigWidget() );
156
#include "KoStarShapeFactory.moc"