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

MovingSelector::MovingSelector(QObject *parent)
    : BaseSelector(parent)
{
    m_type = ST_moving;
}
MovingSelector::~MovingSelector()
{

}

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

}

void MovingSelector::mouseMoveEvent(QGraphicsSceneMouseEvent* event, DesignerScene* scene)
{
    ms_ptMouseLast = event->scenePos();

    QList<QGraphicsItem *> items = scene->selectedItems();
    for(int n = 0; n < items.size(); n++)
    {
        AbstractShape* item = qgraphicsitem_cast<AbstractShape*>(items.at(n));
        if(item)
            item->moveOperationCopy(ms_ptMouseLast - ms_ptMouseDown);
    }
}

void MovingSelector::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, DesignerScene* scene)
{
    QList<QGraphicsItem *> items = scene->selectedItems();
    for(int n = 0; n < items.size(); n++)
    {
        AbstractShape* item = qgraphicsitem_cast<AbstractShape*>(items.at(n));
        if(item)
            item->removeOperationCopy();
    }

    setCursor(scene, Qt::ArrowCursor);
    scene->callParentEvent(event);
    emit setWorkingSelector(ST_base);
}
