diff --git a/src/customWidgets/UBMediaWidget.cpp b/src/customWidgets/UBMediaWidget.cpp index 9dc0a8d0..31523a90 100644 --- a/src/customWidgets/UBMediaWidget.cpp +++ b/src/customWidgets/UBMediaWidget.cpp @@ -12,7 +12,8 @@ UBMediaWidget::UBMediaWidget(eMediaType type, QWidget *parent, const char *name) , mAutoUpdate(false) , mGeneratingThumbnail(false) , mBorder(5) - , mpVideoContainer(NULL) + , mpMediaContainer(NULL) + , mpCover(NULL) { setObjectName(name); @@ -50,6 +51,7 @@ UBMediaWidget::~UBMediaWidget() DELETEPTR(mpAudioOutput); DELETEPTR(mpVideoWidget); DELETEPTR(mpMediaObject); + DELETEPTR(mpCover); } void UBMediaWidget::setFile(const QString &filePath) @@ -72,30 +74,41 @@ eMediaType UBMediaWidget::mediaType() void UBMediaWidget::createMediaPlayer() { + mpMediaContainer = new QWidget(this); + mpMediaContainer->setObjectName("UBMediaVideoContainer"); + mpMediaContainer->setLayout(&mMediaLayout); + if(eMediaType_Video == mType){ + mMediaLayout.setContentsMargins(10, 10, 25, 10); mpVideoWidget = new Phonon::VideoWidget(this); - mpVideoContainer = new QWidget(this); - mpVideoContainer->setObjectName("UBMediaVideoContainer"); - mVideoLayout.setContentsMargins(10, 10, 25, 10); - mpVideoContainer->setLayout(&mVideoLayout); - mVideoLayout.addWidget(mpVideoWidget, 1); + mMediaLayout.addStretch(1); + mMediaLayout.addWidget(mpVideoWidget, 0); + mMediaLayout.addStretch(1); Phonon::createPath(mpMediaObject, mpVideoWidget); adaptSizeToVideo(); - mLayout.addWidget(mpVideoContainer, 1); mpAudioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this); Phonon::createPath(mpMediaObject, mpAudioOutput); }else if(eMediaType_Audio == mType){ + 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); mpAudioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); Phonon::createPath(mpMediaObject, mpAudioOutput); } + mLayout.addWidget(mpMediaContainer, 1); mLayout.addLayout(&mSeekerLayout, 0); } void UBMediaWidget::adaptSizeToVideo() { - if(NULL != mpVideoContainer){ - int origW = mpVideoContainer->width(); - int origH = mpVideoContainer->height(); + if(NULL != mpMediaContainer){ + int origW = mpMediaContainer->width(); + int origH = mpMediaContainer->height(); int newW = width(); float scaleFactor = (float)origW/(float)newW; int newH = origH/scaleFactor; @@ -179,6 +192,13 @@ void UBMediaWidget::resizeEvent(QResizeEvent* ev) Q_UNUSED(ev); } +void UBMediaWidget::setAudioCover(const QString &coverPath) +{ + if(NULL != mpCover){ + mpCover->setPixmap(QPixmap(coverPath)); + } +} + // ----------------------------------------------------------------------------------------------------------- UBMediaButton::UBMediaButton(QWidget *parent, const char *name):QLabel(parent) , mPressed(false) diff --git a/src/customWidgets/UBMediaWidget.h b/src/customWidgets/UBMediaWidget.h index c835ab91..3f4be679 100644 --- a/src/customWidgets/UBMediaWidget.h +++ b/src/customWidgets/UBMediaWidget.h @@ -49,6 +49,7 @@ public: void setFile(const QString& filePath); eMediaType mediaType(); int border(); + void setAudioCover(const QString& coverPath); protected: void resizeEvent(QResizeEvent* ev); @@ -78,8 +79,9 @@ private: bool mAutoUpdate; bool mGeneratingThumbnail; int mBorder; - QWidget* mpVideoContainer; - QVBoxLayout mVideoLayout; + QWidget* mpMediaContainer; + QHBoxLayout mMediaLayout; + QLabel* mpCover; }; #endif // UBMEDIAWIDGET_H diff --git a/src/gui/UBTeacherBarWidget.cpp b/src/gui/UBTeacherBarWidget.cpp index 0f439cf7..c3e31d21 100644 --- a/src/gui/UBTeacherBarWidget.cpp +++ b/src/gui/UBTeacherBarWidget.cpp @@ -123,6 +123,7 @@ UBTeacherBarWidget::UBTeacherBarWidget(QWidget *parent, const char *name):UBDock mpMediaLabel = new QLabel(tr("Medias"), mpContainer); mpLayout->addWidget(mpMediaLabel, 0); mpMediaContainer = new UBTBMediaContainer(this); + mpMediaContainer->setEmptyText(tr("Drop media here")); mpLayout->addWidget(mpMediaContainer, 1); // Links @@ -587,128 +588,6 @@ void UBTeacherStudentAction::setText(const QString& text) } } -// --------------------------------------------------------------------------------------------- -UBTeacherBarDropMediaZone::UBTeacherBarDropMediaZone(QWidget *parent, const char *name):QWidget(parent) - -{ - setObjectName(name); - setAcceptDrops(true); - mWidget = new UBWidgetList(parent); - mWidget->setEmptyText(tr("Drag media here ...")); - mLayout.addWidget(mWidget); - setLayout(&mLayout); - // The next line is disgusting. This is a quickfix that must be reworked later - setContentsMargins(-9, -9, -9, -9); -} - -UBTeacherBarDropMediaZone::~UBTeacherBarDropMediaZone() -{ - cleanMedias(); - if(mWidget){ - delete mWidget; - mWidget = NULL; - } -} - -void UBTeacherBarDropMediaZone::cleanMedias() -{ - foreach(QWidget* eachWidget,mWidgetList){ - mWidget->removeWidget(eachWidget); - delete eachWidget; - } - - mWidgetList.clear(); - - mMediaList.clear(); -} - -bool UBTeacherBarDropMediaZone::empty() -{ - return mWidget->empty(); -} - -void UBTeacherBarDropMediaZone::dragEnterEvent(QDragEnterEvent *pEvent) -{ - pEvent->acceptProposedAction(); -} - -void UBTeacherBarDropMediaZone::dragLeaveEvent(QDragLeaveEvent *pEvent) -{ - pEvent->accept(); -} - - -void UBTeacherBarDropMediaZone::addMedia(QString pMediaPath) -{ - if(!pMediaPath.isEmpty()) - mMediaList.append(pMediaPath); - else - qWarning() << __FUNCTION__ << "empty path"; - - QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(pMediaPath); - if(mimeType.contains("image")){ - QPixmap pix = QPixmap(pMediaPath); - QLabel* label = new QLabel(); - label->setPixmap(pix); - label->setScaledContents(true); - mWidget->addWidget(label); - mWidgetList << label; - } - else if(mimeType.contains("video") || mimeType.contains("audio")){ - UBMediaPlayer* mediaPlayer = new UBMediaPlayer(); - mediaPlayer->setFile(pMediaPath); - mWidget->addWidget(mediaPlayer); - mWidgetList << mediaPlayer; - } - else{ - qWarning() << "pMediaPath" << pMediaPath; - qWarning() << "bad idea to come here"; - } - -} - -void UBTeacherBarDropMediaZone::reloadMedia(QStringList pList) -{ - cleanMedias(); - foreach(QString eachString, pList){ - addMedia(eachString); - } -} - -void UBTeacherBarDropMediaZone::dropEvent(QDropEvent *pEvent) -{ - QPixmap pixFromDropEvent; - QString mimeType; - QString resourcePath; - if(pEvent->mimeData()->hasText()){ - qDebug() << "pEvent->mimeData()->hasText()" << pEvent->mimeData()->text(); - resourcePath = pEvent->mimeData()->text(); - } - else if(pEvent->mimeData()->hasUrls()){ - qDebug() << "pEvent->mimeData()->hasUrls()" << pEvent->mimeData()->urls().at(0); - resourcePath = pEvent->mimeData()->urls().at(0).toLocalFile(); - } - else if(pEvent->mimeData()->hasImage()){ - qDebug() << "pEvent->mimeData()->hasImage()"; - pixFromDropEvent.loadFromData(pEvent->mimeData()->imageData().toByteArray()); - if(!pixFromDropEvent.isNull()) - mimeType = "image"; - } - - if (mimeType.isEmpty() && resourcePath.isEmpty()){ - pEvent->acceptProposedAction(); - return; - } - if(!resourcePath.isEmpty()) - addMedia(resourcePath); - pEvent->acceptProposedAction(); -} - -void UBTeacherBarDropMediaZone::dragMoveEvent(QDragMoveEvent *pEvent) -{ - pEvent->acceptProposedAction(); -} - // --------------------------------------------------------------------------------------------- UBUrlWidget::UBUrlWidget(QWidget *parent, const char *name):QWidget(parent) , mpLayout(NULL) @@ -997,9 +876,7 @@ UBTeacherBarPreviewMedia::UBTeacherBarPreviewMedia(QWidget* parent, const char* { setObjectName(name); mWidget = new UBWidgetList(parent); -// mWidget->setEmptyText(tr("No media found")); mLayout.addWidget(mWidget); -// mWidget->setStyleSheet(QString("background-color: red;")); setLayout(&mLayout); mWidgetList.clear(); } @@ -1235,7 +1112,6 @@ QWidget* UBTBMediaContainer::generateMediaWidget(const QString& url) pW = label; } else if(mimeType.contains("video") || mimeType.contains("audio")){ - //UBMediaPlayer* mediaPlayer = new UBMediaPlayer(); UBMediaWidget* mediaPlayer = new UBMediaWidget(mimeType.contains("audio")?eMediaType_Audio:eMediaType_Video); mediaPlayer->setFile(url); pW = mediaPlayer; diff --git a/src/gui/UBTeacherBarWidget.h b/src/gui/UBTeacherBarWidget.h index f4341a14..7bb80512 100644 --- a/src/gui/UBTeacherBarWidget.h +++ b/src/gui/UBTeacherBarWidget.h @@ -52,36 +52,6 @@ private: QComboBox* mpCombo; }; - -class UBTeacherBarDropMediaZone : public QWidget -{ - Q_OBJECT - -public: - UBTeacherBarDropMediaZone(QWidget* parent=0, const char* name="UBTeacherBarDropMediaZone"); - ~UBTeacherBarDropMediaZone(); - QStringList mediaList() {return mMediaList;} - void reloadMedia(QStringList pList); - void cleanMedias(); - bool empty(); - -private: - void addMedia(QString pMediaPath); - QStringList mMediaList; - QListmWidgetList; - UBWidgetList* mWidget; - QVBoxLayout mLayout; - - -protected: - void dragEnterEvent(QDragEnterEvent* pEvent); - void dropEvent(QDropEvent *pEvent); - void dragMoveEvent(QDragMoveEvent* pEvent); - void dragLeaveEvent(QDragLeaveEvent* pEvent); -}; - - - class UBTeacherBarPreviewMedia : public QWidget { Q_OBJECT @@ -176,7 +146,6 @@ private: UBActionPreview* mpTmpAction; }; - class UBTBMediaContainer : public UBWidgetList , public IDropable {