#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)
{
    s_ptMouseLast = event->scenePos();

    QList<QGraphicsItem *> items = scene->selectedItems();
    for(int n = 0; n < items.size(); n++)
    {
        IShape *item = dynamic_cast<IShape *>(items.at(n));
        if(item)
            item->moveOperationCopy(s_ptMouseLast - s_ptMouseDown);
    }
}

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

    if (s_ptMouseLast != s_ptMouseDown)
        scene->notifyDocumentModified();

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