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

Factory for path shapes. More...

#include <RectangleShapeFactory.h>

+ Inheritance diagram for RectangleShapeFactory:

Public Member Functions

KoShapecreateDefaultShape (KoDocumentResourceManager *documentResources=0) const override
 
KoShapecreateShape (const KoProperties *params, KoDocumentResourceManager *documentResources=0) const override
 
QList< KoShapeConfigWidgetBase * > createShapeOptionPanels () override
 
 RectangleShapeFactory ()
 constructor
 
bool supports (const QDomElement &e, KoShapeLoadingContext &context) const override
 
 ~RectangleShapeFactory () 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 RectangleShapeFactory.h.

Constructor & Destructor Documentation

◆ RectangleShapeFactory()

RectangleShapeFactory::RectangleShapeFactory ( )

constructor

Definition at line 22 of file RectangleShapeFactory.cpp.

23 : KoShapeFactoryBase(RectangleShapeId, i18n("Rectangle"))
24{
25 setToolTip(i18n("A rectangle"));
26 setIconName(koIconNameCStr("rectangle-shape"));
27 setFamily("geometric");
29
30 QList<QPair<QString, QStringList> > elementNamesList;
31 elementNamesList.append(qMakePair(QString(KoXmlNS::draw), QStringList("rect")));
32 elementNamesList.append(qMakePair(QString(KoXmlNS::svg), QStringList("rect")));
33 setXmlElements(elementNamesList);
34}
QList< QString > QStringList
#define RectangleShapeId
void setFamily(const QString &family)
void setToolTip(const QString &tooltip)
void setLoadingPriority(int priority)
void setIconName(const char *iconName)
void setXmlElements(const QList< QPair< QString, QStringList > > &elementNamesList)
KoShapeFactoryBase(const QString &id, const QString &name, const QString &deferredPluginName=QString())
static const QString svg
Definition KoXmlNS.h:39
static const QString draw
Definition KoXmlNS.h:27
#define koIconNameCStr(name)
Definition kis_icon.h:28

References KoXmlNS::draw, koIconNameCStr, KoShapeFactoryBase::setFamily(), KoShapeFactoryBase::setIconName(), KoShapeFactoryBase::setLoadingPriority(), KoShapeFactoryBase::setToolTip(), KoShapeFactoryBase::setXmlElements(), and KoXmlNS::svg.

◆ ~RectangleShapeFactory()

RectangleShapeFactory::~RectangleShapeFactory ( )
inlineoverride

Definition at line 20 of file RectangleShapeFactory.h.

20{}

Member Function Documentation

◆ createDefaultShape()

KoShape * RectangleShapeFactory::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 36 of file RectangleShapeFactory.cpp.

37{
39
40 rect->setStroke(toQShared(new KoShapeStroke(1.0)));
41 rect->setShapeId(KoPathShapeId);
42
43 QLinearGradient *gradient = new QLinearGradient(QPointF(0, 0), QPointF(1, 1));
44 gradient->setCoordinateMode(QGradient::ObjectBoundingMode);
45
46 gradient->setColorAt(0.0, Qt::white);
47 gradient->setColorAt(1.0, Qt::green);
49
50 return rect;
51}
#define KoPathShapeId
Definition KoPathShape.h:20
A gradient shape background.
QSharedPointer< T > toQShared(T *ptr)

References KoPathShapeId, and toQShared().

◆ createShape()

KoShape * RectangleShapeFactory::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 53 of file RectangleShapeFactory.cpp.

54{
55 KoShape *shape = createDefaultShape(documentResources);
56 RectangleShape *rectShape = dynamic_cast<RectangleShape*>(shape);
58
59 rectShape->setSize(
60 QSizeF(params->doubleProperty("width", rectShape->size().width()),
61 params->doubleProperty("height", rectShape->size().height())));
62
63 rectShape->setAbsolutePosition(
64 QPointF(params->doubleProperty("x", rectShape->absolutePosition(KoFlake::TopLeft).x()),
65 params->doubleProperty("y", rectShape->absolutePosition(KoFlake::TopLeft).y())),
67
68
69 rectShape->setCornerRadiusX(params->doubleProperty("rx", 0.0));
70 rectShape->setCornerRadiusY(params->doubleProperty("ry", 0.0));
71
72 return shape;
73}
void setSize(const QSizeF &size) override
reimplemented from KoShape
QSizeF size() const override
reimplemented
qreal doubleProperty(const QString &name, qreal defaultValue=0.0) const
QPointF absolutePosition(KoFlake::AnchorPosition anchor=KoFlake::Center) const
Definition KoShape.cpp:653
void setAbsolutePosition(const QPointF &newPosition, KoFlake::AnchorPosition anchor=KoFlake::Center)
Definition KoShape.cpp:668
KoShape * createDefaultShape(KoDocumentResourceManager *documentResources=0) const override
void setCornerRadiusY(qreal radius)
void setCornerRadiusX(qreal radius)
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
@ TopLeft
Definition KoFlake.h:86

References KoShape::absolutePosition(), createDefaultShape(), KoProperties::doubleProperty(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, KoShape::setAbsolutePosition(), RectangleShape::setCornerRadiusX(), RectangleShape::setCornerRadiusY(), KoParameterShape::setSize(), KoPathShape::size(), and KoFlake::TopLeft.

◆ createShapeOptionPanels()

QList< KoShapeConfigWidgetBase * > RectangleShapeFactory::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 81 of file RectangleShapeFactory.cpp.

82{
84 panels.append(new RectangleShapeConfigWidget());
85 return panels;
86}

◆ supports()

bool RectangleShapeFactory::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 75 of file RectangleShapeFactory.cpp.

76{
77 Q_UNUSED(e);
78 return (e.localName() == "rect" && e.namespaceURI() == KoXmlNS::draw);
79}

References KoXmlNS::draw.


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