partial backup of the ubmediawidget

preferencesAboutTextFull
shibakaneki 13 years ago
parent 81ed0c74c2
commit 955e928930
  1. 1
      Sankore_3.1.pro
  2. 17
      resources/style.qss
  3. 9
      src/customWidgets/UBGlobals.h
  4. 209
      src/customWidgets/UBMediaWidget.cpp
  5. 85
      src/customWidgets/UBMediaWidget.h
  6. 68
      src/customWidgets/UBWidgetList.cpp
  7. 7
      src/customWidgets/UBWidgetList.h
  8. 10
      src/customWidgets/customWidgets.pri
  9. 12
      src/gui/UBMediaPlayer.cpp
  10. 3
      src/gui/UBMediaPlayer.h
  11. 182
      src/gui/UBTeacherBarWidget.cpp
  12. 33
      src/gui/UBTeacherBarWidget.h
  13. 21
      src/interfaces/IDropable.h
  14. 15
      src/interfaces/IResizeable.h
  15. 3
      src/interfaces/interfaces.pri

@ -54,6 +54,7 @@ include(src/web/web.pri)
include(src/softwareupdate/softwareupdate.pri) include(src/softwareupdate/softwareupdate.pri)
include(src/transition/transition.pri) include(src/transition/transition.pri)
include(src/customWidgets/customWidgets.pri) include(src/customWidgets/customWidgets.pri)
include(src/interfaces/interfaces.pri)
DEPENDPATH += src/pdf-merger DEPENDPATH += src/pdf-merger
INCLUDEPATH += src/pdf-merger INCLUDEPATH += src/pdf-merger

