#include "paintscene.h"



PaintScene::PaintScene(QObject *parent) : QGraphicsScene(parent)
{
    setSceneRect(0, 0, 512, 512);
}



PaintScene::~PaintScene()
{
}



void PaintScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
    addEllipse(event->scenePos().x() - 2,
               event->scenePos().y() - 2,
               4,
               4,
               QPen(Qt::NoPen),
               QBrush(Qt::red));

    points.push_back(event->scenePos());
    prevPoint = event->scenePos();
}



void PaintScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
    if ((event->scenePos().x() >= 0) && (event->scenePos().x() <= 512) &&
        (event->scenePos().y() >= 0) && (event->scenePos().y() <= 512))
    {
        addLine(prevPoint.x(),
                prevPoint.y(),
                event->scenePos().x(),
                event->scenePos().y(),
                QPen(Qt::red, 2, Qt::SolidLine, Qt::RoundCap));

        points.push_back(event->scenePos());
        prevPoint = event->scenePos();
    }
}



std::vector<QPointF> PaintScene::getPoints()
{
    return points;
}



void PaintScene::clearScene()
{
    clear();
    points.clear();
}



void PaintScene::addImageItem(QImage image)
{
    addPixmap(QPixmap::fromImage(image));
}
