File indexing completed on 2024-06-23 04:27:04

0001 /* This file is part of the KDE project
0002    SPDX-FileCopyrightText: 2006-2007 Thorsten Zachmann <zachmann@kde.org>
0003    SPDX-FileCopyrightText: 2006-2007 Jan Hambrecht <jaham@gmx.net>
0004 
0005    SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KORECTANGLESHAPE_H
0009 #define KORECTANGLESHAPE_H
0010 
0011 #include "KoParameterShape.h"
0012 #include <SvgShape.h>
0013 
0014 #define RectangleShapeId "RectangleShape"
0015 
0016 /**
0017  * The RectangleShape is a shape that represents a rectangle.
0018  * The rectangle can have rounded corners, with different corner
0019  * radii in x- and y-direction.
0020  */
0021 class RectangleShape : public KoParameterShape, public SvgShape
0022 {
0023 public:
0024     RectangleShape();
0025     ~RectangleShape() override;
0026 
0027     KoShape* cloneShape() const override;
0028 
0029     /// Returns the corner radius in x-direction
0030     qreal cornerRadiusX() const;
0031 
0032     /**
0033      * Sets the corner radius in x-direction.
0034      *
0035      * The corner x-radius is a percent value (a number between 0 and 100)
0036      * of the half size of the rectangles width.
0037      *
0038      * @param radius the new corner radius in x-direction
0039      */
0040     void setCornerRadiusX(qreal radius);
0041 
0042     /// Returns the corner radius in y-direction
0043     qreal cornerRadiusY() const;
0044 
0045     /**
0046      * Sets the corner radius in y-direction.
0047      *
0048      * The corner y-radius is a percent value (a number between 0 and 100)
0049      * of the half size of the rectangles height.
0050      *
0051      * @param radius the new corner radius in y-direction
0052      */
0053     void setCornerRadiusY(qreal radius);
0054     /// reimplemented
0055     QString pathShapeId() const override;
0056 
0057     /// reimplemented from SvgShape
0058     bool saveSvg(SvgSavingContext &context) override;
0059 
0060     /// reimplemented from SvgShape
0061     bool loadSvg(const QDomElement &element, SvgLoadingContext &context) override;
0062 
0063 protected:
0064     RectangleShape(const RectangleShape &rhs);
0065 
0066     void moveHandleAction(int handleId, const QPointF &point, Qt::KeyboardModifiers modifiers = Qt::NoModifier) override;
0067     void updatePath(const QSizeF &size) override;
0068     void createPoints(int requiredPointCount);
0069     void updateHandles();
0070 
0071 private:
0072     qreal m_cornerRadiusX; ///< in percent of half of the rectangle width (a number between 0 and 100)
0073     qreal m_cornerRadiusY; ///< in percent of half of the rectangle height (a number between 0 and 100)
0074 };
0075 
0076 #endif /* KORECTANGLESHAPE_H */
0077