From 6cafdcfcff30fd4ec73adea7bf823c42bac808c9 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Wed, 2 May 2012 21:25:14 +0200 Subject: [PATCH] on stop the video widget show a screen shot instead of the phonon::mediawidget --- src/customWidgets/UBMediaWidget.cpp | 98 ++++++++++++++++------------- src/customWidgets/UBMediaWidget.h | 12 ++-- 2 files changed, 59 insertions(+), 51 deletions(-) diff --git a/src/customWidgets/UBMediaWidget.cpp b/src/customWidgets/UBMediaWidget.cpp index cbc0b842..d192109b 100644 --- a/src/customWidgets/UBMediaWidget.cpp +++ b/src/customWidgets/UBMediaWidget.cpp @@ -26,6 +26,8 @@ UBMediaWidget::UBMediaWidget(eMediaType type, QWidget *parent, const char *name) , mpMediaObject(NULL) , mpVideoWidget(NULL) , mpAudioOutput(NULL) + , mpLayout(NULL) + , mpSeekerLayout(NULL) , mpPlayStopButton(NULL) , mpPauseButton(NULL) , mpSlider(NULL) @@ -33,15 +35,16 @@ UBMediaWidget::UBMediaWidget(eMediaType type, QWidget *parent, const char *name) , mGeneratingThumbnail(false) , mBorder(5) , mpMediaContainer(NULL) + , mMediaLayout(NULL) , mpCover(NULL) -// , mpVideoStackedWidget(NULL) -// , mpSnapshotVideoWidget(NULL) + , mpSnapshotVideoWidget(NULL) { SET_STYLE_SHEET(); addAction(eAction_Close); mType = type; - setLayout(&mLayout); + mpLayout = new QVBoxLayout(this); + setLayout(mpLayout); mpPlayStopButton = new UBMediaButton(this); mpPlayStopButton->setPixmap(QPixmap(":images/play.svg")); @@ -53,10 +56,11 @@ UBMediaWidget::UBMediaWidget(eMediaType type, QWidget *parent, const char *name) mpSlider->setMinimum(0); mpSlider->setMaximum(0); - mSeekerLayout.addWidget(mpPlayStopButton, 0); - mSeekerLayout.addWidget(mpPauseButton, 0); - mSeekerLayout.addWidget(mpSlider, 1); - mSeekerLayout.setContentsMargins(0, 0, 0, 0); + mpSeekerLayout = new QHBoxLayout(this); + mpSeekerLayout->addWidget(mpPlayStopButton, 0); + mpSeekerLayout->addWidget(mpPauseButton, 0); + mpSeekerLayout->addWidget(mpSlider, 1); + mpSeekerLayout->setContentsMargins(0, 0, 0, 0); connect(mpPlayStopButton, SIGNAL(clicked()), this, SLOT(onPlayStopClicked())); connect(mpPauseButton, SIGNAL(clicked()), this, SLOT(onPauseClicked())); @@ -74,10 +78,13 @@ UBMediaWidget::~UBMediaWidget() DELETEPTR(mpPlayStopButton); DELETEPTR(mpAudioOutput); DELETEPTR(mpVideoWidget); -// DELETEPTR(mpVideoStackedWidget); -// DELETEPTR(mpSnapshotVideoWidget); DELETEPTR(mpMediaObject); DELETEPTR(mpCover); + DELETEPTR(mpSnapshotVideoWidget); + DELETEPTR(mpVideoStackedWidget); + DELETEPTR(mpMediaContainer); + DELETEPTR(mpSeekerLayout); + DELETEPTR(mpLayout); } /** @@ -109,10 +116,14 @@ eMediaType UBMediaWidget::mediaType() void UBMediaWidget::showEvent(QShowEvent* event) { if(!mpVideoWidget){ + mpSnapshotVideoWidget = new QLabel(this); mpVideoWidget = new Phonon::VideoWidget(this); - mMediaLayout.addStretch(1); - mMediaLayout.addWidget(mpVideoWidget, 0); - mMediaLayout.addStretch(1); + mpVideoStackedWidget = new QStackedWidget(this); + mpVideoStackedWidget->addWidget(mpVideoWidget); + mpVideoStackedWidget->addWidget(mpSnapshotVideoWidget); + mMediaLayout->addStretch(1); + mMediaLayout->addWidget(mpVideoStackedWidget,0); + mMediaLayout->addStretch(1); Phonon::createPath(mpMediaObject, mpVideoWidget); adaptSizeToVideo(); mpMediaObject->play(); @@ -135,41 +146,39 @@ void UBMediaWidget::createMediaPlayer() { mpMediaContainer = new QWidget(this); mpMediaContainer->setObjectName("UBMediaVideoContainer"); - mpMediaContainer->setLayout(&mMediaLayout); + mMediaLayout = new QHBoxLayout(this); + mpMediaContainer->setLayout(mMediaLayout); if(eMediaType_Video == mType){ - mMediaLayout.setContentsMargins(10, 10, 10, 10); + mMediaLayout->setContentsMargins(10, 10, 10, 10); if(isVisible()){ + mpSnapshotVideoWidget = new QLabel(this); mpVideoWidget = new Phonon::VideoWidget(this); - mMediaLayout.addStretch(1); - -// mpVideoStackedWidget = new QStackedWidget(this); -// mpVideoStackedWidget->addWidget(mpVideoWidget); -// mpSnapshotVideoWidget = new QLabel(this); -// mpVideoStackedWidget->addWidget(mpSnapshotVideoWidget); -// mMediaLayout.addWidget(mpVideoStackedWidget,0); - - mMediaLayout.addWidget(mpVideoWidget, 0); - mMediaLayout.addStretch(1); + mpVideoStackedWidget = new QStackedWidget(this); + mpVideoStackedWidget->addWidget(mpVideoWidget); + mpVideoStackedWidget->addWidget(mpSnapshotVideoWidget); + mMediaLayout->addStretch(1); + mMediaLayout->addWidget(mpVideoStackedWidget, 0); + mMediaLayout->addStretch(1); Phonon::createPath(mpMediaObject, mpVideoWidget); adaptSizeToVideo(); } mpAudioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this); Phonon::createPath(mpMediaObject, mpAudioOutput); }else if(eMediaType_Audio == mType){ - mMediaLayout.setContentsMargins(10, 10, 10, 10); + mMediaLayout->setContentsMargins(10, 10, 10, 10); mpCover = new QLabel(mpMediaContainer); mpMediaContainer->setStyleSheet(QString("background: none;")); setAudioCover(":images/libpalette/soundIcon.svg"); mpCover->setScaledContents(true); - mMediaLayout.addStretch(1); - mMediaLayout.addWidget(mpCover, 0); - mMediaLayout.addStretch(1); + mMediaLayout->addStretch(1); + mMediaLayout->addWidget(mpCover, 0); + mMediaLayout->addStretch(1); mpAudioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); Phonon::createPath(mpMediaObject, mpAudioOutput); } - mLayout.addWidget(mpMediaContainer, 1); - mLayout.addLayout(&mSeekerLayout, 0); + mpLayout->addWidget(mpMediaContainer, 1); + mpLayout->addLayout(mpSeekerLayout, 0); setActionsParent(mpMediaContainer); } @@ -188,21 +197,19 @@ void UBMediaWidget::adaptSizeToVideo() } } -//void UBMediaWidget::updateView(Phonon::State nextState) -//{ -// if(eMediaType_Video == mType){ -// if(nextState != Phonon::PlayingState){ -// const QPixmap& snapshot = QPixmap::grabWindow(mpVideoWidget->winId()); -// if(snapshot.size().width()!= 0){ -// mpSnapshotVideoWidget->setPixmap(snapshot); -// mpVideoStackedWidget->setCurrentWidget(mpSnapshotVideoWidget); -// } -// } -// else -// mpVideoStackedWidget->setCurrentWidget(mpVideoWidget); -// } +void UBMediaWidget::updateView(Phonon::State nextState) +{ + if(eMediaType_Video == mType){ + if(nextState != Phonon::PlayingState){ + const QPixmap& snapshot = QPixmap::grabWindow(mpVideoWidget->winId()); + mpSnapshotVideoWidget->setPixmap(snapshot); + mpVideoStackedWidget->setCurrentWidget(mpSnapshotVideoWidget); + } + else + mpVideoStackedWidget->setCurrentWidget(mpVideoWidget); + } -//} +} /** * \brief Handle the media state change notification @@ -232,7 +239,8 @@ void UBMediaWidget::onStateChanged(Phonon::State newState, Phonon::State oldStat mpPauseButton->setEnabled(false); mpSlider->setValue(0); } - //updateView(newState); + if(mType == eMediaType_Video) + updateView(newState); } } diff --git a/src/customWidgets/UBMediaWidget.h b/src/customWidgets/UBMediaWidget.h index 0d4db8f0..240400a5 100644 --- a/src/customWidgets/UBMediaWidget.h +++ b/src/customWidgets/UBMediaWidget.h @@ -91,7 +91,7 @@ private slots: private: void createMediaPlayer(); void adaptSizeToVideo(); -// void updateView(Phonon::State nextState); + void updateView(Phonon::State nextState); /** The current media type */ eMediaType mType; @@ -102,9 +102,9 @@ private: /** The audio renderer */ Phonon::AudioOutput* mpAudioOutput; /** The principal layout of this widget */ - QVBoxLayout mLayout; + QVBoxLayout* mpLayout; /** The seeker layout */ - QHBoxLayout mSeekerLayout; + QHBoxLayout* mpSeekerLayout; /** The play-stop button */ UBMediaButton* mpPlayStopButton; /** The pause button */ @@ -120,14 +120,14 @@ private: /** A widget that will contain the media */ QWidget* mpMediaContainer; /** The media layout */ - QHBoxLayout mMediaLayout; + QHBoxLayout* mMediaLayout; /** The audio cover */ QLabel* mpCover; /** The media url */ QString mUrl; -// QStackedWidget* mpVideoStackedWidget; -// QLabel* mpSnapshotVideoWidget; + QStackedWidget* mpVideoStackedWidget; + QLabel* mpSnapshotVideoWidget; }; #endif // UBMEDIAWIDGET_H