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

#include <RectangleShape.h>

+ Inheritance diagram for RectangleShape:

Public Member Functions

KoShapecloneShape () const override
 creates a deep copy of the shape or shape's subtree
 
qreal cornerRadiusX () const
 Returns the corner radius in x-direction.
 
qreal cornerRadiusY () const
 Returns the corner radius in y-direction.
 
bool loadSvg (const QDomElement &element, SvgLoadingContext &context) override
 reimplemented from SvgShape
 
QString pathShapeId () const override
 reimplemented
 
 RectangleShape ()
 
bool saveSvg (SvgSavingContext &context) override
 reimplemented from SvgShape
 
void setCornerRadiusX (qreal radius)
 
void setCornerRadiusY (qreal radius)
 
 ~RectangleShape () override
 
- Public Member Functions inherited from KoParameterShape
int handleCount () const
 return the number of handles set on the shape
 
int handleIdAt (const QRectF &rect) const
 Get the id of the handle within the given rect.
 
QPointF handlePosition (int handleId) const
 Get the handle position.
 
bool isParametricShape () const
 Check if object is a parametric shape.
 
 KoParameterShape ()
 
void moveHandle (int handleId, const QPointF &point, Qt::KeyboardModifiers modifiers=Qt::NoModifier)
 Move handle to point.
 
QPointF normalize () override
 Normalizes the path data.
 
void paintHandle (KisHandlePainterHelper &handlesHelper, int handleId)
 Paint the given handles.
 
void paintHandles (KisHandlePainterHelper &handlesHelper)
 Paint the handles.
 
 Private ()
 
 Private (const KoParameterShape::Private &rhs)
 
void setParametricShape (bool parametric)
 Set if the shape can be modified using parameters.
 
void setSize (const QSizeF &size) override
 reimplemented from KoShape
 
 ~KoParameterShape () override
 
virtual ~Private ()=default
 
- Public Member Functions inherited from KoPathShape
bool addSubpath (KoSubpath *subpath, int subpathIndex)
 Adds a subpath at the given index to the path.
 
KoPathPointarcTo (qreal rx, qreal ry, qreal startAngle, qreal sweepAngle)
 Add an arc.
 
bool autoFillMarkers () const
 
QRectF boundingRect () const override
 reimplemented
 
bool breakAfter (const KoPathPointIndex &pointIndex)
 Breaks the path after the point index.
 
void clear ()
 Removes all subpaths and their points from the path.
 
void close ()
 Closes the current subpath.
 
void closeMerge ()
 Closes the current subpath.
 
KoPathPointIndex closeSubpath (const KoPathPointIndex &pointIndex)
 Close a open subpath.
 
int combine (KoPathShape *path)
 Combines two path shapes by appending the data of the specified path.
 
KoPathPointcurveTo (const QPointF &c, const QPointF &p)
 Adds a new quadratic Bezier curve segment.
 
KoPathPointcurveTo (const QPointF &c1, const QPointF &c2, const QPointF &p)
 Adds a new cubic Bezier curve segment.
 
Qt::FillRule fillRule () const
 Returns the fill rule for the path object.
 
bool hasMarkers () const
 
bool hitTest (const QPointF &position) const override
 reimplemented
 
bool insertPoint (KoPathPoint *point, const KoPathPointIndex &pointIndex)
 Inserts a new point into the given subpath at the specified position.
 
bool isClosedSubpath (int subpathIndex) const
 Checks if a subpath is closed.
 
bool join (int subpathIndex)
 Joins the given subpath with the following one.
 
 KoPathShape ()
 constructor
 
KoPathPointlineTo (const QPointF &p)
 Adds a new line segment.
 
void loadNodeTypes (const QString &nodeTypes)
 Loads node types.
 
KoMarkermarker (KoFlake::MarkerPosition pos) const
 
bool moveSubpath (int oldSubpathIndex, int newSubpathIndex)
 Moves the position of a subpath within a path.
 
KoPathPointmoveTo (const QPointF &p)
 Starts a new Subpath.
 
QString nodeTypes () const
 Saves the node types.
 
KoPathPointIndex openSubpath (const KoPathPointIndex &pointIndex)
 Opens a closed subpath.
 
QPainterPath outline () const override
 reimplemented
 
QRectF outlineRect () const override
 reimplemented
 
void paint (QPainter &painter) const override
 reimplemented
 
virtual void paintPoints (KisHandlePainterHelper &handlesHelper)
 
KoPathPointIndex pathPointIndex (const KoPathPoint *point) const
 Returns the path point index of a given path point.
 
QPainterPath pathStroke (const QPen &pen) const
 
KoPathPointpointByIndex (const KoPathPointIndex &pointIndex) const
 Returns the path point specified by a path point index.
 
int pointCount () const
 Returns the number of points in the path.
 
QList< KoPathPoint * > pointsAt (const QRectF &rect, const bool useControlPoints=false) const
 Returns the path points within the given rectangle.
 
void recommendPointSelectionChange (const QList< KoPathPointIndex > &newSelection)
 
