#include "ProcessorWindow.h"

#include <QMessageBox>
#include <QGraphicsPixmapItem>
#include <QLabel>
#include <QCloseEvent>

#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <QPropertyEditorWidget.h>
void ProcessorWindow::contextMenuRequested(QPoint point)
		{
			contextMenu->popup(this->mapToGlobal(point));
			
		}
void ProcessorWindow::contextMenuEvent ( QContextMenuEvent * event )
{

contextMenu->popup(this->mapToGlobal(event->pos()));
			
}
void ProcessorWindow::Properties()
{
	

	dlg->show();
	
	//ui.propertyEditor->addObject(ct->cameraObject);
	//ui.propertyEditor->addObject(ct->cameraObject->cam);
}
ProcessorWindow::ProcessorWindow(ProcessorThread* thread, QWidget *parent, Qt::WindowFlags flags)
	: QWidget(parent, flags)
{
	pt = thread;
	dlg=new QDialog(this);
	prop=new QPropertyEditorWidget(dlg);
	QVBoxLayout *verticalLayout;
	verticalLayout = new QVBoxLayout(dlg);
	verticalLayout->addWidget(prop);
	//prop->addObject(ct->cameraObject);
	//prop->addObject(ct->cameraObject->cam);
		contextMenu=  new QMenu(this);
	actionProperties=contextMenu->addAction("Wlasciwosci");
	actionClose=contextMenu->addAction("Zamknij");
	connect(actionProperties,SIGNAL(triggered()),this,SLOT(Properties()));
	connect(actionClose,SIGNAL(triggered()),this,SLOT(close()));

}

ProcessorWindow::~ProcessorWindow()
{

}

void ProcessorWindow::frameIn(int /*id*/, cv::Mat* /*frame*/) {
};

void ProcessorWindow::closeEvent(QCloseEvent * event)
{
	if(pt->processorObject->isRunning)
	{
		event->ignore();
		return;
	}

	disconnect ( pt->processorObject, SIGNAL( frameOut(int, cv::Mat*) ), this, SLOT( frameIn(int, cv::Mat*) ));
//	disconnect ( pt->processorObject, SIGNAL( sceneOut(int, GLScene*) ), this, SLOT( sceneIn(int, GLScene*) ));
	disconnect ( this, SIGNAL( connectInputs(QList<CameraObject*>, QList<ProcessorObject*>) ), pt->processorObject, SLOT( connectInputs(QList<CameraObject*>, QList<ProcessorObject*>) ));
	disconnect ( this, SIGNAL( signalSpecial(QString) ), pt->processorObject, SLOT( pProcessSpecial(QString) ));

	emit closing(this);
	event->accept();
}
