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

#include <kis_shape_tool_helper.h>

Static Public Member Functions

static KoShapecreateEllipseShape (const QRectF &rect)
 
static KoShapecreateRectangleShape (const QRectF &rect, qreal roundCornersX, qreal roundCornersY)
 

Detailed Description

KisShapeToolHelper provides shapes and fallback shapes for shape based tools

Definition at line 18 of file kis_shape_tool_helper.h.

Member Function Documentation

◆ createEllipseShape()

KoShape * KisShapeToolHelper::createEllipseShape ( const QRectF & rect)
static

Definition at line 47 of file kis_shape_tool_helper.cpp.

48{
49 KoShape* shape;
50 KoShapeFactoryBase *rectFactory = KoShapeRegistry::instance()->value("EllipseShape");
51 if (rectFactory) {
52 shape = rectFactory->createDefaultShape();
53 shape->setSize(rect.size());
54 shape->setPosition(rect.topLeft());
55 } else {
56 //Fallback if the plugin wasn't found
57 KoPathShape* path = new KoPathShape();
58 path->setShapeId(KoPathShapeId);
59
60 QPointF rightMiddle = QPointF(rect.left() + rect.width(), rect.top() + rect.height() / 2);
61 path->moveTo(rightMiddle);
62 path->arcTo(rect.width() / 2, rect.height() / 2, 0, 360.0);
63 path->close();
64 path->normalize();
65 shape = path;
66 }
67 return shape;
68}
#define KoPathShapeId
Definition KoPathShape.h:20
const T value(const QString &id) const
The position of a path point within a path shape.
Definition KoPathShape.h:63
virtual KoShape * createDefaultShape(KoDocumentResourceManager *documentResources=0) const
static KoShapeRegistry * instance()
virtual void setPosition(const QPointF &position)
Set the position of the shape in pt.
Definition KoShape.cpp:295
virtual void setSize(const QSizeF &size)
Resize the shape.
Definition KoShape.cpp:276

References KoShapeFactoryBase::createDefaultShape(), KoShapeRegistry::instance(), KoPathShapeId, KoShape::setPosition(), KoShape::setSize(), and KoGenericRegistry< T >::value().

◆ createRectangleShape()

KoShape * KisShapeToolHelper::createRectangleShape ( const QRectF & rect,
qreal roundCornersX,
qreal roundCornersY )
static

Definition at line 17 of file kis_shape_tool_helper.cpp.

18{
19 KoShape* shape;
20
21 KoShapeFactoryBase *rectFactory = KoShapeRegistry::instance()->value("RectangleShape");
22 if (rectFactory) {
23 KoProperties props;
24 props.setProperty("x", rect.x());
25 props.setProperty("y", rect.y());
26 props.setProperty("width", rect.width());
27 props.setProperty("height", rect.height());
28 props.setProperty("rx", 2 * 100.0 * roundCornersX / rect.width());
29 props.setProperty("ry", 2 * 100.0 * roundCornersY / rect.height());
30
31 shape = rectFactory->createShape(&props);
32 } else {
33 //Fallback if the plugin wasn't found
34 QPainterPath path;
35 if (roundCornersX > 0 || roundCornersY > 0) {
36 path.addRoundedRect(rect, roundCornersX, roundCornersY);
37 } else {
38 path.addRect(rect);
39 }
41 pathShape->normalize();
42 shape = pathShape;
43 }
44 return shape;
45}
virtual QPointF normalize()
Normalizes the path data.
static KoPathShape * createShapeFromPainterPath(const QPainterPath &path)
Creates path shape from given QPainterPath.
void setProperty(const QString &name, const QVariant &value)
virtual KoShape * createShape(const KoProperties *params, KoDocumentResourceManager *documentResources=0) const

References KoShapeFactoryBase::createShape(), KoPathShape::createShapeFromPainterPath(), KoShapeRegistry::instance(), KoPathShape::normalize(), KoProperties::setProperty(), and KoGenericRegistry< T >::value().


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