#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)
{
    ms_ptMouseLast = event->scenePos();
    QList<QGraphicsItem *> items = scene->selectedItems();
    if (items.count() == 1)
    {
        GraphicsBaseItem* item = qgraphicsitem_cast<GraphicsBaseItem*>(items.first());
        if(item)
        {
            if(ms_nDragHandle > H_left)
            {
                item->editShape(ms_nDragHandle, ms_ptMouseLast);
            }
        }
    }
}

void EditingSelector::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, DesignerScene* scene)
{
    QList<QGraphicsItem *> items = scene->selectedItems();
    if (items.count() == 1)
    {
        GraphicsBaseItem* item = qgraphicsitem_cast<GraphicsBaseItem*>(items.first());
        if(item && ms_ptMouseLast != ms_ptMouseDown)
        {
            item->updateCoordinate();
        }
    }

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