BachelorThesis::BachelorThesis(QWidget *parent)
	: QMainWindow(parent),
	videoReader( VideoReader::Type::CPU ),
	playbackSpeed( 1 ),
	doBackgroundSubtraction( false ),
	doMeanShiftFiltering( false ),
	blurAmount( 1 ),
	isMouseButtonDown( false ),
	isVideoPaused( true ),
	originalImage( 640, 480, CV_8UC4 )
{

	ui.setupUi(this);

	timer = Timer();	

	pipeline = new ProcessingPipeline( );

	hardwareInfoDialog = new HardwareInfoDialog( this );

	// passes all events for the videoLabel to this class and handles them via a eventfilter
	ui.videoLabel->installEventFilter( this );
	ui.originalVideoLabel->installEventFilter( this );
	origin = QPoint( 0, 0 );
	roiSelector = new QRubberBand(QRubberBand::Rectangle, ui.videoLabel);
	roiSelector->setGeometry(QRect(QPoint( 0, 0 ), QPoint( 720, 576 ) ).normalized());

	connect( ui.actionOpen_File,			SIGNAL( triggered() ),				this,		SLOT( openFile() ) );
	connect( ui.pushButton,					SIGNAL( clicked() ),				this,		SLOT( startVideo() ) );
	// TODO: fix this, it should only call this slot if the slider is moved by hand
	//connect( ui.progressBarSlider,			SIGNAL( valueChanged( int) ),		this,	SLOT( jumpToFrame( int ) ) );
	connect( ui.actionOpen_Sample,			SIGNAL( triggered() ),				this,		SLOT( openSampleFile() ) );

	connect( ui.actionHardware_Info,		SIGNAL( triggered() ),				this,		SLOT( openHardwareInfoDialog() ) );

	connect( ui.actionProcesingPipeline,	SIGNAL( triggered() ),				( QObject* ) pipeline,	SLOT( toggleProcessingPipelineConfigWidgetDisplay() ) );
	connect( ui.actionOpticalFlowSelector,	SIGNAL( triggered() ),				( QObject* ) pipeline,	SLOT( toggleOpticalFlowSelectorDialog() ) );
	connect( ui.actionOpen_Video_Stream,	SIGNAL( triggered() ),				this,		SLOT( openVideoStream() ) );


}
/* /////////////////////////////////////////////////////////////////////////////
 * Signal from open video action
 */
void TTCutMainWindow::onReadVideoStream(QString fName)
{
  if (openVideoStream(fName) <= 0) 
  {
    return;
  }

  initStreamNavigator();

  QFileInfoList audioInfoList = audioFromVideoName(fName);

  if (audioInfoList.count() == 0)
  {
    TTCut::numAudioTracks = 0;
    audioFileInfo->onFileOpen();
    return;
  }

  for (int i = 0; i < audioInfoList.count(); i++)
    onReadAudioStream(audioInfoList.at(i).absoluteFilePath());
}