@ -5,13 +5,23 @@ QWidget#UBLibNavigatorWidget,
QWidget#UBLibItemProperties, QWidget#UBLibItemProperties,
QWidget#UBDownloadWidget, QWidget#UBDownloadWidget,
QWidget#UBWidgetList, QWidget#UBWidgetList,
QWidget#UBTeacherBarDropMediaZone QWidget#UBTeacherBarDropMediaZone,
QWidget#UBTBMediaContainer
{ {
background: #EEEEEE; background: #EEEEEE;
border-radius: 10px; border-radius: 10px;
border: 2px solid #999999; 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 QWidget#UBTeacherBarPreviewWidget
{ {
background: #FFFFFF; background: #FFFFFF;
@ -26,6 +36,11 @@ QLabel#UBTeacherBarPreviewTitle
font-weight:bold; font-weight:bold;
} }
QLabel#UBMediaPlayerButton
{
padding: 0px 0px 0px 0px;
}
QLabel#UBTeacherBarPreviewSubtitle QLabel#UBTeacherBarPreviewSubtitle
{ {
color: #555555; color: #555555;

@ -0,0 +1,9 @@
#ifndef UBGLOBALS_H
#define UBGLOBALS_H
#define DELETEPTR(ptr) if(NULL != ptr){ \
delete ptr; \
ptr = NULL; \
}
#endif // UBGLOBALS_H

@ -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();
}
}

@ -0,0 +1,85 @@
#ifndef UBMEDIAWIDGET_H
#define UBMEDIAWIDGET_H
#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QSlider>
#include <QMouseEvent>
#include <phonon/MediaObject>
#include <phonon/VideoWidget>
#include <phonon/AudioOutput>
#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

@ -1,4 +1,7 @@
#include <QDebug> #include <QDebug>
#include <QScrollBar>
#include "UBGlobals.h"
#include "UBWidgetList.h" #include "UBWidgetList.h"
UBWidgetList::UBWidgetList(QWidget* parent, eWidgetListOrientation orientation, const char* name):QScrollArea(parent) UBWidgetList::UBWidgetList(QWidget* parent, eWidgetListOrientation orientation, const char* name):QScrollArea(parent)
@ -20,13 +23,11 @@ UBWidgetList::UBWidgetList(QWidget* parent, eWidgetListOrientation orientation,
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
mpLayout = new QVBoxLayout(mpContainer); mpLayout = new QVBoxLayout(mpContainer);
mpContainer->resize(mpContainer->width(), mpContainer->height());
} }
else{ else{
setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
mpLayout = new QHBoxLayout(mpContainer); mpLayout = new QHBoxLayout(mpContainer);
mpContainer->resize(mpContainer->width(), mpContainer->height());
} }
mpLayout->setContentsMargins(margin(), margin(), margin(), margin()); mpLayout->setContentsMargins(margin(), margin(), margin(), margin());
mpContainer->setLayout(mpLayout); mpContainer->setLayout(mpLayout);
@ -35,28 +36,22 @@ UBWidgetList::UBWidgetList(QWidget* parent, eWidgetListOrientation orientation,
UBWidgetList::~UBWidgetList() UBWidgetList::~UBWidgetList()
{ {
if(NULL != mpEmptyLabel){ DELETEPTR(mpEmptyLabel);
delete mpEmptyLabel; DELETEPTR(mpLayout);
mpEmptyLabel = NULL; DELETEPTR(mpContainer);
}
if(NULL != mpLayout){
delete mpLayout;
mpLayout = NULL;
}
if(NULL != mpContainer){
delete mpContainer;
mpContainer = NULL;
}
} }
void UBWidgetList::addWidget(QWidget *widget) void UBWidgetList::addWidget(QWidget *widget)
{ {
if(NULL != mpLayout){ if(NULL != mpLayout && NULL != widget){
widget->setParent(mpContainer);
mpEmptyLabel->setVisible(false); mpEmptyLabel->setVisible(false);
mWidgetInfo[widget] = widget->size(); mWidgetInfo[widget] = widget->size();
qDebug() << __FUNCTION__ << "widget->size () " << widget->size();
updateView(size()); updateView(size());
mpLayout->addWidget(widget); 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. // to remove the first spacing that shouldn't be there.
int result = -mListElementsSpacing; int result = -mListElementsSpacing;
int count = 0;
foreach(QWidget* eachWidget, mWidgetInfo.keys()){ foreach(QWidget* eachWidget, mWidgetInfo.keys()){
qreal scaleFactor = 0; qreal scaleFactor = 0;
int newWidgetWidth = pSize.width(); int newWidgetWidth = pSize.width();
@ -87,21 +81,12 @@ int UBWidgetList::scaleWidgets(QSize pSize)
scaleFactor = (float)mWidgetInfo[eachWidget].width() / (float)pSize.width(); scaleFactor = (float)mWidgetInfo[eachWidget].width() / (float)pSize.width();
newWidgetHeight = mWidgetInfo[eachWidget].height()/scaleFactor; newWidgetHeight = mWidgetInfo[eachWidget].height()/scaleFactor;
result += newWidgetHeight; result += newWidgetHeight;
eachWidget->setMinimumHeight(newWidgetHeight);
} }
else{ else{
scaleFactor = (float)mWidgetInfo[eachWidget].height() / (float)pSize.height(); scaleFactor = (float)mWidgetInfo[eachWidget].height() / (float)pSize.height();
newWidgetWidth = mWidgetInfo[eachWidget].width()/scaleFactor; newWidgetWidth = mWidgetInfo[eachWidget].width()/scaleFactor;
result += newWidgetWidth; 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 //Adding a vertical/horizontal space between each element of the list
result += mListElementsSpacing; result += mListElementsSpacing;
} }
@ -132,11 +117,42 @@ void UBWidgetList::updateView(QSize pSize)
void UBWidgetList::resizeEvent(QResizeEvent *ev) void UBWidgetList::resizeEvent(QResizeEvent *ev)
{ {
Q_UNUSED(ev);
mpEmptyLabel->setGeometry((width() - mpEmptyLabel->width()) / 2, mpEmptyLabel->setGeometry((width() - mpEmptyLabel->width()) / 2,
(height() - mpEmptyLabel->height()) /2, (height() - mpEmptyLabel->height()) /2,
mpEmptyLabel->width(), mpEmptyLabel->width(),
mpEmptyLabel->height()); mpEmptyLabel->height());
updateView(size()); 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) void UBWidgetList::setMargin(int margin)

@ -3,13 +3,15 @@
#include <QWidget> #include <QWidget>
#include <QScrollArea> #include <QScrollArea>
#include <QLayout> #include <QBoxLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QResizeEvent> #include <QResizeEvent>
#include <QVector> #include <QVector>
#include <QLabel> #include <QLabel>
#include "interfaces/IResizeable.h"
typedef enum{ typedef enum{
eWidgetListOrientation_Vertical, eWidgetListOrientation_Vertical,
eWidgetListOrientation_Horizontal eWidgetListOrientation_Horizontal
@ -39,7 +41,8 @@ private:
int scaleWidgets(QSize pSize); int scaleWidgets(QSize pSize);
void scaleContainer(QSize pSize, int updateValue); void scaleContainer(QSize pSize, int updateValue);
void updateView(QSize pSize); void updateView(QSize pSize);
QLayout* mpLayout; void updateSizes();
QBoxLayout* mpLayout;
QWidget* mpContainer; QWidget* mpContainer;
eWidgetListOrientation mOrientation; eWidgetListOrientation mOrientation;
int mMargin; int mMargin;

@ -1,9 +1,9 @@
HEADERS += src/customWidgets/UBWidgetList.h \ 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 \ SOURCES += src/customWidgets/UBWidgetList.cpp \
src/customWidgets/UBDraggableLabel.cpp src/customWidgets/UBDraggableLabel.cpp \
src/customWidgets/UBMediaWidget.cpp

@ -346,6 +346,18 @@ void UBMediaPlayer::hasVideoChanged(bool bHasVideo)
m_videoWindow.setVisible(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() UBDraggableMediaPlayer::UBDraggableMediaPlayer():UBMediaPlayer()
{ {

@ -62,6 +62,9 @@ public slots:
void finished(); void finished();
void playPause(); void playPause();
protected:
void resizeEvent(QResizeEvent* pEvent);
private slots: private slots:
void stateChanged(Phonon::State newstate, Phonon::State oldstate); void stateChanged(Phonon::State newstate, Phonon::State oldstate);
void bufferStatus(int percent); void bufferStatus(int percent);

@ -16,6 +16,7 @@
#include "frameworks/UBFileSystemUtils.h" #include "frameworks/UBFileSystemUtils.h"
#include "customWidgets/UBDraggableLabel.h" #include "customWidgets/UBDraggableLabel.h"
#include "customWidgets/UBMediaWidget.h"
#include "core/memcheck.h" #include "core/memcheck.h"
@ -27,7 +28,6 @@ UBTeacherBarWidget::UBTeacherBarWidget(QWidget *parent, const char *name):UBDock
, mpDurationLabel(NULL) , mpDurationLabel(NULL)
, mpTitle(NULL) , mpTitle(NULL)
, mpMediaLabel(NULL) , mpMediaLabel(NULL)
, mpDropMediaZone(NULL)
, mpContainer(NULL) , mpContainer(NULL)
, mpContainerLayout(NULL) , mpContainerLayout(NULL)
, mpDuration1(NULL) , mpDuration1(NULL)
@ -46,6 +46,7 @@ UBTeacherBarWidget::UBTeacherBarWidget(QWidget *parent, const char *name):UBDock
, mpLinkLayout(NULL) , mpLinkLayout(NULL)
, mpStackWidget(NULL) , mpStackWidget(NULL)
, mpPreview(NULL) , mpPreview(NULL)
, mpMediaContainer(NULL)
{ {
setObjectName(name); setObjectName(name);
mName = "TeacherBarWidget"; mName = "TeacherBarWidget";
@ -121,8 +122,8 @@ UBTeacherBarWidget::UBTeacherBarWidget(QWidget *parent, const char *name):UBDock
// Media // Media
mpMediaLabel = new QLabel(tr("Media"), mpContainer); mpMediaLabel = new QLabel(tr("Media"), mpContainer);
mpLayout->addWidget(mpMediaLabel, 0); mpLayout->addWidget(mpMediaLabel, 0);
mpDropMediaZone = new UBTeacherBarDropMediaZone(mpContainer); mpMediaContainer = new UBTBMediaContainer(this);
mpLayout->addWidget(mpDropMediaZone, 1); mpLayout->addWidget(mpMediaContainer, 1);
// Links // Links
mpLinkLabel = new QLabel(tr("Links"), mpContainer); 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(mpActionButton, SIGNAL(clicked()), this, SLOT(onActionButton()));
connect(mpLinkButton, SIGNAL(clicked()), this, SLOT(onLinkButton())); connect(mpLinkButton, SIGNAL(clicked()), this, SLOT(onLinkButton()));
connect(mpPreview, SIGNAL(showEditMode()), this, SLOT(onShowEditMode())); connect(mpPreview, SIGNAL(showEditMode()), this, SLOT(onShowEditMode()));
connect(mpMediaContainer, SIGNAL(mediaDropped(QString)), this, SLOT(onMediaDropped(QString)));
} }
UBTeacherBarWidget::~UBTeacherBarWidget() UBTeacherBarWidget::~UBTeacherBarWidget()
{ {
if(NULL != mpMediaContainer){
delete mpMediaContainer;
mpMediaContainer = NULL;
}
if(NULL != mpComments){ if(NULL != mpComments){
delete mpComments; delete mpComments;
mpComments = NULL; mpComments = NULL;
@ -179,10 +185,6 @@ UBTeacherBarWidget::~UBTeacherBarWidget()
delete mpLinkLayout; delete mpLinkLayout;
mpLinkLayout = NULL; mpLinkLayout = NULL;
} }
if(NULL != mpDropMediaZone){
delete mpDropMediaZone;
mpDropMediaZone = NULL;
}
if(NULL != mpMediaLabel){ if(NULL != mpMediaLabel){
delete mpMediaLabel; delete mpMediaLabel;
mpMediaLabel = NULL; mpMediaLabel = NULL;
@ -291,8 +293,9 @@ void UBTeacherBarWidget::saveContent()
infos.actions << QString("%0;%1").arg(mActionList.at(i)->comboValue()).arg(mActionList.at(i)->text()); infos.actions << QString("%0;%1").arg(mActionList.at(i)->comboValue()).arg(mActionList.at(i)->text());
} }
// Media // Media
// TODO : Get the url of the dropped medias and store them in infos.medias foreach(QString media, mpMediaContainer->mediaUrls()){
infos.medias = mpDropMediaZone->mediaList(); infos.medias << media;
}
// Links // Links
for(int j=0; j<mUrlList.size(); j++){ for(int j=0; j<mUrlList.size(); j++){
@ -335,7 +338,15 @@ void UBTeacherBarWidget::loadContent()
} }
} }
// Media // Media
mpDropMediaZone->reloadMedia(nextInfos.medias); foreach(QString url, nextInfos.medias){
if("" != url){
QWidget* pMedia = mpMediaContainer->generateMediaWidget(url);
if(NULL != pMedia){
mMediaList << pMedia;
mpMediaContainer->addWidget(pMedia);
}
}
}
// Links // Links
for(int j=0; j<nextInfos.urls.size(); j++){ for(int j=0; j<nextInfos.urls.size(); j++){
@ -411,7 +422,7 @@ bool UBTeacherBarWidget::isEmpty()
return mpTitle->text() == "" && return mpTitle->text() == "" &&
mpLinks->empty() && mpLinks->empty() &&
mpActions->empty() && mpActions->empty() &&
mpDropMediaZone->empty() && mpMediaContainer->empty() &&
mpComments->document()->toPlainText() == ""; mpComments->document()->toPlainText() == "";
} }
@ -436,11 +447,19 @@ void UBTeacherBarWidget::onLinkButton()
void UBTeacherBarWidget::clearWidgetLists() void UBTeacherBarWidget::clearWidgetLists()
{ {
mpDropMediaZone->cleanMedias(); if(NULL != mpMediaContainer){
for(int i=0; i<mMediaList.size(); i++){
mpMediaContainer->removeWidget(mMediaList.at(i));
delete mMediaList.at(i);
}
mMediaList.clear();
mpMediaContainer->cleanMedias();
}
if(NULL != mpActions){ if(NULL != mpActions){
for(int i=0; i<mActionList.size(); i++){ for(int i=0; i<mActionList.size(); i++){
mpActions->removeWidget(mActionList.at(i)); mpActions->removeWidget(mActionList.at(i));
delete mActionList.at(i);
} }
mActionList.clear(); mActionList.clear();
} }
@ -448,6 +467,7 @@ void UBTeacherBarWidget::clearWidgetLists()
if(NULL != mpLinks){ if(NULL != mpLinks){
for(int i=0; i<mUrlList.size(); i++){ for(int i=0; i<mUrlList.size(); i++){
mpLinks->removeWidget(mUrlList.at(i)); mpLinks->removeWidget(mUrlList.at(i));
delete mUrlList.at(i);
} }
mUrlList.clear(); mUrlList.clear();
} }
@ -458,6 +478,17 @@ void UBTeacherBarWidget::onShowEditMode()
mpStackWidget->setCurrentWidget(mpContainer); 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) UBTeacherStudentAction::UBTeacherStudentAction(QWidget *parent, const char *name):QWidget(parent)
, mpText(NULL) , mpText(NULL)
@ -1071,3 +1102,130 @@ void UBActionPreview::setContent(const QString &content)
mpContent->setText(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;
}

@ -18,6 +18,7 @@ class UBMediaPlayer;
#include "UBDockPaletteWidget.h" #include "UBDockPaletteWidget.h"
#include "customWidgets/UBWidgetList.h" #include "customWidgets/UBWidgetList.h"
#include "interfaces/IDropable.h"
#define LABEL_MINWIDHT 80 #define LABEL_MINWIDHT 80
@ -174,6 +175,33 @@ private:
UBActionPreview* mpTmpAction; 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 class UBTeacherBarWidget : public UBDockPaletteWidget
{ {
Q_OBJECT Q_OBJECT
@ -189,6 +217,7 @@ private slots:
void onActionButton(); void onActionButton();
void onLinkButton(); void onLinkButton();
void onShowEditMode(); void onShowEditMode();
void onMediaDropped(const QString& url);
private: private:
void clearWidgetLists(); void clearWidgetLists();
@ -200,7 +229,6 @@ private:
QLabel* mpDurationLabel; QLabel* mpDurationLabel;
QLineEdit* mpTitle; QLineEdit* mpTitle;
QLabel* mpMediaLabel; QLabel* mpMediaLabel;
UBTeacherBarDropMediaZone* mpDropMediaZone;
QWidget* mpContainer; QWidget* mpContainer;
QVBoxLayout* mpContainerLayout; QVBoxLayout* mpContainerLayout;
QCheckBox* mpDuration1; QCheckBox* mpDuration1;
@ -222,6 +250,9 @@ private:
QVector<UBTeacherStudentAction*> mActionList; QVector<UBTeacherStudentAction*> mActionList;
QVector<UBUrlWidget*> mUrlList; QVector<UBUrlWidget*> mUrlList;
QVector<QWidget*> mMediaList;
UBTBMediaContainer* mpMediaContainer;
}; };
#endif // UBTEACHERBARWIDGET_H #endif // UBTEACHERBARWIDGET_H

@ -0,0 +1,21 @@
#ifndef IDROPABLE_H
#define IDROPABLE_H
#include <QDropEvent>
#include <QDragEnterEvent>
#include <QDragLeaveEvent>
#include <QDragMoveEvent>
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

@ -0,0 +1,15 @@
#ifndef IRESIZEABLE_H
#define IRESIZEABLE_H
#include <QResizeEvent>
class IResizeable
{
public:
~IResizeable();
protected:
virtual void resizeEvent(QResizeEvent* pEvent) = 0;
};
#endif // IRESIZEABLE_H

@ -0,0 +1,3 @@
HEADERS += src/interfaces/IDropable.h \
src/interfaces/IDropable.h \
src/interfaces/IResizeable.h
Loading…
Cancel
Save