Commit e9e5cb63 authored by Arseniy Lartsev's avatar Arseniy Lartsev Committed by Albert Astals Cid

Repeat videos in PDFs automatically when needed

REVIEW: 125341
BUGS: 353171
parent 7b8f0a74
......@@ -28,7 +28,8 @@ class Movie::Private
Private( const QString &url )
: m_url( url ),
m_rotation( Rotation0 ),
m_playMode( PlayOnce ),
m_playMode( PlayLimited ),
m_playRepetitions( 1.0 ),
m_tmp( 0 ),
m_showControls( false ),
m_autoPlay( false ),
......@@ -40,6 +41,7 @@ class Movie::Private
QSize m_aspect;
Rotation m_rotation;
PlayMode m_playMode;
double m_playRepetitions;
QTemporaryFile *m_tmp;
QImage m_posterImage;
bool m_showControls : 1;
......@@ -124,6 +126,16 @@ Movie::PlayMode Movie::playMode() const
return d->m_playMode;
}
void Movie::setPlayRepetitions( double repetitions )
{
d->m_playRepetitions = repetitions;
}
double Movie::playRepetitions() const
{
return d->m_playRepetitions;
}
void Movie::setAutoPlay( bool autoPlay )
{
d->m_autoPlay = autoPlay;
......
......@@ -33,8 +33,8 @@ class OKULAR_EXPORT Movie
*/
enum PlayMode
{
PlayOnce, ///< Play the movie once, closing the movie controls at the end
PlayOpen, ///< Like PlayOnce, but leaving the controls open
PlayLimited, ///< Play a fixed amount of times, closing the movie controls at the end @since 0.24
PlayOpen, ///< Like PlayLimited, but leaving the controls open
PlayRepeat, ///< Play continuously until stopped
PlayPalindrome ///< Play forward, then backward, then again forward and so on until stopped
};
......@@ -99,6 +99,18 @@ class OKULAR_EXPORT Movie
*/
PlayMode playMode() const;
/**
* Sets how many times the movie should be played
* @since 0.24
*/
void setPlayRepetitions( double repetitions );
/**
* How many times to play the movie
* @since 0.24
*/
double playRepetitions() const;
/**
* Sets whether to play the movie automatically
*/
......
......@@ -200,7 +200,12 @@ Okular::Movie* createMovieFromPopplerScreen( const Poppler::LinkRendition *poppl
movie = new Okular::Movie( rendition->fileName() );
movie->setSize( rendition->size() );
movie->setShowControls( rendition->showControls() );
movie->setPlayMode( Okular::Movie::PlayOnce );
if ( rendition->repeatCount() == 0 ) {
movie->setPlayMode( Okular::Movie::PlayRepeat );
} else {
movie->setPlayMode( Okular::Movie::PlayLimited );
movie->setPlayRepetitions( rendition->repeatCount() );
}
movie->setAutoPlay( rendition->autoPlay() );
return movie;
}
......
......@@ -96,10 +96,12 @@ public:
QStackedLayout *pageLayout;
QLabel *posterImagePage;
bool loaded : 1;
double repetitionsLeft;
};
void VideoWidget::Private::load()
{
repetitionsLeft = movie->playRepetitions();
if ( loaded )
return;
......@@ -176,14 +178,20 @@ void VideoWidget::Private::finished()
{
switch ( movie->playMode() )
{
case Okular::Movie::PlayOnce:
case Okular::Movie::PlayLimited:
case Okular::Movie::PlayOpen:
// playback has ended, nothing to do
stopAction->setEnabled( false );
setupPlayPauseAction( PlayMode );
if ( movie->playMode() == Okular::Movie::PlayOnce )
controlBar->setVisible( false );
videoStopped();
repetitionsLeft -= 1.0;
if ( repetitionsLeft < 1e-5 ) { // allow for some calculation error
// playback has ended
stopAction->setEnabled( false );
setupPlayPauseAction( PlayMode );
if ( movie->playMode() == Okular::Movie::PlayLimited )
controlBar->setVisible( false );
videoStopped();
} else
// not done yet, repeat
// if repetitionsLeft is less than 1, we are supposed to stop midway, but not even Adobe reader does this
player->play();
break;
case Okular::Movie::PlayRepeat:
// repeat the playback
......@@ -360,6 +368,7 @@ void VideoWidget::play()
{
d->controlBar->setVisible( d->movie->showControls() );
d->load();
// if d->repetitionsLeft is less than 1, we are supposed to stop midway, but not even Adobe reader does this
d->player->play();
d->stopAction->setEnabled( true );
d->setupPlayPauseAction( Private::PauseMode );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment