Files
calyp/app/VideoHandle.cpp
T
jfmcarreira 0b429a0c34 Refactor Playuver into Calyp
commit 1fd9cf34f06ba2a156919b5c9b73c31d4c6c6257
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Mon Mar 12 18:06:39 2018 +0000

    Remove code style

commit 165588840126a7ab35b32e5be47f00c613829ef3
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Mon Mar 12 18:06:25 2018 +0000

    Update Mainpage.dox

commit 5b1a2773c48697346c7b0b64519b81a5aecc0150
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Mon Feb 19 03:46:24 2018 +0000

    Re-add CalypPixel.cpp but keep include with frame class

commit 2343be49ff4906c3171d2df7791e3cf34494eb21
Author: Joao Santos <joaompssantos@gmail.com>
Date:   Sun Feb 18 21:06:57 2018 +0000

    Fixed several things:
    - Removed unused define
    - Added: #include <cassert> to MainWindow.cpp
    - Fixed compilation issue when USE_FFMPEG is OFF on CalypStream.cpp

commit 8d1d64bac828a6bcdfa6af977a5d17d0792acb69
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Thu Feb 15 02:14:13 2018 +0000

    Fix several things:
    - Fix examples
    - Improve code formatting script
    - Change generated cmake config file

commit ea1d0265f1e9300f76fd3f0c8ca03d110ec13eaa
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Thu Feb 15 01:28:50 2018 +0000

    Fix dump of the module list: remove the use of char arrays

commit b4d19dda169715113a74713ca62d05f5a18fd0b5
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Wed Feb 14 23:20:56 2018 +0000

    Increase linesize of tools help

commit 8b3eab54e376863276b0d7e032f9e1de8aaf90e5
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Wed Feb 14 23:20:35 2018 +0000

    Fix CalypPixel

commit 1c6ba03c379518acf5fc6f1fdf328ca740a8851d
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Wed Feb 14 22:24:10 2018 +0000

    Enums CalypPixelFormats and CalypColorSpace are now class independent

commit 5dcc35e1716a70095e1720b01823c2e3a3980576
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Wed Feb 14 02:04:31 2018 +0000

    Change functions input and return types

commit 5514e3e24f9b428d5db71156561b2d8b6f61dd23
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Wed Feb 14 02:04:31 2018 +0000

    Change functions input and return types

commit fae7a9a91e1899e7a2833c634221f970d44b8fb6
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Wed Feb 14 01:39:14 2018 +0000

    Replace custom types with std ones

commit 0c3b62b8ea01903e213d9e8dd73a5b49c7c8c36e
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Wed Feb 14 00:37:18 2018 +0000

    Refactoring entries with Playuver name with Calyp
    Replace number of frames and add CLP tag into public definitions

commit e8cd8d7a219446513a5dda2c183dd892ec25a6f1
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Sat Feb 10 14:42:15 2018 +0000

    Fix min opencv version and missing ffmpeg module

commit 1233598af8ac15c88fa84569942cc6f865325452
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Sat Feb 10 03:10:12 2018 +0000

    Change version to 0.999.0 untill finishing refactoring

commit 1fe0cac8f0e70f352bf6c63b8cb2e06ab43fb633
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Sat Feb 10 00:21:47 2018 +0000

    Change project library

commit 44e9d330bc63b8b8a1687a14ff0be05af0bf2eb5
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Fri Feb 9 01:42:58 2018 +0000

    Change doxygen files and upload new ico

commit 0d6f3408a2682cfac1533a57a2f1b4e2cc1f0f29
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Thu Feb 8 21:25:31 2018 +0000

    Fix logos - different when it is icon or the full logo

commit 9f3561acd4b51c7de5f21d63d7e8f2b43c253148
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Thu Feb 8 01:25:39 2018 +0000

    fix install files

commit 832154e3e40f17a863898a77c929a6c6850ffded
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Thu Feb 8 01:21:23 2018 +0000

    rename calip to calyp

commit 341b32bfcc0133fdbceea9b8390d59190e495b79
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Thu Feb 8 00:58:29 2018 +0000

    Refactor lib, modules and tools

commit b4b988cf80052fdcfe0e1f9099d5435ef7945584
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Thu Feb 8 00:02:33 2018 +0000

    Refactor classes and filename in app

commit 6b4ab728202531ad00db1e6299ee69a01f3594ba
Author: Joao Carreira <jfmcarreira@gmail.com>
Date:   Wed Feb 7 17:49:53 2018 +0000

    Refactor about dialog and background logo

commit d5c954d39fb89d735c4feddf62f529077840ab6c
Author: João Santos <joaompssantos@gmail.com>
Date:   Wed Feb 7 15:05:19 2018 +0000

    Added the misteriously missing new logo.

commit f40d81f765bfdd2dc89c0647cf5f4a80eef845c7
Author: João Santos <joaompssantos@gmail.com>
Date:   Wed Feb 7 14:45:08 2018 +0000

    Added new logo to resource folder.

