Commit 5ce549f1 authored by shibakaneki's avatar shibakaneki

Implemented the drag and drop from the teacherbar to the board

parent d461e3a7
......@@ -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<UBThumbnailWidget *>(event->source()) || dynamic_cast<QWebView*>(event->source()) || dynamic_cast<UBDraggableMediaPlayer *>(event->source()) || dynamic_cast<UBDraggableLabel *>(event->source()))
if(!event->source() || dynamic_cast<UBThumbnailWidget *>(event->source()) || dynamic_cast<QWebView*>(event->source()) || dynamic_cast<UBDraggableMediaPlayer *>(event->source()) || dynamic_cast<UBDraggableLabel *>(event->source()) || dynamic_cast<UBDraggableMedia *>(event->source()))
{
mController->processMimeData (event->mimeData (), mapToScene (event->pos ()));
event->acceptProposedAction ();
......
#include <QApplication>
#include <QUrl>
#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<QUrl> urls;
urls << QUrl(mFilePath);
mimeData->setText(mFilePath);
mimeData->setUrls(urls);
drag->setMimeData(mimeData);
Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
}
#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
......@@ -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 */
......
......@@ -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
......@@ -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()
{
}
......@@ -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
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment