#include "graphicsItem/itemControlHandle.h"
#include <QPainter>

#define HNDLE_SIZE 8

ItemControlHandle::ItemControlHandle(QGraphicsItem *parent)
    : QGraphicsRectItem(-HNDLE_SIZE / 2,
                        -HNDLE_SIZE / 2,
                        HNDLE_SIZE,
                        HNDLE_SIZE, parent)
{
    m_type = T_resize;
    m_tag = H_none;
}

ItemControlHandle::~ItemControlHandle()
{
}

void ItemControlHandle::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
    Q_UNUSED(option)
    Q_UNUSED(widget)

    painter->setPen(Qt::SolidLine);
    painter->setRenderHint(QPainter::Antialiasing, true);

    if(m_type==T_resize)
    {
        painter->setBrush(Qt::white);
        painter->drawRect(rect());
    }
    else if(m_type==T_rotate)
    {
        painter->setPen(Qt::NoPen);
        painter->setBrush(Qt::NoBrush);
        painter->drawRect(rect());
    }
    else if(m_type==T_editShape)
    {
        painter->setBrush(Qt::green);
        painter->drawEllipse(rect().center(), HNDLE_SIZE / 2, HNDLE_SIZE / 2);
    }
}

void ItemControlHandle::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{
    QGraphicsRectItem::hoverEnterEvent(event);
}

void ItemControlHandle::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
{
    QGraphicsRectItem::hoverLeaveEvent(event);
}

int ItemControlHandle::getSize()
{
    int nSize = HNDLE_SIZE;
    return nSize;
}

void ItemControlHandle::move(double x, double y)
{
    setPos(x, y);
}
