#include "SlugsVideoCamControl.h"
#include "ui_SlugsVideoCamControl.h"

#include <QGraphicsScene>
#include <QGraphicsTextItem>
#include <QTextStream>
#include <QScrollBar>
#include <QMouseEvent>
#include <QWheelEvent>
#include <QDebug>


SlugsVideoCamControl::SlugsVideoCamControl(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SlugsVideoCamControl),
    dragging(0)
{
    ui->setupUi(this);

//    QGraphicsScene *scene = new QGraphicsScene(ui->CamControlPanel_graphicsView);
//         scene->setItemIndexMethod(QGraphicsScene::NoIndex);
//         scene->setSceneRect(-200, -200, 400, 400);
//         setScene(scene);
//         setCacheMode(CacheBackground);
//         setViewportUpdateMode(BoundingRectViewportUpdate);
//         setRenderHint(QPainter::Antialiasing);
//         setTransformationAnchor(AnchorUnderMouse);
//         setResizeAnchor(AnchorViewCenter);

//      ui->CamControlPanel_graphicsView->installEventFilter(this);
//      ui->label_x->installEventFilter(this);

}

SlugsVideoCamControl::~SlugsVideoCamControl()
{
    delete ui;
}

void SlugsVideoCamControl::mouseMoveEvent(QMouseEvent *event)
{
  QPoint tL = ui->widget->frameGeometry().topLeft();
  QPoint bR = ui->widget->frameGeometry().bottomRight();

  if (!(event->x() > bR.x() || event->x() < tL.x() ||
      event->y() > bR.y() || event->y() < tL.y() ) && dragging){
    ui->label_x->setText(QString::number(event->x()));
    ui->label_y->setText(QString::number(event->y()));
  }

}


void SlugsVideoCamControl::mousePressEvent(QMouseEvent *evnt)
{
  Q_UNUSED(evnt);

  dragging = true;
}

void SlugsVideoCamControl::mouseReleaseEvent(QMouseEvent *evnt)
{
dragging = false;
}

//void SlugsVideoCamControl::mouseDoubleClickEvent(QMouseEvent *evnt)
//{

//}
