~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to plugins/pathshapes/star/KoStarShapeFactory.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE project
2
 
 * Copyright (C) 2006-2007 Jan Hambrecht <jaham@gmx.net>
3
 
 *
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.
8
 
 *
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.
13
 
 *
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.
18
 
 */
19
 
 
20
 
#include "star/KoStarShapeFactory.h"
21
 
#include "star/KoStarShape.h"
22
 
#include "star/StarShapeConfigWidget.h"
23
 
 
24
 
#include <KoShapeFactory.h>
25
 
#include <KoLineBorder.h>
26
 
#include <KoProperties.h>
27
 
#include <KoXmlNS.h>
28
 
#include <KoXmlReader.h>
29
 
#include <KoColorBackground.h>
30
 
 
31
 
#include <klocale.h>
32
 
 
33
 
KoStarShapeFactory::KoStarShapeFactory( QObject *parent )
34
 
    : KoShapeFactory( parent, KoStarShapeId, i18n( "A star shape" ) )
35
 
{
36
 
    setToolTip( i18n( "A star" ) );
37
 
    setIcon("star");
38
 
    QStringList elementNames;
39
 
    elementNames << "regular-polygon" << "custom-shape";
40
 
    setOdfElementNames(KoXmlNS::draw, elementNames);
41
 
    setLoadingPriority( 5 );
42
 
 
43
 
    KoShapeTemplate t;
44
 
    t.id = KoPathShapeId;
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 );
52
 
    QVariant v;
53
 
    v.setValue( QColor( Qt::yellow ) );
54
 
    props->setProperty( "background", v );
55
 
    t.properties = props;
56
 
    addTemplate(t);
57
 
 
58
 
    t.id = KoPathShapeId;
59
 
    t.templateId = "flower";
60
 
    t.name = i18n("Flower");
61
 
    t.family = "funny";
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 );
72
 
    t.properties = props;
73
 
    addTemplate(t);
74
 
 
75
 
    t.id = KoPathShapeId;
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 );
88
 
    t.properties = props;
89
 
    addTemplate(t);
90
 
 
91
 
    t.id = KoPathShapeId;
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;
105
 
    addTemplate(t);
106
 
}
107
 
 
108
 
KoShape * KoStarShapeFactory::createDefaultShape() const
109
 
{
110
 
    KoStarShape *star = new KoStarShape();
111
 
 
112
 
    star->setBorder( new KoLineBorder( 1.0 ) );
113
 
    star->setShapeId( KoPathShapeId );
114
 
 
115
 
    return star;
116
 
}
117
 
 
118
 
KoShape * KoStarShapeFactory::createShape( const KoProperties * params ) const
119
 
{
120
 
    KoStarShape *star = new KoStarShape();
121
 
    if( ! star )
122
 
        return 0;
123
 
 
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 );
132
 
    QVariant v;
133
 
    if( params->property( "background", v ) )
134
 
        star->setBackground( new KoColorBackground( v.value<QColor>() ) );
135
 
 
136
 
    return star;
137
 
}
138
 
 
139
 
bool KoStarShapeFactory::supports(const KoXmlElement & e) const
140
 
{
141
 
    if ( e.localName() == "regular-polygon" && e.namespaceURI() == KoXmlNS::draw )
142
 
        return true;
143
 
    if ( e.localName() == "custom-shape" && e.namespaceURI() == KoXmlNS::draw )
144
 
        return true;
145
 
 
146
 
    return false;
147
 
}
148
 
 
149
 
QList<KoShapeConfigWidgetBase*> KoStarShapeFactory::createShapeOptionPanels()
150
 
{
151
 
    QList<KoShapeConfigWidgetBase*> panels;
152
 
    panels.append( new StarShapeConfigWidget() );
153
 
    return panels;
154
 
}
155
 
 
156
 
#include "KoStarShapeFactory.moc"