ClipPreviewWidget.cpp 3.07 KB
Newer Older
Christophe Courtaut's avatar
Christophe Courtaut committed
1
/*****************************************************************************
2
 * ClipPreviewWidget: Preview widget
Christophe Courtaut's avatar
Christophe Courtaut committed
3 4 5
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
6
 * Authors: Geoffroy Lacarrière <geoffroylaca@gmail.com>
Christophe Courtaut's avatar
Christophe Courtaut committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * 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.
 *****************************************************************************/

23 24
#include <QtDebug>

25
#include "ClipPreviewWidget.h"
geoff's avatar
geoff committed
26

27
ClipPreviewWidget::ClipPreviewWidget( QWidget* renderWidget ) :
28
    GenericPreviewWidget( renderWidget ),
29
    m_clipLoaded( false ), m_videoStopped( true )
geoff's avatar
geoff committed
30 31 32
{
}

33
ClipPreviewWidget::~ClipPreviewWidget()
geoff's avatar
geoff committed
34 35
{
}
36

37
void        ClipPreviewWidget::startPreview( Media* media )
38
{
39 40
    media->flushParameters();
    m_mediaPlayer->setMedia( media->getVLCMedia() );
41

42 43 44 45 46
    connect( m_mediaPlayer,     SIGNAL( stopped() ),            this,   SLOT( __videoPaused() ) );
    connect( m_mediaPlayer,     SIGNAL( paused() ),             this,   SLOT( __videoPaused() ) );
    connect( m_mediaPlayer,     SIGNAL( playing() ),            this,   SLOT( __videoPlaying() ) );
    connect( m_mediaPlayer,     SIGNAL( positionChanged() ),    this,   SLOT( __positionChanged() ) );
    connect( m_mediaPlayer,     SIGNAL( endReached() ),         this,   SLOT( __endReached() ) );
47 48

    m_mediaPlayer->play();
49
    m_clipLoaded = true;
50
    m_videoStopped = false;
51 52
}

53
void        ClipPreviewWidget::setPosition( float newPos )
Ludovic Fauvet's avatar
Ludovic Fauvet committed
54
{
55
    if ( m_clipLoaded == false || m_videoStopped == true )
56
        return ;
57
    m_mediaPlayer->setPosition( newPos / 1000.0 );
58 59
}

60
void        ClipPreviewWidget::togglePlayPause()
61
{
62 63
    if ( m_clipLoaded == false)
        return ;
64 65 66
    if ( m_videoStopped == true )
        m_videoStopped = false;

67 68 69 70
    if ( m_mediaPlayer->isPlaying() )
        m_mediaPlayer->pause();
    else
        m_mediaPlayer->play();
71
}
72

73 74 75 76 77 78 79 80 81
/////////////////////////////////////////////////////////////////////
/////SLOTS :
/////////////////////////////////////////////////////////////////////
void        ClipPreviewWidget::__videoPaused()
{
    emit paused();
}

void        ClipPreviewWidget::__videoPlaying()
82
{
83
    emit playing();
84 85
}

86
void        ClipPreviewWidget::__positionChanged()
87
{
88 89 90
    if ( m_clipLoaded == false)
        return ;
    emit positionChanged( m_mediaPlayer->getPosition() );
91
}
92

93
void        ClipPreviewWidget::__endReached()
94 95
{
    m_mediaPlayer->stop();
96
    m_videoStopped = true;
97
    emit endReached();
98
}