Krita Source Code Documentation
Loading...
Searching...
No Matches
StarShapeFactory Class Reference

Factory for path shapes. More...

#include <StarShapeFactory.h>

+ Inheritance diagram for StarShapeFactory:

Public Member Functions

KoShapecreateDefaultShape (KoDocumentResourceManager *documentResources=0) const override
 
KoShapecreateShape (const KoProperties *params, KoDocumentResourceManager *documentResources=0) const override
 
QList< KoShapeConfigWidgetBase * > createShapeOptionPanels () override
 
 StarShapeFactory ()
 constructor
 
bool supports (const QDomElement &e, KoShapeLoadingContext &context) const override
 
 ~StarShapeFactory () override
 
- Public Member Functions inherited from KoShapeFactoryBase
QString family () const
 
bool hidden () const
 
QString iconName () const
 
QString id () const
 
 KoShapeFactoryBase (const QString &id, const QString &name, const QString &deferredPluginName=QString())
 
int loadingPriority () const
 lower prio means the shape is more generic and will be checked later
 
QString name () const
 
virtual void newDocumentResourceManager (KoDocumentResourceManager *manager) const
 
QList< QPair< QString, QStringList > > odfElements () const
 
 Private (const QString &_id, const QString &_name, const QString &_deferredPluginName)
 
QList< KoShapeTemplatetemplates () const
 
QString toolTip () const
 
 ~KoShapeFactoryBase () override
 
 ~Private ()
 

Additional Inherited Members

- Public Attributes inherited from KoShapeFactoryBase
KoDeferredShapeFactoryBasedeferredFactory
 
QString deferredPluginName
 
QString family
 
bool hidden
 
QString iconName
 
const QString id
 
int loadingPriority
 
const QString name
 
QMutex pluginLoadingMutex
 
QList< QPointer< KoDocumentResourceManager > > resourceManagers
 
QList< KoShapeTemplatetemplates
 
QString tooltip
 
QList< QPair< QString, QStringList > > xmlElements
 
- Protected Member Functions inherited from KoShapeFactoryBase
void addTemplate (const KoShapeTemplate &params)
 
void setFamily (const QString &family)
 
void setHidden (bool hidden)
 
void setIconName (const char *iconName)
 
void setLoadingPriority (int priority)
 
void setToolTip (const QString &tooltip)
 
void setXmlElementNames (const QString &nameSpace, const QStringList &elementNames)
 
void setXmlElements (const QList< QPair< QString, QStringList > > &elementNamesList)
 

Detailed Description

Factory for path shapes.

Definition at line 15 of file StarShapeFactory.h.

Constructor & Destructor Documentation

◆ StarShapeFactory()

StarShapeFactory::StarShapeFactory ( )

constructor

Definition at line 24 of file StarShapeFactory.cpp.

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}
qreal v
#define KoPathShapeId
Definition KoPathShape.h:20
#define StarShapeId
Definition StarShape.h:13
void setProperty(const QString &name, const QVariant &value)
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)
KoShapeFactoryBase(const QString &id, const QString &name, const QString &deferredPluginName=QString())
static const QString draw
Definition KoXmlNS.h:27
#define koIconNameCStr(name)
Definition kis_icon.h:28
#define koIconName(name)
Definition kis_icon.h:27
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.

References KoShapeFactoryBase::addTemplate(), KoXmlNS::draw, KoShapeTemplate::family, KoShapeTemplate::iconName, KoShapeTemplate::id, koIconName, koIconNameCStr, KoPathShapeId, KoShapeTemplate::name, KoShapeTemplate::properties, KoShapeFactoryBase::setIconName(), KoShapeFactoryBase::setLoadingPriority(), KoProperties::setProperty(), KoShapeFactoryBase::setToolTip(), KoShapeFactoryBase::setXmlElementNames(), KoShapeTemplate::templateId, KoShapeTemplate::toolTip, and v.

◆ ~StarShapeFactory()

StarShapeFactory::~StarShapeFactory ( )
inlineoverride

