#ifndef GRAPHICSRECTITEM_H
#define GRAPHICSRECTITEM_H

#include "graphicsBaseItem.h"

class GraphicsRectItem : public GraphicsBaseItem
{
    Q_OBJECT

public:
    GraphicsRectItem(const QRect &rect, bool isRound = false, QGraphicsItem *parent = 0);
    virtual ~GraphicsRectItem();

    void resize(int,double, double, const QPointF&) override;
    void updateCoordinate() override;
    bool isRound() const { return m_bIsRound; }
    double ratioX() const { return m_dRatioX; }
    double ratioY() const { return m_dRatioY; }
    void setRatioX(double rx) { m_dRatioX = rx; }
    void setRatioY(double ry) { m_dRatioY = ry; }
    void move(const QPointF&) override;
    QJsonObject serialize() const override;
    static QGraphicsItem *createFromJson(const QJsonObject &obj);
    void editShape(int, const QPointF&) override;

protected:
    QPainterPath shape() override;
    void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) override;

private:
    void updateHandles() override;

    QRectF  m_lastBoudingRect; //记录上一时刻的boundingRect
    bool    m_bIsRound; //是否为圆角矩形
    double  m_dRatioX;
    double  m_dRatioY;
};

#endif