KoPathPointremovePoint (const KoPathPointIndex &pointIndex)
 Removes a point from the path.
 
KoSubpathremoveSubpath (int subpathIndex)
 Removes subpath from the path.
 
bool reverseSubpath (int subpathIndex)
 Reverse subpath.
 
KoPathSegment segmentByIndex (const KoPathPointIndex &pointIndex) const
 Returns the segment specified by a path point index.
 
QList< KoPathSegmentsegmentsAt (const QRectF &rect) const
 Returns the list of path segments within the given rectangle.
 
bool separate (QList< KoPathShape * > &separatedPaths)
 Creates separate path shapes, one for each existing subpath.
 
void setAutoFillMarkers (bool value)
 
void setFillRule (Qt::FillRule fillRule)
 Sets the fill rule to be used for painting the background.
 
void setMarker (KoMarker *marker, KoFlake::MarkerPosition pos)
 
void setSize (const QSizeF &size) override
 
QSizeF size () const override
 reimplemented
 
int subpathCount () const
 Returns the number of subpaths in the path.
 
int subpathPointCount (int subpathIndex) const
 Returns the number of points in a subpath.
 
QString toString (const QTransform &matrix=QTransform()) const
 Returns a odf/svg string representation of the path data with the given matrix applied.
 
 ~KoPathShape () override
 
- Public Member Functions inherited from KoTosContainer
KoShapecreateTextShape (KoDocumentResourceManager *documentResources=0)
 
 KoTosContainer ()
 
virtual bool loadText (const QDomElement &element)
 
void paintComponent (QPainter &painter) const override
 Paint the component Implement this method to allow the shape to paint itself, just like the KoShape::paint() method does.
 
ResizeBehavior resizeBehavior () const
 
void setPlainText (const QString &text)
 
void setResizeBehavior (ResizeBehavior resizeBehavior)
 
void setRunThrough (short int runThrough) override
 
void setTextAlignment (Qt::Alignment alignment)
 
Qt::Alignment textAlignment () const
 
 ~KoTosContainer () override
 
- Public Member Functions inherited from KoShapeContainer
void addShape (KoShape *shape)
 
bool inheritsTransform (const KoShape *shape) const
 
bool isClipped (const KoShape *child) const
 
 KoShapeContainer (KoShapeContainerModel *model=0)
 
KoShapeContainerModelmodel () const
 
void paint (QPainter &painter) const override
 reimplemented
 
 Private (const Private &rhs, KoShapeContainer *q)
 
 Private (KoShapeContainer *q)
 
void removeShape (KoShape *shape)
 
void setClipped (const KoShape *child, bool clipping)
 
void setInheritsTransform (const KoShape *shape, bool inherit)
 
int shapeCount () const
 
ShapeInterfaceshapeInterface ()
 
QList< KoShape * > shapes () const
 
virtual void update () const
 
void update () const override
 reimplemented
 
 ~KoShapeContainer () override
 
- Public Member Functions inherited from KoShape
QRectF absoluteOutlineRect () const
 
QPointF absolutePosition (KoFlake::AnchorPosition anchor=KoFlake::Center) const
 
QTransform absoluteTransformation () const
 
bool addDependee (KoShape *shape)
 
QString additionalAttribute (const QString &name) const
 
void addShapeChangeListener (ShapeChangeListener *listener)
 
KoShapeAnchoranchor () const
 
void applyAbsoluteTransformation (const QTransform &matrix)
 
void applyTransformation (const QTransform &matrix)
 
virtual QSharedPointer< KoShapeBackgroundbackground () const
 
virtual ChildZOrderPolicy childZOrderPolicy ()
 
KoClipMaskclipMask () const
 Returns the currently set clip mask or 0 if there is no clip mask set.
 
KoClipPathclipPath () const
 Returns the currently set clip path or 0 if there is no clip path set.
 
KoShapecloneShapeAndBakeAbsoluteTransform () const
 creates a deep copy of the shape/shapes tree and bakes the absolute transform of this into the resulting shape.
 
void copySettings (const KoShape *shape)
 
QList< KoShape * > dependees () const
 Returns list of shapes depending on this shape.
 
QPointF documentToShape (const QPointF &point) const
 Transforms point from document coordinates to shape coordinates.
 
QRectF documentToShape (const QRectF &rect) const
 Transform rect from document coordinates to shape coordinates.
 
KoFilterEffectStackfilterEffectStack () const
 
bool hasAdditionalAttribute (const QString &name) const
 
bool hasCommonParent (const KoShape *shape) const
 
bool hasDependee (KoShape *shape) const
 Returns if the given shape is dependent on this shape.
 
virtual bool hasTransparency () const
 
QString hyperLink () const
 
bool inheritBackground () const
 inheritBackground shows if the shape inherits background from its parent
 
bool inheritPaintOrder () const
 inheritPaintOrder
 
bool inheritsTransformFromAny (const QList< KoShape * > ancestorsInQuestion) const
 inheritsTransformFromAny checks if the shape inherits transformation from any of the shapes listed in ancestorsInQuestion. The inheritance is checked in recursive way.
 
