#include "util/editingSelector.h"
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsView>
#include <graphicsItem/graphicsBaseItem.h>

EditingSelector::EditingSelector(QObject *parent)
    : BaseSelector(parent)
{
    m_type = ST_editing;
}
EditingSelector::~EditingSelector()
{

}

void EditingSelector::mousePressEvent(QGraphicsSceneMouseEvent* event, DesignerScene* scene)
{

}

void EditingSelector::mouseMoveEvent(QGraphicsSceneMouseEvent* event, DesignerScene* scene)
{
    s_ptMouseLast = event->scenePos();
    QList<QGraphicsItem *> items = scene->selectedItems();
    if (items.count() == 1)
    {
        IShape *item = dynamic_cast<IShape *>(items.first());
        if(item)
        {
            if(s_nDragHandle > H_left)
            {
                item->editShape(s_nDragHandle, s_ptMouseLast);
            }
        }
    }
}

void EditingSelector::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, DesignerScene* scene)
{
    QList<QGraphicsItem *> items = scene->selectedItems();
    if (items.count() == 1)
    {
        IShape *item = dynamic_cast<IShape *>(items.first());
        if(item && s_ptMouseLast != s_ptMouseDown)
        {
            item->updateCoordinate();
            scene->notifyDocumentModified();
        }
    }

    s_nDragHandle = H_none;
    setCursor(scene, Qt::ArrowCursor);
    emit setWorkingSelector(ST_base);
}
