diff --git a/Sankore_3.1.pro b/Sankore_3.1.pro index 5dfa1b33..78afe48f 100644 --- a/Sankore_3.1.pro +++ b/Sankore_3.1.pro @@ -54,6 +54,7 @@ include(src/web/web.pri) include(src/softwareupdate/softwareupdate.pri) include(src/transition/transition.pri) include(src/customWidgets/customWidgets.pri) +include(src/interfaces/interfaces.pri) DEPENDPATH += src/pdf-merger INCLUDEPATH += src/pdf-merger diff --git a/resources/style.qss b/resources/style.qss index e279c597..a3fec87d 100644 --- a/resources/style.qss +++ b/resources/style.qss @@ -5,13 +5,23 @@ QWidget#UBLibNavigatorWidget, QWidget#UBLibItemProperties, QWidget#UBDownloadWidget, QWidget#UBWidgetList, -QWidget#UBTeacherBarDropMediaZone +QWidget#UBTeacherBarDropMediaZone, +QWidget#UBTBMediaContainer { background: #EEEEEE; border-radius: 10px; border: 2px solid #999999; } +QWidget#UBMediaVideoContainer +{ + background: #000000; + border-radius: 10px; + border: 2px solid #999999; + margin: 0px 0px 0px 0px; + padding: 0px 0px 0px 0px; +} + QWidget#UBTeacherBarPreviewWidget { background: #FFFFFF; @@ -26,6 +36,11 @@ QLabel#UBTeacherBarPreviewTitle font-weight:bold; } +QLabel#UBMediaPlayerButton +{ + padding: 0px 0px 0px 0px; +} + QLabel#UBTeacherBarPreviewSubtitle { color: #555555; diff --git a/src/customWidgets/UBGlobals.h b/src/customWidgets/UBGlobals.h new file mode 100644 index 00000000..1707ceac --- /dev/null +++ b/src/customWidgets/UBGlobals.h @@ -0,0 +1,9 @@ +#ifndef UBGLOBALS_H +#define UBGLOBALS_H + +#define DELETEPTR(ptr) if(NULL != ptr){ \ + delete ptr; \ + ptr = NULL; \ + } + +#endif // UBGLOBALS_H diff --git a/src/customWidgets/UBMediaWidget.cpp b/src/customWidgets/UBMediaWidget.cpp new file mode 100644 index 00000000..eabe51bd --- /dev/null +++ b/src/customWidgets/UBMediaWidget.cpp @@ -0,0 +1,209 @@ +#include "core/UBApplication.h" +#include "UBGlobals.h" +#include "UBMediaWidget.h" + +UBMediaWidget::UBMediaWidget(eMediaType type, QWidget *parent, const char *name):QWidget(parent) + , mpMediaObject(NULL) + , mpVideoWidget(NULL) + , mpAudioOutput(NULL) + , mpPlayStopButton(NULL) + , mpPauseButton(NULL) + , mpSlider(NULL) + , mAutoUpdate(false) + , mGeneratingThumbnail(false) + , mBorder(5) + , mpVideoContainer(NULL) +{ + setObjectName(name); + + setAttribute(Qt::WA_StyledBackground, true); + setStyleSheet(UBApplication::globalStyleSheet()); + + mType = type; + setLayout(&mLayout); + + mpPlayStopButton = new UBMediaButton(this); + mpPlayStopButton->setPixmap(QPixmap(":images/play.svg")); + mpPauseButton = new UBMediaButton(this); + mpPauseButton->setPixmap(QPixmap(":images/pause.svg")); + mpPauseButton->setEnabled(false); + mpSlider = new QSlider(this); + mpSlider->setOrientation(Qt::Horizontal); + mpSlider->setMinimum(0); + mpSlider->setMaximum(0); + + mSeekerLayout.addWidget(mpPlayStopButton, 0); + mSeekerLayout.addWidget(mpPauseButton, 0); + mSeekerLayout.addWidget(mpSlider, 1); + + connect(mpPlayStopButton, SIGNAL(clicked()), this, SLOT(onPlayStopClicked())); + connect(mpPauseButton, SIGNAL(clicked()), this, SLOT(onPauseClicked())); + connect(mpSlider, SIGNAL(valueChanged(int)), this, SLOT(onSliderChanged(int))); +} + +UBMediaWidget::~UBMediaWidget() +{ + DELETEPTR(mpSlider); + DELETEPTR(mpPauseButton); + DELETEPTR(mpPlayStopButton); + DELETEPTR(mpAudioOutput); + DELETEPTR(mpVideoWidget); + DELETEPTR(mpVideoContainer); + DELETEPTR(mpMediaObject); +} + +void UBMediaWidget::setFile(const QString &filePath) +{ + Q_ASSERT("" != filePath); + mFilePath = filePath; + mpMediaObject = new Phonon::MediaObject(this); + mpMediaObject->setTickInterval(TICK_INTERVAL); + connect(mpMediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(onStateChanged(Phonon::State,Phonon::State))); + connect(mpMediaObject, SIGNAL(totalTimeChanged(qint64)), this, SLOT(onTotalTimeChanged(qint64))); + connect(mpMediaObject, SIGNAL(tick(qint64)), this, SLOT(onTick(qint64))); + mpMediaObject->setCurrentSource(Phonon::MediaSource(filePath)); + createMediaPlayer(); +} + +eMediaType UBMediaWidget::mediaType() +{ + return mType; +} + +void UBMediaWidget::createMediaPlayer() +{ + if(eMediaType_Video == mType){ + mpVideoWidget = new Phonon::VideoWidget(this); + mpVideoWidget->setStyleSheet(QString("margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px;")); + mpVideoContainer = new QWidget(this); + mpVideoContainer->setObjectName("UBMediaVideoContainer"); + mpVideoContainer->setLayout(&mVideoLayout); + mVideoLayout.addWidget(mpVideoWidget, 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){ + mpAudioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); + Phonon::createPath(mpMediaObject, mpAudioOutput); + } + mLayout.addLayout(&mSeekerLayout, 0); +} + +void UBMediaWidget::adaptSizeToVideo() +{ + if(NULL != mpVideoWidget){ + int origW = mpVideoWidget->width(); + int origH = mpVideoWidget->height(); + int newW = width(); + float scaleFactor = (float)origW/(float)newW; + int newH = origH/scaleFactor; + resize(width(), height() + newH); + } +} + +void UBMediaWidget::onStateChanged(Phonon::State newState, Phonon::State oldState) +{ + if(!mGeneratingThumbnail){ + if(Phonon::LoadingState == oldState && Phonon::StoppedState == newState){ + if(eMediaType_Video == mType){ + // We do that here to generate the thumbnail of the video + mGeneratingThumbnail = true; + mpMediaObject->play(); + mpMediaObject->pause(); + mGeneratingThumbnail = false; + } + }else if(Phonon::PlayingState == oldState && Phonon::PausedState == newState){ + mpPlayStopButton->setPixmap(QPixmap(":images/play.svg")); + mpPauseButton->setEnabled(false); + }else if((Phonon::PausedState == oldState && Phonon::PlayingState == newState) || + (Phonon::StoppedState == oldState && Phonon::PlayingState == newState)){ + mpPlayStopButton->setPixmap(QPixmap(":images/stop.svg")); + mpPauseButton->setEnabled(true); + }else if(Phonon::PlayingState == oldState && Phonon::StoppedState == newState){ + mpPlayStopButton->setPixmap(QPixmap(":images/play.svg")); + mpPauseButton->setEnabled(false); + mpSlider->setValue(0); + } + } +} + +void UBMediaWidget::onTotalTimeChanged(qint64 total) +{ + mpSlider->setMaximum(total); +} + +void UBMediaWidget::onTick(qint64 currentTime) +{ + mAutoUpdate = true; + mpSlider->setValue((int)currentTime); + mAutoUpdate = false; +} + +void UBMediaWidget::onSliderChanged(int value) +{ + if(!mAutoUpdate){ + mpMediaObject->seek(value); + } +} + +void UBMediaWidget::onPlayStopClicked() +{ + switch(mpMediaObject->state()){ + case Phonon::PlayingState: + mpMediaObject->stop(); + break; + + case Phonon::StoppedState: + case Phonon::PausedState: + mpMediaObject->play(); + break; + default: + break; + } +} + +void UBMediaWidget::onPauseClicked() +{ + mpMediaObject->pause(); +} + +int UBMediaWidget::border() +{ + return mBorder; +} + +void UBMediaWidget::resizeEvent(QResizeEvent* ev) +{ + Q_UNUSED(ev); +} + +// ----------------------------------------------------------------------------------------------------------- +UBMediaButton::UBMediaButton(QWidget *parent, const char *name):QLabel(parent) + , mPressed(false) +{ + setObjectName(name); + resize(UBMEDIABUTTON_SIZE, UBMEDIABUTTON_SIZE); + setStyleSheet(QString("padding:0px 0px 0px 0px;")); +} + +UBMediaButton::~UBMediaButton() +{ + +} + +void UBMediaButton::mousePressEvent(QMouseEvent* ev) +{ + Q_UNUSED(ev); + mPressed = true; +} + +void UBMediaButton::mouseReleaseEvent(QMouseEvent* ev) +{ + Q_UNUSED(ev); + if(mPressed){ + mPressed = false; + emit clicked(); + } +} diff --git a/src/customWidgets/UBMediaWidget.h b/src/customWidgets/UBMediaWidget.h new file mode 100644 index 00000000..c835ab91 --- /dev/null +++ b/src/customWidgets/UBMediaWidget.h @@ -0,0 +1,85 @@ +#ifndef UBMEDIAWIDGET_H +#define UBMEDIAWIDGET_H + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "interfaces/IResizeable.h" + +#define UBMEDIABUTTON_SIZE 32 +#define TICK_INTERVAL 1000 + +typedef enum{ + eMediaType_Video, + eMediaType_Audio +}eMediaType; + +class UBMediaButton : public QLabel +{ + Q_OBJECT +public: + UBMediaButton(QWidget* parent=0, const char* name="UBMediaButton"); + ~UBMediaButton(); + +signals: + void clicked(); + +protected: + void mousePressEvent(QMouseEvent* ev); + void mouseReleaseEvent(QMouseEvent* ev); + +private: + bool mPressed; +}; + +class UBMediaWidget : public QWidget +{ + Q_OBJECT +public: + UBMediaWidget(eMediaType type = eMediaType_Video, QWidget* parent=0, const char* name="UBMediaWidget"); + ~UBMediaWidget(); + void setFile(const QString& filePath); + eMediaType mediaType(); + int border(); + +protected: + void resizeEvent(QResizeEvent* ev); + +private slots: + void onPlayStopClicked(); + void onPauseClicked(); + void onStateChanged(Phonon::State newState, Phonon::State oldState); + void onTotalTimeChanged(qint64 total); + void onTick(qint64 currentTime); + void onSliderChanged(int value); + +private: + void createMediaPlayer(); + void adaptSizeToVideo(); + + QString mFilePath; + eMediaType mType; + Phonon::MediaObject* mpMediaObject; + Phonon::VideoWidget* mpVideoWidget; + Phonon::AudioOutput* mpAudioOutput; + QVBoxLayout mLayout; + QHBoxLayout mSeekerLayout; + UBMediaButton* mpPlayStopButton; + UBMediaButton* mpPauseButton; + QSlider* mpSlider; + bool mAutoUpdate; + bool mGeneratingThumbnail; + int mBorder; + QWidget* mpVideoContainer; + QVBoxLayout mVideoLayout; +}; + +#endif // UBMEDIAWIDGET_H diff --git a/src/customWidgets/UBWidgetList.cpp b/src/customWidgets/UBWidgetList.cpp index 7115b14f..b025bfdb 100644 --- a/src/customWidgets/UBWidgetList.cpp +++ b/src/customWidgets/UBWidgetList.cpp @@ -1,4 +1,7 @@ #include +#include + +#include "UBGlobals.h" #include "UBWidgetList.h" UBWidgetList::UBWidgetList(QWidget* parent, eWidgetListOrientation orientation, const char* name):QScrollArea(parent) @@ -20,13 +23,11 @@ UBWidgetList::UBWidgetList(QWidget* parent, eWidgetListOrientation orientation, setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); mpLayout = new QVBoxLayout(mpContainer); - mpContainer->resize(mpContainer->width(), mpContainer->height()); } else{ setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); mpLayout = new QHBoxLayout(mpContainer); - mpContainer->resize(mpContainer->width(), mpContainer->height()); } mpLayout->setContentsMargins(margin(), margin(), margin(), margin()); mpContainer->setLayout(mpLayout); @@ -35,28 +36,22 @@ UBWidgetList::UBWidgetList(QWidget* parent, eWidgetListOrientation orientation, UBWidgetList::~UBWidgetList() { - if(NULL != mpEmptyLabel){ - delete mpEmptyLabel; - mpEmptyLabel = NULL; - } - if(NULL != mpLayout){ - delete mpLayout; - mpLayout = NULL; - } - if(NULL != mpContainer){ - delete mpContainer; - mpContainer = NULL; - } + DELETEPTR(mpEmptyLabel); + DELETEPTR(mpLayout); + DELETEPTR(mpContainer); } void UBWidgetList::addWidget(QWidget *widget) { - if(NULL != mpLayout){ + if(NULL != mpLayout && NULL != widget){ + widget->setParent(mpContainer); mpEmptyLabel->setVisible(false); mWidgetInfo[widget] = widget->size(); - qDebug() << __FUNCTION__ << "widget->size () " << widget->size(); updateView(size()); mpLayout->addWidget(widget); + + // This call is used only to refresh the size of the widgets + updateSizes(); } } @@ -78,7 +73,6 @@ int UBWidgetList::scaleWidgets(QSize pSize) { // to remove the first spacing that shouldn't be there. int result = -mListElementsSpacing; - int count = 0; foreach(QWidget* eachWidget, mWidgetInfo.keys()){ qreal scaleFactor = 0; int newWidgetWidth = pSize.width(); @@ -87,21 +81,12 @@ int UBWidgetList::scaleWidgets(QSize pSize) scaleFactor = (float)mWidgetInfo[eachWidget].width() / (float)pSize.width(); newWidgetHeight = mWidgetInfo[eachWidget].height()/scaleFactor; result += newWidgetHeight; - eachWidget->setMinimumHeight(newWidgetHeight); } else{ scaleFactor = (float)mWidgetInfo[eachWidget].height() / (float)pSize.height(); newWidgetWidth = mWidgetInfo[eachWidget].width()/scaleFactor; result += newWidgetWidth; } -#ifndef Q_WS_WIN - qDebug() << __PRETTY_FUNCTION__ << "widget " << &eachWidget; - qDebug() << __PRETTY_FUNCTION__ << "count " << count++; - qDebug() << __PRETTY_FUNCTION__ << "widget orignal size " << mWidgetInfo[eachWidget]; - qDebug() << __PRETTY_FUNCTION__ << "containes size " << pSize; - qDebug() << __PRETTY_FUNCTION__ << "scale factor " << scaleFactor; - qDebug() << __PRETTY_FUNCTION__ << "new height " << result; -#endif //Adding a vertical/horizontal space between each element of the list result += mListElementsSpacing; } @@ -132,11 +117,42 @@ void UBWidgetList::updateView(QSize pSize) void UBWidgetList::resizeEvent(QResizeEvent *ev) { + Q_UNUSED(ev); mpEmptyLabel->setGeometry((width() - mpEmptyLabel->width()) / 2, (height() - mpEmptyLabel->height()) /2, mpEmptyLabel->width(), mpEmptyLabel->height()); updateView(size()); + updateSizes(); +} + +void UBWidgetList::updateSizes() +{ + // Resize all the widgets + foreach(QWidget* eachWidget, mWidgetInfo.keys()){ + if(NULL != eachWidget){ + QSize originalSize = mWidgetInfo[eachWidget]; + int currentWidth = mpContainer->width(); + int currentHeight = mpContainer->height(); + if(eWidgetListOrientation_Vertical == mOrientation){ + if(verticalScrollBar()->isVisible()){ + currentWidth -= verticalScrollBar()->width(); + eachWidget->setStyleSheet(QString("margin-right:%0;").arg(verticalScrollBar()->width())); + } + float scaleFactor = (float)currentWidth/(float)originalSize.width(); + currentHeight = originalSize.height()*scaleFactor; + }else{ + if(horizontalScrollBar()->isVisible()){ + currentHeight -= horizontalScrollBar()->height(); + eachWidget->setStyleSheet(QString("padding-bottom:%0;").arg(horizontalScrollBar()->height())); + } + float scaleFactor = (float)currentHeight/(float)originalSize.height(); + currentWidth = originalSize.width()*scaleFactor; + } + + eachWidget->resize(currentWidth, currentHeight); + } + } } void UBWidgetList::setMargin(int margin) diff --git a/src/customWidgets/UBWidgetList.h b/src/customWidgets/UBWidgetList.h index 6cdfef66..fc7d9627 100644 --- a/src/customWidgets/UBWidgetList.h +++ b/src/customWidgets/UBWidgetList.h @@ -3,13 +3,15 @@ #include #include -#include +#include #include #include #include #include #include +#include "interfaces/IResizeable.h" + typedef enum{ eWidgetListOrientation_Vertical, eWidgetListOrientation_Horizontal @@ -39,7 +41,8 @@ private: int scaleWidgets(QSize pSize); void scaleContainer(QSize pSize, int updateValue); void updateView(QSize pSize); - QLayout* mpLayout; + void updateSizes(); + QBoxLayout* mpLayout; QWidget* mpContainer; eWidgetListOrientation mOrientation; int mMargin; diff --git a/src/customWidgets/customWidgets.pri b/src/customWidgets/customWidgets.pri index 321f3d45..e46249f5 100644 --- a/src/customWidgets/customWidgets.pri +++ b/src/customWidgets/customWidgets.pri @@ -1,9 +1,9 @@ HEADERS += src/customWidgets/UBWidgetList.h \ - src/customWidgets/UBDraggableLabel.h + src/customWidgets/UBDraggableLabel.h \ + src/customWidgets/UBMediaWidget.h \ + src/customWidgets/UBGlobals.h SOURCES += src/customWidgets/UBWidgetList.cpp \ - src/customWidgets/UBDraggableLabel.cpp - - - + src/customWidgets/UBDraggableLabel.cpp \ + src/customWidgets/UBMediaWidget.cpp diff --git a/src/gui/UBMediaPlayer.cpp b/src/gui/UBMediaPlayer.cpp index 8bb60905..cae48d13 100644 --- a/src/gui/UBMediaPlayer.cpp +++ b/src/gui/UBMediaPlayer.cpp @@ -346,6 +346,18 @@ void UBMediaPlayer::hasVideoChanged(bool bHasVideo) m_videoWindow.setVisible(bHasVideo); } +void UBMediaPlayer::resizeEvent(QResizeEvent* pEvent) +{ +// int origWidth = m_videoWindow.width(); +// int origHeight = m_videoWindow.height(); + +// float scaleFactor = (float)origWidth / (float)width(); +// int newWidth = width(); +// int newHeigth = origHeight/scaleFactor; + +// m_videoWindow.resize(newWidth, newHeigth); +} + //************************************************************************* UBDraggableMediaPlayer::UBDraggableMediaPlayer():UBMediaPlayer() { diff --git a/src/gui/UBMediaPlayer.h b/src/gui/UBMediaPlayer.h index 86534802..9e5e0e1a 100644 --- a/src/gui/UBMediaPlayer.h +++ b/src/gui/UBMediaPlayer.h @@ -62,6 +62,9 @@ public slots: void finished(); void playPause(); +protected: + void resizeEvent(QResizeEvent* pEvent); + private slots: void stateChanged(Phonon::State newstate, Phonon::State oldstate); void bufferStatus(int percent); diff --git a/src/gui/UBTeacherBarWidget.cpp b/src/gui/UBTeacherBarWidget.cpp index 3b311908..87c4b4b5 100644 --- a/src/gui/UBTeacherBarWidget.cpp +++ b/src/gui/UBTeacherBarWidget.cpp @@ -16,6 +16,7 @@ #include "frameworks/UBFileSystemUtils.h" #include "customWidgets/UBDraggableLabel.h" +#include "customWidgets/UBMediaWidget.h" #include "core/memcheck.h" @@ -27,7 +28,6 @@ UBTeacherBarWidget::UBTeacherBarWidget(QWidget *parent, const char *name):UBDock , mpDurationLabel(NULL) , mpTitle(NULL) , mpMediaLabel(NULL) - , mpDropMediaZone(NULL) , mpContainer(NULL) , mpContainerLayout(NULL) , mpDuration1(NULL) @@ -46,6 +46,7 @@ UBTeacherBarWidget::UBTeacherBarWidget(QWidget *parent, const char *name):UBDock , mpLinkLayout(NULL) , mpStackWidget(NULL) , mpPreview(NULL) + , mpMediaContainer(NULL) { setObjectName(name); mName = "TeacherBarWidget"; @@ -121,8 +122,8 @@ UBTeacherBarWidget::UBTeacherBarWidget(QWidget *parent, const char *name):UBDock // Media mpMediaLabel = new QLabel(tr("Media"), mpContainer); mpLayout->addWidget(mpMediaLabel, 0); - mpDropMediaZone = new UBTeacherBarDropMediaZone(mpContainer); - mpLayout->addWidget(mpDropMediaZone, 1); + mpMediaContainer = new UBTBMediaContainer(this); + mpLayout->addWidget(mpMediaContainer, 1); // Links mpLinkLabel = new QLabel(tr("Links"), mpContainer); @@ -151,10 +152,15 @@ UBTeacherBarWidget::UBTeacherBarWidget(QWidget *parent, const char *name):UBDock connect(mpActionButton, SIGNAL(clicked()), this, SLOT(onActionButton())); connect(mpLinkButton, SIGNAL(clicked()), this, SLOT(onLinkButton())); connect(mpPreview, SIGNAL(showEditMode()), this, SLOT(onShowEditMode())); + connect(mpMediaContainer, SIGNAL(mediaDropped(QString)), this, SLOT(onMediaDropped(QString))); } UBTeacherBarWidget::~UBTeacherBarWidget() { + if(NULL != mpMediaContainer){ + delete mpMediaContainer; + mpMediaContainer = NULL; + } if(NULL != mpComments){ delete mpComments; mpComments = NULL; @@ -179,10 +185,6 @@ UBTeacherBarWidget::~UBTeacherBarWidget() delete mpLinkLayout; mpLinkLayout = NULL; } - if(NULL != mpDropMediaZone){ - delete mpDropMediaZone; - mpDropMediaZone = NULL; - } if(NULL != mpMediaLabel){ delete mpMediaLabel; mpMediaLabel = NULL; @@ -291,8 +293,9 @@ void UBTeacherBarWidget::saveContent() infos.actions << QString("%0;%1").arg(mActionList.at(i)->comboValue()).arg(mActionList.at(i)->text()); } // Media - // TODO : Get the url of the dropped medias and store them in infos.medias - infos.medias = mpDropMediaZone->mediaList(); + foreach(QString media, mpMediaContainer->mediaUrls()){ + infos.medias << media; + } // Links for(int j=0; jreloadMedia(nextInfos.medias); + foreach(QString url, nextInfos.medias){ + if("" != url){ + QWidget* pMedia = mpMediaContainer->generateMediaWidget(url); + if(NULL != pMedia){ + mMediaList << pMedia; + mpMediaContainer->addWidget(pMedia); + } + } + } // Links for(int j=0; jtext() == "" && mpLinks->empty() && mpActions->empty() && - mpDropMediaZone->empty() && + mpMediaContainer->empty() && mpComments->document()->toPlainText() == ""; } @@ -436,11 +447,19 @@ void UBTeacherBarWidget::onLinkButton() void UBTeacherBarWidget::clearWidgetLists() { - mpDropMediaZone->cleanMedias(); + if(NULL != mpMediaContainer){ + for(int i=0; iremoveWidget(mMediaList.at(i)); + delete mMediaList.at(i); + } + mMediaList.clear(); + mpMediaContainer->cleanMedias(); + } if(NULL != mpActions){ for(int i=0; iremoveWidget(mActionList.at(i)); + delete mActionList.at(i); } mActionList.clear(); } @@ -448,6 +467,7 @@ void UBTeacherBarWidget::clearWidgetLists() if(NULL != mpLinks){ for(int i=0; iremoveWidget(mUrlList.at(i)); + delete mUrlList.at(i); } mUrlList.clear(); } @@ -458,6 +478,17 @@ void UBTeacherBarWidget::onShowEditMode() mpStackWidget->setCurrentWidget(mpContainer); } +void UBTeacherBarWidget::onMediaDropped(const QString &url) +{ + if("" != url){ + QWidget* pMedia = mpMediaContainer->generateMediaWidget(url); + if(NULL != pMedia){ + mMediaList << pMedia; + mpMediaContainer->addWidget(pMedia); + } + } +} + // --------------------------------------------------------------------------------------------- UBTeacherStudentAction::UBTeacherStudentAction(QWidget *parent, const char *name):QWidget(parent) , mpText(NULL) @@ -1071,3 +1102,130 @@ void UBActionPreview::setContent(const QString &content) mpContent->setText(content); } } + +// ------------------------------------------------------------------------------------------------------------------------------------ +UBTBMediaContainer::UBTBMediaContainer(QWidget *parent, const char *name) : UBWidgetList(parent) +{ + setObjectName(name); + setAcceptDrops(true); +} + +UBTBMediaContainer::~UBTBMediaContainer() +{ + +} + +void UBTBMediaContainer::dropEvent(QDropEvent* pEvent) +{ + QPixmap pixFromDropEvent; + QString mimeType; + QString resourcePath; + if(pEvent->mimeData()->hasText()){ + qDebug() << "text dropped"; + resourcePath = pEvent->mimeData()->text(); + } + else if(pEvent->mimeData()->hasUrls()){ + qDebug() << "url dropped"; + resourcePath = pEvent->mimeData()->urls().at(0).toLocalFile(); + } + else if(pEvent->mimeData()->hasImage()){ + qDebug() << "image dropped"; + pixFromDropEvent.loadFromData(pEvent->mimeData()->imageData().toByteArray()); + if(!pixFromDropEvent.isNull()) + mimeType = "image"; + } + + if (mimeType.isEmpty() && resourcePath.isEmpty()){ + pEvent->acceptProposedAction(); + return; + } + if(!resourcePath.isEmpty()){ + qDebug() << "emitting 'mediaDropped'"; + emit mediaDropped(resourcePath); + pEvent->acceptProposedAction(); + } +} + +void UBTBMediaContainer::dragEnterEvent(QDragEnterEvent* pEvent) +{ + pEvent->acceptProposedAction(); +} + +void UBTBMediaContainer::dragMoveEvent(QDragMoveEvent* pEvent) +{ + pEvent->acceptProposedAction(); +} + +void UBTBMediaContainer::dragLeaveEvent(QDragLeaveEvent* pEvent) +{ + pEvent->accept(); +} + +void UBTBMediaContainer::addMedia(const QString& mediaPath) +{ + if(!mediaPath.isEmpty()) + mMediaList.append(mediaPath); + else + qWarning() << __FUNCTION__ << "empty path"; + + QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(mediaPath); + if(mimeType.contains("image")){ + QPixmap pix = QPixmap(mediaPath); + QLabel* label = new QLabel(); + label->setPixmap(pix); + label->setScaledContents(true); + addWidget(label); + } + else if(mimeType.contains("video") || mimeType.contains("audio")){ + UBMediaPlayer* mediaPlayer = new UBMediaPlayer(); + mediaPlayer->setFile(mediaPath); + addWidget(mediaPlayer); + } + else{ + qWarning() << "pMediaPath" << mediaPath; + qWarning() << "bad idea to come here"; + } +} + +QStringList UBTBMediaContainer::mediaUrls() +{ + return mMediaList; +} + +void UBTBMediaContainer::cleanMedias() +{ + mMediaList.clear(); +} + +QWidget* UBTBMediaContainer::generateMediaWidget(const QString& url) +{ + QWidget* pW = NULL; + + if(!url.isEmpty()) + mMediaList.append(url); + else + qWarning() << __FUNCTION__ << "empty path"; + + QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(url); + if(mimeType.contains("image")){ + QPixmap pix = QPixmap(url); + QLabel* label = new QLabel(); + pix.scaledToWidth(label->width()); + label->resize(pix.width(), pix.height()); + label->setPixmap(pix); + label->setScaledContents(true); + 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; + } + else{ + qWarning() << "pMediaPath" << url; + qWarning() << "bad idea to come here"; + } + + return pW; +} diff --git a/src/gui/UBTeacherBarWidget.h b/src/gui/UBTeacherBarWidget.h index 3916d528..e23ec228 100644 --- a/src/gui/UBTeacherBarWidget.h +++ b/src/gui/UBTeacherBarWidget.h @@ -18,6 +18,7 @@ class UBMediaPlayer; #include "UBDockPaletteWidget.h" #include "customWidgets/UBWidgetList.h" +#include "interfaces/IDropable.h" #define LABEL_MINWIDHT 80 @@ -174,6 +175,33 @@ private: UBActionPreview* mpTmpAction; }; + +class UBTBMediaContainer : public UBWidgetList + , public IDropable +{ + Q_OBJECT +public: + UBTBMediaContainer(QWidget* parent=0, const char* name="UBTBMediaContainer"); + ~UBTBMediaContainer(); + QStringList mediaUrls(); + QWidget* generateMediaWidget(const QString& url); + void cleanMedias(); + +signals: + void mediaDropped(const QString& url); + +protected: + void dropEvent(QDropEvent* pEvent); + void dragEnterEvent(QDragEnterEvent* pEvent); + void dragMoveEvent(QDragMoveEvent* pEvent); + void dragLeaveEvent(QDragLeaveEvent* pEvent); + +private: + void addMedia(const QString& mediaPath); + + QStringList mMediaList; +}; + class UBTeacherBarWidget : public UBDockPaletteWidget { Q_OBJECT @@ -189,6 +217,7 @@ private slots: void onActionButton(); void onLinkButton(); void onShowEditMode(); + void onMediaDropped(const QString& url); private: void clearWidgetLists(); @@ -200,7 +229,6 @@ private: QLabel* mpDurationLabel; QLineEdit* mpTitle; QLabel* mpMediaLabel; - UBTeacherBarDropMediaZone* mpDropMediaZone; QWidget* mpContainer; QVBoxLayout* mpContainerLayout; QCheckBox* mpDuration1; @@ -222,6 +250,9 @@ private: QVector mActionList; QVector mUrlList; + QVector mMediaList; + + UBTBMediaContainer* mpMediaContainer; }; #endif // UBTEACHERBARWIDGET_H diff --git a/src/interfaces/IDropable.h b/src/interfaces/IDropable.h new file mode 100644 index 00000000..a75f4f16 --- /dev/null +++ b/src/interfaces/IDropable.h @@ -0,0 +1,21 @@ +#ifndef IDROPABLE_H +#define IDROPABLE_H + +#include +#include +#include +#include + +class IDropable +{ +public: + virtual ~IDropable(){} + +protected: + virtual void dropEvent(QDropEvent* pEvent) = 0; + virtual void dragEnterEvent(QDragEnterEvent* pEvent) = 0; + virtual void dragMoveEvent(QDragMoveEvent* pEvent) = 0; + virtual void dragLeaveEvent(QDragLeaveEvent* pEvent) = 0; +}; + +#endif // IDROPABLE_H diff --git a/src/interfaces/IResizeable.h b/src/interfaces/IResizeable.h new file mode 100644 index 00000000..b84ac8e5 --- /dev/null +++ b/src/interfaces/IResizeable.h @@ -0,0 +1,15 @@ +#ifndef IRESIZEABLE_H +#define IRESIZEABLE_H + +#include + +class IResizeable +{ +public: + ~IResizeable(); + +protected: + virtual void resizeEvent(QResizeEvent* pEvent) = 0; +}; + +#endif // IRESIZEABLE_H diff --git a/src/interfaces/interfaces.pri b/src/interfaces/interfaces.pri new file mode 100644 index 00000000..55098bf3 --- /dev/null +++ b/src/interfaces/interfaces.pri @@ -0,0 +1,3 @@ +HEADERS += src/interfaces/IDropable.h \ + src/interfaces/IDropable.h \ + src/interfaces/IResizeable.h