commit 52dc6d60d6590995d32de33f8199e954e0a6e120
Author: João Santos <joaompssantos@gmail.com>
Date:   Wed Feb 7 14:41:13 2018 +0000

    Added new logo where it was previously forgotten.

commit 6d8e064c3154e5202f01b1b10ba6ab3637383ecd
Author: João Santos <joaompssantos@gmail.com>
Date:   Tue Feb 6 17:44:11 2018 +0000

    About window no longer resizable. Added new logo.
2018-03-12 18:21:07 +00:00

828 lines
28 KiB
C++

/* This file is a part of Calyp project
* Copyright (C) 2014-2018 by Joao Carreira (jfmcarreira@gmail.com)
* Luis Lucas (luisfrlucas@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**
* \file VideoHandle.h
* \brief Class to handle video playback
*/
#include "VideoHandle.h"
#include "FrameNumberWidget.h"
#include "FramePropertiesDock.h"
#include "MainWindow.h"
#include "SeekStreamDialog.h"
#include "SubWindowHandle.h"
#include "SubWindowSelectorDialog.h"
#include "VideoSubWindow.h"
#include <QDockWidget>
#include <QElapsedTimer>
#include <QLabel>
#include <QSignalMapper>
#include <QSlider>
#include <QToolBar>
#include <QtGui>
#if( _CONTROL_PLAYING_TIME_ == 1 )
#include <QElapsedTimer>
#endif
VideoHandle::VideoHandle( QWidget* parent, SubWindowHandle* windowManager )
: m_pcParet( parent ), m_pcMainWindowManager( windowManager )
{
m_pcCurrentVideoSubWindow = NULL;
m_bIsPlaying = false;
m_pcPlayingTimer = new QTimer;
m_pcPlayingTimer->setTimerType( Qt::PreciseTimer );
connect( m_pcPlayingTimer, SIGNAL( timeout() ), this, SLOT( playEvent() ) );
m_acPlayingSubWindows.clear();
}
VideoHandle::~VideoHandle() {}
void VideoHandle::createActions()
{
m_arrayActions.resize( TOTAL_ACT );
m_arrayActions[PLAY_ACT] = new QAction( "Play", this );
m_arrayActions[PLAY_ACT]->setStatusTip( "Play/Pause" );
m_arrayActions[PLAY_ACT]->setIcon( QIcon( m_pcParet->style()->standardIcon( QStyle::SP_MediaPlay ) ) );
m_arrayActions[PLAY_ACT]->setShortcut( Qt::Key_Space );
connect( m_arrayActions[PLAY_ACT], SIGNAL( triggered() ), this, SLOT( play() ) );
m_arrayActions[STOP_ACT] = new QAction( "Stop", this );
m_arrayActions[STOP_ACT]->setStatusTip( "Stop" );
m_arrayActions[STOP_ACT]->setIcon( QIcon( m_pcParet->style()->standardIcon( QStyle::SP_MediaStop ) ) );
connect( m_arrayActions[STOP_ACT], SIGNAL( triggered() ), this, SLOT( stop() ) );
m_mapperVideoSeek = new QSignalMapper( this );
connect( m_mapperVideoSeek, SIGNAL( mapped( int ) ), this, SLOT( seekEvent( int ) ) );
m_arrayActions[VIDEO_BACKWARD_ACT] = new QAction( "Video Backward", this );
m_arrayActions[VIDEO_BACKWARD_ACT]->setStatusTip( "Seek backward" );
m_arrayActions[VIDEO_BACKWARD_ACT]->setIcon(
QIcon( m_pcParet->style()->standardIcon( QStyle::SP_MediaSeekBackward ) ) );
m_arrayActions[VIDEO_BACKWARD_ACT]->setShortcut( Qt::Key_Left );
connect( m_arrayActions[VIDEO_BACKWARD_ACT], SIGNAL( triggered() ), m_mapperVideoSeek, SLOT( map() ) );
m_mapperVideoSeek->setMapping( m_arrayActions[VIDEO_BACKWARD_ACT], 0 );
m_arrayActions[VIDEO_FORWARD_ACT] = new QAction( "Video Forward", this );
m_arrayActions[VIDEO_FORWARD_ACT]->setStatusTip( "Seek forward" );
m_arrayActions[VIDEO_FORWARD_ACT]->setIcon(
QIcon( m_pcParet->style()->standardIcon( QStyle::SP_MediaSeekForward ) ) );
m_arrayActions[VIDEO_FORWARD_ACT]->setShortcut( Qt::Key_Right );
connect( m_arrayActions[VIDEO_FORWARD_ACT], SIGNAL( triggered() ), m_mapperVideoSeek, SLOT( map() ) );
m_mapperVideoSeek->setMapping( m_arrayActions[VIDEO_FORWARD_ACT], 1 );
m_arrayActions[VIDEO_GOTO_ACT] = new QAction( "Go to", this );
m_arrayActions[VIDEO_GOTO_ACT]->setStatusTip( "Seek to a specific frame number" );
m_arrayActions[VIDEO_GOTO_ACT]->setShortcut( tr( "Ctrl+G" ) );
connect( m_arrayActions[VIDEO_GOTO_ACT], SIGNAL( triggered() ), this, SLOT( seekVideo() ) );
m_arrayActions[VIDEO_REPEAT_ACT] = new QAction( "Repeat", this );
m_arrayActions[VIDEO_REPEAT_ACT]->setStatusTip( "Enable loop through the sequence" );
m_arrayActions[VIDEO_REPEAT_ACT]->setShortcut( tr( "Ctrl+R" ) );
m_arrayActions[VIDEO_REPEAT_ACT]->setCheckable( true );
m_arrayActions[VIDEO_REPEAT_ACT]->setChecked( false );
m_arrayActions[VIDEO_ZOOM_LOCK_ACT] = new QAction( "Zoom Lock", this );
m_arrayActions[VIDEO_ZOOM_LOCK_ACT]->setStatusTip( "Sync zoom between all video windows" );
m_arrayActions[VIDEO_ZOOM_LOCK_ACT]->setShortcut( tr( "Ctrl+L" ) );
m_arrayActions[VIDEO_ZOOM_LOCK_ACT]->setCheckable( true );
m_arrayActions[VIDEO_ZOOM_LOCK_ACT]->setChecked( false );
m_arrayActions[VIDEO_LOCK_SELECTION_ACT] = new QAction( "Sync Play", this );
m_arrayActions[VIDEO_LOCK_SELECTION_ACT]->setStatusTip(
"Select which windows should be played synchronized. Press Ctrl while "
"click to quickly to select all!" );
connect( m_arrayActions[VIDEO_LOCK_SELECTION_ACT], SIGNAL( triggered() ), this, SLOT( videoSelectionButtonEvent() ) );
m_pcFrameSlider = new QSlider;
m_pcFrameSlider->setOrientation( Qt::Horizontal );
m_pcFrameSlider->setMaximumWidth( 2000 );
m_pcFrameSlider->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ) );
m_pcFrameSlider->setEnabled( false );
m_pcFrameSlider->setTracking( false );
connect( m_pcFrameSlider, SIGNAL( valueChanged( int ) ), this, SLOT( seekSliderEvent( int ) ) );
// ------------ Tools ------------
actionGroupTools = new QActionGroup( this );
actionGroupTools->setExclusive( true );
m_mapperTools = new QSignalMapper( this );
connect( m_mapperTools, SIGNAL( mapped( int ) ), this, SLOT( setTool( int ) ) );
m_uiViewTool = ViewArea::NavigationView;
m_arrayActions[NAVIGATION_TOOL_ACT] = new QAction( tr( "Navigation Tool" ), this );
m_arrayActions[NAVIGATION_TOOL_ACT]->setCheckable( true );
m_arrayActions[NAVIGATION_TOOL_ACT]->setChecked( true );
m_arrayActions[NAVIGATION_TOOL_ACT]->setShortcut( Qt::CTRL + Qt::Key_1 );
actionGroupTools->addAction( m_arrayActions[NAVIGATION_TOOL_ACT] );
connect( m_arrayActions[NAVIGATION_TOOL_ACT], SIGNAL( triggered() ), m_mapperTools, SLOT( map() ) );
m_mapperTools->setMapping( m_arrayActions[NAVIGATION_TOOL_ACT], ViewArea::NavigationView );
m_arrayActions[SELECTION_TOOL_ACT] = new QAction( "Selection Tool", this );
m_arrayActions[SELECTION_TOOL_ACT]->setCheckable( true );
m_arrayActions[SELECTION_TOOL_ACT]->setChecked( false );
m_arrayActions[SELECTION_TOOL_ACT]->setShortcut( Qt::CTRL + Qt::Key_2 );
actionGroupTools->addAction( m_arrayActions[SELECTION_TOOL_ACT] );
connect( m_arrayActions[SELECTION_TOOL_ACT], SIGNAL( triggered() ), m_mapperTools, SLOT( map() ) );
m_mapperTools->setMapping( m_arrayActions[SELECTION_TOOL_ACT], ViewArea::NormalSelectionView );
m_arrayActions[BLOCK_SELECTION_TOOL_ACT] = new QAction( "Block Selection Tool", this );
m_arrayActions[BLOCK_SELECTION_TOOL_ACT]->setCheckable( true );
m_arrayActions[BLOCK_SELECTION_TOOL_ACT]->setChecked( false );
m_arrayActions[BLOCK_SELECTION_TOOL_ACT]->setShortcut( Qt::CTRL + Qt::Key_3 );
actionGroupTools->addAction( m_arrayActions[BLOCK_SELECTION_TOOL_ACT] );
connect( m_arrayActions[BLOCK_SELECTION_TOOL_ACT], SIGNAL( triggered() ), m_mapperTools, SLOT( map() ) );
m_mapperTools->setMapping( m_arrayActions[BLOCK_SELECTION_TOOL_ACT], ViewArea::BlockSelectionView );
m_arrayActions[SHOW_GRID_ACT] = new QAction( "Show grid", this );
m_arrayActions[SHOW_GRID_ACT]->setCheckable( true );
m_arrayActions[SHOW_GRID_ACT]->setChecked( false );
connect( m_arrayActions[SHOW_GRID_ACT], SIGNAL( toggled( bool ) ), this, SLOT( toggleGrid( bool ) ) );
}
QMenu* VideoHandle::createVideoMenu()
{
m_pcMenuVideo = new QMenu( "Video", m_pcParet );
m_pcMenuVideo->addAction( m_arrayActions[PLAY_ACT] );
m_pcMenuVideo->addAction( m_arrayActions[STOP_ACT] );
m_pcMenuVideo->addAction( m_arrayActions[VIDEO_BACKWARD_ACT] );
m_pcMenuVideo->addAction( m_arrayActions[VIDEO_FORWARD_ACT] );
m_pcMenuVideo->addAction( m_arrayActions[VIDEO_GOTO_ACT] );
m_pcMenuVideo->addSeparator();
m_pcMenuVideo->addAction( m_arrayActions[VIDEO_REPEAT_ACT] );
m_pcMenuVideo->addAction( m_arrayActions[VIDEO_ZOOM_LOCK_ACT] );
m_pcMenuVideo->addAction( m_arrayActions[VIDEO_LOCK_SELECTION_ACT] );
return m_pcMenuVideo;
}
QMenu* VideoHandle::createImageMenu()
{
m_pcMenuImage = new QMenu( "Image", m_pcParet );
m_pcMenuImage->addAction( m_arrayActions[NAVIGATION_TOOL_ACT] );
m_pcMenuImage->addAction( m_arrayActions[SELECTION_TOOL_ACT] );
m_pcMenuImage->addAction( m_arrayActions[BLOCK_SELECTION_TOOL_ACT] );
m_pcMenuImage->addSeparator();
m_pcMenuImage->addAction( m_arrayActions[SHOW_GRID_ACT] );
return m_pcMenuImage;
}
QToolBar* VideoHandle::createToolBar()
{
m_toolbarVideo = new QToolBar( tr( "Video" ) );
m_toolbarVideo->setAllowedAreas( Qt::TopToolBarArea | Qt::BottomToolBarArea );
m_toolbarVideo->addAction( m_arrayActions[PLAY_ACT] );
m_toolbarVideo->addAction( m_arrayActions[STOP_ACT] );
QLabel* pcLockLabel = new QLabel( "PlayingLock" );
pcLockLabel->setAlignment( Qt::AlignCenter );
m_arrayActions[VIDEO_LOCK_ACT] = m_toolbarVideo->addWidget( pcLockLabel );
m_arrayActions[VIDEO_LOCK_ACT]->setVisible( false );
m_toolbarVideo->addAction( m_arrayActions[VIDEO_BACKWARD_ACT] );
m_toolbarVideo->addWidget( m_pcFrameSlider );
m_toolbarVideo->addAction( m_arrayActions[VIDEO_FORWARD_ACT] );
m_toolbarVideo->addWidget( new QLabel );
m_pcFrameNumInfo = new FrameNumberWidget;
m_toolbarVideo->addWidget( m_pcFrameNumInfo );
return m_toolbarVideo;
}
QDockWidget* VideoHandle::createDock()
{
m_pcFramePropertiesSideBar = new FramePropertiesDock( m_pcParet, &m_bIsPlaying );
m_pcFramePropertiesDock = new QDockWidget( tr( "Frame Information" ), m_pcParet );
m_pcFramePropertiesDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
m_pcFramePropertiesDock->setWidget( m_pcFramePropertiesSideBar );
connect( m_pcFramePropertiesDock, SIGNAL( visibilityChanged( bool ) ), this, SLOT( update() ) );
return m_pcFramePropertiesDock;
}
QWidget* VideoHandle::createStatusBarMessage()
{
QWidget* pcStatusBarWidget = new QWidget;
QHBoxLayout* mainlayout = new QHBoxLayout;
m_pcVideoFormatLabel = new QLabel;
m_pcVideoFormatLabel->setText( " " );
m_pcVideoFormatLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
m_pcVideoFormatLabel->setMinimumWidth( 150 );
m_pcVideoFormatLabel->setAlignment( Qt::AlignCenter );
m_pcResolutionLabel = new QLabel;
m_pcResolutionLabel->setText( " " );
m_pcResolutionLabel->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
m_pcResolutionLabel->setMinimumWidth( 90 );
m_pcResolutionLabel->setAlignment( Qt::AlignCenter );
mainlayout->addWidget( m_pcVideoFormatLabel );
mainlayout->addWidget( m_pcResolutionLabel );
pcStatusBarWidget->setLayout( mainlayout );
return pcStatusBarWidget;
}
void VideoHandle::updateMenus()
{
VideoSubWindow* pcSubWindow = qobject_cast<VideoSubWindow*>( m_pcMainWindowManager->activeSubWindow() );
bool hasSubWindow = pcSubWindow ? true : false;
m_arrayActions[PLAY_ACT]->setEnabled( hasSubWindow );
// m_arrayActions[PAUSE_ACT]->setEnabled( hasSubWindow );
m_arrayActions[STOP_ACT]->setEnabled( hasSubWindow );
m_arrayActions[VIDEO_BACKWARD_ACT]->setEnabled( hasSubWindow );
m_arrayActions[VIDEO_FORWARD_ACT]->setEnabled( hasSubWindow );
m_arrayActions[VIDEO_GOTO_ACT]->setEnabled( hasSubWindow );
m_arrayActions[VIDEO_LOCK_SELECTION_ACT]->setEnabled( hasSubWindow );
m_pcFrameSlider->setEnabled( hasSubWindow );
if( !hasSubWindow )
{
disconnect( m_pcFrameSlider, SIGNAL( valueChanged( int ) ), this, SLOT( seekSliderEvent( int ) ) );
m_pcFrameSlider->setValue( 0 );
m_pcFrameNumInfo->clear();
}
else
{
connect( m_pcFrameSlider, SIGNAL( valueChanged( int ) ), this, SLOT( seekSliderEvent( int ) ) );
}
m_arrayActions[NAVIGATION_TOOL_ACT]->setEnabled( hasSubWindow );
m_arrayActions[SELECTION_TOOL_ACT]->setEnabled( hasSubWindow );
m_arrayActions[BLOCK_SELECTION_TOOL_ACT]->setEnabled( hasSubWindow );
m_arrayActions[SHOW_GRID_ACT]->setEnabled( hasSubWindow );
}
void VideoHandle::readSettings()
{
QSettings appSettings;
m_arrayActions[VIDEO_REPEAT_ACT]->setChecked( appSettings.value( "VideoHandle/Repeat", false ).toBool() );
m_arrayActions[VIDEO_ZOOM_LOCK_ACT]->setChecked( appSettings.value( "VideoHandle/VideoZoomLock", false ).toBool() );
if( !appSettings.value( "VideoHandle/FrameProperties", true ).toBool() )
m_pcFramePropertiesDock->close();
m_uiViewTool = appSettings.value( "VideoHandle/SelectedTool", ViewArea::NavigationView ).toUInt();
setTool( m_uiViewTool );
}
void VideoHandle::writeSettings()
{
QSettings appSettings;
appSettings.setValue( "VideoHandle/Repeat", m_arrayActions[VIDEO_REPEAT_ACT]->isChecked() );
appSettings.setValue( "VideoHandle/VideoZoomLock", m_arrayActions[VIDEO_ZOOM_LOCK_ACT]->isChecked() );
appSettings.setValue( "VideoHandle/FrameProperties", m_pcFramePropertiesSideBar->isVisible() );
appSettings.setValue( "VideoHandle/SelectedTool", m_uiViewTool );
}
void VideoHandle::update()
{
if( m_pcCurrentVideoSubWindow )
{
CalypStream* pcStream = m_pcCurrentVideoSubWindow->getInputStream();
CalypFrame* pcFrame = m_pcCurrentVideoSubWindow->getCurrFrame();
int frame_num = 0;
unsigned long long int total_frame_num = 1;
m_pcVideoFormatLabel->setText( m_pcCurrentVideoSubWindow->getStreamInformation() );
QString resolution;
if( pcFrame )
{
resolution.append( QString( "%1x%2" ).arg( pcFrame->getWidth() ).arg( pcFrame->getHeight() ) );
}
if( pcStream )
{
frame_num = pcStream->getCurrFrameNum();
m_pcFrameNumInfo->setCurrFrameNum( frame_num );
total_frame_num = getMaxFrameNumber();
resolution.append( QString( "@%1" ).arg( pcStream->getFrameRate() ) );
}
if( pcFrame )
{
resolution.append( QString( " %1 bpp" ).arg( pcFrame->getBitsPel() ) );
}
if( pcStream && pcFrame->getBitsPel() > 8 )
{
if( pcStream->getEndianess() == CLP_BIG_ENDIAN )
{
resolution.append( QStringLiteral( " (BE)" ) );
}
else
{
resolution.append( QStringLiteral( " (LE)" ) );
}
}
m_pcResolutionLabel->setText( resolution );
m_pcFramePropertiesSideBar->setFrame( pcFrame );
m_pcFrameNumInfo->setTotalFrameNum( total_frame_num );
m_pcFrameNumInfo->setCurrFrameNum( frame_num );
m_pcFrameSlider->blockSignals( true ); // Disable signals otherwise it will loop this function
m_pcFrameSlider->setMaximum( total_frame_num - 1 );
m_pcFrameSlider->setValue( frame_num );
m_pcFrameSlider->blockSignals( false );
if( m_pcCurrentVideoSubWindow->isPlaying() )
{
m_arrayActions[PLAY_ACT]->setText( "Pause" );
m_arrayActions[PLAY_ACT]->setIcon( m_pcParet->style()->standardIcon( QStyle::SP_MediaPause ) );
}
else
{
m_arrayActions[PLAY_ACT]->setText( "Play" );
m_arrayActions[PLAY_ACT]->setIcon( m_pcParet->style()->standardIcon( QStyle::SP_MediaPlay ) );
}
}
else
{
m_pcVideoFormatLabel->setText( "" );
m_pcResolutionLabel->setText( "" );
m_pcFramePropertiesSideBar->reset();
m_pcFrameSlider->setValue( 0 );
m_pcFrameNumInfo->clear();
}
}
void VideoHandle::update( VideoSubWindow* currSubWindow )
{
m_pcCurrentVideoSubWindow = currSubWindow;
update();
}
void VideoHandle::updateSelectionArea( QRect area )
{
if( m_pcCurrentVideoSubWindow )
{
m_pcFramePropertiesSideBar->setSelection( area );
}
}
void VideoHandle::addSubWindow( VideoSubWindow* window )
{
window->zoomToFit();
window->getViewArea()->setTool( m_uiViewTool );
window->getViewArea()->setGridVisible( m_arrayActions[SHOW_GRID_ACT]->isChecked() );
connect( window, &SubWindowAbstract::aboutToClose,
this, &VideoHandle::closeSubWindow );
connect( window, &SubWindowAbstract::zoomFactorChanged,
this, &VideoHandle::zoomToFactorAll );
connect( window, &SubWindowAbstract::scrollBarMoved,
this, &VideoHandle::moveAllScrollBars );
connect( window->getViewArea(), SIGNAL( selectionChanged( QRect ) ), this, SLOT( updateSelectionArea( QRect ) ) );
}
void VideoHandle::closeSubWindow( SubWindowAbstract* subWindow )
{
VideoSubWindow* videoSubWindow = qobject_cast<VideoSubWindow*>( subWindow );
if( m_acPlayingSubWindows.contains( videoSubWindow ) )
{
int pos = m_acPlayingSubWindows.indexOf( videoSubWindow );
m_acPlayingSubWindows.at( pos )->stop();
m_acPlayingSubWindows.remove( pos );
if( m_acPlayingSubWindows.size() < 2 )
{
m_arrayActions[VIDEO_LOCK_ACT]->setVisible( false );
}
}
}
void VideoHandle::zoomToFactorAll( const double scale, const QPoint center )
{
double factor;
if( m_arrayActions[VIDEO_ZOOM_LOCK_ACT]->isChecked() )
{
factor = m_pcCurrentVideoSubWindow->getScaleFactor();
SubWindowAbstract* subWindow;
QList<SubWindowAbstract*> subWindowList =
m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW );
for( int i = 0; i < subWindowList.size(); i++ )
{
subWindow = subWindowList.at( i );
if( m_pcCurrentVideoSubWindow == subWindow )
continue;
else
{
subWindow->zoomToFactor( factor, center );
}
}
}
}
#if 0
void VideoHandle::moveAllScrollBars( const QPoint& offset )
{
QPoint newOffset = offset;
if( m_arrayActions[VIDEO_ZOOM_LOCK_ACT]->isChecked() && m_pcCurrentVideoSubWindow )
{
VideoSubWindow* videoSubWindow;
QList<SubWindowAbstract*> subWindowList =
m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW );
QScrollBar* scrollBar;
scrollBar = m_pcCurrentVideoSubWindow->getScroll()->horizontalScrollBar();
// Do not move other images, if current image reached maximum or minimum
// scroll position
if( scrollBar->value() == scrollBar->maximum() && offset.x() > 0 )
newOffset.setX( 0 );
if( scrollBar->value() == scrollBar->minimum() && offset.x() < 0 )
newOffset.setX( 0 );
scrollBar = m_pcCurrentVideoSubWindow->getScroll()->verticalScrollBar();
if( scrollBar->value() == scrollBar->maximum() && offset.y() > 0 )
newOffset.setY( 0 );
if( scrollBar->value() == scrollBar->minimum() && offset.y() < 0 )
newOffset.setY( 0 );
for( int i = 0; i < subWindowList.size(); i++ )
{
videoSubWindow = qobject_cast<VideoSubWindow*>( subWindowList.at( i ) );
if( m_pcCurrentVideoSubWindow == videoSubWindow )
continue;
else
{
videoSubWindow->adjustScrollBarByOffset( newOffset );
}
}
}
}
#else
void VideoHandle::moveAllScrollBars( const double& horRatio, const double& verRatio )
{
if( m_arrayActions[VIDEO_ZOOM_LOCK_ACT]->isChecked() && m_pcCurrentVideoSubWindow )
{
VideoSubWindow* videoSubWindow;
QList<SubWindowAbstract*> subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW );
for( int i = 0; i < subWindowList.size(); i++ )
{
videoSubWindow = qobject_cast<VideoSubWindow*>( subWindowList.at( i ) );
if( m_pcCurrentVideoSubWindow == videoSubWindow )
continue;
else
{
videoSubWindow->adjustScrollBarToRatio( horRatio, verRatio );
}
}
}
}
#endif
unsigned long long int VideoHandle::getMaxFrameNumber()
{
unsigned int currFrames;
unsigned long long int maxFrames = INT_MAX;
if( m_pcCurrentVideoSubWindow )
{
if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) )
{
for( int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{
currFrames = m_acPlayingSubWindows.at( i )->getInputStream()->getFrameNum();
if( currFrames < maxFrames )
maxFrames = currFrames;
}
}
else
{
maxFrames = m_pcCurrentVideoSubWindow->getInputStream()->getFrameNum();
}
}
return maxFrames;
}
void VideoHandle::setTimerStatus()
{
bool status = false;
for( int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{
status |= m_acPlayingSubWindows.at( i )->isPlaying();
}
if( m_pcCurrentVideoSubWindow )
{
status |= m_pcCurrentVideoSubWindow->isPlaying();
}
if( status )
{
if( !m_bIsPlaying )
{
m_pcPlayingTimer->start();
m_bIsPlaying = true;
#if( _CONTROL_PLAYING_TIME_ == 1 )
m_uiNumberPlayedFrames = 0;
m_pcPlayControlTimer = new QElapsedTimer;
m_pcPlayControlTimer->start();
m_dAverageFps = 0;
#endif
}
}
else
{
#if( _CONTROL_PLAYING_TIME_ == 1 )
if( m_pcPlayControlTimer && m_pcPlayingTimer->interval() > 0 )
{
qDebug() << "Desired Fps: " << 1000 / m_pcPlayingTimer->interval() << "Real Fps: " << 1000 / m_dAverageFps;
delete m_pcPlayControlTimer;
m_pcPlayControlTimer = NULL;
}
#endif
m_pcPlayingTimer->stop();
m_bIsPlaying = false;
}
}
void VideoHandle::play()
{
if( !m_pcCurrentVideoSubWindow )
return;
if( !m_pcCurrentVideoSubWindow->getInputStream() )
return;
if( !m_pcCurrentVideoSubWindow->isPlaying() ) // Not playing
{
double frameRate;
unsigned int timeinterval;
if( m_acPlayingSubWindows.size() < 2 )
{
for( int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{
m_acPlayingSubWindows.at( i )->pause();
}
m_acPlayingSubWindows.clear();
m_acPlayingSubWindows.append( m_pcCurrentVideoSubWindow );
}
if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) )
{
for( int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{
m_acPlayingSubWindows.at( i )->play();
}
frameRate = m_acPlayingSubWindows.at( 0 )->getInputStream()->getFrameRate();
timeinterval = (unsigned int)( 1000.0 / frameRate + 0.5 );
m_pcPlayingTimer->setInterval( timeinterval );
}
}
else
{
if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) )
{
for( int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{
m_acPlayingSubWindows.at( i )->pause();
}
}
else
{
m_pcCurrentVideoSubWindow->pause();
}
}
setTimerStatus();
emit changed();
// update();
}
void VideoHandle::stop()
{
if( m_acPlayingSubWindows.size() > 0 )
{
for( int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{
m_acPlayingSubWindows.at( i )->stop();
}
m_acPlayingSubWindows.clear();
setTimerStatus();
}
else
{
if( m_pcCurrentVideoSubWindow )
{
m_pcCurrentVideoSubWindow->stop();
}
}
emit changed();
m_arrayActions[VIDEO_LOCK_ACT]->setVisible( false );
}
void VideoHandle::playEvent()
{
bool bEndOfSequence = false;
#if( _CONTROL_PLAYING_TIME_ == 1 )
m_dAverageFps = Double( m_dAverageFps * m_uiNumberPlayedFrames + m_pcPlayControlTimer->elapsed() ) /
Double( m_uiNumberPlayedFrames + 1 );
m_uiNumberPlayedFrames++;
m_pcPlayControlTimer->restart();
#endif
try
{
for( int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{
bEndOfSequence |= m_acPlayingSubWindows.at( i )->playEvent();
}
if( bEndOfSequence )
{
if( !m_arrayActions[VIDEO_REPEAT_ACT]->isChecked() )
stop();
else
for( int i = 0; i < m_acPlayingSubWindows.size(); i++ )
m_acPlayingSubWindows.at( i )->seekAbsoluteEvent( 0 );
}
}
catch( const char* msg )
{
QString warningMsg = "Error while playing " +
QFileInfo( m_pcCurrentVideoSubWindow->getCurrentFileName() ).fileName() +
" with the following error: \n" + msg;
QMessageBox::warning( m_pcParet, QApplication::applicationName(), warningMsg );
qDebug() << warningMsg;
stop();
m_pcCurrentVideoSubWindow->close();
}
emit changed();
}
void VideoHandle::seekEvent( int direction )
{
if( m_pcCurrentVideoSubWindow )
{
if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) )
{
if( !( (unsigned int)( m_pcCurrentVideoSubWindow->getInputStream()->getCurrFrameNum() + 1 ) >= getMaxFrameNumber() &&
direction > 0 ) )
{
for( int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{
m_acPlayingSubWindows.at( i )->seekRelativeEvent( direction > 0 ? true : false );
}
}
}
else
{
m_pcCurrentVideoSubWindow->seekRelativeEvent( direction > 0 ? true : false );
}
emit changed();
// update();
}
}
void VideoHandle::seekVideo()
{
if( m_pcCurrentVideoSubWindow )
{
if( m_pcCurrentVideoSubWindow->getInputStream() )
{
SeekStreamDialog* dialogSeekVideo =
new SeekStreamDialog( m_pcCurrentVideoSubWindow->getInputStream(), m_pcParet );
int newFrameNum = dialogSeekVideo->runDialog();
if( newFrameNum >= 0 )
{
if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) )
{
for( int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{
m_acPlayingSubWindows.at( i )->seekAbsoluteEvent( (unsigned int)newFrameNum );
}
}
else
{
m_pcCurrentVideoSubWindow->seekAbsoluteEvent( (unsigned int)newFrameNum );
}
emit changed();
}
}
}
}
void VideoHandle::seekSliderEvent( int new_frame_num )
{
if( m_pcCurrentVideoSubWindow && !m_bIsPlaying ) // TODO: Fix this slot
{
if( m_acPlayingSubWindows.contains( m_pcCurrentVideoSubWindow ) )
{
for( int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{
m_acPlayingSubWindows.at( i )->seekAbsoluteEvent( (unsigned int)new_frame_num );
}
}
else
{
m_pcCurrentVideoSubWindow->seekAbsoluteEvent( (unsigned int)new_frame_num );
}
emit changed();
}
}
void VideoHandle::videoSelectionButtonEvent()
{
VideoSubWindow* videoSubWindow;
Qt::KeyboardModifiers keyModifiers = QApplication::keyboardModifiers();
if( keyModifiers & Qt::ControlModifier )
{
QList<SubWindowAbstract*> subWindowList =
m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_STREAM_SUBWINDOW );
for( int i = 0; i < subWindowList.size(); i++ )
{
videoSubWindow = qobject_cast<VideoSubWindow*>( subWindowList.at( i ) );
m_acPlayingSubWindows.append( videoSubWindow );
}
}
else
{
SubWindowSelectorDialog dialogWindowsSelection( m_pcParet, m_pcMainWindowManager,
SubWindowAbstract::VIDEO_STREAM_SUBWINDOW );
QStringList cWindowListNames;
for( int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{
dialogWindowsSelection.selectSubWindow( m_acPlayingSubWindows.at( i ) );
}
if( dialogWindowsSelection.exec() == QDialog::Accepted )
{
m_acPlayingSubWindows.clear();
QList<SubWindowAbstract*> selectedSubWindowList = dialogWindowsSelection.getSelectedWindows();
for( int i = 0; i < selectedSubWindowList.size(); i++ )
{
videoSubWindow = qobject_cast<VideoSubWindow*>( selectedSubWindowList.at( i ) );
m_acPlayingSubWindows.append( videoSubWindow );
}
}
else
{
return;
}
}
if( m_acPlayingSubWindows.size() > 0 )
{
m_acPlayingSubWindows.at( 0 )->activateWindow();
if( m_acPlayingSubWindows.size() > 1 )
{
m_arrayActions[VIDEO_LOCK_ACT]->setVisible( true );
}
if( m_bIsPlaying )
{
for( int i = 0; i < m_acPlayingSubWindows.size(); i++ )
{
m_acPlayingSubWindows.at( i )->play();
}
}
}
else
{
stop();
}
}
void VideoHandle::setTool( int tool )
{
m_uiViewTool = tool;
actionGroupTools->actions().at( m_uiViewTool )->setChecked( true );
QList<SubWindowAbstract*> subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW );
for( int i = 0; i < subWindowList.size(); i++ )
{
qobject_cast<VideoSubWindow*>( subWindowList.at( i ) )->getViewArea()->setTool( m_uiViewTool );
}
}
void VideoHandle::toggleGrid( bool checked )
{
QList<SubWindowAbstract*> subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW );
for( int i = 0; i < subWindowList.size(); i++ )
{
qobject_cast<VideoSubWindow*>( subWindowList.at( i ) )->getViewArea()->setGridVisible( checked );
}
}