mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-25 02:45:38 +00:00
add a video widget class that encapsulates a Phonon video player and includes all the logic for repeated playbacks, media controls, etc
at the moment, it provides just playback and repeat mode svn path=/trunk/KDE/kdegraphics/okular/; revision=851956
This commit is contained in:
parent
a8fab80008
commit
3ede96ef1b
|
@ -154,6 +154,7 @@ set(okularpart_SRCS
|
||||||
ui/tocmodel.cpp
|
ui/tocmodel.cpp
|
||||||
ui/toolaction.cpp
|
ui/toolaction.cpp
|
||||||
ui/tts.cpp
|
ui/tts.cpp
|
||||||
|
ui/videowidget.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
kde4_add_ui_files(okularpart_SRCS
|
kde4_add_ui_files(okularpart_SRCS
|
||||||
|
|
150
ui/videowidget.cpp
Normal file
150
ui/videowidget.cpp
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* Copyright (C) 2008 by Pino Toscano <pino@kde.org> *
|
||||||
|
* *
|
||||||
|
* 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 <qdir.h>
|
||||||
|
#include <qevent.h>
|
||||||
|
#include <qlayout.h>
|
||||||
|
|
||||||
|
#include <phonon/videoplayer.h>
|
||||||
|
|
||||||
|
#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"
|
47
ui/videowidget.h
Normal file
47
ui/videowidget.h
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* Copyright (C) 2008 by Pino Toscano <pino@kde.org> *
|
||||||
|
* *
|
||||||
|
* 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 <qwidget.h>
|
||||||
|
|
||||||
|
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
|
Loading…
Reference in a new issue