Implemented the drag and drop from the teacherbar to the board

preferencesAboutTextFull
shibakaneki 13 years ago
parent d461e3a786
commit 5ce549f174
  1. 3
      src/board/UBBoardView.cpp
  2. 42
      src/customWidgets/UBDraggableMedia.cpp
  3. 19
      src/customWidgets/UBDraggableMedia.h
  4. 4
      src/customWidgets/UBMediaWidget.h
  5. 6
      src/customWidgets/customWidgets.pri
  6. 24
      src/gui/UBTeacherBarPreviewWidget.cpp
  7. 12
      src/gui/UBTeacherBarPreviewWidget.h
  8. 4
      src/gui/UBTeacherBarWidget.cpp

@ -47,6 +47,7 @@
#include "document/UBDocumentProxy.h" #include "document/UBDocumentProxy.h"
#include "customWidgets/UBDraggableLabel.h" #include "customWidgets/UBDraggableLabel.h"
#include "customWidgets/UBDraggableMedia.h"
#include "core/memcheck.h" #include "core/memcheck.h"
@ -727,7 +728,7 @@ void
UBBoardView::dropEvent (QDropEvent *event) UBBoardView::dropEvent (QDropEvent *event)
{ {
qDebug() << event->source(); 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 ())); mController->processMimeData (event->mimeData (), mapToScene (event->pos ()));
event->acceptProposedAction (); event->acceptProposedAction ();

@ -0,0 +1,42 @@
#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);
}

@ -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

@ -72,6 +72,8 @@ public:
protected: protected:
void resizeEvent(QResizeEvent* ev); void resizeEvent(QResizeEvent* ev);
void showEvent(QShowEvent* event); void showEvent(QShowEvent* event);
/** The current media file path */
QString mFilePath;
private slots: private slots:
void onPlayStopClicked(); void onPlayStopClicked();
@ -85,8 +87,6 @@ private:
void createMediaPlayer(); void createMediaPlayer();
void adaptSizeToVideo(); void adaptSizeToVideo();
/** The current media file path */
QString mFilePath;
/** The current media type */ /** The current media type */
eMediaType mType; eMediaType mType;
/** The media object */ /** The media object */

@ -2,8 +2,10 @@
HEADERS += src/customWidgets/UBWidgetList.h \ HEADERS += src/customWidgets/UBWidgetList.h \
src/customWidgets/UBDraggableLabel.h \ src/customWidgets/UBDraggableLabel.h \
src/customWidgets/UBMediaWidget.h \ src/customWidgets/UBMediaWidget.h \
src/customWidgets/UBGlobals.h src/customWidgets/UBGlobals.h \
src/customWidgets/UBDraggableMedia.h
SOURCES += src/customWidgets/UBWidgetList.cpp \ SOURCES += src/customWidgets/UBWidgetList.cpp \
src/customWidgets/UBDraggableLabel.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()){ foreach(QString mediaUrl, *mpDataMgr->mediaUrls()){
QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(mediaUrl); QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(mediaUrl);
if(mimeType.contains("image")){ if(mimeType.contains("image")){
QPixmap pix = QPixmap(mediaUrl); mpTmpLabel = new UBDraggableLabel();
QLabel* label = new QLabel(); mpTmpLabel->loadImage(mediaUrl);
pix.scaledToWidth(label->width()); mStoredWidgets << mpTmpLabel;
label->resize(pix.width(), pix.height()); mpContentContainer->addWidget(mpTmpLabel);
label->setPixmap(pix);
label->setScaledContents(true);
mStoredWidgets << label;
mpContentContainer->addWidget(label);
} }
else if(mimeType.contains("video") || mimeType.contains("audio")){ 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); mediaPlayer->setFile(mediaUrl);
mStoredWidgets << mediaPlayer; mStoredWidgets << mediaPlayer;
mpContentContainer->addWidget(mediaPlayer); mpContentContainer->addWidget(mediaPlayer);
@ -365,13 +361,3 @@ void UBTeacherBarPreviewWidget::showEvent(QShowEvent* ev)
updateFields(); 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 "core/UBPersistenceManager.h"
#include "customWidgets/UBWidgetList.h" #include "customWidgets/UBWidgetList.h"
#include "customWidgets/UBMediaWidget.h" #include "customWidgets/UBMediaWidget.h"
#include "customWidgets/UBDraggableMedia.h"
#include "customWidgets/UBDraggableLabel.h"
#include "UBTeacherBarDataMgr.h" #include "UBTeacherBarDataMgr.h"
class UBTeacherBarPreviewMedia : public QWidget class UBTeacherBarPreviewMedia : public QWidget
@ -57,14 +59,6 @@ public:
~UBTBPreviewSeparator(); ~UBTBPreviewSeparator();
}; };
class UBDraggableMedia : public UBMediaWidget
{
public:
UBDraggableMedia(eMediaType type = eMediaType_Video, QWidget* parent=0, const char* name="UBDraggableMedia");
~UBDraggableMedia();
};
class UBTeacherBarPreviewWidget : public QWidget class UBTeacherBarPreviewWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -125,6 +119,8 @@ private:
QTextEdit* mpTmpComment; QTextEdit* mpTmpComment;
/** A temporary media object */ /** A temporary media object */
UBDraggableMedia* mTmpMedia; UBDraggableMedia* mTmpMedia;
/** A temporary label object */
UBDraggableLabel* mpTmpLabel;
}; };
#endif // UBTEACHERBARPREVIEWWIDGET_H #endif // UBTEACHERBARPREVIEWWIDGET_H

@ -170,7 +170,9 @@ void UBTeacherBarWidget::onTBStateChanged(eTeacherBarState state)
case eTeacherBarState_PagePreview: case eTeacherBarState_PagePreview:
saveContent(); saveContent();
mpPreview->clearFields(); mpPreview->clearFields();
//mpPreview->updateFields(); if(mpPreview->isVisible()){
mpPreview->updateFields();
}
mpStackWidget->setCurrentWidget(mpPreview); mpStackWidget->setCurrentWidget(mpPreview);
break; break;
} }

Loading…
Cancel
Save