Definition at line 20 of file StarShapeFactory.h.

20{}

Member Function Documentation

◆ createDefaultShape()

KoShape * StarShapeFactory::createDefaultShape ( KoDocumentResourceManager * documentResources = 0) const
overridevirtual

This method should be implemented by factories to create a shape that the user gets when doing a base insert. For example from a script. The created shape should have its values set to good defaults that the user can then adjust further if needed. Including the KoShape:setShapeId(), with the Id from this factory The default shape position is not relevant, it will be moved by the caller.

Parameters
documentResourcesthe resources manager that has all the document wide resources which can be used to create the object.
Returns
a new shape
See also
createShape() newDocumentResourceManager()

Reimplemented from KoShapeFactoryBase.

Definition at line 99 of file StarShapeFactory.cpp.

100{
101 StarShape *star = new StarShape();
102
103 star->setStroke(toQShared(new KoShapeStroke(1.0)));
105
106 return star;
107}
virtual void setStroke(KoShapeStrokeModelSP stroke)
Definition KoShape.cpp:1081
void setShapeId(const QString &id)
Definition KoShape.cpp:1062
QSharedPointer< T > toQShared(T *ptr)

References KoPathShapeId, KoShape::setShapeId(), KoShape::setStroke(), and toQShared().

◆ createShape()

KoShape * StarShapeFactory::createShape ( const KoProperties * params,
KoDocumentResourceManager * documentResources = 0 ) const
overridevirtual

This method should be implemented by factories to create a shape based on a set of properties that are specifically made for this shape-type. This method should also set this factories shapeId on the shape using KoShape::setShapeId() The default implementation just ignores 'params' and calls createDefaultShape()

Returns
a new shape
Parameters
paramsthe parameters to use when creating the shape
documentResourcesthe resources manager that has all the document wide resources which can be used to create the object.
See also
createDefaultShape() newDocumentResourceManager() addTemplate()
KoShapeTemplate::properties

Reimplemented from KoShapeFactoryBase.

Definition at line 109 of file StarShapeFactory.cpp.

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}
A simple solid color shape background.
int intProperty(const QString &name, int defaultValue=0) const
bool boolProperty(const QString &name, bool defaultValue=false) const
bool property(const QString &name, QVariant &value) const
qreal doubleProperty(const QString &name, qreal defaultValue=0.0) const
virtual void setBackground(QSharedPointer< KoShapeBackground > background)
Definition KoShape.cpp:918
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)

References KoProperties::boolProperty(), KoProperties::doubleProperty(), KoProperties::intProperty(), KoPathShapeId, KoProperties::property(), KoShape::setBackground(), StarShape::setBaseRadius(), StarShape::setBaseRoundness(), StarShape::setConvex(), StarShape::setCornerCount(), KoShape::setShapeId(), KoShape::setStroke(), StarShape::setTipRadius(), StarShape::setTipRoundness(), toQShared(), and v.

◆ createShapeOptionPanels()

QList< KoShapeConfigWidgetBase * > StarShapeFactory::createShapeOptionPanels ( )
overridevirtual

Create a list of option panels to show on creating a new shape. The shape type this factory creates may have general or specific setting panels that will be shown after inserting a new shape. The first item in the list will be shown as the first tab in the list of panels, behind all app specific panels. This is a separate list as set by setOptionPanels() and fetched by panelFactories()

Reimplemented from KoShapeFactoryBase.

Definition at line 142 of file StarShapeFactory.cpp.

143{
145 panels.append(new StarShapeConfigWidget());
146 return panels;
147}

◆ supports()

bool StarShapeFactory::supports ( const QDomElement & element,
KoShapeLoadingContext & context ) const
overridevirtual

returns true if this shapeFactory is able to load the ODF type started at argument element. ('draw:line' / 'draw:frame' / etc)

Implements KoShapeFactoryBase.

Definition at line 132 of file StarShapeFactory.cpp.

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}

References KoXmlNS::draw.


The documentation for this class was generated from the following files: