]> git.sur5r.net Git - minitube/commitdiff
Ability to drag playlist items on the video area
authorFlavio Tordini <flavio.tordini@gmail.com>
Wed, 29 Jul 2009 09:56:57 +0000 (11:56 +0200)
committerFlavio Tordini <flavio.tordini@gmail.com>
Wed, 29 Jul 2009 09:56:57 +0000 (11:56 +0200)
src/MediaView.cpp
src/videoareawidget.cpp
src/videoareawidget.h

index 45282b8e018a158f9d686e4adfaa77a057069871..bf5d53d3cdc26199a18d81317ee822889e434af9 100644 (file)
@@ -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);
index 645fc65cde405f77e6bc6ac4930714d2c55f0d71..ca38f67ed5da67ba000e543bd9a3abeaac9fb948 100644 (file)
@@ -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<const VideoMimeData*>( event->mimeData() );
+    if(!videoMimeData ) return;
+
+    QList<Video*> droppedVideos = videoMimeData->videos();
+    foreach( Video *video, droppedVideos) {
+        int row = listModel->rowForVideo(video);
+        if (row != -1)
+            listModel->setActiveRow(row);
+    }
+    event->acceptProposedAction();
+}
index 1af14c559d1b09389e18f4b8c9b2be37e1aeab61..2d6e7639950147077ee8fa4d853ce2b75626b734 100644 (file)
@@ -4,6 +4,7 @@
 #include <QWidget>
 #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;
 
 };