bool inheritStroke () const
 inheritStroke shows if the shape inherits the stroke from its parent
 
bool isContentProtected () const
 
bool isGeometryProtected () const
 
bool isPrintable () const
 
bool isSelectable () const
 
virtual bool isShapeEditable (bool recursive=true) const
 checks recursively if the shape or one of its parents is not visible or locked
 
bool isVisible (bool recursive=true) const
 
bool keepAspectRatio () const
 
 KoShape ()
 Constructor.
 
qreal minimumHeight () const
 
QString name () const
 
void notifyChanged ()
 
virtual void paintMarkers (QPainter &painter) const
 paintStroke paints the shape's markers
 
virtual QVector< PaintOrderpaintOrder () const
 paintOrder
 
virtual void paintStroke (QPainter &painter) const
 paintStroke paints the shape's stroked outline
 
KoShapeContainerparent () const
 
QPointF position () const
 Get the position of the shape in pt.
 
void removeAdditionalAttribute (const QString &name)
 
void removeAdditionalStyleAttribute (const char *name)
 
void removeDependee (KoShape *shape)
 
void removeShapeChangeListener (ShapeChangeListener *listener)
 
void rotate (qreal angle)
 Rotate the shape (relative)
 
qreal rotation () const
 
int runThrough () const
 
void scale (qreal sx, qreal sy)
 Scale the shape using the zero-point which is the top-left corner.
 
void setAbsolutePosition (const QPointF &newPosition, KoFlake::AnchorPosition anchor=KoFlake::Center)
 
void setAdditionalAttribute (const QString &name, const QString &value)
 
void setAdditionalStyleAttribute (const char *name, const QString &value)
 
void setAnchor (KoShapeAnchor *anchor)
 
virtual void setBackground (QSharedPointer< KoShapeBackground > background)
 
void setClipMask (KoClipMask *clipMask)
 Sets a new clip mask, removing the old one. The mask is owned by the shape.
 
void setClipPath (KoClipPath *clipPath)
 Sets a new clip path, removing the old one.
 
void setContentProtected (bool protect)
 
void setFilterEffectStack (KoFilterEffectStack *filterEffectStack)
 Sets the new filter effect stack, removing the old one.
 
void setGeometryProtected (bool on)
 
void setHyperLink (const QString &hyperLink)
 
void setInheritBackground (bool value)
 setInheritBackground marks a shape as inheriting the background from the parent shape. NOTE: The currently selected background is destroyed.
 
void setInheritPaintOrder (bool value)
 setInheritPaintOrder set inherit paint order.
 
void setInheritStroke (bool value)
 setInheritStroke marks a shape as inheriting the stroke from the parent shape. NOTE: The currently selected stroke is destroyed.
 
void setKeepAspectRatio (bool keepAspect)
 
void setMinimumHeight (qreal height)
 
void setName (const QString &name)
 
virtual void setPaintOrder (PaintOrder first, PaintOrder second)
 setPaintOrder set the paint order. As there's only three entries in any given paintorder, you only need to have the first and second entry to set it.
 
void setParent (KoShapeContainer *parent)
 
virtual void setPosition (const QPointF &position)
 Set the position of the shape in pt.
 
void setPrintable (bool on)
 
virtual void setResolution (qreal xRes, qreal yRes)
 
void setSelectable (bool selectable)
 
void setShadow (KoShapeShadow *shadow)
 Sets the new shadow, removing the old one.
 
void setShapeId (const QString &id)
 
virtual void setStroke (KoShapeStrokeModelSP stroke)
 
void setTextRunAroundContour (TextRunAroundContour contour)
 
void setTextRunAroundDistanceBottom (qreal distance)
 
void setTextRunAroundDistanceLeft (qreal distance)
 
void setTextRunAroundDistanceRight (qreal distance)
 
void setTextRunAroundDistanceTop (qreal distance)
 
void setTextRunAroundSide (TextRunAroundSide side, RunThroughLevel runThrough=Background)
 
void setTextRunAroundThreshold (qreal threshold)
 
void setToolDelegates (const QSet< KoShape * > &delegates)
 
void setTransformation (const QTransform &matrix)
 
void setTransparency (qreal transparency)
 
void setUserData (KoShapeUserData *userData)
 
void setVisible (bool on)
 
void setZIndex (qint16 zIndex)
 
KoShapeShadowshadow () const
 Returns the currently set shadow or 0 if there is no shadow set.
 
virtual QPainterPath shadowOutline () const
 
QString shapeId () const
 
QPointF shapeToDocument (const QPointF &point) const
 Transforms point from shape coordinates to document coordinates.
 
QRectF shapeToDocument (const QRectF &rect) const
 Transforms rect from shape coordinates to document coordinates.
 
void shear (qreal sx, qreal sy)
 Shear the shape The shape will be sheared using the zero-point which is the top-left corner.
 
virtual KoSnapData snapData () const
 Returns additional snap data the shape wants to have snapping to.
 
virtual KoShapeStrokeModelSP stroke () const
 
KoInsets strokeInsets () const
 
TextRunAroundContour textRunAroundContour () const
 
