/*
* Event handler for the any widget using the installEventFilter function
*/
bool VideoViewerWindow
::eventFilter( QObject *obj,
QEvent *event
) {
if( obj == mpVideoPlayer )
{
QMouseEvent *mouseEvent
= static_cast<QMouseEvent
*>
(event
);
// Mouse Button Release handlers
if( event
->type
() == QEvent::MouseButtonPress ) {
AzElPoint point;
int azElSize = azElPoints.size( );
point.frameNumber = getCurrentFrame( );
point.xPos = mouseEvent->x( );
point.yPos = mouseEvent->y( );
if( mouseEvent->button() == Qt::LeftButton )
{
// If left button, place mark on overlay to indicate position
// and store position in array at the current frame index
for( int i = 0 ; i < azElSize ; i++ )
{
if( azElPoints[i].frameNumber == point.frameNumber )
{
azElPoints.removeAt( i );
erasePoint = true;
break;
}
}
azElPoints.push_back( point );
return true;
}
}
if( event
->type
() == QEvent::MouseButtonRelease ) {
if( mouseEvent->button() == Qt::RightButton )
{
// If right button, remove any point located in current frame
AzElPoint point;
point.frameNumber = getCurrentFrame( );
point.xPos = mouseEvent->x( );
point.yPos = mouseEvent->y( );
for( int i = 0 ; i < azElPoints.size( ) ; i++ )
{
if( azElPoints[i].frameNumber == getCurrentFrame( ) &&
( azElPoints[i].xPos >= point.xPos - 2 && azElPoints[i].xPos <= point.xPos + 2 ) &&
( azElPoints[i].yPos >= point.yPos - 2 && azElPoints[i].yPos <= point.yPos + 2 ) )
{
azElPoints.removeAt( i );
break;
}
}
update( );
return true;
}
}
}
if( event
->type
( ) == QEvent::Move ) {
if( pMediaSeeking != NULL )
{
repaintWindow( );
return true;
}
}
if( event
->type
( ) == QEvent::Paint ) {
if( pMediaSeeking != NULL )
{
repaintWindow( );
return true;
}
}
if( event
->type
( ) == QEvent::KeyPress ) {
if( pMediaSeeking!= NULL )
{
int key = pressedKey->key( );
switch( key )
{
case Qt::Key_Space:
pressedKey->accept( );
skipAheadPressed( );
return true;
break;
case Qt::Key_Right:
pressedKey->accept( );
skipAheadPressed( );
return true;
break;
case Qt::Key_Left:
pressedKey->accept( );
skipBackPressed( );
return true;
break;
case Qt::Key_P:
pressedKey->accept( );
pausePressed( );
return true;
break;
case Qt::Key_S:
pressedKey->accept( );
stopPressed( );
return true;
break;
case Qt::Key_Home:
pressedKey->accept( );
jumpToStartPressed( );
return true;
break;
case Qt::Key_End:
pressedKey->accept( );
jumpToEndPressed( );
return true;
break;
default:
pressedKey->ignore( );
}
}
}
return QObject::eventFilter( obj, event
);
}
/*
* Event handler for the any widget using the installEventFilter function
*/
bool VideoViewerWindow::eventFilter( QObject *obj, QEvent *event )
{
if( obj == mpVideoPlayer )
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
// Mouse Button Release handlers
if( event->type() == QEvent::MouseButtonPress )
{
AzElPoint point;
int azElSize = azElPoints.size( );
point.frameNumber = getCurrentFrame( );
point.xPos = mouseEvent->x( );
point.yPos = mouseEvent->y( );
if( mouseEvent->button() == Qt::LeftButton )
{
// If left button, place mark on overlay to indicate position
// and store position in array at the current frame index
for( int i = 0 ; i < azElSize ; i++ )
{
if( azElPoints[i].frameNumber == point.frameNumber )
{
azElPoints.removeAt( i );
erasePoint = true;
break;
}
}
azElPoints.push_back( point );
return true;
}
}
if( event->type() == QEvent::MouseButtonRelease )
{
if( mouseEvent->button() == Qt::RightButton )
{
// If right button, remove any point located in current frame
AzElPoint point;
point.frameNumber = getCurrentFrame( );
point.xPos = mouseEvent->x( );
point.yPos = mouseEvent->y( );
for( int i = 0 ; i < azElPoints.size( ) ; i++ )
{
if( azElPoints[i].frameNumber == getCurrentFrame( ) &&
( azElPoints[i].xPos >= point.xPos - 2 && azElPoints[i].xPos <= point.xPos + 2 ) &&
( azElPoints[i].yPos >= point.yPos - 2 && azElPoints[i].yPos <= point.yPos + 2 ) )
{
azElPoints.removeAt( i );
break;
}
}
update( );
return true;
}
}
}
if( event->type( ) == QEvent::Move )
{
if( pMediaSeeking != NULL )
{
repaintWindow( );
return true;
}
}
if( event->type( ) == QEvent::Paint )
{
if( pMediaSeeking != NULL )
{
repaintWindow( );
return true;
}
}
if( event->type( ) == QEvent::KeyPress )
{
if( pMediaSeeking!= NULL )
{
QKeyEvent *pressedKey = (QKeyEvent*) event;
int key = pressedKey->key( );
switch( key )
{
case Qt::Key_Space:
pressedKey->accept( );
skipAheadPressed( );
return true;
break;
case Qt::Key_Right:
pressedKey->accept( );
skipAheadPressed( );
return true;
break;
case Qt::Key_Left:
pressedKey->accept( );
skipBackPressed( );
return true;
break;
case Qt::Key_P:
pressedKey->accept( );
pausePressed( );
return true;
break;
case Qt::Key_S:
pressedKey->accept( );
stopPressed( );
return true;
break;
case Qt::Key_Home:
pressedKey->accept( );
jumpToStartPressed( );
return true;
break;
case Qt::Key_End:
pressedKey->accept( );
jumpToEndPressed( );
return true;
break;
default:
pressedKey->ignore( );
}
}
}
return QObject::eventFilter( obj, event );
}
To copy to clipboard, switch view to plain text mode
/*
*
* repaintWindow( )
*
* This function repaints the video in its video frame so that the video will be
* upon loading and flipping back and forth between open windows.
*
*/
void VideoViewerWindow::repaintWindow( )
{
long lWidth, lHeight;
HRESULT hr = pWindowlessControl->GetNativeVideoSize( &lWidth, &lHeight, NULL, NULL );
RECT rcSrc, rcDest;
// Set the source rectangle.
SetRect( &rcSrc, 0, 0, lWidth, lHeight );
// Get the window client area.
GetClientRect( (HWND) mpVideoPlayer->winId( ), &rcDest );
// Set the destination rectangle.
SetRect(&rcDest, 1, 1, 558, 349);
// Set the video position.
hr = pWindowlessControl->SetVideoPosition( &rcSrc, &rcDest );
PAINTSTRUCT ps;
HDC hdc;
RECT rcClient;
GetClientRect( (HWND) mpVideoPlayer->winId( ), &rcClient );
hdc = BeginPaint( (HWND) mpVideoPlayer->winId( ), &ps );
if( pWindowlessControl != NULL )
{
// Find the region where the application can paint by subtracting
// the video destination rectangle from the client area.
// (Assume that g_rcDest was calculated previously.)
HRGN rgnClient = CreateRectRgnIndirect( &rcClient );
HRGN rgnVideo = CreateRectRgnIndirect( &rcDest );
CombineRgn( rgnClient, rgnClient, rgnVideo, RGN_DIFF );
// Paint on window.
HBRUSH hbr = GetSysColorBrush( COLOR_BTNFACE );
FillRgn( hdc, rgnClient, hbr );
// Clean up.
DeleteObject( hbr );
DeleteObject( rgnClient );
DeleteObject( rgnVideo );
int azElSize = azElPoints.size( );
int currentFrame = getCurrentFrame( );
// Request the VMR to paint the video and draw the point chosen by the user.
int i;
for( i = 0 ; i < azElSize ; i++ )
{
if( azElPoints[i].frameNumber == currentFrame )
{
mpOverlayLabel->move( azElPoints[i].xPos - 2, azElPoints[i].yPos - 2 );
mpOverlayLabel->show( );
break;
}
}
if( i == azElPoints.size( ) )
{
mpOverlayLabel->hide( );
}
HRESULT hr = pWindowlessControl->RepaintVideo( (HWND) mpVideoPlayer->winId( ), hdc );
}
}
/*
*
* repaintWindow( )
*
* This function repaints the video in its video frame so that the video will be
* upon loading and flipping back and forth between open windows.
*
*/
void VideoViewerWindow::repaintWindow( )
{
long lWidth, lHeight;
HRESULT hr = pWindowlessControl->GetNativeVideoSize( &lWidth, &lHeight, NULL, NULL );
RECT rcSrc, rcDest;
// Set the source rectangle.
SetRect( &rcSrc, 0, 0, lWidth, lHeight );
// Get the window client area.
GetClientRect( (HWND) mpVideoPlayer->winId( ), &rcDest );
// Set the destination rectangle.
SetRect(&rcDest, 1, 1, 558, 349);
// Set the video position.
hr = pWindowlessControl->SetVideoPosition( &rcSrc, &rcDest );
PAINTSTRUCT ps;
HDC hdc;
RECT rcClient;
GetClientRect( (HWND) mpVideoPlayer->winId( ), &rcClient );
hdc = BeginPaint( (HWND) mpVideoPlayer->winId( ), &ps );
if( pWindowlessControl != NULL )
{
// Find the region where the application can paint by subtracting
// the video destination rectangle from the client area.
// (Assume that g_rcDest was calculated previously.)
HRGN rgnClient = CreateRectRgnIndirect( &rcClient );
HRGN rgnVideo = CreateRectRgnIndirect( &rcDest );
CombineRgn( rgnClient, rgnClient, rgnVideo, RGN_DIFF );
// Paint on window.
HBRUSH hbr = GetSysColorBrush( COLOR_BTNFACE );
FillRgn( hdc, rgnClient, hbr );
// Clean up.
DeleteObject( hbr );
DeleteObject( rgnClient );
DeleteObject( rgnVideo );
int azElSize = azElPoints.size( );
int currentFrame = getCurrentFrame( );
// Request the VMR to paint the video and draw the point chosen by the user.
int i;
for( i = 0 ; i < azElSize ; i++ )
{
if( azElPoints[i].frameNumber == currentFrame )
{
mpOverlayLabel->move( azElPoints[i].xPos - 2, azElPoints[i].yPos - 2 );
mpOverlayLabel->show( );
break;
}
}
if( i == azElPoints.size( ) )
{
mpOverlayLabel->hide( );
}
HRESULT hr = pWindowlessControl->RepaintVideo( (HWND) mpVideoPlayer->winId( ), hdc );
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks