|
|
@ -43,7 +43,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include "core/memcheck.h" |
|
|
|
#include "core/memcheck.h" |
|
|
|
|
|
|
|
|
|
|
|
UBGraphicsMediaItemDelegate::UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pDelegated, Phonon::MediaObject* pMedia, QObject * parent) |
|
|
|
UBGraphicsMediaItemDelegate::UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pDelegated, QMediaPlayer* pMedia, QObject * parent) |
|
|
|
: UBGraphicsItemDelegate(pDelegated, parent, GF_COMMON |
|
|
|
: UBGraphicsItemDelegate(pDelegated, parent, GF_COMMON |
|
|
|
| GF_RESPECT_RATIO |
|
|
|
| GF_RESPECT_RATIO |
|
|
|
| GF_TOOLBAR_USED |
|
|
|
| GF_TOOLBAR_USED |
|
|
@ -56,11 +56,22 @@ UBGraphicsMediaItemDelegate::UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pD |
|
|
|
QPalette palette; |
|
|
|
QPalette palette; |
|
|
|
palette.setBrush ( QPalette::Light, Qt::darkGray ); |
|
|
|
palette.setBrush ( QPalette::Light, Qt::darkGray ); |
|
|
|
|
|
|
|
|
|
|
|
mMedia->setTickInterval(50); |
|
|
|
mMedia->setNotifyInterval(50); |
|
|
|
connect(mMedia, SIGNAL(stateChanged (Phonon::State, Phonon::State)), this, SLOT(mediaStateChanged (Phonon::State, Phonon::State))); |
|
|
|
|
|
|
|
connect(mMedia, SIGNAL(finished()), this, SLOT(updatePlayPauseState())); |
|
|
|
connect(mMedia, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), |
|
|
|
connect(mMedia, SIGNAL(tick(qint64)), this, SLOT(updateTicker(qint64))); |
|
|
|
this, SLOT(mediaStatusChanged(QMediaPlayer::MediaStatus))); |
|
|
|
connect(mMedia, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64))); |
|
|
|
|
|
|
|
|
|
|
|
connect(mMedia, SIGNAL(stateChanged(QMediaPlayer::State)), |
|
|
|
|
|
|
|
this, SLOT(mediaStateChanged(QMediaPlayer::State))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connect(mMedia, static_cast<void(QMediaPlayer::*)(QMediaPlayer::Error)>(&QMediaPlayer::error), |
|
|
|
|
|
|
|
this, &UBGraphicsMediaItemDelegate::mediaError); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connect(mMedia, SIGNAL(positionChanged(qint64)), |
|
|
|
|
|
|
|
this, SLOT(updateTicker(qint64))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connect(mMedia, SIGNAL(durationChanged(qint64)), |
|
|
|
|
|
|
|
this, SLOT(totalTimeChanged(qint64))); |
|
|
|
|
|
|
|
|
|
|
|
if (delegated()->hasLinkedImage()) |
|
|
|
if (delegated()->hasLinkedImage()) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -95,10 +106,12 @@ void UBGraphicsMediaItemDelegate::buildButtons() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(!mPlayPauseButton){ |
|
|
|
if(!mPlayPauseButton){ |
|
|
|
mPlayPauseButton = new DelegateButton(":/images/play.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); |
|
|
|
mPlayPauseButton = new DelegateButton(":/images/play.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); |
|
|
|
connect(mPlayPauseButton, SIGNAL(clicked(bool)), this, SLOT(togglePlayPause())); |
|
|
|
connect(mPlayPauseButton, SIGNAL(clicked(bool)), |
|
|
|
|
|
|
|
this, SLOT(togglePlayPause())); |
|
|
|
|
|
|
|
|
|
|
|
mStopButton = new DelegateButton(":/images/stop.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); |
|
|
|
mStopButton = new DelegateButton(":/images/stop.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); |
|
|
|
connect(mStopButton, SIGNAL(clicked(bool)), mMedia, SLOT(stop())); |
|
|
|
connect(mStopButton, SIGNAL(clicked(bool)), |
|
|
|
|
|
|
|
mMedia, SLOT(stop())); |
|
|
|
|
|
|
|
|
|
|
|
mMediaControl = new DelegateMediaControl(delegated(), mToolBarItem); |
|
|
|
mMediaControl = new DelegateMediaControl(delegated(), mToolBarItem); |
|
|
|
mMediaControl->setFlag(QGraphicsItem::ItemIsSelectable, true); |
|
|
|
mMediaControl->setFlag(QGraphicsItem::ItemIsSelectable, true); |
|
|
@ -109,8 +122,10 @@ void UBGraphicsMediaItemDelegate::buildButtons() |
|
|
|
else |
|
|
|
else |
|
|
|
mMuteButton = new DelegateButton(":/images/soundOn.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); |
|
|
|
mMuteButton = new DelegateButton(":/images/soundOn.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); |
|
|
|
|
|
|
|
|
|
|
|
connect(mMuteButton, SIGNAL(clicked(bool)), delegated(), SLOT(toggleMute())); |
|
|
|
connect(mMuteButton, SIGNAL(clicked(bool)), |
|
|
|
connect(mMuteButton, SIGNAL(clicked(bool)), this, SLOT(toggleMute())); // for changing button image
|
|
|
|
delegated(), SLOT(toggleMute())); |
|
|
|
|
|
|
|
connect(mMuteButton, SIGNAL(clicked(bool)), |
|
|
|
|
|
|
|
this, SLOT(toggleMute())); // for changing button image
|
|
|
|
|
|
|
|
|
|
|
|
mToolBarButtons << mPlayPauseButton << mStopButton << mMuteButton; |
|
|
|
mToolBarButtons << mPlayPauseButton << mStopButton << mMuteButton; |
|
|
|
|
|
|
|
|
|
|
@ -120,10 +135,17 @@ void UBGraphicsMediaItemDelegate::buildButtons() |
|
|
|
|
|
|
|
|
|
|
|
if (mToolBarShowTimer) |
|
|
|
if (mToolBarShowTimer) |
|
|
|
{ |
|
|
|
{ |
|
|
|
connect(mPlayPauseButton, SIGNAL(clicked(bool)), mToolBarShowTimer, SLOT(start())); |
|
|
|
connect(mPlayPauseButton, SIGNAL(clicked(bool)), |
|
|
|
connect(mStopButton, SIGNAL(clicked(bool)), mToolBarShowTimer, SLOT(start())); |
|
|
|
mToolBarShowTimer, SLOT(start())); |
|
|
|
connect(mMediaControl, SIGNAL(used()), mToolBarShowTimer, SLOT(start())); |
|
|
|
|
|
|
|
connect(mMuteButton, SIGNAL(clicked(bool)), mToolBarShowTimer, SLOT(start())); |
|
|
|
connect(mStopButton, SIGNAL(clicked(bool)), |
|
|
|
|
|
|
|
mToolBarShowTimer, SLOT(start())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connect(mMediaControl, SIGNAL(used()), |
|
|
|
|
|
|
|
mToolBarShowTimer, SLOT(start())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connect(mMuteButton, SIGNAL(clicked(bool)), |
|
|
|
|
|
|
|
mToolBarShowTimer, SLOT(start())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -195,55 +217,82 @@ UBGraphicsMediaItem* UBGraphicsMediaItemDelegate::delegated() |
|
|
|
return dynamic_cast<UBGraphicsMediaItem*>(mDelegated); |
|
|
|
return dynamic_cast<UBGraphicsMediaItem*>(mDelegated); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBGraphicsMediaItemDelegate::togglePlayPause() |
|
|
|
void UBGraphicsMediaItemDelegate::togglePlayPause() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (delegated() && delegated()->mediaObject()) { |
|
|
|
if (delegated() && delegated()->mediaObject()) { |
|
|
|
|
|
|
|
|
|
|
|
Phonon::MediaObject* media = delegated()->mediaObject(); |
|
|
|
QMediaPlayer * media = delegated()->mediaObject(); |
|
|
|
if (media->state() == Phonon::StoppedState) { |
|
|
|
|
|
|
|
|
|
|
|
if (media->state() == QMediaPlayer::StoppedState) |
|
|
|
media->play(); |
|
|
|
media->play(); |
|
|
|
} else if (media->state() == Phonon::PlayingState) { |
|
|
|
|
|
|
|
if (media->remainingTime() <= 0) { |
|
|
|
else if (media->state() == QMediaPlayer::PlayingState) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((media->duration() - media->position()) <= 0) { |
|
|
|
media->stop(); |
|
|
|
media->stop(); |
|
|
|
media->play(); |
|
|
|
media->play(); |
|
|
|
} else { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else { |
|
|
|
media->pause(); |
|
|
|
media->pause(); |
|
|
|
if(delegated()->scene()) |
|
|
|
if(delegated()->scene()) |
|
|
|
delegated()->scene()->setModified(true); |
|
|
|
delegated()->scene()->setModified(true); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (media->state() == Phonon::PausedState) { |
|
|
|
|
|
|
|
if (media->remainingTime() <= 0) { |
|
|
|
|
|
|
|
media->stop(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else if (media->state() == QMediaPlayer::PausedState) { |
|
|
|
|
|
|
|
if ((media->duration() - media->position()) <= 0) |
|
|
|
|
|
|
|
media->stop(); |
|
|
|
|
|
|
|
|
|
|
|
media->play(); |
|
|
|
media->play(); |
|
|
|
} else if ( media->state() == Phonon::LoadingState ) { |
|
|
|
} |
|
|
|
delegated()->mediaObject()->setCurrentSource(delegated()->mediaFileUrl()); |
|
|
|
|
|
|
|
|
|
|
|
else if ( media->mediaStatus() == QMediaPlayer::LoadingMedia) { |
|
|
|
|
|
|
|
delegated()->mediaObject()->setMedia(delegated()->mediaFileUrl()); |
|
|
|
media->play(); |
|
|
|
media->play(); |
|
|
|
} else if (media->state() == Phonon::ErrorState){ |
|
|
|
|
|
|
|
qDebug() << "Error appeared." << media->errorString(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else if (media->error()) |
|
|
|
|
|
|
|
qDebug() << "Error appeared." << media->errorString(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void UBGraphicsMediaItemDelegate::mediaStateChanged ( Phonon::State newstate, Phonon::State oldstate ) |
|
|
|
void UBGraphicsMediaItemDelegate::mediaStatusChanged(QMediaPlayer::MediaStatus status) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Q_UNUSED(newstate); |
|
|
|
// Possible statuses are: UnknownMediaStatus, NoMedia, LoadingMedia, LoadedMedia,
|
|
|
|
Q_UNUSED(oldstate); |
|
|
|
// StalledMedia, BufferingMedia, BufferedMedia, EndOfMedia, InvalidMedia
|
|
|
|
|
|
|
|
|
|
|
|
if (oldstate == Phonon::LoadingState) |
|
|
|
if (status == QMediaPlayer::LoadedMedia) |
|
|
|
{ |
|
|
|
mMediaControl->totalTimeChanged(delegated()->mediaObject()->duration()); |
|
|
|
mMediaControl->totalTimeChanged(delegated()->mediaObject()->totalTime()); |
|
|
|
|
|
|
|
} |
|
|
|
// in most cases, the only necessary action is to update the play/pause state
|
|
|
|
updatePlayPauseState(); |
|
|
|
updatePlayPauseState(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBGraphicsMediaItemDelegate::mediaStateChanged(QMediaPlayer::State state) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Possible states are StoppedState, PlayingState and PausedState
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// updatePlayPauseState handles this functionality
|
|
|
|
|
|
|
|
updatePlayPauseState(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBGraphicsMediaItemDelegate::mediaError(QMediaPlayer::Error error) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Possible errors are NoError, ResourceError, FormatError, NetworkError, AccessDeniedError,
|
|
|
|
|
|
|
|
// ServiceMissingError
|
|
|
|
|
|
|
|
Q_UNUSED(error); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
qDebug() << "Error appeared." << mMedia->errorString(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UBGraphicsMediaItemDelegate::updatePlayPauseState() |
|
|
|
void UBGraphicsMediaItemDelegate::updatePlayPauseState() |
|
|
|
{ |
|
|
|
{ |
|
|
|
Phonon::MediaObject* media = delegated()->mediaObject(); |
|
|
|
QMediaPlayer * media = delegated()->mediaObject(); |
|
|
|
|
|
|
|
|
|
|
|
if (media->state() == Phonon::PlayingState) |
|
|
|
if (media->state() == QMediaPlayer::PlayingState) |
|
|
|
mPlayPauseButton->setFileName(":/images/pause.svg"); |
|
|
|
mPlayPauseButton->setFileName(":/images/pause.svg"); |
|
|
|
else |
|
|
|
else |
|
|
|
mPlayPauseButton->setFileName(":/images/play.svg"); |
|
|
|
mPlayPauseButton->setFileName(":/images/play.svg"); |
|
|
@ -252,8 +301,8 @@ void UBGraphicsMediaItemDelegate::updatePlayPauseState() |
|
|
|
|
|
|
|
|
|
|
|
void UBGraphicsMediaItemDelegate::updateTicker(qint64 time) |
|
|
|
void UBGraphicsMediaItemDelegate::updateTicker(qint64 time) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Phonon::MediaObject* media = delegated()->mediaObject(); |
|
|
|
QMediaPlayer* media = delegated()->mediaObject(); |
|
|
|
mMediaControl->totalTimeChanged(media->totalTime()); |
|
|
|
mMediaControl->totalTimeChanged(media->duration()); |
|
|
|
mMediaControl->updateTicker(time); |
|
|
|
mMediaControl->updateTicker(time); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|