qreal textRunAroundDistanceBottom () const
 
qreal textRunAroundDistanceLeft () const
 
qreal textRunAroundDistanceRight () const
 
qreal textRunAroundDistanceTop () const
 
TextRunAroundSide textRunAroundSide () const
 
qreal textRunAroundThreshold () const
 
QSet< KoShape * > toolDelegates () const
 
QTransform transformation () const
 Returns the shapes local transformation matrix.
 
qreal transparency (bool recursive=false) const
 
virtual void updateAbsolute (const QRectF &rect) const
 
KoShapeUserDatauserData () const
 
virtual void waitUntilReady (bool asynchronous=true) const
 
qint16 zIndex () const
 
virtual ~KoShape ()
 Destructor.
 
- Public Member Functions inherited from SvgShape
void saveMetadata (SvgSavingContext &context)
 
virtual ~SvgShape ()
 

Protected Member Functions

void createPoints (int requiredPointCount)
 
void moveHandleAction (int handleId, const QPointF &point, Qt::KeyboardModifiers modifiers=Qt::NoModifier) override
 Updates the internal state of a KoParameterShape.
 
 RectangleShape (const RectangleShape &rhs)
 
void updateHandles ()
 
void updatePath (const QSizeF &size) override
 Update the path of the parameter shape.
 
- Protected Member Functions inherited from KoParameterShape
QList< QPointF > handles () const
 
 KoParameterShape (const KoParameterShape &rhs)
 constructor
 
void setHandles (const QList< QPointF > &handles)
 
- Protected Member Functions inherited from KoPathShape
int arcToCurve (qreal rx, qreal ry, qreal startAngle, qreal sweepAngle, const QPointF &offset, QPointF *curvePoints) const
 Add an arc.
 
 KoPathShape (const KoPathShape &rhs)
 
void map (const QTransform &matrix)
 
void notifyPointsChanged ()
 
QTransform resizeMatrix (const QSizeF &newSize) const
 
KoSubpathListsubpaths ()
 XXX: refactor this using setter?
 
const KoSubpathListsubpaths () const
 
- Protected Member Functions inherited from KoTosContainer
 KoTosContainer (const KoTosContainer &rhs)
 
QRectF preferredTextRect () const
 
void setPreferredTextRect (const QRectF &rect)
 
void shapeChanged (ChangeType type, KoShape *shape=0) override
 
KoShapetextShape () const
 
- Protected Member Functions inherited from KoShapeContainer
 KoShapeContainer (const KoShapeContainer &rhs)
 
void setModel (KoShapeContainerModel *model)
 
void setModelInit (KoShapeContainerModel *model)
 
virtual void shapeCountChanged ()
 
- Protected Member Functions inherited from KoShape
 KoShape (const KoShape &rhs)
 
QList< ShapeChangeListener * > listeners () const
 
void setSizeImpl (const QSizeF &size) const
 
void shapeChangedPriv (KoShape::ChangeType type)
 
QTransform transform () const
 return the current matrix that contains the rotation/scale/position of this shape
 

Private Attributes

qreal m_cornerRadiusX
 in percent of half of the rectangle width (a number between 0 and 100)
 
qreal m_cornerRadiusY
 in percent of half of the rectangle height (a number between 0 and 100)
 

Additional Inherited Members

- Public Types inherited from KoTosContainer
enum  ResizeBehavior { TextFollowsSize , FollowTextSize , IndependentSizes , TextFollowsPreferredTextRect }
 different kinds of resizing behavior to determine how to treat text overflow More...
 
- Public Types inherited from KoShape
enum  ChangeType {
  PositionChanged , RotationChanged , ScaleChanged , ShearChanged ,
  SizeChanged , GenericMatrixChange , KeepAspectRatioChange , ParentChanged ,
  Deleted , StrokeChanged , BackgroundChanged , ShadowChanged ,
  BorderChanged , ParameterChanged , ContentChanged , TextRunAroundChanged ,
  ChildChanged , ConnectionPointChanged , ClipPathChanged , ClipMaskChanged ,
  TransparencyChanged
}
 Used by shapeChanged() to select which change was made. More...
 
enum  ChildZOrderPolicy { ChildZDefault , ChildZParentChild = ChildZDefault , ChildZPassThrough }
 Used by compareShapeZIndex() to order shapes. More...
 
enum  PaintOrder { Fill , Stroke , Markers }
 
enum  RunThroughLevel { Background , Foreground }
 
enum  TextRunAroundContour { ContourBox , ContourFull , ContourOutside }
 The behavior text should do when intersecting this shape. More...
 
enum  TextRunAroundSide {
  BiggestRunAroundSide , LeftRunAroundSide , RightRunAroundSide , EnoughRunAroundSide ,
  BothRunAroundSide , NoRunAround , RunThrough
}
 The behavior text should do when intersecting this shape. More...
 
- Static Public Member Functions inherited from KoPathShape
static KoPathShapecreateShapeFromPainterPath (const QPainterPath &path)
 Creates path shape from given QPainterPath.
 
