Commit fe9affee authored by Craig Watson's avatar Craig Watson

Overhaul of UBGraphicsMediaItem class

- Removed inheritance of UBGraphicsProxyWidget; cleaned up related code
- Added two children classes: UBGraphicsVideoItem and
UBGraphicsAudioItem. UBGraphicsMediaItem is now an abstract class.
- Better encapsulation; the Scene and other external classes no longer
access the mediaObject directly

There is now less distinction between audio and video items to outside
code: apart from the UBSvgSubsetAdaptor, there is no need to know
whether a media item holds a video or audio file. Creation is handled
through the static function `UBGraphicsMediaItem::createMediaItem(URL,
parent)`
parent 3879e9a3
...@@ -661,9 +661,8 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() ...@@ -661,9 +661,8 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
audioItem->show(); audioItem->show();
//force start to load the video and display the first frame audioItem->play();
audioItem->mediaObject()->play(); audioItem->pause();
audioItem->mediaObject()->pause();
} }
} }
else if (mXmlReader.name() == "video") else if (mXmlReader.name() == "video")
...@@ -676,16 +675,12 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() ...@@ -676,16 +675,12 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
videoItem->setFlag(QGraphicsItem::ItemIsSelectable, true); videoItem->setFlag(QGraphicsItem::ItemIsSelectable, true);
mScene->addItem(videoItem); mScene->addItem(videoItem);
mScene->addItem(videoItem->videoItem());
// Update the child QGraphicsVideoItem's transformation matrix
videoItem->setMatrix(videoItem->matrix());
videoItem->show(); videoItem->show();
//force start to load the video and display the first frame //force start to load the video and display the first frame
videoItem->mediaObject()->play(); videoItem->play();
videoItem->mediaObject()->pause(); videoItem->pause();
} }
} }
else if (mXmlReader.name() == "text")//This is for backward compatibility with proto text field prior to version 4.3 else if (mXmlReader.name() == "text")//This is for backward compatibility with proto text field prior to version 4.3
...@@ -1210,14 +1205,17 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex) ...@@ -1210,14 +1205,17 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex)
continue; continue;
} }
UBGraphicsMediaItem *mediaItem = qgraphicsitem_cast<UBGraphicsMediaItem*> (item); UBGraphicsVideoItem * videoItem = qgraphicsitem_cast<UBGraphicsVideoItem*> (item);
if (mediaItem && mediaItem->isVisible()) if (videoItem && videoItem->isVisible()) {
{ videoItemToLinkedVideo(videoItem);
if (UBGraphicsMediaItem::mediaType_Video == mediaItem->getMediaType()) continue;
videoItemToLinkedVideo(mediaItem); }
else
audioItemToLinkedAudio(mediaItem); UBGraphicsAudioItem * audioItem = qgraphicsitem_cast<UBGraphicsAudioItem*> (item);
if (audioItem && audioItem->isVisible()) {
audioItemToLinkedAudio(audioItem);
continue; continue;
} }
...@@ -2019,15 +2017,16 @@ UBGraphicsPDFItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::pdfItemFromPDF() ...@@ -2019,15 +2017,16 @@ UBGraphicsPDFItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::pdfItemFromPDF()
return pdfItem; return pdfItem;
} }
void UBSvgSubsetAdaptor::UBSvgSubsetWriter::audioItemToLinkedAudio(UBGraphicsMediaItem* audioItem) void UBSvgSubsetAdaptor::UBSvgSubsetWriter::audioItemToLinkedAudio(UBGraphicsAudioItem *audioItem)
{ {
mXmlWriter.writeStartElement("audio"); mXmlWriter.writeStartElement("audio");
graphicsItemToSvg(audioItem); graphicsItemToSvg(audioItem);
if (audioItem->mediaObject()->state() == QMediaPlayer::PausedState && (audioItem->mediaObject()->duration() - audioItem->mediaObject()->position()) > 0) if (audioItem->playerState() == QMediaPlayer::PausedState &&
(audioItem->mediaDuration() - audioItem->mediaPosition()) > 0)
{ {
qint64 pos = audioItem->mediaObject()->position(); qint64 pos = audioItem->mediaPosition();
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "position", QString("%1").arg(pos)); mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "position", QString("%1").arg(pos));
} }
...@@ -2038,7 +2037,7 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::audioItemToLinkedAudio(UBGraphicsMed ...@@ -2038,7 +2037,7 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::audioItemToLinkedAudio(UBGraphicsMed
} }
void UBSvgSubsetAdaptor::UBSvgSubsetWriter::videoItemToLinkedVideo(UBGraphicsMediaItem* videoItem) void UBSvgSubsetAdaptor::UBSvgSubsetWriter::videoItemToLinkedVideo(UBGraphicsVideoItem* videoItem)
{ {
/* w3c sample /* w3c sample
* *
...@@ -2051,9 +2050,10 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::videoItemToLinkedVideo(UBGraphicsMed ...@@ -2051,9 +2050,10 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::videoItemToLinkedVideo(UBGraphicsMed
graphicsItemToSvg(videoItem); graphicsItemToSvg(videoItem);
if (videoItem->mediaObject()->state() == QMediaPlayer::PausedState && (videoItem->mediaObject()->duration() - videoItem->mediaObject()->position()) > 0) if (videoItem->playerState() == QMediaPlayer::PausedState &&
(videoItem->mediaDuration() - videoItem->mediaPosition()) > 0)
{ {
qint64 pos = videoItem->mediaObject()->position(); qint64 pos = videoItem->mediaPosition();
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "position", QString("%1").arg(pos)); mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "position", QString("%1").arg(pos));
} }
...@@ -2083,7 +2083,7 @@ UBGraphicsMediaItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::audioItemFromSvg() ...@@ -2083,7 +2083,7 @@ UBGraphicsMediaItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::audioItemFromSvg()
href = mDocumentPath + "/" + href.right(href.length() - indexOfAudioDirectory); href = mDocumentPath + "/" + href.right(href.length() - indexOfAudioDirectory);
} }
UBGraphicsMediaItem* audioItem = new UBGraphicsMediaItem(QUrl::fromLocalFile(href)); UBGraphicsMediaItem* audioItem = UBGraphicsMediaItem::createMediaItem(QUrl::fromLocalFile(href));
if(audioItem) if(audioItem)
audioItem->connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), audioItem, SLOT(activeSceneChanged())); audioItem->connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), audioItem, SLOT(activeSceneChanged()));
...@@ -2118,7 +2118,7 @@ UBGraphicsMediaItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::videoItemFromSvg() ...@@ -2118,7 +2118,7 @@ UBGraphicsMediaItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::videoItemFromSvg()
href = mDocumentPath + "/" + href.right(href.length() - indexOfAudioDirectory); href = mDocumentPath + "/" + href.right(href.length() - indexOfAudioDirectory);
} }
UBGraphicsMediaItem* videoItem = new UBGraphicsMediaItem(QUrl::fromLocalFile(href)); UBGraphicsMediaItem* videoItem = UBGraphicsMediaItem::createMediaItem(QUrl::fromLocalFile(href));
if(videoItem){ if(videoItem){
videoItem->connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), videoItem, SLOT(activeSceneChanged())); videoItem->connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), videoItem, SLOT(activeSceneChanged()));
} }
......
...@@ -40,6 +40,8 @@ class UBGraphicsPixmapItem; ...@@ -40,6 +40,8 @@ class UBGraphicsPixmapItem;
class UBGraphicsPDFItem; class UBGraphicsPDFItem;
class UBGraphicsWidgetItem; class UBGraphicsWidgetItem;
class UBGraphicsMediaItem; class UBGraphicsMediaItem;
class UBGraphicsVideoItem;
class UBGraphicsAudioItem;
class UBGraphicsAppleWidgetItem; class UBGraphicsAppleWidgetItem;
class UBGraphicsW3CWidgetItem; class UBGraphicsW3CWidgetItem;
class UBGraphicsTextItem; class UBGraphicsTextItem;
...@@ -232,8 +234,8 @@ class UBSvgSubsetAdaptor ...@@ -232,8 +234,8 @@ class UBSvgSubsetAdaptor
void pixmapItemToLinkedImage(UBGraphicsPixmapItem *pixmapItem); void pixmapItemToLinkedImage(UBGraphicsPixmapItem *pixmapItem);
void svgItemToLinkedSvg(UBGraphicsSvgItem *svgItem); void svgItemToLinkedSvg(UBGraphicsSvgItem *svgItem);
void pdfItemToLinkedPDF(UBGraphicsPDFItem *pdfItem); void pdfItemToLinkedPDF(UBGraphicsPDFItem *pdfItem);
void videoItemToLinkedVideo(UBGraphicsMediaItem *videoItem); void videoItemToLinkedVideo(UBGraphicsVideoItem *videoItem);
void audioItemToLinkedAudio(UBGraphicsMediaItem *audioItem); void audioItemToLinkedAudio(UBGraphicsAudioItem *audioItem);
void graphicsItemToSvg(QGraphicsItem *item); void graphicsItemToSvg(QGraphicsItem *item);
void graphicsAppleWidgetToSvg(UBGraphicsAppleWidgetItem *item); void graphicsAppleWidgetToSvg(UBGraphicsAppleWidgetItem *item);
void graphicsW3CWidgetToSvg(UBGraphicsW3CWidgetItem *item); void graphicsW3CWidgetToSvg(UBGraphicsW3CWidgetItem *item);
......
...@@ -51,8 +51,6 @@ class UBVersion; ...@@ -51,8 +51,6 @@ class UBVersion;
class UBSoftwareUpdate; class UBSoftwareUpdate;
class UBSoftwareUpdateDialog; class UBSoftwareUpdateDialog;
class UBGraphicsMediaItem; class UBGraphicsMediaItem;
class UBGraphicsVideoItem;
class UBGraphicsAudioItem;
class UBGraphicsWidgetItem; class UBGraphicsWidgetItem;
class UBBoardPaletteManager; class UBBoardPaletteManager;
class UBItem; class UBItem;
......
...@@ -566,7 +566,7 @@ void UBPersistenceManager::duplicateDocumentScene(UBDocumentProxy* proxy, int in ...@@ -566,7 +566,7 @@ void UBPersistenceManager::duplicateDocumentScene(UBDocumentProxy* proxy, int in
QString fileName = QFileInfo(source).completeBaseName(); QString fileName = QFileInfo(source).completeBaseName();
destination = destination.replace(fileName,newUuid.toString()); destination = destination.replace(fileName,newUuid.toString());
QFile::copy(source,destination); QFile::copy(source,destination);
mediaItem->mediaFileUrl(QUrl::fromLocalFile(destination)); mediaItem->setMediaFileUrl(QUrl::fromLocalFile(destination));
continue; continue;
} }
......
...@@ -1439,10 +1439,10 @@ void DelegateMediaControl::seekToMousePos(QPointF mousePos) ...@@ -1439,10 +1439,10 @@ void DelegateMediaControl::seekToMousePos(QPointF mousePos)
mouseX = mSeecArea.width() - mSeecArea.height()/2; mouseX = mSeecArea.width() - mSeecArea.height()/2;
if (mTotalTimeInMs > 0 && length > 0 && mDelegate if (mTotalTimeInMs > 0 && length > 0 && mDelegate
&& mDelegate->mediaObject() && mDelegate->mediaObject()->isSeekable()) && mDelegate->isMediaSeekable())
{ {
qint64 tickPos = (mTotalTimeInMs/length)* (mouseX - minX); qint64 tickPos = (mTotalTimeInMs/length)* (mouseX - minX);
mDelegate->mediaObject()->setPosition(tickPos); mDelegate->setMediaPos(tickPos);
//OSX is a bit lazy //OSX is a bit lazy
updateTicker(tickPos); updateTicker(tickPos);
......
This diff is collapsed.
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
class QGraphicsVideoItem; class QGraphicsVideoItem;
class UBGraphicsMediaItem : public UBGraphicsProxyWidget class UBGraphicsMediaItem : public QObject, public UBItem, public UBGraphicsItem, public QGraphicsRectItem, public UBResizableGraphicsItem
{ {
Q_OBJECT Q_OBJECT
...@@ -55,9 +55,6 @@ public: ...@@ -55,9 +55,6 @@ public:
mediaType_Audio mediaType_Audio
} mediaType; } mediaType;
UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsItem *parent = 0);
~UBGraphicsMediaItem();
enum { Type = UBGraphicsItemType::MediaItemType }; enum { Type = UBGraphicsItemType::MediaItemType };
virtual int type() const virtual int type() const
...@@ -65,48 +62,46 @@ public: ...@@ -65,48 +62,46 @@ public:
return Type; return Type;
} }
virtual QUrl mediaFileUrl() const static UBGraphicsMediaItem* createMediaItem(const QUrl& pMediaFileUrl, QGraphicsItem* parent = 0);
{
return mMediaFileUrl;
}
virtual void mediaFileUrl(QUrl url){mMediaFileUrl=url;} UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsItem* parent = 0);
~UBGraphicsMediaItem();
QMediaPlayer* mediaObject() const
{
return mMediaObject;
}
void setInitialPos(qint64 p) { // Getters
mInitialPos = p;
}
qint64 initialPos() {
return mInitialPos;
}
bool isMuted() const virtual mediaType getMediaType() const = 0;
{
return mMuted;
}
QGraphicsVideoItem * videoItem() const virtual UBGraphicsScene* scene();
{ bool hasLinkedImage() const { return haveLinkedImage; }
return mVideoItem; virtual QUrl mediaFileUrl() const { return mMediaFileUrl; }
} bool isMuted() const { return mMuted; }
qint64 initialPos() const { return mInitialPos; }
bool hasLinkedImage(){return haveLinkedImage;} bool isMediaSeekable() const;
qint64 mediaDuration() const;
qint64 mediaPosition() const;
mediaType getMediaType() { return mMediaType; } QMediaPlayer::State playerState() const;
virtual UBGraphicsScene* scene(); QRectF boundingRect() const;
virtual UBItem* deepCopy() const; QSizeF size() const { return rect().size(); }
// Setters
virtual void setMediaFileUrl(QUrl url);
void setInitialPos(qint64 p);
void setMediaPos(qint64 p);
virtual void setSourceUrl(const QUrl &pSourceUrl);
void setSelected(bool selected);
void setMinimumSize(const QSize& size);
virtual void copyItemParameters(UBItem *copy) const; virtual void copyItemParameters(UBItem *copy) const;
virtual void setSourceUrl(const QUrl &pSourceUrl); virtual void setSize(int width, int height);
void resize(qreal w, qreal h) { setSize(w, h); }
void setSelected(bool selected); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
public slots: public slots:
...@@ -116,23 +111,22 @@ public slots: ...@@ -116,23 +111,22 @@ public slots:
void activeSceneChanged(); void activeSceneChanged();
void hasMediaChanged(bool hasMedia); void hasMediaChanged(bool hasMedia);
void showOnDisplayChanged(bool shown); void showOnDisplayChanged(bool shown);
virtual void resize(qreal w, qreal h);
virtual void resize(const QSizeF & pSize); virtual void play();
virtual void pause();
virtual void stop();
virtual void togglePlayPause();
protected: protected:
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void clearSource(); virtual void clearSource();
QMediaPlayer *mMediaObject; QMediaPlayer *mMediaObject;
QWidget *mDummyVideoWidget;
QGraphicsVideoItem *mVideoItem;
QWidget *mAudioWidget; QSize mMinimumSize;
private:
bool mMuted; bool mMuted;
bool mMutedByUserAction; bool mMutedByUserAction;
...@@ -141,8 +135,6 @@ private: ...@@ -141,8 +135,6 @@ private:
QUrl mMediaFileUrl; QUrl mMediaFileUrl;
QString mMediaSource; QString mMediaSource;
mediaType mMediaType;
bool mShouldMove; bool mShouldMove;
QPointF mMousePressPos; QPointF mMousePressPos;
QPointF mMouseMovePos; QPointF mMouseMovePos;
...@@ -152,4 +144,40 @@ private: ...@@ -152,4 +144,40 @@ private:
qint64 mInitialPos; qint64 mInitialPos;
}; };
class UBGraphicsAudioItem: public UBGraphicsMediaItem
{
Q_OBJECT
public:
UBGraphicsAudioItem(const QUrl& pMediaFileUrl, QGraphicsItem *parent = 0);
mediaType getMediaType() const { return mediaType_Audio; }
virtual UBItem* deepCopy() const;
};
class UBGraphicsVideoItem: public UBGraphicsMediaItem
{
Q_OBJECT
public:
UBGraphicsVideoItem(const QUrl& pMediaFileUrl, QGraphicsItem *parent = 0);
mediaType getMediaType() const { return mediaType_Video; }
void setSize(int width, int height);
virtual UBItem* deepCopy() const;
public slots:
void videoSizeChanged(QSizeF newSize);
protected:
QGraphicsVideoItem *mVideoItem;
};
#endif // UBGRAPHICSMEDIAITEM_H #endif // UBGRAPHICSMEDIAITEM_H
...@@ -43,42 +43,17 @@ ...@@ -43,42 +43,17 @@
#include "core/memcheck.h" #include "core/memcheck.h"
UBGraphicsMediaItemDelegate::UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pDelegated, QMediaPlayer* pMedia, QObject * parent) UBGraphicsMediaItemDelegate::UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pDelegated, QObject * parent)
: UBGraphicsItemDelegate(pDelegated, parent, GF_COMMON : UBGraphicsItemDelegate(pDelegated, parent, GF_COMMON
| GF_RESPECT_RATIO | GF_RESPECT_RATIO
| GF_TOOLBAR_USED) | GF_TOOLBAR_USED)
, mPlayPauseButton(NULL) , mPlayPauseButton(NULL)
, mMedia(pMedia)
, mToolBarShowTimer(NULL) , mToolBarShowTimer(NULL)
, m_iToolBarShowingInterval(5000) , m_iToolBarShowingInterval(5000)
{ {
QPalette palette; QPalette palette;
palette.setBrush ( QPalette::Light, Qt::darkGray ); palette.setBrush ( QPalette::Light, Qt::darkGray );
mMedia->setNotifyInterval(50);
connect(mMedia, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
this, SLOT(mediaStatusChanged(QMediaPlayer::MediaStatus)));
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())
{
mToolBarShowTimer = new QTimer();
connect(mToolBarShowTimer, SIGNAL(timeout()), this, SLOT(hideToolBar()));
mToolBarShowTimer->setInterval(m_iToolBarShowingInterval);
}
if (delegated()->isMuted()) if (delegated()->isMuted())
delegated()->setMute(true); delegated()->setMute(true);
...@@ -110,7 +85,7 @@ void UBGraphicsMediaItemDelegate::buildButtons() ...@@ -110,7 +85,7 @@ void UBGraphicsMediaItemDelegate::buildButtons()
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)), connect(mStopButton, SIGNAL(clicked(bool)),
mMedia, SLOT(stop())); delegated(), SLOT(stop()));
mMediaControl = new DelegateMediaControl(delegated(), mToolBarItem); mMediaControl = new DelegateMediaControl(delegated(), mToolBarItem);
mMediaControl->setFlag(QGraphicsItem::ItemIsSelectable, true); mMediaControl->setFlag(QGraphicsItem::ItemIsSelectable, true);
...@@ -132,8 +107,16 @@ void UBGraphicsMediaItemDelegate::buildButtons() ...@@ -132,8 +107,16 @@ void UBGraphicsMediaItemDelegate::buildButtons()
mToolBarItem->setVisibleOnBoard(true); mToolBarItem->setVisibleOnBoard(true);
mToolBarItem->setShifting(false); mToolBarItem->setShifting(false);
if (mToolBarShowTimer) if (!mToolBarShowTimer) {
{
if (delegated()->hasLinkedImage()) {
mToolBarShowTimer = new QTimer();
connect(mToolBarShowTimer, SIGNAL(timeout()), this, SLOT(hideToolBar()));
mToolBarShowTimer->setInterval(m_iToolBarShowingInterval);
}
}
else {
connect(mPlayPauseButton, SIGNAL(clicked(bool)), connect(mPlayPauseButton, SIGNAL(clicked(bool)),
mToolBarShowTimer, SLOT(start())); mToolBarShowTimer, SLOT(start()));
...@@ -195,13 +178,15 @@ void UBGraphicsMediaItemDelegate::positionHandles() ...@@ -195,13 +178,15 @@ void UBGraphicsMediaItemDelegate::positionHandles()
void UBGraphicsMediaItemDelegate::remove(bool canUndo) void UBGraphicsMediaItemDelegate::remove(bool canUndo)
{ {
if (delegated() && delegated()->mediaObject()) if (delegated())
delegated()->mediaObject()->stop(); delegated()->stop();
/*
if (delegated()->videoItem()) { if (delegated()->videoItem()) {
UBGraphicsScene* scene = dynamic_cast<UBGraphicsScene*>(mDelegated->scene()); UBGraphicsScene* scene = dynamic_cast<UBGraphicsScene*>(mDelegated->scene());
scene->removeItem(delegated()->videoItem()); scene->removeItem(delegated()->videoItem());
} }
*/
UBGraphicsItemDelegate::remove(canUndo); UBGraphicsItemDelegate::remove(canUndo);
} }
...@@ -223,43 +208,8 @@ UBGraphicsMediaItem* UBGraphicsMediaItemDelegate::delegated() ...@@ -223,43 +208,8 @@ UBGraphicsMediaItem* UBGraphicsMediaItemDelegate::delegated()
void UBGraphicsMediaItemDelegate::togglePlayPause() void UBGraphicsMediaItemDelegate::togglePlayPause()
{ {
if (delegated() && delegated()->mediaObject()) { if (delegated())
delegated()->togglePlayPause();
QMediaPlayer * media = delegated()->mediaObject();
if (media->state() == QMediaPlayer::StoppedState)
media->play();
else if (media->state() == QMediaPlayer::PlayingState) {
if ((media->duration() - media->position()) <= 0) {
media->stop();
media->play();
}
else {
media->pause();
if(delegated()->scene())
delegated()->scene()->setModified(true);
}
}
else if (media->state() == QMediaPlayer::PausedState) {
if ((media->duration() - media->position()) <= 0)
media->stop();
media->play();
}
else if ( media->mediaStatus() == QMediaPlayer::LoadingMedia) {
delegated()->mediaObject()->setMedia(delegated()->mediaFileUrl());
media->play();
}
if (media->error())
qDebug() << "Error appeared." << media->errorString();
}
} }
void UBGraphicsMediaItemDelegate::mediaStatusChanged(QMediaPlayer::MediaStatus status) void UBGraphicsMediaItemDelegate::mediaStatusChanged(QMediaPlayer::MediaStatus status)
...@@ -268,7 +218,7 @@ void UBGraphicsMediaItemDelegate::mediaStatusChanged(QMediaPlayer::MediaStatus s ...@@ -268,7 +218,7 @@ void UBGraphicsMediaItemDelegate::mediaStatusChanged(QMediaPlayer::MediaStatus s
// StalledMedia, BufferingMedia, BufferedMedia, EndOfMedia, InvalidMedia // StalledMedia, BufferingMedia, BufferedMedia, EndOfMedia, InvalidMedia
if (status == QMediaPlayer::LoadedMedia) if (status == QMediaPlayer::LoadedMedia)
mMediaControl->totalTimeChanged(delegated()->mediaObject()->duration()); mMediaControl->totalTimeChanged(delegated()->mediaDuration());
// in most cases, the only necessary action is to update the play/pause state // in most cases, the only necessary action is to update the play/pause state
updatePlayPauseState(); updatePlayPauseState();
...@@ -288,15 +238,13 @@ void UBGraphicsMediaItemDelegate::mediaError(QMediaPlayer::Error error) ...@@ -288,15 +238,13 @@ void UBGraphicsMediaItemDelegate::mediaError(QMediaPlayer::Error error)
// ServiceMissingError // ServiceMissingError
Q_UNUSED(error); Q_UNUSED(error);
qDebug() << "Error appeared." << mMedia->errorString(); qDebug() << "Error appeared.";// << mMedia->errorString();
} }
void UBGraphicsMediaItemDelegate::updatePlayPauseState() void UBGraphicsMediaItemDelegate::updatePlayPauseState()
{ {
QMediaPlayer * media = delegated()->mediaObject(); if (delegated()->playerState() == QMediaPlayer::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");
...@@ -305,8 +253,10 @@ void UBGraphicsMediaItemDelegate::updatePlayPauseState() ...@@ -305,8 +253,10 @@ void UBGraphicsMediaItemDelegate::updatePlayPauseState()
void UBGraphicsMediaItemDelegate::updateTicker(qint64 time) void UBGraphicsMediaItemDelegate::updateTicker(qint64 time)
{ {
QMediaPlayer* media = delegated()->mediaObject(); // TODO: duration() getter for UBGMediaItem
mMediaControl->totalTimeChanged(media->duration()); // make sure that all delegate()->mediaObject() calls are removed. 'tis dirty.
mMediaControl->totalTimeChanged(delegated()->mediaDuration());
mMediaControl->updateTicker(time); mMediaControl->updateTicker(time);
} }
...@@ -320,7 +270,7 @@ void UBGraphicsMediaItemDelegate::showHide(bool show) ...@@ -320,7 +270,7 @@ void UBGraphicsMediaItemDelegate::showHide(bool show)
{ {
QVariant showFlag = QVariant(show ? UBItemLayerType::Object : UBItemLayerType::Control); QVariant showFlag = QVariant(show ? UBItemLayerType::Object : UBItemLayerType::Control);
showHideRecurs(showFlag, mDelegated); showHideRecurs(showFlag, mDelegated);
showHideRecurs(showFlag, delegated()->videoItem()); // TODO: call showHideRecurs on the videoItem too (from UBGMI?)
mDelegated->update(); mDelegated->update();
emit showOnDisplayChanged(show); emit showOnDisplayChanged(show);
......
...@@ -43,7 +43,7 @@ class UBGraphicsMediaItemDelegate : public UBGraphicsItemDelegate ...@@ -43,7 +43,7 @@ class UBGraphicsMediaItemDelegate : public UBGraphicsItemDelegate
Q_OBJECT Q_OBJECT
public: public:
UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pDelegated, QMediaPlayer* pMedia, QObject * parent = 0); UBGraphicsMediaItemDelegate(UBGraphicsMediaItem* pDelegated, QObject * parent = 0);
virtual ~UBGraphicsMediaItemDelegate(); virtual ~UBGraphicsMediaItemDelegate();
virtual void positionHandles(); virtual void positionHandles();
...@@ -56,6 +56,10 @@ class UBGraphicsMediaItemDelegate : public UBGraphicsItemDelegate ...@@ -56,6 +56,10 @@ class UBGraphicsMediaItemDelegate : public UBGraphicsItemDelegate
void updateTicker(qint64 time); void updateTicker(qint64 time);
virtual void showHide(bool show); virtual void showHide(bool show);
void mediaStatusChanged(QMediaPlayer::MediaStatus status);
void mediaStateChanged(QMediaPlayer::State state);
void mediaError(QMediaPlayer::Error error);
protected slots: protected slots:
virtual void remove(bool canUndo = true); virtual void remove(bool canUndo = true);
...@@ -68,11 +72,6 @@ class UBGraphicsMediaItemDelegate : public UBGraphicsItemDelegate ...@@ -68,11 +72,6 @@ class UBGraphicsMediaItemDelegate : public UBGraphicsItemDelegate
void hideToolBar(); void hideToolBar();
void mediaStatusChanged(QMediaPlayer::MediaStatus status);
void mediaStateChanged(QMediaPlayer::State state);
void mediaError(QMediaPlayer::Error error);
protected: protected:
virtual void buildButtons(); virtual void buildButtons();
...@@ -84,8 +83,6 @@ class UBGraphicsMediaItemDelegate : public UBGraphicsItemDelegate ...@@ -84,8 +83,6 @@ class UBGraphicsMediaItemDelegate : public UBGraphicsItemDelegate
DelegateButton* mMuteButton; DelegateButton* mMuteButton;
DelegateMediaControl* mMediaControl; DelegateMediaControl* mMediaControl;
QMediaPlayer* mMedia; // mMedia belongs to the associated UBGraphicsMediaItem (mDelegated)
QTimer* mToolBarShowTimer; QTimer* mToolBarShowTimer;
int m_iToolBarShowingInterval; int m_iToolBarShowingInterval;
}; };
......
...@@ -1349,10 +1349,10 @@ UBGraphicsMediaItem* UBGraphicsScene::addMedia(const QUrl& pMediaFileUrl, bool s ...@@ -1349,10 +1349,10 @@ UBGraphicsMediaItem* UBGraphicsScene::addMedia(const QUrl& pMediaFileUrl, bool s
if (!QFile::exists(pMediaFileUrl.toString())) if (!QFile::exists(pMediaFileUrl.toString()))
return NULL; return NULL;
UBGraphicsMediaItem* mediaItem = new UBGraphicsMediaItem(pMediaFileUrl); UBGraphicsMediaItem * mediaItem = UBGraphicsMediaItem::createMediaItem(pMediaFileUrl);
if(mediaItem){
if(mediaItem)
connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), mediaItem, SLOT(activeSceneChanged())); connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), mediaItem, SLOT(activeSceneChanged()));
}
mediaItem->setPos(pPos); mediaItem->setPos(pPos);
...@@ -1361,11 +1361,6 @@ UBGraphicsMediaItem* UBGraphicsScene::addMedia(const QUrl& pMediaFileUrl, bool s ...@@ -1361,11 +1361,6 @@ UBGraphicsMediaItem* UBGraphicsScene::addMedia(const QUrl& pMediaFileUrl, bool s
addItem(mediaItem); addItem(mediaItem);
if (mediaItem->videoItem()) {
addItem(mediaItem->videoItem());
mediaItem->videoItem()->show();
}
mediaItem->show(); mediaItem->show();
if (mUndoRedoStackEnabled) { //should be deleted after scene own undo stack implemented if (mUndoRedoStackEnabled) { //should be deleted after scene own undo stack implemented
...@@ -1373,12 +1368,11 @@ UBGraphicsMediaItem* UBGraphicsScene::addMedia(const QUrl& pMediaFileUrl, bool s ...@@ -1373,12 +1368,11 @@ UBGraphicsMediaItem* UBGraphicsScene::addMedia(const QUrl& pMediaFileUrl, bool s
UBApplication::undoStack->push(uc); UBApplication::undoStack->push(uc);
} }
mediaItem->mediaObject()->play(); mediaItem->play();
if (!shouldPlayAsap) if (!shouldPlayAsap) {
{ mediaItem->pause();
mediaItem->mediaObject()->pause(); mediaItem->setMediaPos(0);
mediaItem->mediaObject()->setPosition(0);
} }
setDocumentUpdated(); setDocumentUpdated();
......
...@@ -40,8 +40,6 @@ class UBGraphicsProxyWidget; ...@@ -40,8 +40,6 @@ class UBGraphicsProxyWidget;
class UBGraphicsSvgItem; class UBGraphicsSvgItem;
class UBGraphicsPolygonItem; class UBGraphicsPolygonItem;
class UBGraphicsMediaItem; class UBGraphicsMediaItem;
class UBGraphicsVideoItem;
class UBGraphicsAudioItem;
class UBGraphicsWidgetItem; class UBGraphicsWidgetItem;
class UBGraphicsW3CWidgetItem; class UBGraphicsW3CWidgetItem;
class UBGraphicsAppleWidgetItem; class UBGraphicsAppleWidgetItem;
......
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