Conflicts: src/adaptors/UBSvgSubsetAdaptor.cpppreferencesAboutTextFull
commit
90f038664a
@ -1,120 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 3 of the License, or |
|
||||||
* (at your option) any later version. |
|
||||||
* |
|
||||||
* This program is distributed in the hope that it will be useful, |
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
* GNU General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU General Public License |
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include "UBGraphicsAudioItem.h" |
|
||||||
#include "UBGraphicsAudioItemDelegate.h" |
|
||||||
#include "UBGraphicsDelegateFrame.h" |
|
||||||
|
|
||||||
#include "core/memcheck.h" |
|
||||||
|
|
||||||
UBGraphicsAudioItem::UBGraphicsAudioItem(const QUrl& pAudioFileUrl, QGraphicsItem *parent): |
|
||||||
UBGraphicsMediaItem(pAudioFileUrl,parent) |
|
||||||
{ |
|
||||||
update(); |
|
||||||
|
|
||||||
mAudioOutput = new Phonon::AudioOutput ( Phonon::MusicCategory, this ); |
|
||||||
mMediaObject = new Phonon::MediaObject ( this ); |
|
||||||
mMediaObject->setTickInterval ( 1000 ); |
|
||||||
Phonon::createPath ( mMediaObject, mAudioOutput ); |
|
||||||
|
|
||||||
mMediaObject->clearQueue(); |
|
||||||
mSource = Phonon::MediaSource(pAudioFileUrl); |
|
||||||
mMediaObject->setCurrentSource (mSource ); |
|
||||||
|
|
||||||
connect (mMediaObject,SIGNAL ( tick ( qint64 ) ), this, SLOT ( tick ( qint64 ) ) ); |
|
||||||
connect(mMediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(onStateChanged(Phonon::State,Phonon::State))); |
|
||||||
|
|
||||||
mAudioWidget = new QWidget(); |
|
||||||
|
|
||||||
mSeekSlider = new Phonon::SeekSlider ( mAudioWidget ); |
|
||||||
mSeekSlider->setMediaObject ( mMediaObject ); |
|
||||||
|
|
||||||
QPalette palette; |
|
||||||
palette.setBrush ( QPalette::Light, Qt::darkGray ); |
|
||||||
|
|
||||||
mTimeLcd = new QLCDNumber; |
|
||||||
mTimeLcd->setPalette ( palette ); |
|
||||||
mTimeLcd->display ( "00:00" ); |
|
||||||
|
|
||||||
QHBoxLayout *seekerLayout = new QHBoxLayout; |
|
||||||
seekerLayout->addWidget ( mSeekSlider ); |
|
||||||
seekerLayout->addWidget ( mTimeLcd ); |
|
||||||
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout; |
|
||||||
mainLayout->addLayout ( seekerLayout ); |
|
||||||
|
|
||||||
mAudioWidget->setLayout ( mainLayout ); |
|
||||||
setWidget ( mAudioWidget ); |
|
||||||
|
|
||||||
UBGraphicsAudioItemDelegate* delegate = new UBGraphicsAudioItemDelegate ( this, mMediaObject ); |
|
||||||
delegate->init(); |
|
||||||
setDelegate ( delegate ); |
|
||||||
|
|
||||||
mDelegate->frame()->setOperationMode ( UBGraphicsDelegateFrame::Resizing ); |
|
||||||
|
|
||||||
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly
|
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
void UBGraphicsAudioItem::onStateChanged(Phonon::State newState, Phonon::State oldState) |
|
||||||
{ |
|
||||||
qDebug() << "STATE CHANGED!"; |
|
||||||
qDebug() << "old state:" << oldState; |
|
||||||
qDebug() << "new state:" << newState; |
|
||||||
|
|
||||||
if(oldState == Phonon::ErrorState) |
|
||||||
{ |
|
||||||
qDebug() << "ERROR! : " << mMediaObject->errorString(); |
|
||||||
} |
|
||||||
else if(newState == Phonon::LoadingState) |
|
||||||
{ |
|
||||||
int itotaltime = mMediaObject->totalTime(); |
|
||||||
qDebug() << "[Loading State entered!] Total time : " << itotaltime; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
UBGraphicsAudioItem::~UBGraphicsAudioItem() |
|
||||||
{ |
|
||||||
//NOOP
|
|
||||||
} |
|
||||||
|
|
||||||
UBItem* UBGraphicsAudioItem::deepCopy() const |
|
||||||
{ |
|
||||||
QUrl audioUrl = this->mediaFileUrl(); |
|
||||||
|
|
||||||
UBGraphicsAudioItem *copy = new UBGraphicsAudioItem(audioUrl, parentItem()); |
|
||||||
|
|
||||||
copy->setPos(this->pos()); |
|
||||||
copy->setTransform(this->transform()); |
|
||||||
copy->setFlag(QGraphicsItem::ItemIsMovable, true); |
|
||||||
copy->setFlag(QGraphicsItem::ItemIsSelectable, true); |
|
||||||
copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); |
|
||||||
copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); |
|
||||||
copy->setUuid(this->uuid()); // this is OK as long as Videos are imutable
|
|
||||||
copy->setSourceUrl(this->sourceUrl()); |
|
||||||
|
|
||||||
copy->resize(this->size()); |
|
||||||
|
|
||||||
// TODO UB 4.7 complete all members
|
|
||||||
|
|
||||||
return copy; |
|
||||||
} |
|
||||||
|
|
||||||
void UBGraphicsAudioItem::tick ( qint64 time ) |
|
||||||
{ |
|
||||||
QTime displayTime ( 0, ( time / 60000 ) % 60, ( time / 1000 ) % 60 ); |
|
||||||
|
|
||||||
mTimeLcd->display ( displayTime.toString ( "mm:ss" ) ); |
|
||||||
} |
|
@ -1,65 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 3 of the License, or |
|
||||||
* (at your option) any later version. |
|
||||||
* |
|
||||||
* This program is distributed in the hope that it will be useful, |
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
* GNU General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU General Public License |
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/ |
|
||||||
#ifndef UBGRAPHICSAUDIOITEM_H |
|
||||||
#define UBGRAPHICSAUDIOITEM_H |
|
||||||
|
|
||||||
#include "UBGraphicsMediaItem.h" |
|
||||||
#include "phonon/seekslider.h" |
|
||||||
#include "phonon/mediasource.h" |
|
||||||
#include "core/UB.h" |
|
||||||
#include "core/UBApplication.h" |
|
||||||
#include "board/UBBoardController.h" |
|
||||||
|
|
||||||
class UBGraphicsAudioItem : public UBGraphicsMediaItem |
|
||||||
{ |
|
||||||
Q_OBJECT |
|
||||||
|
|
||||||
public: |
|
||||||
|
|
||||||
UBGraphicsAudioItem(const QUrl& pAudioFileUrl, QGraphicsItem *parent = 0); |
|
||||||
~UBGraphicsAudioItem(); |
|
||||||
|
|
||||||
enum { Type = UBGraphicsItemType::AudioItemType }; |
|
||||||
|
|
||||||
virtual int type() const |
|
||||||
{ |
|
||||||
return Type; |
|
||||||
} |
|
||||||
|
|
||||||
virtual UBItem* deepCopy () const; |
|
||||||
virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;} |
|
||||||
|
|
||||||
virtual void clearSource() |
|
||||||
{ |
|
||||||
UBGraphicsMediaItem::clearSource(); |
|
||||||
} |
|
||||||
|
|
||||||
private slots: |
|
||||||
|
|
||||||
void tick ( qint64 time ); |
|
||||||
void onStateChanged(Phonon::State newState,Phonon::State oldState); |
|
||||||
|
|
||||||
protected: |
|
||||||
|
|
||||||
QWidget* mAudioWidget; |
|
||||||
QLCDNumber* mTimeLcd; |
|
||||||
|
|
||||||
Phonon::SeekSlider* mSeekSlider; |
|
||||||
private: |
|
||||||
Phonon::MediaSource mSource; |
|
||||||
|
|
||||||
}; |
|
||||||
|
|
||||||
#endif // UBGRAPHICSAUDIOITEM_H
|
|
@ -1,123 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 3 of the License, or |
|
||||||
* (at your option) any later version. |
|
||||||
* |
|
||||||
* This program is distributed in the hope that it will be useful, |
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
* GNU General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU General Public License |
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include "UBGraphicsAudioItemDelegate.h" |
|
||||||
#include "domain/UBGraphicsAudioItem.h" |
|
||||||
#include "domain/UBGraphicsDelegateFrame.h" |
|
||||||
#include "UBGraphicsScene.h" |
|
||||||
|
|
||||||
#include "core/memcheck.h" |
|
||||||
|
|
||||||
UBGraphicsAudioItemDelegate::UBGraphicsAudioItemDelegate ( UBGraphicsAudioItem* pDelegated, QObject *parent ) |
|
||||||
: UBGraphicsItemDelegate ( pDelegated, parent ) |
|
||||||
, mDelegated ( pDelegated ) |
|
||||||
{ |
|
||||||
//NOOP
|
|
||||||
} |
|
||||||
|
|
||||||
UBGraphicsAudioItemDelegate::~UBGraphicsAudioItemDelegate() |
|
||||||
{ |
|
||||||
//NNOP
|
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
void UBGraphicsAudioItemDelegate::buildButtons() |
|
||||||
{ |
|
||||||
mPlayPauseButton = new DelegateButton ( ":/images/play.svg", mDelegated, mFrame ); |
|
||||||
|
|
||||||
mStopButton = new DelegateButton ( ":/images/stop.svg", mDelegated, mFrame ); |
|
||||||
mStopButton->hide(); |
|
||||||
|
|
||||||
if ( mDelegated->isMuted() ) |
|
||||||
mMuteButton = new DelegateButton ( ":/images/soundOff.svg", mDelegated, mFrame ); |
|
||||||
else |
|
||||||
mMuteButton = new DelegateButton ( ":/images/soundOn.svg", mDelegated, mFrame ); |
|
||||||
|
|
||||||
mMuteButton->hide(); |
|
||||||
|
|
||||||
|
|
||||||
connect ( mPlayPauseButton, SIGNAL ( clicked ( bool ) ), this, SLOT ( togglePlayPause() ) ); |
|
||||||
connect ( mStopButton, SIGNAL ( clicked ( bool ) ), mDelegated->mediaObject(), SLOT ( stop() ) ); |
|
||||||
connect ( mMuteButton, SIGNAL ( clicked ( bool ) ), mDelegated, SLOT ( toggleMute() ) ); |
|
||||||
connect ( mMuteButton, SIGNAL ( clicked ( bool ) ), this, SLOT ( toggleMute() ) ); |
|
||||||
|
|
||||||
connect ( mDelegated->mediaObject(), SIGNAL ( stateChanged ( Phonon::State, Phonon::State ) ), this, SLOT ( mediaStateChanged ( Phonon::State, Phonon::State ) ) ); |
|
||||||
connect ( mDelegated->mediaObject(), SIGNAL ( finished() ), this, SLOT ( updatePlayPauseState() ) ); |
|
||||||
|
|
||||||
mButtons << mPlayPauseButton << mStopButton << mMuteButton; |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
void UBGraphicsAudioItemDelegate::togglePlayPause() |
|
||||||
{ |
|
||||||
if ( mDelegated && mDelegated->mediaObject() ) |
|
||||||
{ |
|
||||||
Phonon::MediaObject* media = mDelegated->mediaObject(); |
|
||||||
|
|
||||||
if ( media->state() == Phonon::StoppedState ) { |
|
||||||
media->play(); |
|
||||||
} else if ( media->state() == Phonon::PlayingState ) { |
|
||||||
if ( media->remainingTime() <= 0 ) { |
|
||||||
media->stop(); |
|
||||||
media->play(); |
|
||||||
} else { |
|
||||||
media->pause(); |
|
||||||
if ( mDelegated->scene() ) |
|
||||||
mDelegated->scene()->setModified ( true ); |
|
||||||
} |
|
||||||
} else if ( media->state() == Phonon::PausedState ) { |
|
||||||
if ( media->remainingTime() <= 0 ) { |
|
||||||
media->stop(); |
|
||||||
} |
|
||||||
media->play(); |
|
||||||
} else if ( media->state() == Phonon::LoadingState ) { |
|
||||||
mDelegated->mediaObject()->setCurrentSource(mDelegated->mediaFileUrl()); |
|
||||||
media->play(); |
|
||||||
} else if (media->state() == Phonon::ErrorState){ |
|
||||||
qDebug() << "Error appeared." << media->errorString(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void UBGraphicsAudioItemDelegate::toggleMute() |
|
||||||
{ |
|
||||||
if ( mDelegated->isMuted() ) |
|
||||||
mMuteButton->setFileName ( ":/images/soundOff.svg" ); |
|
||||||
else |
|
||||||
mMuteButton->setFileName ( ":/images/soundOn.svg" ); |
|
||||||
} |
|
||||||
|
|
||||||
void UBGraphicsAudioItemDelegate::updatePlayPauseState() |
|
||||||
{ |
|
||||||
Phonon::MediaObject* media = mDelegated->mediaObject(); |
|
||||||
|
|
||||||
if ( media->state() == Phonon::PlayingState ) |
|
||||||
mPlayPauseButton->setFileName ( ":/images/pause.svg" ); |
|
||||||
else |
|
||||||
mPlayPauseButton->setFileName ( ":/images/play.svg" ); |
|
||||||
} |
|
||||||
|
|
||||||
void UBGraphicsAudioItemDelegate::mediaStateChanged ( Phonon::State newstate, Phonon::State oldstate ) |
|
||||||
{ |
|
||||||
Q_UNUSED ( newstate ); |
|
||||||
Q_UNUSED ( oldstate ); |
|
||||||
updatePlayPauseState(); |
|
||||||
} |
|
||||||
|
|
||||||
void UBGraphicsAudioItemDelegate::remove ( bool canUndo ) |
|
||||||
{ |
|
||||||
mDelegated->mediaObject()->stop(); |
|
||||||
UBGraphicsItemDelegate::remove ( canUndo ); |
|
||||||
} |
|
@ -0,0 +1,231 @@ |
|||||||
|
/*
|
||||||
|
* 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 3 of the License, or |
||||||
|
* (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU General Public License |
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/ |
||||||
|
|
||||||
|
#include <QtGui> |
||||||
|
#include <QtSvg> |
||||||
|
|
||||||
|
#include "UBGraphicsMediaItem.h" |
||||||
|
#include "UBGraphicsMediaItemDelegate.h" |
||||||
|
|
||||||
|
#include "UBGraphicsScene.h" |
||||||
|
|
||||||
|
#include "core/UBSettings.h" |
||||||
|
#include "core/UBApplication.h" |
||||||
|
#include "core/UBApplicationController.h" |
||||||
|
#include "core/UBDisplayManager.h" |
||||||
|
|
||||||
|
#include "domain/UBGraphicsMediaItem.h" |
||||||
|
|
||||||
|
#include "core/memcheck.h" |
||||||
|
|
||||||
|
UBGraphicsMediaItemDelegate::UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pDelegated, Phonon::MediaObject* pMedia, QObject * parent) |
||||||
|
: UBGraphicsItemDelegate(pDelegated, parent, true, false) |
||||||
|
, mMedia(pMedia) |
||||||
|
{ |
||||||
|
QPalette palette; |
||||||
|
palette.setBrush ( QPalette::Light, Qt::darkGray ); |
||||||
|
|
||||||
|
mMedia->setTickInterval(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(tick(qint64)), this, SLOT(updateTicker(qint64))); |
||||||
|
connect(mMedia, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64))); |
||||||
|
} |
||||||
|
|
||||||
|
bool UBGraphicsMediaItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event) |
||||||
|
{ |
||||||
|
Q_UNUSED(event); |
||||||
|
mToolBarItem->show(); |
||||||
|
return UBGraphicsItemDelegate::mousePressEvent(event); |
||||||
|
} |
||||||
|
|
||||||
|
void UBGraphicsMediaItemDelegate::buildButtons() |
||||||
|
{ |
||||||
|
mPlayPauseButton = new DelegateButton(":/images/play.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); |
||||||
|
connect(mPlayPauseButton, SIGNAL(clicked(bool)), this, SLOT(togglePlayPause())); |
||||||
|
|
||||||
|
mStopButton = new DelegateButton(":/images/stop.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); |
||||||
|
connect(mStopButton, SIGNAL(clicked(bool)), mMedia, SLOT(stop())); |
||||||
|
|
||||||
|
mMediaControl = new DelegateMediaControl(delegated(), mToolBarItem); |
||||||
|
mMediaControl->setFlag(QGraphicsItem::ItemIsSelectable, true); |
||||||
|
UBGraphicsItem::assignZValue(mMediaControl, delegated()->zValue()); |
||||||
|
|
||||||
|
if (delegated()->isMuted()) |
||||||
|
mMuteButton = new DelegateButton(":/images/soundOff.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); |
||||||
|
else |
||||||
|
mMuteButton = new DelegateButton(":/images/soundOn.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); |
||||||
|
|
||||||
|
connect(mMuteButton, SIGNAL(clicked(bool)), delegated(), SLOT(toggleMute()));
|
||||||
|
connect(mMuteButton, SIGNAL(clicked(bool)), this, SLOT(toggleMute())); // for changing button image
|
||||||
|
|
||||||
|
mButtons << mPlayPauseButton << mStopButton << mMuteButton; |
||||||
|
|
||||||
|
mToolBarItem->setItemsOnToolBar(QList<QGraphicsItem*>() << mPlayPauseButton << mStopButton << mMediaControl << mMuteButton); |
||||||
|
mToolBarItem->setVisibleOnBoard(true); |
||||||
|
mToolBarItem->setShifting(false); |
||||||
|
|
||||||
|
UBGraphicsMediaItem *audioItem = dynamic_cast<UBGraphicsMediaItem*>(mDelegated); |
||||||
|
if (audioItem) |
||||||
|
{ |
||||||
|
if (audioItem->getMediaType() == UBGraphicsMediaItem::mediaType_Audio) |
||||||
|
{ |
||||||
|
positionHandles(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
UBGraphicsMediaItemDelegate::~UBGraphicsMediaItemDelegate() |
||||||
|
{ |
||||||
|
//NOOP
|
||||||
|
} |
||||||
|
|
||||||
|
void UBGraphicsMediaItemDelegate::positionHandles() |
||||||
|
{ |
||||||
|
UBGraphicsItemDelegate::positionHandles(); |
||||||
|
|
||||||
|
qreal AntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom());
|
||||||
|
|
||||||
|
UBGraphicsMediaItem *mediaItem = dynamic_cast<UBGraphicsMediaItem*>(mDelegated); |
||||||
|
if (mediaItem) |
||||||
|
{ |
||||||
|
if (mediaItem->getMediaType() != UBGraphicsMediaItem::mediaType_Audio) |
||||||
|
{ |
||||||
|
mToolBarItem->setPos(0, delegated()->boundingRect().height()-mToolBarItem->rect().height()*AntiScaleRatio); |
||||||
|
mToolBarItem->setScale(AntiScaleRatio); |
||||||
|
QRectF toolBarRect = mToolBarItem->rect(); |
||||||
|
toolBarRect.setWidth(delegated()->boundingRect().width()/AntiScaleRatio); |
||||||
|
mToolBarItem->setRect(toolBarRect);
|
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
mToolBarItem->setPos(0, 0); |
||||||
|
mToolBarItem->show(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
int mediaItemWidth = mToolBarItem->boundingRect().width(); |
||||||
|
foreach (DelegateButton* button, mButtons) |
||||||
|
{ |
||||||
|
if (button->getSection() == Qt::TitleBarArea) |
||||||
|
mediaItemWidth -= button->boundingRect().width(); |
||||||
|
} |
||||||
|
|
||||||
|
QRectF mediaItemRect = mMediaControl->rect(); |
||||||
|
mediaItemRect.setWidth(mediaItemWidth); |
||||||
|
mediaItemRect.setHeight(mToolBarItem->boundingRect().height()); |
||||||
|
mMediaControl->setRect(mediaItemRect); |
||||||
|
|
||||||
|
mToolBarItem->positionHandles(); |
||||||
|
mMediaControl->positionHandles();
|
||||||
|
|
||||||
|
if (mediaItem) |
||||||
|
{ |
||||||
|
if (mediaItem->getMediaType() == UBGraphicsMediaItem::mediaType_Audio) |
||||||
|
{ |
||||||
|
mToolBarItem->show(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void UBGraphicsMediaItemDelegate::remove(bool canUndo) |
||||||
|
{ |
||||||
|
if (delegated() && delegated()->mediaObject()) |
||||||
|
delegated()->mediaObject()->stop(); |
||||||
|
|
||||||
|
QGraphicsScene* scene = mDelegated->scene(); |
||||||
|
|
||||||
|
scene->removeItem(mMediaControl); |
||||||
|
|
||||||
|
UBGraphicsItemDelegate::remove(canUndo); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
void UBGraphicsMediaItemDelegate::toggleMute() |
||||||
|
{ |
||||||
|
if (delegated()->isMuted()) |
||||||
|
mMuteButton->setFileName(":/images/soundOff.svg"); |
||||||
|
else |
||||||
|
mMuteButton->setFileName(":/images/soundOn.svg"); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
UBGraphicsMediaItem* UBGraphicsMediaItemDelegate::delegated() |
||||||
|
{ |
||||||
|
return dynamic_cast<UBGraphicsMediaItem*>(mDelegated); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
void UBGraphicsMediaItemDelegate::togglePlayPause() |
||||||
|
{ |
||||||
|
if (delegated() && delegated()->mediaObject()) { |
||||||
|
|
||||||
|
Phonon::MediaObject* media = delegated()->mediaObject(); |
||||||
|
if (media->state() == Phonon::StoppedState) { |
||||||
|
media->play(); |
||||||
|
} else if (media->state() == Phonon::PlayingState) { |
||||||
|
if (media->remainingTime() <= 0) { |
||||||
|
media->stop(); |
||||||
|
media->play(); |
||||||
|
} else { |
||||||
|
media->pause(); |
||||||
|
if(delegated()->scene()) |
||||||
|
delegated()->scene()->setModified(true); |
||||||
|
} |
||||||
|
} else if (media->state() == Phonon::PausedState) { |
||||||
|
if (media->remainingTime() <= 0) { |
||||||
|
media->stop(); |
||||||
|
} |
||||||
|
media->play(); |
||||||
|
} else if ( media->state() == Phonon::LoadingState ) { |
||||||
|
delegated()->mediaObject()->setCurrentSource(delegated()->mediaFileUrl()); |
||||||
|
media->play(); |
||||||
|
} else if (media->state() == Phonon::ErrorState){ |
||||||
|
qDebug() << "Error appeared." << media->errorString(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void UBGraphicsMediaItemDelegate::mediaStateChanged ( Phonon::State newstate, Phonon::State oldstate ) |
||||||
|
{ |
||||||
|
Q_UNUSED(newstate); |
||||||
|
Q_UNUSED(oldstate); |
||||||
|
updatePlayPauseState(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
void UBGraphicsMediaItemDelegate::updatePlayPauseState() |
||||||
|
{ |
||||||
|
Phonon::MediaObject* media = delegated()->mediaObject(); |
||||||
|
|
||||||
|
if (media->state() == Phonon::PlayingState) |
||||||
|
mPlayPauseButton->setFileName(":/images/pause.svg"); |
||||||
|
else |
||||||
|
mPlayPauseButton->setFileName(":/images/play.svg"); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
void UBGraphicsMediaItemDelegate::updateTicker(qint64 time) |
||||||
|
{ |
||||||
|
Phonon::MediaObject* media = delegated()->mediaObject(); |
||||||
|
mMediaControl->totalTimeChanged(media->totalTime()); |
||||||
|
mMediaControl->updateTicker(time); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
void UBGraphicsMediaItemDelegate::totalTimeChanged(qint64 newTotalTime) |
||||||
|
{ |
||||||
|
mMediaControl->totalTimeChanged(newTotalTime); |
||||||
|
} |
@ -0,0 +1,70 @@ |
|||||||
|
/*
|
||||||
|
* 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 3 of the License, or |
||||||
|
* (at your option) any later version. |
||||||
|
* |
||||||
|
* This program is distributed in the hope that it will be useful, |
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
* GNU General Public License for more details. |
||||||
|
* |
||||||
|
* You should have received a copy of the GNU General Public License |
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef UBGRAPHICSMEDIAITEMDELEGATE_H_ |
||||||
|
#define UBGRAPHICSMEDIAITEMDELEGATE_H_ |
||||||
|
|
||||||
|
#include <QtGui> |
||||||
|
#include <phonon/MediaObject> |
||||||
|
|
||||||
|
#include "core/UB.h" |
||||||
|
#include "UBGraphicsItemDelegate.h" |
||||||
|
|
||||||
|
class QGraphicsSceneMouseEvent; |
||||||
|
class QGraphicsItem; |
||||||
|
|
||||||
|
class UBGraphicsMediaItemDelegate : public UBGraphicsItemDelegate |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
|
||||||
|
public: |
||||||
|
UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pDelegated, Phonon::MediaObject* pMedia, QObject * parent = 0); |
||||||
|
virtual ~UBGraphicsMediaItemDelegate(); |
||||||
|
|
||||||
|
virtual void positionHandles(); |
||||||
|
|
||||||
|
bool mousePressEvent(QGraphicsSceneMouseEvent *event); |
||||||
|
|
||||||
|
public slots: |
||||||
|
|
||||||
|
void toggleMute(); |
||||||
|
void updateTicker(qint64 time); |
||||||
|
|
||||||
|
protected slots: |
||||||
|
|
||||||
|
virtual void remove(bool canUndo = true); |
||||||
|
|
||||||
|
void togglePlayPause(); |
||||||
|
|
||||||
|
void mediaStateChanged ( Phonon::State newstate, Phonon::State oldstate ); |
||||||
|
|
||||||
|
void updatePlayPauseState(); |
||||||
|
|
||||||
|
void totalTimeChanged(qint64 newTotalTime); |
||||||
|
|
||||||
|
protected: |
||||||
|
virtual void buildButtons(); |
||||||
|
|
||||||
|
UBGraphicsMediaItem* delegated(); |
||||||
|
|
||||||
|
DelegateButton* mPlayPauseButton; |
||||||
|
DelegateButton* mStopButton; |
||||||
|
DelegateButton* mMuteButton; |
||||||
|
DelegateMediaControl *mMediaControl; |
||||||
|
|
||||||
|
Phonon::MediaObject* mMedia; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif /* UBGRAPHICSMEDIAITEMDELEGATE_H_ */ |
@ -1,141 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 3 of the License, or |
|
||||||
* (at your option) any later version. |
|
||||||
* |
|
||||||
* This program is distributed in the hope that it will be useful, |
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
* GNU General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU General Public License |
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include "UBGraphicsVideoItem.h" |
|
||||||
#include "UBGraphicsVideoItemDelegate.h" |
|
||||||
#include "UBGraphicsDelegateFrame.h" |
|
||||||
|
|
||||||
#include "core/memcheck.h" |
|
||||||
|
|
||||||
UBGraphicsVideoItem::UBGraphicsVideoItem(const QUrl& pVideoFileUrl, QGraphicsItem *parent): |
|
||||||
UBGraphicsMediaItem(pVideoFileUrl,parent) |
|
||||||
, mShouldMove(false) |
|
||||||
{ |
|
||||||
update(); |
|
||||||
|
|
||||||
mMediaObject = new Phonon::MediaObject(this); |
|
||||||
mVideoWidget = new Phonon::VideoWidget(); // owned and destructed by the scene ...
|
|
||||||
|
|
||||||
Phonon::createPath(mMediaObject, mVideoWidget); |
|
||||||
|
|
||||||
mAudioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this); |
|
||||||
Phonon::createPath(mMediaObject, mAudioOutput); |
|
||||||
|
|
||||||
/*
|
|
||||||
* The VideoVidget should recover the size from the original movie, but this is not always true expecially on |
|
||||||
* windows and linux os. I don't know why? |
|
||||||
* In this case the wiget size is equal to QSize(1,1). |
|
||||||
*/ |
|
||||||
|
|
||||||
if(mVideoWidget->sizeHint() == QSize(1,1)){ |
|
||||||
mVideoWidget->resize(320,240); |
|
||||||
} |
|
||||||
|
|
||||||
setWidget(mVideoWidget); |
|
||||||
|
|
||||||
UBGraphicsVideoItemDelegate* delegate = new UBGraphicsVideoItemDelegate(this, mMediaObject); |
|
||||||
delegate->init(); |
|
||||||
setDelegate(delegate); |
|
||||||
|
|
||||||
mDelegate->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); |
|
||||||
|
|
||||||
setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly
|
|
||||||
|
|
||||||
connect(mDelegate, SIGNAL(showOnDisplayChanged(bool)), this, SLOT(showOnDisplayChanged(bool))); |
|
||||||
connect(mMediaObject, SIGNAL(hasVideoChanged(bool)), this, SLOT(hasVideoChanged(bool))); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
UBGraphicsVideoItem::~UBGraphicsVideoItem() |
|
||||||
{ |
|
||||||
//NOOP
|
|
||||||
} |
|
||||||
|
|
||||||
UBItem* UBGraphicsVideoItem::deepCopy() const |
|
||||||
{ |
|
||||||
QUrl videoUrl = this->mediaFileUrl(); |
|
||||||
|
|
||||||
UBGraphicsVideoItem *copy = new UBGraphicsVideoItem(videoUrl, parentItem()); |
|
||||||
|
|
||||||
copy->setPos(this->pos()); |
|
||||||
copy->setTransform(this->transform()); |
|
||||||
copy->setFlag(QGraphicsItem::ItemIsMovable, true); |
|
||||||
copy->setFlag(QGraphicsItem::ItemIsSelectable, true); |
|
||||||
copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); |
|
||||||
copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); |
|
||||||
copy->setUuid(this->uuid()); // this is OK as long as Videos are imutable
|
|
||||||
copy->setSourceUrl(this->sourceUrl()); |
|
||||||
|
|
||||||
copy->resize(this->size()); |
|
||||||
|
|
||||||
// TODO UB 4.7 complete all members
|
|
||||||
|
|
||||||
return copy; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void UBGraphicsVideoItem::hasVideoChanged(bool hasVideo) |
|
||||||
{ |
|
||||||
if(hasVideo && mMediaObject->isSeekable()) |
|
||||||
{ |
|
||||||
hasMediaChanged(hasVideo); |
|
||||||
UBGraphicsVideoItemDelegate *vid = dynamic_cast<UBGraphicsVideoItemDelegate *>(mDelegate); |
|
||||||
if (vid) |
|
||||||
vid->updateTicker(initialPos()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void UBGraphicsVideoItem::showOnDisplayChanged(bool shown) |
|
||||||
{ |
|
||||||
UBGraphicsMediaItem::showOnDisplayChanged(shown); |
|
||||||
UBGraphicsVideoItemDelegate *vid = dynamic_cast<UBGraphicsVideoItemDelegate*>(mDelegate); |
|
||||||
|
|
||||||
if (vid) |
|
||||||
vid->toggleMute(); |
|
||||||
} |
|
||||||
|
|
||||||
void UBGraphicsVideoItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
||||||
{ |
|
||||||
mShouldMove = (event->buttons() & Qt::LeftButton); |
|
||||||
mMousePressPos = event->scenePos(); |
|
||||||
mMouseMovePos = mMousePressPos; |
|
||||||
|
|
||||||
event->accept(); |
|
||||||
setSelected(true); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
void UBGraphicsVideoItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
||||||
{ |
|
||||||
if(mShouldMove && (event->buttons() & Qt::LeftButton)) |
|
||||||
{ |
|
||||||
QPointF offset = event->scenePos() - mMousePressPos; |
|
||||||
|
|
||||||
if (offset.toPoint().manhattanLength() > QApplication::startDragDistance()) |
|
||||||
{ |
|
||||||
QPointF mouseMovePos = mapFromScene(mMouseMovePos); |
|
||||||
QPointF eventPos = mapFromScene( event->scenePos()); |
|
||||||
|
|
||||||
QPointF translation = eventPos - mouseMovePos; |
|
||||||
translate(translation.x(), translation.y()); |
|
||||||
} |
|
||||||
|
|
||||||
mMouseMovePos = event->scenePos(); |
|
||||||
} |
|
||||||
|
|
||||||
event->accept(); |
|
||||||
|
|
||||||
} |
|
@ -1,75 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 3 of the License, or |
|
||||||
* (at your option) any later version. |
|
||||||
* |
|
||||||
* This program is distributed in the hope that it will be useful, |
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
* GNU General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU General Public License |
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/ |
|
||||||
#ifndef UBGRAPHICSVIDEOITEM_H |
|
||||||
#define UBGRAPHICSVIDEOITEM_H |
|
||||||
|
|
||||||
#include <phonon/VideoWidget> |
|
||||||
#include "UBGraphicsMediaItem.h" |
|
||||||
#include "core/UB.h" |
|
||||||
#include "core/UBApplication.h" |
|
||||||
#include "board/UBBoardController.h" |
|
||||||
|
|
||||||
class UBGraphicsVideoItem : public UBGraphicsMediaItem |
|
||||||
{ |
|
||||||
Q_OBJECT; |
|
||||||
|
|
||||||
public: |
|
||||||
UBGraphicsVideoItem(const QUrl& pMediaFileUrl, QGraphicsItem *parent = 0); |
|
||||||
~UBGraphicsVideoItem(); |
|
||||||
|
|
||||||
enum { Type = UBGraphicsItemType::VideoItemType }; |
|
||||||
|
|
||||||
virtual int type() const |
|
||||||
{ |
|
||||||
return Type; |
|
||||||
} |
|
||||||
|
|
||||||
virtual UBItem* deepCopy() const; |
|
||||||
|
|
||||||
Phonon::VideoWidget* videoWidget() const |
|
||||||
{ |
|
||||||
return mVideoWidget; |
|
||||||
} |
|
||||||
virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;} |
|
||||||
|
|
||||||
virtual void clearSource() |
|
||||||
{ |
|
||||||
UBGraphicsMediaItem::clearSource(); |
|
||||||
} |
|
||||||
|
|
||||||
public slots: |
|
||||||
void hasVideoChanged(bool hasVideo); |
|
||||||
|
|
||||||
|
|
||||||
protected: |
|
||||||
|
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
||||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); |
|
||||||
|
|
||||||
Phonon::VideoWidget *mVideoWidget; |
|
||||||
|
|
||||||
private slots: |
|
||||||
void showOnDisplayChanged(bool shown); |
|
||||||
|
|
||||||
|
|
||||||
private: |
|
||||||
bool mShouldMove; |
|
||||||
QPointF mMousePressPos; |
|
||||||
QPointF mMouseMovePos; |
|
||||||
|
|
||||||
|
|
||||||
}; |
|
||||||
|
|
||||||
#endif // UBGRAPHICSVIDEOITEM_H
|
|
@ -1,351 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 3 of the License, or |
|
||||||
* (at your option) any later version. |
|
||||||
* |
|
||||||
* This program is distributed in the hope that it will be useful, |
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
* GNU General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU General Public License |
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/ |
|
||||||
|
|
||||||
#include <QtGui> |
|
||||||
#include <QtSvg> |
|
||||||
|
|
||||||
#include "UBGraphicsVideoItemDelegate.h" |
|
||||||
|
|
||||||
#include "UBGraphicsScene.h" |
|
||||||
|
|
||||||
#include "core/UBSettings.h" |
|
||||||
#include "core/UBApplication.h" |
|
||||||
#include "core/UBApplicationController.h" |
|
||||||
#include "core/UBDisplayManager.h" |
|
||||||
|
|
||||||
#include "domain/UBGraphicsVideoItem.h" |
|
||||||
#include "domain/UBGraphicsDelegateFrame.h" |
|
||||||
|
|
||||||
#include "core/memcheck.h" |
|
||||||
|
|
||||||
UBGraphicsVideoItemDelegate::UBGraphicsVideoItemDelegate(UBGraphicsVideoItem* pDelegated, Phonon::MediaObject* pMedia, QObject * parent) |
|
||||||
: UBGraphicsItemDelegate(pDelegated, parent, true, false) |
|
||||||
, mMedia(pMedia) |
|
||||||
{ |
|
||||||
// NOOP
|
|
||||||
} |
|
||||||
|
|
||||||
void UBGraphicsVideoItemDelegate::buildButtons() |
|
||||||
{ |
|
||||||
mPlayPauseButton = new DelegateButton(":/images/play.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); |
|
||||||
|
|
||||||
mStopButton = new DelegateButton(":/images/stop.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); |
|
||||||
|
|
||||||
mVideoControl = new DelegateVideoControl(delegated(), mToolBarItem); |
|
||||||
UBGraphicsItem::assignZValue(mVideoControl, delegated()->zValue()); |
|
||||||
mVideoControl->setFlag(QGraphicsItem::ItemIsSelectable, true); |
|
||||||
|
|
||||||
if (delegated()->isMuted()) |
|
||||||
mMuteButton = new DelegateButton(":/images/soundOff.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); |
|
||||||
else |
|
||||||
mMuteButton = new DelegateButton(":/images/soundOn.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); |
|
||||||
|
|
||||||
connect(mPlayPauseButton, SIGNAL(clicked(bool)), this, SLOT(togglePlayPause())); |
|
||||||
connect(mStopButton, SIGNAL(clicked(bool)), mMedia, SLOT(stop())); |
|
||||||
connect(mMuteButton, SIGNAL(clicked(bool)), delegated(), SLOT(toggleMute())); |
|
||||||
connect(mMuteButton, SIGNAL(clicked(bool)), this, SLOT(toggleMute())); |
|
||||||
|
|
||||||
mButtons << mPlayPauseButton << mStopButton << mMuteButton; |
|
||||||
|
|
||||||
QList<QGraphicsItem*> itemsOnToolBar; |
|
||||||
itemsOnToolBar << mPlayPauseButton << mStopButton << mVideoControl << mMuteButton; |
|
||||||
mToolBarItem->setItemsOnToolBar(itemsOnToolBar); |
|
||||||
|
|
||||||
mMedia->setTickInterval(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(tick(qint64)), this, SLOT(updateTicker(qint64))); |
|
||||||
connect(mMedia, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64))); |
|
||||||
|
|
||||||
mToolBarItem->setVisibleOnBoard(true); |
|
||||||
mToolBarItem->setShifting(false); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
UBGraphicsVideoItemDelegate::~UBGraphicsVideoItemDelegate() |
|
||||||
{ |
|
||||||
//NOOP
|
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
void UBGraphicsVideoItemDelegate::positionHandles() |
|
||||||
{ |
|
||||||
UBGraphicsItemDelegate::positionHandles(); |
|
||||||
|
|
||||||
if (mDelegated->isSelected()) |
|
||||||
{ |
|
||||||
qreal scaledFrameWidth = mFrameWidth * mAntiScaleRatio; |
|
||||||
|
|
||||||
int offset = 0; |
|
||||||
foreach (DelegateButton* button, mButtons) |
|
||||||
{ |
|
||||||
if (button->getSection() == Qt::TitleBarArea) |
|
||||||
offset += button->boundingRect().width() * mAntiScaleRatio; |
|
||||||
} |
|
||||||
|
|
||||||
mVideoControl->setRect(mVideoControl->rect().x() |
|
||||||
, scaledFrameWidth/6 - 0.5 |
|
||||||
, (mToolBarItem->rect().width() - 35 - offset) / mAntiScaleRatio
|
|
||||||
, (2 * scaledFrameWidth) / mAntiScaleRatio); |
|
||||||
|
|
||||||
offset += (mVideoControl->rect().width() + 5) * mAntiScaleRatio; |
|
||||||
mMuteButton->setPos(offset, 0); |
|
||||||
|
|
||||||
if (!mVideoControl->scene()) |
|
||||||
{ |
|
||||||
mVideoControl->setParentItem(mToolBarItem);//update parent for the case the item has been previously removed from scene
|
|
||||||
mDelegated->scene()->addItem(mVideoControl); |
|
||||||
} |
|
||||||
|
|
||||||
mVideoControl->setAntiScale(mAntiScaleRatio); |
|
||||||
mVideoControl->setZValue(delegated()->zValue()); |
|
||||||
mVideoControl->show(); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
mVideoControl->hide(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
void UBGraphicsVideoItemDelegate::remove(bool canUndo) |
|
||||||
{ |
|
||||||
if (delegated() && delegated()->mediaObject()) |
|
||||||
delegated()->mediaObject()->stop(); |
|
||||||
|
|
||||||
QGraphicsScene* scene = mDelegated->scene(); |
|
||||||
|
|
||||||
scene->removeItem(mVideoControl); |
|
||||||
|
|
||||||
UBGraphicsItemDelegate::remove(canUndo); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
void UBGraphicsVideoItemDelegate::toggleMute() |
|
||||||
{ |
|
||||||
if (delegated()->isMuted()) |
|
||||||
mMuteButton->setFileName(":/images/soundOff.svg"); |
|
||||||
else |
|
||||||
mMuteButton->setFileName(":/images/soundOn.svg"); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
UBGraphicsVideoItem* UBGraphicsVideoItemDelegate::delegated() |
|
||||||
{ |
|
||||||
return static_cast<UBGraphicsVideoItem*>(mDelegated); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
void UBGraphicsVideoItemDelegate::togglePlayPause() |
|
||||||
{ |
|
||||||
if (delegated() && delegated()->mediaObject()) { |
|
||||||
|
|
||||||
Phonon::MediaObject* media = delegated()->mediaObject(); |
|
||||||
if (media->state() == Phonon::StoppedState) { |
|
||||||
media->play(); |
|
||||||
} else if (media->state() == Phonon::PlayingState) { |
|
||||||
if (media->remainingTime() <= 0) { |
|
||||||
media->stop(); |
|
||||||
media->play(); |
|
||||||
} else { |
|
||||||
media->pause(); |
|
||||||
if(delegated()->scene()) |
|
||||||
delegated()->scene()->setModified(true); |
|
||||||
} |
|
||||||
} else if (media->state() == Phonon::PausedState) { |
|
||||||
if (media->remainingTime() <= 0) { |
|
||||||
media->stop(); |
|
||||||
} |
|
||||||
media->play(); |
|
||||||
} else if ( media->state() == Phonon::LoadingState ) { |
|
||||||
delegated()->mediaObject()->setCurrentSource(delegated()->mediaFileUrl()); |
|
||||||
media->play(); |
|
||||||
} else if (media->state() == Phonon::ErrorState){ |
|
||||||
qDebug() << "Error appeared." << media->errorString(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void UBGraphicsVideoItemDelegate::mediaStateChanged ( Phonon::State newstate, Phonon::State oldstate ) |
|
||||||
{ |
|
||||||
Q_UNUSED(newstate); |
|
||||||
Q_UNUSED(oldstate); |
|
||||||
updatePlayPauseState(); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
void UBGraphicsVideoItemDelegate::updatePlayPauseState() |
|
||||||
{ |
|
||||||
Phonon::MediaObject* media = delegated()->mediaObject(); |
|
||||||
|
|
||||||
if (media->state() == Phonon::PlayingState) |
|
||||||
mPlayPauseButton->setFileName(":/images/pause.svg"); |
|
||||||
else |
|
||||||
mPlayPauseButton->setFileName(":/images/play.svg"); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
void UBGraphicsVideoItemDelegate::updateTicker(qint64 time) |
|
||||||
{ |
|
||||||
Phonon::MediaObject* media = delegated()->mediaObject(); |
|
||||||
mVideoControl->totalTimeChanged(media->totalTime()); |
|
||||||
|
|
||||||
mVideoControl->updateTicker(time); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
void UBGraphicsVideoItemDelegate::totalTimeChanged(qint64 newTotalTime) |
|
||||||
{ |
|
||||||
mVideoControl->totalTimeChanged(newTotalTime); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
DelegateVideoControl::DelegateVideoControl(UBGraphicsVideoItem* pDelegated, QGraphicsItem * parent) |
|
||||||
: QGraphicsRectItem(parent) |
|
||||||
, mDelegate(pDelegated) |
|
||||||
, mDisplayCurrentTime(false) |
|
||||||
, mAntiScale(1.0) |
|
||||||
, mCurrentTimeInMs(0) |
|
||||||
, mTotalTimeInMs(0) |
|
||||||
, mStartWidth(200) |
|
||||||
{ |
|
||||||
setAcceptedMouseButtons(Qt::LeftButton); |
|
||||||
|
|
||||||
setBrush(QBrush(Qt::white)); |
|
||||||
setPen(Qt::NoPen); |
|
||||||
setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); |
|
||||||
|
|
||||||
QRectF rect = this->rect(); |
|
||||||
rect.setWidth(mStartWidth); |
|
||||||
this->setRect(rect); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
void DelegateVideoControl::paint(QPainter *painter, |
|
||||||
const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
||||||
{ |
|
||||||
Q_UNUSED(option); |
|
||||||
Q_UNUSED(widget); |
|
||||||
|
|
||||||
painter->fillPath(shape(), brush()); |
|
||||||
|
|
||||||
qreal frameWidth = rect().height() / 2; |
|
||||||
int position = frameWidth; |
|
||||||
|
|
||||||
if (mTotalTimeInMs > 0) |
|
||||||
{ |
|
||||||
position = frameWidth + (rect().width() - (2 * frameWidth)) / mTotalTimeInMs * mCurrentTimeInMs; |
|
||||||
} |
|
||||||
|
|
||||||
int radius = rect().height() / 6; |
|
||||||
QRectF r(rect().x() + position - radius, rect().y() + (rect().height() / 4) - radius, radius * 2, radius * 2); |
|
||||||
|
|
||||||
painter->setBrush(UBSettings::documentViewLightColor); |
|
||||||
painter->drawEllipse(r); |
|
||||||
|
|
||||||
if(mDisplayCurrentTime) |
|
||||||
{ |
|
||||||
painter->setBrush(UBSettings::paletteColor); |
|
||||||
painter->setPen(QPen(Qt::NoPen)); |
|
||||||
mBalloon.setRect(rect().x() + position - frameWidth, rect().y() - (frameWidth * 1.2), 2 * frameWidth, frameWidth); |
|
||||||
painter->drawRoundedRect(mBalloon, frameWidth/2, frameWidth/2); |
|
||||||
|
|
||||||
QTime t; |
|
||||||
t = t.addMSecs(mCurrentTimeInMs < 0 ? 0 : mCurrentTimeInMs); |
|
||||||
QFont f = painter->font(); |
|
||||||
f.setPointSizeF(f.pointSizeF() * mAntiScale); |
|
||||||
painter->setFont(f); |
|
||||||
painter->setPen(Qt::white); |
|
||||||
painter->drawText(mBalloon, Qt::AlignCenter, t.toString("m:ss")); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
QPainterPath DelegateVideoControl::shape() const |
|
||||||
{ |
|
||||||
QPainterPath path; |
|
||||||
QRectF r = rect().adjusted(0,0,0,- rect().height() / 2); |
|
||||||
path.addRoundedRect(r, rect().height() / 4, rect().height() / 4); |
|
||||||
return path; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
void DelegateVideoControl::updateTicker(qint64 time ) |
|
||||||
{ |
|
||||||
mCurrentTimeInMs = time; |
|
||||||
update(); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
void DelegateVideoControl::totalTimeChanged(qint64 newTotalTime) |
|
||||||
{ |
|
||||||
mTotalTimeInMs = newTotalTime; |
|
||||||
update(); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
void DelegateVideoControl::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
||||||
{ |
|
||||||
mDisplayCurrentTime = true; |
|
||||||
seekToMousePos(event->pos()); |
|
||||||
update(); |
|
||||||
event->accept(); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
void DelegateVideoControl::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
||||||
{ |
|
||||||
if (shape().contains(event->pos() - QPointF(mBalloon.width()/2,0))
|
|
||||||
&& shape().contains(event->pos() + QPointF(mBalloon.width()/2,0))) |
|
||||||
{
|
|
||||||
seekToMousePos(event->pos()); |
|
||||||
update(); |
|
||||||
event->accept(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
void DelegateVideoControl::seekToMousePos(QPointF mousePos) |
|
||||||
{ |
|
||||||
qreal minX, length; |
|
||||||
qreal frameWidth = rect().height() / 2; |
|
||||||
|
|
||||||
minX = rect().x() + frameWidth; |
|
||||||
length = rect().width() - (2 * frameWidth); |
|
||||||
|
|
||||||
qreal mouseX = mousePos.x(); |
|
||||||
|
|
||||||
if (mTotalTimeInMs > 0 && length > 0 && mDelegate |
|
||||||
&& mDelegate->mediaObject() && mDelegate->mediaObject()->isSeekable()) |
|
||||||
{ |
|
||||||
qint64 tickPos = mTotalTimeInMs / length * (mouseX - minX); |
|
||||||
mDelegate->mediaObject()->seek(tickPos); |
|
||||||
|
|
||||||
//OSX is a bit lazy
|
|
||||||
updateTicker(tickPos); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void DelegateVideoControl::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
||||||
{ |
|
||||||
mDisplayCurrentTime = false; |
|
||||||
update(); |
|
||||||
event->accept(); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in new issue