From 013f1b191db8f6d4db77e46a3bb338f067b27a73 Mon Sep 17 00:00:00 2001 From: Flavio Tordini Date: Wed, 29 Jul 2009 11:56:57 +0200 Subject: [PATCH] Ability to drag playlist items on the video area --- src/MediaView.cpp | 3 ++- src/videoareawidget.cpp | 23 +++++++++++++++++++++++ src/videoareawidget.h | 7 +++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/MediaView.cpp b/src/MediaView.cpp index 45282b8..bf5d53d 100644 --- a/src/MediaView.cpp +++ b/src/MediaView.cpp @@ -37,7 +37,7 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent) { listView->setDragEnabled(true); listView->setAcceptDrops(true); listView->setDropIndicatorShown(true); - listView->setDragDropMode(QAbstractItemView::InternalMove); + listView->setDragDropMode(QAbstractItemView::DragDrop); // cosmetics listView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); @@ -67,6 +67,7 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent) { videoWidget = new Phonon::VideoWidget(this); videoAreaWidget->setVideoWidget(videoWidget); + videoAreaWidget->setListModel(listModel); loadingWidget = new LoadingWidget(this); videoAreaWidget->setLoadingWidget(loadingWidget); diff --git a/src/videoareawidget.cpp b/src/videoareawidget.cpp index 645fc65..ca38f67 100644 --- a/src/videoareawidget.cpp +++ b/src/videoareawidget.cpp @@ -1,8 +1,10 @@ #include "videoareawidget.h" +#include "videomimedata.h" VideoAreaWidget::VideoAreaWidget(QWidget *parent) : QWidget(parent) { stackedLayout = new QStackedLayout(this); setLayout(stackedLayout); + setAcceptDrops(true); } void VideoAreaWidget::setVideoWidget(QWidget *videoWidget) { @@ -33,3 +35,24 @@ void VideoAreaWidget::mousePressEvent(QMouseEvent *event) { switch(event->button() == Qt::RightButton) emit rightClicked(); } + +void VideoAreaWidget::dragEnterEvent(QDragEnterEvent *event) { + qDebug() << event->mimeData()->formats(); + if (event->mimeData()->hasFormat("application/x-minitube-video")) { + event->acceptProposedAction(); + } +} + +void VideoAreaWidget::dropEvent(QDropEvent *event) { + + const VideoMimeData* videoMimeData = dynamic_cast( event->mimeData() ); + if(!videoMimeData ) return; + + QList droppedVideos = videoMimeData->videos(); + foreach( Video *video, droppedVideos) { + int row = listModel->rowForVideo(video); + if (row != -1) + listModel->setActiveRow(row); + } + event->acceptProposedAction(); +} diff --git a/src/videoareawidget.h b/src/videoareawidget.h index 1af14c5..2d6e763 100644 --- a/src/videoareawidget.h +++ b/src/videoareawidget.h @@ -4,6 +4,7 @@ #include #include "video.h" #include "loadingwidget.h" +#include "ListModel.h" class VideoAreaWidget : public QWidget { @@ -15,6 +16,9 @@ public: void setLoadingWidget(LoadingWidget *loadingWidget); void showLoading(Video* video); void showVideo(); + void setListModel(ListModel *listModel) { + this->listModel = listModel; + } signals: void doubleClicked(); @@ -23,11 +27,14 @@ signals: protected: void mouseDoubleClickEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event); + void dragEnterEvent(QDragEnterEvent *event); + void dropEvent(QDropEvent *event); private: QStackedLayout *stackedLayout; QWidget *videoWidget; LoadingWidget *loadingWidget; + ListModel *listModel; }; -- 2.39.5