void UBGraphicsMediaItem::setSourceUrl(const QUrl &pSourceUrl) { UBAudioPresentationWidget* pAudioWidget = dynamic_cast<UBAudioPresentationWidget*>(mAudioWidget); if (pAudioWidget) { pAudioWidget->setTitle(UBFileSystemUtils::lastPathComponent(pSourceUrl.toString())); } UBItem::setSourceUrl(pSourceUrl); }
UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsItem *parent) : UBGraphicsProxyWidget(parent) , mVideoWidget(NULL) , mAudioWidget(NULL) , mMuted(sIsMutedByDefault) , mMutedByUserAction(sIsMutedByDefault) , mMediaFileUrl(pMediaFileUrl) , mLinkedImage(NULL) , mInitialPos(0) { update(); mMediaObject = new Phonon::MediaObject(this); QString mediaPath = pMediaFileUrl.toString(); if ("" == mediaPath) mediaPath = pMediaFileUrl.toLocalFile(); if (mediaPath.toLower().contains("videos")) { mMediaType = mediaType_Video; mAudioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this); mMediaObject->setTickInterval(50); mVideoWidget = new Phonon::VideoWidget(); // owned and destructed by the scene ... Phonon::createPath(mMediaObject, mVideoWidget); if(mVideoWidget->sizeHint() == QSize(1,1)){ mVideoWidget->resize(320,240); } mVideoWidget->setMinimumSize(140,26); haveLinkedImage = true; } else if (mediaPath.toLower().contains("audios")) { mMediaType = mediaType_Audio; mAudioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); mMediaObject->setTickInterval(1000); mAudioWidget = new UBAudioPresentationWidget(); int borderSize = 0; UBAudioPresentationWidget* pAudioWidget = dynamic_cast<UBAudioPresentationWidget*>(mAudioWidget); if (pAudioWidget) { borderSize = pAudioWidget->borderSize(); } mAudioWidget->resize(320,26+2*borderSize); //3*border size with enabled title mAudioWidget->setMinimumSize(150,26+borderSize); haveLinkedImage = false; } Phonon::createPath(mMediaObject, mAudioOutput); mSource = Phonon::MediaSource(pMediaFileUrl); mMediaObject->setCurrentSource(mSource); // we should create delegate after media objects because delegate uses his properties at creation. setDelegate(new UBGraphicsMediaItemDelegate(this, mMediaObject)); // delegate should be created earler because we setWidget calls resize event for graphics proxy widgt. // resize uses delegate. if (mediaType_Video == mMediaType) setWidget(mVideoWidget); else setWidget(mAudioWidget); // media widget should be created and placed on proxy widget here. Delegate()->init(); if (mediaType_Audio == mMediaType) Delegate()->frame()->setOperationMode(UBGraphicsDelegateFrame::ResizingHorizontally); else Delegate()->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly connect(Delegate(), SIGNAL(showOnDisplayChanged(bool)), this, SLOT(showOnDisplayChanged(bool))); connect(mMediaObject, SIGNAL(hasVideoChanged(bool)), this, SLOT(hasMediaChanged(bool))); }
UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsItem *parent) : UBGraphicsProxyWidget(parent) , mVideoWidget(NULL) , mAudioWidget(NULL) , mMuted(sIsMutedByDefault) , mMutedByUserAction(sIsMutedByDefault) , mMediaFileUrl(pMediaFileUrl) , mLinkedImage(NULL) , mInitialPos(0) { update(); mMediaObject = new Phonon::MediaObject(this); if (pMediaFileUrl.toLocalFile().contains("videos")) { mMediaType = mediaType_Video; mAudioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this); mMediaObject->setTickInterval(50); mVideoWidget = new Phonon::VideoWidget(); // owned and destructed by the scene ... Phonon::createPath(mMediaObject, mVideoWidget); if(mVideoWidget->sizeHint() == QSize(1,1)){ mVideoWidget->resize(320,240); } mVideoWidget->setMinimumSize(140,26); setWidget(mVideoWidget); haveLinkedImage = true; } else if (pMediaFileUrl.toLocalFile().contains("audios")) { mMediaType = mediaType_Audio; mAudioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); mMediaObject->setTickInterval(1000); mAudioWidget = new UBAudioPresentationWidget(); int borderSize = 0; UBAudioPresentationWidget* pAudioWidget = dynamic_cast<UBAudioPresentationWidget*>(mAudioWidget); if (pAudioWidget) { borderSize = pAudioWidget->borderSize(); } mAudioWidget->resize(320,26+3*borderSize); mAudioWidget->setMinimumSize(150,26+borderSize); setWidget(mAudioWidget); haveLinkedImage = false; } Phonon::createPath(mMediaObject, mAudioOutput); mSource = Phonon::MediaSource(pMediaFileUrl); mMediaObject->setCurrentSource(mSource); UBGraphicsMediaItemDelegate* itemDelegate = new UBGraphicsMediaItemDelegate(this, mMediaObject); itemDelegate->init(); setDelegate(itemDelegate); if (mediaType_Audio == mMediaType) mDelegate->frame()->setOperationMode(UBGraphicsDelegateFrame::ResizingHorizontally); else 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(hasMediaChanged(bool))); }