Commit 70d9ff6c authored by Pino Toscano's avatar Pino Toscano
Browse files

- add a real basic control bar with the play/pause and stop actions for the...

- add a real basic control bar with the play/pause and stop actions for the movie control, only shown whether the movie asks for it
- make the "click to play" function working for the video area only

svn path=/trunk/KDE/kdegraphics/okular/; revision=852067
parent bf6c19c1
......@@ -10,9 +10,14 @@
#include "videowidget.h"
// qt/kde includes
#include <qaction.h>
#include <qdir.h>
#include <qevent.h>
#include <qlayout.h>
#include <qtoolbar.h>
#include <kicon.h>
#include <klocale.h>
#include <phonon/videoplayer.h>
......@@ -30,16 +35,23 @@ public:
{
}
enum PlayPauseMode { PlayMode, PauseMode };
void load();
void setupPlayPauseAction( PlayPauseMode mode );
// slots
void finished();
void playOrPause();
VideoWidget *q;
Okular::MovieAnnotation *anno;
Okular::Document *document;
Okular::NormalizedRect geom;
Phonon::VideoPlayer *player;
QToolBar *controlBar;
QAction *playPauseAction;
QAction *stopAction;
bool loaded : 1;
};
......@@ -67,15 +79,31 @@ void VideoWidget::Private::load()
player->load( newurl );
}
void VideoWidget::Private::setupPlayPauseAction( PlayPauseMode mode )
{
if ( mode == PlayMode )
{
playPauseAction->setIcon( KIcon( "media-playback-start" ) );
playPauseAction->setText( i18nc( "start the movie playback", "Play" ) );
}
else if ( mode == PauseMode )
{
playPauseAction->setIcon( KIcon( "media-playback-pause" ) );
playPauseAction->setText( i18nc( "pause the movie playback", "Pause" ) );
}
}
void VideoWidget::Private::finished()
{
switch ( anno->movie()->playMode() )
{
case Okular::Movie::PlayOnce:
// TODO hide the control bar
break;
case Okular::Movie::PlayOpen:
// playback has ended, nothing to do
stopAction->setEnabled( false );
setupPlayPauseAction( PlayMode );
if ( anno->movie()->playMode() == Okular::Movie::PlayOnce )
controlBar->setVisible( false );
break;
case Okular::Movie::PlayRepeat:
// repeat the playback
......@@ -88,6 +116,19 @@ void VideoWidget::Private::finished()
}
}
void VideoWidget::Private::playOrPause()
{
if ( player->isPlaying() )
{
player->pause();
setupPlayPauseAction( PlayMode );
}
else
{
q->play();
}
}
VideoWidget::VideoWidget( Okular::MovieAnnotation *movieann, Okular::Document *document, QWidget *parent )
: QWidget( parent ), d( new Private( movieann, document, this ) )
{
......@@ -99,9 +140,27 @@ VideoWidget::VideoWidget( Okular::MovieAnnotation *movieann, Okular::Document *d
mainlay->setMargin( 0 );
d->player = new Phonon::VideoPlayer( Phonon::NoCategory, this );
d->player->installEventFilter( this );
mainlay->addWidget( d->player );
d->controlBar = new QToolBar( this );
d->controlBar->setIconSize( QSize( 16, 16 ) );
d->controlBar->setAutoFillBackground( true );
mainlay->addWidget( d->controlBar );
d->playPauseAction = new QAction( d->controlBar );
d->controlBar->addAction( d->playPauseAction );
d->setupPlayPauseAction( Private::PlayMode );
d->stopAction = d->controlBar->addAction(
KIcon( "media-playback-stop" ),
i18nc( "stop the movie playback", "Stop" ),
this, SLOT( stop() ) );
d->stopAction->setEnabled( false );
d->controlBar->setVisible( movieann->movie()->showControls() );
connect( d->player, SIGNAL( finished() ), this, SLOT( finished() ) );
connect( d->playPauseAction, SIGNAL( triggered() ), this, SLOT( playOrPause() ) );
d->geom = movieann->transformedBoundingRectangle();
}
......@@ -125,30 +184,39 @@ void VideoWidget::play()
{
d->load();
d->player->play();
d->stopAction->setEnabled( true );
d->setupPlayPauseAction( Private::PauseMode );
}
void VideoWidget::stop()
{
d->player->stop();
d->stopAction->setEnabled( false );
d->setupPlayPauseAction( Private::PlayMode );
}
void VideoWidget::pause()
{
d->player->pause();
d->setupPlayPauseAction( Private::PlayMode );
}
void VideoWidget::mousePressEvent( QMouseEvent * event )
bool VideoWidget::eventFilter( QObject * object, QEvent * event )
{
if ( event->button() == Qt::LeftButton )
if ( object == d->player )
{
if ( !d->player->isPlaying() )
QMouseEvent * me = static_cast< QMouseEvent * >( event );
if ( me->button() == Qt::LeftButton )
{
play();
if ( !d->player->isPlaying() )
{
play();
}
event->accept();
}
event->accept();
}
QWidget::mousePressEvent( event );
return false;
}
#include "videowidget.moc"
......@@ -34,10 +34,11 @@ class VideoWidget : public QWidget
void stop();
protected:
/* reimp */ void mousePressEvent( QMouseEvent * event );
/* reimp */ bool eventFilter( QObject * object, QEvent * event );
private:
Q_PRIVATE_SLOT( d, void finished() )
Q_PRIVATE_SLOT( d, void playOrPause() )
// private storage
class Private;
......
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