- Static Public Member Functions inherited from KoShape
static QRectF absoluteOutlineRect (const QList< KoShape * > &shapes)
 
static QRectF boundingRect (const QList< KoShape * > &shapes)
 
static bool compareShapeZIndex (KoShape *s1, KoShape *s2)
 
static KisHandlePainterHelper createHandlePainterHelperDocument (QPainter *painter, KoShape *shape, qreal handleRadius, int decorationThickness)
 
static KisHandlePainterHelper createHandlePainterHelperView (QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
 
static QVector< PaintOrderdefaultPaintOrder ()
 default paint order as per SVG specification
 
static QList< KoShape * > linearizeSubtree (const QList< KoShape * > &shapes)
 
static QList< KoShape * > linearizeSubtreeSorted (const QList< KoShape * > &shapes)
 
- Public Attributes inherited from KoParameterShape
QList< QPointF > handles
 the handles that the user can grab and change
 
bool parametric
 
- Public Attributes inherited from KoShapeContainer
KoShapeContainerModelmodel
 
KoShapeContainer::ShapeInterface shapeInterface
 
- Static Public Attributes inherited from KoShape
static const qint16 maxZIndex = std::numeric_limits<qint16>::max()
 
static const qint16 minZIndex = std::numeric_limits<qint16>::min()
 

Detailed Description

The RectangleShape is a shape that represents a rectangle. The rectangle can have rounded corners, with different corner radii in x- and y-direction.

Definition at line 21 of file RectangleShape.h.

Constructor & Destructor Documentation

◆ RectangleShape() [1/2]

RectangleShape::RectangleShape ( )

Definition at line 22 of file RectangleShape.cpp.

26{
28 handles.push_back(QPointF(100, 0));
29 handles.push_back(QPointF(100, 0));
31 QSizeF size(100, 100);
33}
QList< QPointF > handles
the handles that the user can grab and change
void setHandles(const QList< QPointF > &handles)
QSizeF size() const override
reimplemented
qreal m_cornerRadiusX
in percent of half of the rectangle width (a number between 0 and 100)
void updatePath(const QSizeF &size) override
Update the path of the parameter shape.
qreal m_cornerRadiusY
in percent of half of the rectangle height (a number between 0 and 100)

References KoParameterShape::handles, KoParameterShape::setHandles(), KoPathShape::size(), and updatePath().

◆ ~RectangleShape()

RectangleShape::~RectangleShape ( )
override

Definition at line 42 of file RectangleShape.cpp.

43{
44}

◆ RectangleShape() [2/2]

RectangleShape::RectangleShape ( const RectangleShape & rhs)
protected

Definition at line 35 of file RectangleShape.cpp.

Member Function Documentation

◆ cloneShape()

KoShape * RectangleShape::cloneShape ( ) const
overridevirtual

creates a deep copy of the shape or shape's subtree

Returns
a cloned shape

Reimplemented from KoPathShape.

Definition at line 46 of file RectangleShape.cpp.

47{
48 return new RectangleShape(*this);
49}

References RectangleShape().

◆ cornerRadiusX()

qreal RectangleShape::cornerRadiusX ( ) const

Returns the corner radius in x-direction.

Definition at line 235 of file RectangleShape.cpp.

236{
237 return m_cornerRadiusX;
238}

References m_cornerRadiusX.

◆ cornerRadiusY()

qreal RectangleShape::cornerRadiusY ( ) const

Returns the corner radius in y-direction.

Definition at line 248 of file RectangleShape.cpp.

249{
250 return m_cornerRadiusY;
251}

References m_cornerRadiusY.

◆ createPoints()

void RectangleShape::createPoints ( int requiredPointCount)
protected

Definition at line 214 of file RectangleShape.cpp.

215{
216 if (subpaths().count() != 1) {
217 clear();
218 subpaths().append(new KoSubpath());
219 }
220 int currentPointCount = subpaths()[0]->count();
221 if (currentPointCount > requiredPointCount) {
222 for (int i = 0; i < currentPointCount - requiredPointCount; ++i) {
223 delete subpaths()[0]->front();
224 subpaths()[0]->pop_front();
225 }
226 } else if (requiredPointCount > currentPointCount) {
227 for (int i = 0; i < requiredPointCount - currentPointCount; ++i) {
228 subpaths()[0]->append(new KoPathPoint(this, QPointF()));
229 }
230 }
231
233}
QList< KoPathPoint * > KoSubpath
a KoSubpath contains a path from a moveTo until a close or a new moveTo
Definition KoPathShape.h:31
A KoPathPoint represents a point in a path.
const KoSubpathList & subpaths() const
void notifyPointsChanged()
void clear()
Removes all subpaths and their points from the path.

References KoPathShape::clear(), KoPathShape::notifyPointsChanged(), and KoPathShape::subpaths().

◆ loadSvg()

bool RectangleShape::loadSvg ( const QDomElement & element,
SvgLoadingContext & context )
overridevirtual

reimplemented from SvgShape

Reimplemented from SvgShape.

Definition at line 296 of file RectangleShape.cpp.

297{
298 const qreal x = SvgUtil::parseUnitX(context.currentGC(), context.resolvedProperties(), element.attribute("x"));
299 const qreal y = SvgUtil::parseUnitY(context.currentGC(), context.resolvedProperties(), element.attribute("y"));
300 const qreal w = SvgUtil::parseUnitX(context.currentGC(), context.resolvedProperties(), element.attribute("width"));
301 const qreal h = SvgUtil::parseUnitY(context.currentGC(), context.resolvedProperties(), element.attribute("height"));
302 const QString rxStr = element.attribute("rx");
303 const QString ryStr = element.attribute("ry");
304 qreal rx = rxStr.isEmpty() ? 0.0 : SvgUtil::parseUnitX(context.currentGC(), context.resolvedProperties(), rxStr);
305 qreal ry = ryStr.isEmpty() ? 0.0 : SvgUtil::parseUnitY(context.currentGC(), context.resolvedProperties(), ryStr);
306 // if one radius is given but not the other, use the same value for both
307 if (!rxStr.isEmpty() && ryStr.isEmpty()) {
308 ry = rx;
309 }
310 if (rxStr.isEmpty() && !ryStr.isEmpty()) {
311 rx = ry;
312 }
313
314 setSize(QSizeF(w, h));
315 setPosition(QPointF(x, y));
316 if (rx >= 0.0) {
317 setCornerRadiusX(qMin(qreal(100.0), qreal(rx / (0.5 * w) * 100.0)));
318 }
319 if (ry >= 0.0) {
320 setCornerRadiusY(qMin(qreal(100.0), qreal(ry / (0.5 * h) * 100.0)));
321 }
322 if (w == 0.0 || h == 0.0) {
323 setVisible(false);
324 }
325
326 return true;
327}
void setSize(const QSizeF &size) override
reimplemented from KoShape
virtual void setPosition(const QPointF &position)
Set the position of the shape in pt.
Definition KoShape.cpp:295
void setVisible(bool on)
Definition KoShape.cpp:972
void setCornerRadiusY(qreal radius)
void setCornerRadiusX(qreal radius)
SvgGraphicsContext * currentGC() const
Returns the current graphics context.
KoSvgTextProperties resolvedProperties() const
These are the text properties, completely resolved, ensuring that everything is inherited and the siz...
static qreal parseUnitX(SvgGraphicsContext *gc, const KoSvgTextProperties &resolved, const QString &unit)
parses a length attribute in x-direction
Definition SvgUtil.cpp:304
static qreal parseUnitY(SvgGraphicsContext *gc, const KoSvgTextProperties &resolved, const QString &unit)
parses a length attribute in y-direction
Definition SvgUtil.cpp:313

References SvgLoadingContext::currentGC(), SvgUtil::parseUnitX(), SvgUtil::parseUnitY(), SvgLoadingContext::resolvedProperties(), setCornerRadiusX(), setCornerRadiusY(), KoShape::setPosition(), KoParameterShape::setSize(), and KoShape::setVisible().

◆ moveHandleAction()

void RectangleShape::moveHandleAction ( int handleId,
const QPointF & point,
Qt::KeyboardModifiers modifiers = Qt::NoModifier )
overrideprotectedvirtual

Updates the internal state of a KoParameterShape.

This method is called from moveHandle.

Parameters
handleIdof the handle
pointto move the handle to in shape coordinates
modifiersused during move to point

Implements KoParameterShape.

Definition at line 51 of file RectangleShape.cpp.

52{
53 Q_UNUSED(modifiers);
54 QPointF p(point);
55
56 qreal width2 = size().width() / 2.0;
57 qreal height2 = size().height() / 2.0;
58 switch (handleId) {
59 case 0:
60 if (p.x() < width2) {
61 p.setX(width2);
62 } else if (p.x() > size().width()) {
63 p.setX(size().width());
64 }
65 p.setY(0);
66 m_cornerRadiusX = (size().width() - p.x()) / width2 * 100.0;
67 if (!(modifiers & Qt::ControlModifier)) {
68 m_cornerRadiusY = (size().width() - p.x()) / height2 * 100.0;
69 }
70 break;
71 case 1:
72 if (p.y() < 0) {
73 p.setY(0);
74 } else if (p.y() > height2) {
75 p.setY(height2);
76 }
77 p.setX(size().width());
78 m_cornerRadiusY = p.y() / height2 * 100.0;
79 if (!(modifiers & Qt::ControlModifier)) {
80 m_cornerRadiusX = p.y() / width2 * 100.0;
81 }
82 break;
83 }
84 // this is needed otherwise undo/redo might not end in the same result
85 if (100 - m_cornerRadiusX < 1e-10) {
86 m_cornerRadiusX = 100;
87 }
88 if (100 - m_cornerRadiusY < 1e-10) {
89 m_cornerRadiusY = 100;
90 }
91
93}
const Params2D p

References m_cornerRadiusX, m_cornerRadiusY, p, KoPathShape::size(), and updateHandles().

◆ pathShapeId()

QString RectangleShape::pathShapeId ( ) const
overridevirtual

reimplemented

Reimplemented from KoPathShape.

Definition at line 261 of file RectangleShape.cpp.

262{
263 return RectangleShapeId;
264}
#define RectangleShapeId

References RectangleShapeId.

◆ saveSvg()

bool RectangleShape::saveSvg ( SvgSavingContext & context)
overridevirtual

reimplemented from SvgShape

Reimplemented from SvgShape.

Definition at line 266 of file RectangleShape.cpp.

267{
268 // let basic path saiving code handle our saving
269 if (!isParametricShape()) return false;
270
271 context.shapeWriter().startElement("rect");
272 context.shapeWriter().addAttribute("id", context.getID(this));
274
275 SvgStyleWriter::saveSvgStyle(this, context);
276 SvgStyleWriter::saveMetadata(this, context);
277
278 const QSizeF size = this->size();
279 context.shapeWriter().addAttribute("width", size.width());
280 context.shapeWriter().addAttribute("height", size.height());
281
282 double rx = cornerRadiusX();
283 if (rx > 0.0) {
284 context.shapeWriter().addAttribute("rx", 0.01 * rx * 0.5 * size.width());
285 }
286 double ry = cornerRadiusY();
287 if (ry > 0.0) {
288 context.shapeWriter().addAttribute("ry", 0.01 * ry * 0.5 * size.height());
289 }
290
291 context.shapeWriter().endElement();
292
293 return true;
294}
bool isParametricShape() const
Check if object is a parametric shape.
QTransform transformation() const
Returns the shapes local transformation matrix.
Definition KoShape.cpp:424
qreal cornerRadiusX() const
Returns the corner radius in x-direction.
qreal cornerRadiusY() const
Returns the corner radius in y-direction.
QScopedPointer< KoXmlWriter > shapeWriter
QString getID(const KoShape *obj)
Returns the unique id for the given shape.
static void saveSvgStyle(KoShape *shape, SvgSavingContext &context)
Saves the style of the specified shape.
static void saveMetadata(const KoShape *shape, SvgSavingContext &context)
static void writeTransformAttributeLazy(const QString &name, const QTransform &transform, KoXmlWriter &shapeWriter)
Writes a transform as an attribute name iff the transform is not empty.
Definition SvgUtil.cpp:124

References cornerRadiusX(), cornerRadiusY(), SvgSavingContext::getID(), KoParameterShape::isParametricShape(), SvgStyleWriter::saveMetadata(), SvgStyleWriter::saveSvgStyle(), SvgSavingContext::shapeWriter, KoPathShape::size(), KoShape::transformation(), and SvgUtil::writeTransformAttributeLazy().

◆ setCornerRadiusX()

void RectangleShape::setCornerRadiusX ( qreal radius)

Sets the corner radius in x-direction.

The corner x-radius is a percent value (a number between 0 and 100) of the half size of the rectangles width.

Parameters
radiusthe new corner radius in x-direction

Definition at line 240 of file RectangleShape.cpp.

241{
242 radius = qBound(0.0, radius, 100.0);
243 m_cornerRadiusX = radius;
244 updatePath(size());
246}

References m_cornerRadiusX, KoPathShape::size(), updateHandles(), and updatePath().

◆ setCornerRadiusY()

void RectangleShape::setCornerRadiusY ( qreal radius)

Sets the corner radius in y-direction.

The corner y-radius is a percent value (a number between 0 and 100) of the half size of the rectangles height.

Parameters
radiusthe new corner radius in y-direction

Definition at line 253 of file RectangleShape.cpp.

254{
255 radius = qBound(0.0, radius, 100.0);
256 m_cornerRadiusY = radius;
257 updatePath(size());
259}

References m_cornerRadiusY, KoPathShape::size(), updateHandles(), and updatePath().

◆ updateHandles()

void RectangleShape::updateHandles ( )
protected

Definition at line 95 of file RectangleShape.cpp.

96{
98 handles.append(QPointF(size().width() - m_cornerRadiusX / 100.0 * 0.5 * size().width(), 0.0));
99 handles.append(QPointF(size().width(), m_cornerRadiusY / 100.0 * 0.5 * size().height()));
101}

References KoParameterShape::handles, m_cornerRadiusX, m_cornerRadiusY, KoParameterShape::setHandles(), and KoPathShape::size().

◆ updatePath()

void RectangleShape::updatePath ( const QSizeF & size)
overrideprotectedvirtual

Update the path of the parameter shape.

Parameters
sizeof the shape

Implements KoParameterShape.

Definition at line 103 of file RectangleShape.cpp.

104{
105 qreal rx = 0;
106 qreal ry = 0;
107 if (m_cornerRadiusX > 0 && m_cornerRadiusY > 0) {
108 rx = size.width() / 200.0 * m_cornerRadiusX;
109 ry = size.height() / 200.0 * m_cornerRadiusY;
110 }
111
112 qreal x2 = size.width() - rx;
113 qreal y2 = size.height() - ry;
114
115 QPointF curvePoints[12];
116
117 int requiredCurvePointCount = 4;
118 if (rx && m_cornerRadiusX < 100) {
119 requiredCurvePointCount += 2;
120 }
121 if (ry && m_cornerRadiusY < 100) {
122 requiredCurvePointCount += 2;
123 }
124
125 createPoints(requiredCurvePointCount);
126
127 KoSubpath &points = *subpaths()[0];
128
129 int cp = 0;
130
131 // first path starts and closes path
132 points[cp]->setProperty(KoPathPoint::StartSubpath);
133 points[cp]->setProperty(KoPathPoint::CloseSubpath);
134 points[cp]->setPoint(QPointF(rx, 0));
135 points[cp]->removeControlPoint1();
136 points[cp]->removeControlPoint2();
137
138 if (m_cornerRadiusX < 100 || m_cornerRadiusY == 0) {
139 // end point of the top edge
140 points[++cp]->setPoint(QPointF(x2, 0));
141 points[cp]->removeControlPoint1();
142 points[cp]->removeControlPoint2();
143 }
144
145 if (rx) {
146 // the top right radius
147 arcToCurve(rx, ry, 90, -90, points[cp]->point(), curvePoints);
148 points[cp]->setControlPoint2(curvePoints[0]);
149 points[++cp]->setControlPoint1(curvePoints[1]);
150 points[cp]->setPoint(curvePoints[2]);
151 points[cp]->removeControlPoint2();
152 }
153
154 if (m_cornerRadiusY < 100 || m_cornerRadiusX == 0) {
155 // the right edge
156 points[++cp]->setPoint(QPointF(size.width(), y2));
157 points[cp]->removeControlPoint1();
158 points[cp]->removeControlPoint2();
159 }
160
161 if (rx) {
162 // the bottom right radius
163 arcToCurve(rx, ry, 0, -90, points[cp]->point(), curvePoints);
164 points[cp]->setControlPoint2(curvePoints[0]);
165 points[++cp]->setControlPoint1(curvePoints[1]);
166 points[cp]->setPoint(curvePoints[2]);
167 points[cp]->removeControlPoint2();
168 }
169
170 if (m_cornerRadiusX < 100 || m_cornerRadiusY == 0) {
171 // the bottom edge
172 points[++cp]->setPoint(QPointF(rx, size.height()));
173 points[cp]->removeControlPoint1();
174 points[cp]->removeControlPoint2();
175 }
176
177 if (rx) {
178 // the bottom left radius
179 arcToCurve(rx, ry, 270, -90, points[cp]->point(), curvePoints);
180 points[cp]->setControlPoint2(curvePoints[0]);
181 points[++cp]->setControlPoint1(curvePoints[1]);
182 points[cp]->setPoint(curvePoints[2]);
183 points[cp]->removeControlPoint2();
184 }
185
186 if ((m_cornerRadiusY < 100 || m_cornerRadiusX == 0) && ry) {
187 // the right edge
188 points[++cp]->setPoint(QPointF(0, ry));
189 points[cp]->removeControlPoint1();
190 points[cp]->removeControlPoint2();
191 }
192
193 if (rx) {
194 // the top left radius
195 arcToCurve(rx, ry, 180, -90, points[cp]->point(), curvePoints);
196 points[cp]->setControlPoint2(curvePoints[0]);
197 points[0]->setControlPoint1(curvePoints[1]);
198 points[0]->setPoint(curvePoints[2]);
199 }
200
201 // unset all stop/close path properties
202 for (int i = 1; i < cp; ++i) {
203 points[i]->unsetProperty(KoPathPoint::StopSubpath);
204 points[i]->unsetProperty(KoPathPoint::CloseSubpath);
205 }
206
207 // last point stops and closes path
208 points.last()->setProperty(KoPathPoint::StopSubpath);
209 points.last()->setProperty(KoPathPoint::CloseSubpath);
210
212}
@ StartSubpath
it starts a new subpath by a moveTo command
Definition KoPathPoint.h:38
@ CloseSubpath
it closes a subpath (only applicable on StartSubpath and StopSubpath)
Definition KoPathPoint.h:40
@ StopSubpath
it stops a subpath (last point of subpath)
Definition KoPathPoint.h:39
int arcToCurve(qreal rx, qreal ry, qreal startAngle, qreal sweepAngle, const QPointF &offset, QPointF *curvePoints) const
Add an arc.
void createPoints(int requiredPointCount)

References KoPathShape::arcToCurve(), KoPathPoint::CloseSubpath, createPoints(), m_cornerRadiusX, m_cornerRadiusY, KoPathShape::notifyPointsChanged(), KoPathShape::size(), KoPathPoint::StartSubpath, KoPathPoint::StopSubpath, and KoPathShape::subpaths().

Member Data Documentation

◆ m_cornerRadiusX

qreal RectangleShape::m_cornerRadiusX
private

in percent of half of the rectangle width (a number between 0 and 100)

Definition at line 72 of file RectangleShape.h.

◆ m_cornerRadiusY

qreal RectangleShape::m_cornerRadiusY
private

in percent of half of the rectangle height (a number between 0 and 100)

Definition at line 73 of file RectangleShape.h.


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