diff --git a/CMakeLists.txt b/CMakeLists.txt index 1467f8da2..75ddfd07d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,6 +154,7 @@ set(okularpart_SRCS ui/tocmodel.cpp ui/toolaction.cpp ui/tts.cpp + ui/videowidget.cpp ) kde4_add_ui_files(okularpart_SRCS diff --git a/ui/videowidget.cpp b/ui/videowidget.cpp new file mode 100644 index 000000000..f3664c91b --- /dev/null +++ b/ui/videowidget.cpp @@ -0,0 +1,150 @@ +/*************************************************************************** + * Copyright (C) 2008 by Pino Toscano * + * * + * 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. * + ***************************************************************************/ + +#include "videowidget.h" + +// qt/kde includes +#include +#include +#include + +#include + +#include "core/area.h" +#include "core/annotations.h" +#include "core/document.h" +#include "core/movie.h" + +/* Private storage. */ +class VideoWidget::Private +{ +public: + Private( Okular::MovieAnnotation *ma, Okular::Document *doc, VideoWidget *qq ) + : q( qq ), anno( ma ), document( doc ), loaded( false ) + { + } + + void load(); + + // slots + void finished(); + + VideoWidget *q; + Okular::MovieAnnotation *anno; + Okular::Document *document; + Okular::NormalizedRect geom; + Phonon::VideoPlayer *player; + bool loaded : 1; +}; + +void VideoWidget::Private::load() +{ + if ( loaded ) + return; + + loaded = true; + + QString url = anno->movie()->url(); + KUrl newurl; + if ( QDir::isRelativePath( url ) ) + { + newurl = document->currentDocument(); + newurl.setFileName( url ); + } + else + { + newurl = url; + } + if ( newurl.isLocalFile() ) + player->load( newurl.toLocalFile() ); + else + player->load( newurl ); +} + +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 + break; + case Okular::Movie::PlayRepeat: + // repeat the playback + player->play(); + break; + case Okular::Movie::PlayPalindrome: + // FIXME we should play backward, but we cannot + player->play(); + break; + } +} + +VideoWidget::VideoWidget( Okular::MovieAnnotation *movieann, Okular::Document *document, QWidget *parent ) + : QWidget( parent ), d( new Private( movieann, document, this ) ) +{ + QVBoxLayout *mainlay = new QVBoxLayout( this ); + mainlay->setMargin( 0 ); + + d->player = new Phonon::VideoPlayer( Phonon::NoCategory, this ); + mainlay->addWidget( d->player ); + + connect( d->player, SIGNAL( finished() ), this, SLOT( finished() ) ); + + d->geom = movieann->transformedBoundingRectangle(); +} + +VideoWidget::~VideoWidget() +{ + delete d; +} + +void VideoWidget::setNormGeometry( const Okular::NormalizedRect &rect ) +{ + d->geom = rect; +} + +Okular::NormalizedRect VideoWidget::normGeometry() const +{ + return d->geom; +} + +void VideoWidget::play() +{ + d->load(); + d->player->play(); +} + +void VideoWidget::stop() +{ + d->player->stop(); +} + +void VideoWidget::pause() +{ + d->player->pause(); +} + +void VideoWidget::mousePressEvent( QMouseEvent * event ) +{ + if ( event->button() == Qt::LeftButton ) + { + if ( !d->player->isPlaying() ) + { + play(); + } + event->accept(); + } + + QWidget::mousePressEvent( event ); +} + +#include "videowidget.moc" diff --git a/ui/videowidget.h b/ui/videowidget.h new file mode 100644 index 000000000..51f1007da --- /dev/null +++ b/ui/videowidget.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2008 by Pino Toscano * + * * + * 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. * + ***************************************************************************/ + +#ifndef _OKULAR_VIDEOWIDGET_H_ +#define _OKULAR_VIDEOWIDGET_H_ + +#include + +namespace Okular { +class Document; +class MovieAnnotation; +class NormalizedRect; +} + +class VideoWidget : public QWidget +{ + Q_OBJECT + public: + VideoWidget( Okular::MovieAnnotation *movieann, Okular::Document *document, QWidget *parent = 0 ); + ~VideoWidget(); + + void setNormGeometry( const Okular::NormalizedRect &rect ); + Okular::NormalizedRect normGeometry() const; + + public slots: + void play(); + void pause(); + void stop(); + + protected: + /* reimp */ void mousePressEvent( QMouseEvent * event ); + + private: + Q_PRIVATE_SLOT( d, void finished() ) + + // private storage + class Private; + Private *d; +}; + +#endif