diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 4cbfe088..5bd63181 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -47,6 +47,7 @@ #include "document/UBDocumentProxy.h" #include "customWidgets/UBDraggableLabel.h" +#include "customWidgets/UBDraggableMedia.h" #include "core/memcheck.h" @@ -727,7 +728,7 @@ void UBBoardView::dropEvent (QDropEvent *event) { qDebug() << event->source(); - if(!event->source() || dynamic_cast(event->source()) || dynamic_cast(event->source()) || dynamic_cast(event->source()) || dynamic_cast(event->source())) + if(!event->source() || dynamic_cast(event->source()) || dynamic_cast(event->source()) || dynamic_cast(event->source()) || dynamic_cast(event->source()) || dynamic_cast(event->source())) { mController->processMimeData (event->mimeData (), mapToScene (event->pos ())); event->acceptProposedAction (); diff --git a/src/customWidgets/UBDraggableMedia.cpp b/src/customWidgets/UBDraggableMedia.cpp new file mode 100644 index 00000000..6d2551f2 --- /dev/null +++ b/src/customWidgets/UBDraggableMedia.cpp @@ -0,0 +1,42 @@ +#include +#include + +#include "UBDraggableMedia.h" + +UBDraggableMedia::UBDraggableMedia(eMediaType type, QWidget *parent, const char *name):UBMediaWidget(type, parent, name) +{ + +} + +UBDraggableMedia::~UBDraggableMedia() +{ + +} + +void UBDraggableMedia::mousePressEvent(QMouseEvent* ev) +{ + if(Qt::LeftButton == ev->button()){ + mDragStartPos = ev->pos(); + } +} + +void UBDraggableMedia::mouseMoveEvent(QMouseEvent* ev) +{ + if(!(ev->buttons() & Qt::LeftButton)){ + return; + } + if((ev->pos() - mDragStartPos).manhattanLength() < QApplication::startDragDistance()){ + return; + } + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + + QList urls; + urls << QUrl(mFilePath); + mimeData->setText(mFilePath); + mimeData->setUrls(urls); + + drag->setMimeData(mimeData); + + Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction); +} diff --git a/src/customWidgets/UBDraggableMedia.h b/src/customWidgets/UBDraggableMedia.h new file mode 100644 index 00000000..b45c9391 --- /dev/null +++ b/src/customWidgets/UBDraggableMedia.h @@ -0,0 +1,19 @@ +#ifndef UBDRAGGABLEMEDIA_H +#define UBDRAGGABLEMEDIA_H + +#include "UBMediaWidget.h" + +class UBDraggableMedia : public UBMediaWidget +{ +public: + UBDraggableMedia(eMediaType type = eMediaType_Video, QWidget* parent=0, const char* name="UBDraggableMedia"); + ~UBDraggableMedia(); +protected: + void mousePressEvent(QMouseEvent* ev); + void mouseMoveEvent(QMouseEvent* ev); + +private: + QPoint mDragStartPos; +}; + +#endif // UBDRAGGABLEMEDIA_H diff --git a/src/customWidgets/UBMediaWidget.h b/src/customWidgets/UBMediaWidget.h index ef8a65a2..5192c3c7 100644 --- a/src/customWidgets/UBMediaWidget.h +++ b/src/customWidgets/UBMediaWidget.h @@ -72,6 +72,8 @@ public: protected: void resizeEvent(QResizeEvent* ev); void showEvent(QShowEvent* event); + /** The current media file path */ + QString mFilePath; private slots: void onPlayStopClicked(); @@ -85,8 +87,6 @@ private: void createMediaPlayer(); void adaptSizeToVideo(); - /** The current media file path */ - QString mFilePath; /** The current media type */ eMediaType mType; /** The media object */ diff --git a/src/customWidgets/customWidgets.pri b/src/customWidgets/customWidgets.pri index e46249f5..aa7b0255 100644 --- a/src/customWidgets/customWidgets.pri +++ b/src/customWidgets/customWidgets.pri @@ -2,8 +2,10 @@ HEADERS += src/customWidgets/UBWidgetList.h \ src/customWidgets/UBDraggableLabel.h \ src/customWidgets/UBMediaWidget.h \ - src/customWidgets/UBGlobals.h + src/customWidgets/UBGlobals.h \ + src/customWidgets/UBDraggableMedia.h SOURCES += src/customWidgets/UBWidgetList.cpp \ src/customWidgets/UBDraggableLabel.cpp \ - src/customWidgets/UBMediaWidget.cpp + src/customWidgets/UBMediaWidget.cpp \ + src/customWidgets/UBDraggableMedia.cpp diff --git a/src/gui/UBTeacherBarPreviewWidget.cpp b/src/gui/UBTeacherBarPreviewWidget.cpp index fb225ef8..43331956 100644 --- a/src/gui/UBTeacherBarPreviewWidget.cpp +++ b/src/gui/UBTeacherBarPreviewWidget.cpp @@ -316,17 +316,13 @@ void UBTeacherBarPreviewWidget::generateMedias() foreach(QString mediaUrl, *mpDataMgr->mediaUrls()){ QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(mediaUrl); if(mimeType.contains("image")){ - QPixmap pix = QPixmap(mediaUrl); - QLabel* label = new QLabel(); - pix.scaledToWidth(label->width()); - label->resize(pix.width(), pix.height()); - label->setPixmap(pix); - label->setScaledContents(true); - mStoredWidgets << label; - mpContentContainer->addWidget(label); + mpTmpLabel = new UBDraggableLabel(); + mpTmpLabel->loadImage(mediaUrl); + mStoredWidgets << mpTmpLabel; + mpContentContainer->addWidget(mpTmpLabel); } else if(mimeType.contains("video") || mimeType.contains("audio")){ - UBMediaWidget* mediaPlayer = new UBMediaWidget(mimeType.contains("audio")?eMediaType_Audio:eMediaType_Video); + UBDraggableMedia* mediaPlayer = new UBDraggableMedia(mimeType.contains("audio")?eMediaType_Audio:eMediaType_Video); mediaPlayer->setFile(mediaUrl); mStoredWidgets << mediaPlayer; mpContentContainer->addWidget(mediaPlayer); @@ -365,13 +361,3 @@ void UBTeacherBarPreviewWidget::showEvent(QShowEvent* ev) updateFields(); } -// ----------------------------------------------------------------------------------------------------- -UBDraggableMedia::UBDraggableMedia(eMediaType type, QWidget *parent, const char *name):UBMediaWidget(type, parent, name) -{ - -} - -UBDraggableMedia::~UBDraggableMedia() -{ - -} diff --git a/src/gui/UBTeacherBarPreviewWidget.h b/src/gui/UBTeacherBarPreviewWidget.h index 36b75f38..c1820777 100644 --- a/src/gui/UBTeacherBarPreviewWidget.h +++ b/src/gui/UBTeacherBarPreviewWidget.h @@ -9,6 +9,8 @@ #include "core/UBPersistenceManager.h" #include "customWidgets/UBWidgetList.h" #include "customWidgets/UBMediaWidget.h" +#include "customWidgets/UBDraggableMedia.h" +#include "customWidgets/UBDraggableLabel.h" #include "UBTeacherBarDataMgr.h" class UBTeacherBarPreviewMedia : public QWidget @@ -57,14 +59,6 @@ public: ~UBTBPreviewSeparator(); }; -class UBDraggableMedia : public UBMediaWidget -{ -public: - UBDraggableMedia(eMediaType type = eMediaType_Video, QWidget* parent=0, const char* name="UBDraggableMedia"); - ~UBDraggableMedia(); - -}; - class UBTeacherBarPreviewWidget : public QWidget { Q_OBJECT @@ -125,6 +119,8 @@ private: QTextEdit* mpTmpComment; /** A temporary media object */ UBDraggableMedia* mTmpMedia; + /** A temporary label object */ + UBDraggableLabel* mpTmpLabel; }; #endif // UBTEACHERBARPREVIEWWIDGET_H diff --git a/src/gui/UBTeacherBarWidget.cpp b/src/gui/UBTeacherBarWidget.cpp index 3a66e246..8b988526 100644 --- a/src/gui/UBTeacherBarWidget.cpp +++ b/src/gui/UBTeacherBarWidget.cpp @@ -170,7 +170,9 @@ void UBTeacherBarWidget::onTBStateChanged(eTeacherBarState state) case eTeacherBarState_PagePreview: saveContent(); mpPreview->clearFields(); - //mpPreview->updateFields(); + if(mpPreview->isVisible()){ + mpPreview->updateFields(); + } mpStackWidget->setCurrentWidget(mpPreview); break; }