Krita Source Code Documentation
Loading...
Searching...
No Matches
StarShapeFactory.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2006-2007 Jan Hambrecht <jaham@gmx.net>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
8#include "star/StarShape.h"
10
11#include <KoShapeFactoryBase.h>
12#include <KoShapeStroke.h>
13#include <KoProperties.h>
14#include <KoXmlNS.h>
15#include <KoColorBackground.h>
17
18#include <KoIcon.h>
19
20#include <klocalizedstring.h>
21
22#include "kis_pointer_utils.h"
23
25 : KoShapeFactoryBase(StarShapeId, i18n("A star shape"))
26{
27 setToolTip(i18n("A star"));
28 setIconName(koIconNameCStr("star-shape"));
29 QStringList elementNames;
30 elementNames << "regular-polygon" << "custom-shape";
31 setXmlElementNames(KoXmlNS::draw, elementNames);
33
35 t.id = KoPathShapeId;
36 t.templateId = "star";
37 t.name = i18n("Star");
38 t.family = "geometric";
39 t.toolTip = i18n("A star");
40 t.iconName = koIconName("star-shape");
41 KoProperties *props = new KoProperties();
42 props->setProperty("corners", 5);
43 QVariant v;
44 v.setValue(QColor(Qt::yellow));
45 props->setProperty("background", v);
46 t.properties = props;
47 addTemplate(t);
48
49 t.id = KoPathShapeId;
50 t.templateId = "flower";
51 t.name = i18n("Flower");
52 t.family = "funny";
53 t.toolTip = i18n("A flower");
54 t.iconName = koIconName("flower-shape");
55 props = new KoProperties();
56 props->setProperty("corners", 5);
57 props->setProperty("baseRadius", 10.0);
58 props->setProperty("tipRadius", 50.0);
59 props->setProperty("baseRoundness", 0.0);
60 props->setProperty("tipRoundness", 40.0);
61 v.setValue(QColor(Qt::magenta));
62 props->setProperty("background", v);
63 t.properties = props;
64 addTemplate(t);
65
66 t.id = KoPathShapeId;
67 t.templateId = "pentagon";
68 t.name = i18n("Pentagon");
69 t.family = "geometric";
70 t.toolTip = i18n("A pentagon");
71 t.iconName = koIconName("pentagon-shape");
72 props = new KoProperties();
73 props->setProperty("corners", 5);
74 props->setProperty("convex", true);
75 props->setProperty("tipRadius", 50.0);
76 props->setProperty("tipRoundness", 0.0);
77 v.setValue(QColor(Qt::blue));
78 props->setProperty("background", v);
79 t.properties = props;
80 addTemplate(t);
81
82 t.id = KoPathShapeId;
83 t.templateId = "hexagon";
84 t.name = i18n("Hexagon");
85 t.family = "geometric";
86 t.toolTip = i18n("A hexagon");
87 t.iconName = koIconName("hexagon-shape");
88 props = new KoProperties();
89 props->setProperty("corners", 6);
90 props->setProperty("convex", true);
91 props->setProperty("tipRadius", 50.0);
92 props->setProperty("tipRoundness", 0.0);
93 v.setValue(QColor(Qt::blue));
94 props->setProperty("background", v);
95 t.properties = props;
96 addTemplate(t);
97}
98
100{
101 StarShape *star = new StarShape();
102
103 star->setStroke(toQShared(new KoShapeStroke(1.0)));
105
106 return star;
107}
108
110{
111 StarShape *star = new StarShape();
112 if (!star) {
113 return 0;
114 }
115
116 star->setCornerCount(params->intProperty("corners", 5));
117 star->setConvex(params->boolProperty("convex", false));
118 star->setBaseRadius(params->doubleProperty("baseRadius", 25.0));
119 star->setTipRadius(params->doubleProperty("tipRadius", 50.0));
120 star->setBaseRoundness(params->doubleProperty("baseRoundness", 0.0));
121 star->setTipRoundness(params->doubleProperty("tipRoundness", 0.0));
122 star->setStroke(toQShared(new KoShapeStroke(1.0)));
124 QVariant v;
125 if (params->property("background", v)) {
127 }
128
129 return star;
130}
131
132bool StarShapeFactory::supports(const QDomElement &e, KoShapeLoadingContext &context) const
133{
134 Q_UNUSED(context);
135 if (e.localName() == "regular-polygon" && e.namespaceURI() == KoXmlNS::draw) {
136 return true;
137 }
138 return (e.localName() == "custom-shape" && e.namespaceURI() == KoXmlNS::draw
139 && e.attributeNS(KoXmlNS::draw, "engine", "") == "calligra:star");
140}
141
qreal v
#define KoPathShapeId
Definition KoPathShape.h:20
#define StarShapeId
Definition StarShape.h:13
A simple solid color shape background.
int intProperty(const QString &name, int defaultValue=0) const
bool boolProperty(const QString &name, bool defaultValue=false) const
void setProperty(const QString &name, const QVariant &value)
bool property(const QString &name, QVariant &value) const
qreal doubleProperty(const QString &name, qreal defaultValue=0.0) const
void addTemplate(const KoShapeTemplate &params)
void setToolTip(const QString &tooltip)
void setLoadingPriority(int priority)
void setIconName(const char *iconName)
void setXmlElementNames(const QString &nameSpace, const QStringList &elementNames)
virtual void setStroke(KoShapeStrokeModelSP stroke)
Definition KoShape.cpp:1081
virtual void setBackground(QSharedPointer< KoShapeBackground > background)
Definition KoShape.cpp:918
void setShapeId(const QString &id)
Definition KoShape.cpp:1062
static const QString draw
Definition KoXmlNS.h:27
StarShapeFactory()
constructor
bool supports(const QDomElement &e, KoShapeLoadingContext &context) const override
QList< KoShapeConfigWidgetBase * > createShapeOptionPanels() override
KoShape * createDefaultShape(KoDocumentResourceManager *documentResources=0) const override
KoShape * createShape(const KoProperties *params, KoDocumentResourceManager *documentResources=0) const override
void setBaseRadius(qreal baseRadius)
Definition StarShape.cpp:75
void setCornerCount(uint cornerCount)
Definition StarShape.cpp:57
void setTipRadius(qreal tipRadius)
Definition StarShape.cpp:86
void setTipRoundness(qreal tipRoundness)
void setBaseRoundness(qreal baseRoundness)
Definition StarShape.cpp:97
void setConvex(bool convex)
#define koIconNameCStr(name)
Definition kis_icon.h:28
#define koIconName(name)
Definition kis_icon.h:27
QSharedPointer< T > toQShared(T *ptr)
QString iconName
Icon name.
QString family
The family of the shape (possible values are: "funny","arrow")
QString id
The id of the shape.
QString toolTip
The tooltip text for the template.
QString name
The name to be shown for this template.
const KoProperties * properties
QString templateId
The id of this particular template - only has to be unique with the shape.