Commit 1ea51dd9 authored by Aurélien Gâteau's avatar Aurélien Gâteau
Browse files

Add widgets to control video playback.

svn path=/trunk/KDE/kdegraphics/gwenview/; revision=959274
parent b2a1df32
......@@ -25,36 +25,78 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
#include <Phonon/AudioOutput>
#include <Phonon/MediaObject>
#include <Phonon/Path>
#include <Phonon/SeekSlider>
#include <Phonon/VideoWidget>
#include <Phonon/VolumeSlider>
#include <QHBoxLayout>
#include <QToolButton>
// KDE
#include <kicon.h>
#include <kurl.h>
// Local
#include "document/documentfactory.h"
#include "widgetfloater.h"
#include "hudwidget.h"
namespace Gwenview {
struct VideoViewAdapterPrivate {
VideoViewAdapter* q;
Document::Ptr mDocument;
Phonon::MediaObject* mMediaObject;
Phonon::VideoWidget* mVideoWidget;
Phonon::AudioOutput* mAudioOutput;
QFrame* mHud;
QToolButton* mPlayPauseButton;
void setupHud(QWidget* parent) {
WidgetFloater* floater = new WidgetFloater(parent);
mHud = new QFrame(parent);
mHud->setAutoFillBackground(true);
QHBoxLayout* layout = new QHBoxLayout(mHud);
mPlayPauseButton = new QToolButton;
mPlayPauseButton->setAutoRaise(true);
mPlayPauseButton->setIcon(KIcon("media-playback-start"));
QObject::connect(mPlayPauseButton, SIGNAL(clicked()),
q, SLOT(slotPlayPauseClicked()));
Phonon::SeekSlider* seekSlider = new Phonon::SeekSlider;
seekSlider->setMediaObject(mMediaObject);
Phonon::VolumeSlider* volumeSlider = new Phonon::VolumeSlider;
volumeSlider->setAudioOutput(mAudioOutput);
volumeSlider->setMinimumWidth(100);
layout->addWidget(mPlayPauseButton);
layout->addWidget(seekSlider, 5 /* stretch */);
layout->addWidget(volumeSlider, 1 /* stretch */);
mHud->adjustSize();
floater->setChildWidget(mHud);
floater->setAlignment(Qt::AlignJustify | Qt::AlignBottom);
}
};
VideoViewAdapter::VideoViewAdapter(QWidget* parent)
: AbstractDocumentViewAdapter(parent)
, d(new VideoViewAdapterPrivate) {
d->q = this;
d->mMediaObject = new Phonon::MediaObject(this);
d->mVideoWidget = new Phonon::VideoWidget(parent);
d->mVideoWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
Phonon::createPath(d->mMediaObject, d->mVideoWidget);
Phonon::AudioOutput* audioOutput =
new Phonon::AudioOutput(Phonon::VideoCategory, this);
Phonon::createPath(d->mMediaObject, audioOutput);
d->mAudioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this);
Phonon::createPath(d->mMediaObject, d->mAudioOutput);
d->setupHud(d->mVideoWidget);
setWidget(d->mVideoWidget);
}
......@@ -73,7 +115,6 @@ VideoViewAdapter::~VideoViewAdapter() {
void VideoViewAdapter::setDocument(Document::Ptr doc) {
d->mDocument = doc;
d->mMediaObject->setCurrentSource(d->mDocument->url());
d->mMediaObject->play();
}
......@@ -82,4 +123,18 @@ Document::Ptr VideoViewAdapter::document() const {
}
void VideoViewAdapter::slotPlayPauseClicked() {
switch (d->mMediaObject->state()) {
case Phonon::StoppedState:
case Phonon::PausedState:
d->mMediaObject->play();
d->mPlayPauseButton->setIcon(KIcon("media-playback-pause"));
break;
default:
d->mMediaObject->pause();
d->mPlayPauseButton->setIcon(KIcon("media-playback-start"));
}
}
} // namespace
......@@ -48,6 +48,9 @@ public:
virtual void setDocument(Document::Ptr);
private Q_SLOTS:
void slotPlayPauseClicked();
private:
VideoViewAdapterPrivate* const d;
};
......
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