- 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
remotes/origin/old/work/tiff-improvements
Pino Toscano 18 years ago
parent bf6c19c108
commit 70d9ff6c02
  1. 84
      ui/videowidget.cpp
  2. 3
      ui/videowidget.h

@ -10,9 +10,14 @@
#include "videowidget.h" #include "videowidget.h"
// qt/kde includes // qt/kde includes
#include <qaction.h>
#include <qdir.h> #include <qdir.h>
#include <qevent.h> #include <qevent.h>
#include <qlayout.h> #include <qlayout.h>
#include <qtoolbar.h>
#include <kicon.h>
#include <klocale.h>
#include <phonon/videoplayer.h> #include <phonon/videoplayer.h>
@ -30,16 +35,23 @@ public:
{ {
} }
enum PlayPauseMode { PlayMode, PauseMode };
void load(); void load();
void setupPlayPauseAction( PlayPauseMode mode );
// slots // slots
void finished(); void finished();
void playOrPause();
VideoWidget *q; VideoWidget *q;
Okular::MovieAnnotation *anno; Okular::MovieAnnotation *anno;
Okular::Document *document; Okular::Document *document;
Okular::NormalizedRect geom; Okular::NormalizedRect geom;
Phonon::VideoPlayer *player; Phonon::VideoPlayer *player;
QToolBar *controlBar;
QAction *playPauseAction;
QAction *stopAction;
bool loaded : 1; bool loaded : 1;
}; };
@ -67,15 +79,31 @@ void VideoWidget::Private::load()
player->load( newurl ); 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() void VideoWidget::Private::finished()
{ {
switch ( anno->movie()->playMode() ) switch ( anno->movie()->playMode() )
{ {
case Okular::Movie::PlayOnce: case Okular::Movie::PlayOnce:
// TODO hide the control bar
break;
case Okular::Movie::PlayOpen: case Okular::Movie::PlayOpen:
// playback has ended, nothing to do // playback has ended, nothing to do
stopAction->setEnabled( false );
setupPlayPauseAction( PlayMode );
if ( anno->movie()->playMode() == Okular::Movie::PlayOnce )
controlBar->setVisible( false );
break; break;
case Okular::Movie::PlayRepeat: case Okular::Movie::PlayRepeat:
// repeat the playback // 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 ) VideoWidget::VideoWidget( Okular::MovieAnnotation *movieann, Okular::Document *document, QWidget *parent )
: QWidget( parent ), d( new Private( movieann, document, this ) ) : QWidget( parent ), d( new Private( movieann, document, this ) )
{ {
@ -99,9 +140,27 @@ VideoWidget::VideoWidget( Okular::MovieAnnotation *movieann, Okular::Document *d
mainlay->setMargin( 0 ); mainlay->setMargin( 0 );
d->player = new Phonon::VideoPlayer( Phonon::NoCategory, this ); d->player = new Phonon::VideoPlayer( Phonon::NoCategory, this );
d->player->installEventFilter( this );
mainlay->addWidget( d->player ); 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->player, SIGNAL( finished() ), this, SLOT( finished() ) );
connect( d->playPauseAction, SIGNAL( triggered() ), this, SLOT( playOrPause() ) );
d->geom = movieann->transformedBoundingRectangle(); d->geom = movieann->transformedBoundingRectangle();
} }
@ -125,30 +184,39 @@ void VideoWidget::play()
{ {
d->load(); d->load();
d->player->play(); d->player->play();
d->stopAction->setEnabled( true );
d->setupPlayPauseAction( Private::PauseMode );
} }
void VideoWidget::stop() void VideoWidget::stop()
{ {
d->player->stop(); d->player->stop();
d->stopAction->setEnabled( false );
d->setupPlayPauseAction( Private::PlayMode );
} }
void VideoWidget::pause() void VideoWidget::pause()
{ {
d->player->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" #include "videowidget.moc"

@ -34,10 +34,11 @@ class VideoWidget : public QWidget
void stop(); void stop();
protected: protected:
/* reimp */ void mousePressEvent( QMouseEvent * event ); /* reimp */ bool eventFilter( QObject * object, QEvent * event );
private: private:
Q_PRIVATE_SLOT( d, void finished() ) Q_PRIVATE_SLOT( d, void finished() )
Q_PRIVATE_SLOT( d, void playOrPause() )
// private storage // private storage
class Private; class Private;

Loading…
Cancel
Save