[vlc-commits] commit: Qt: use Qt::DropAction properly throughout playlist drag-and-drop ( Jakob Leben )

git at videolan.org git at videolan.org
Wed Mar 10 18:34:58 CET 2010


vlc | branch: master | Jakob Leben <jleben at videolan.org> | Wed Mar 10 18:31:24 2010 +0100| [d49a326387222f30a4882cbbbda54172941ba679] | committer: Jakob Leben 

Qt: use Qt::DropAction properly throughout playlist drag-and-drop

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d49a326387222f30a4882cbbbda54172941ba679
---

 modules/gui/qt4/components/playlist/icon_view.cpp  |   26 +++++++++++++++++
 modules/gui/qt4/components/playlist/icon_view.hpp  |    3 ++
 .../gui/qt4/components/playlist/playlist_model.cpp |   30 +++----------------
 modules/gui/qt4/components/playlist/selector.cpp   |    6 ++++
 modules/gui/qt4/components/playlist/selector.hpp   |    1 +
 5 files changed, 41 insertions(+), 25 deletions(-)

diff --git a/modules/gui/qt4/components/playlist/icon_view.cpp b/modules/gui/qt4/components/playlist/icon_view.cpp
index 290300a..c76c2d1 100644
--- a/modules/gui/qt4/components/playlist/icon_view.cpp
+++ b/modules/gui/qt4/components/playlist/icon_view.cpp
@@ -33,6 +33,7 @@
 #include <QFontMetrics>
 #include <QPixmapCache>
 #include <QDrag>
+#include <QDragMoveEvent>
 
 #include "assert.h"
 
@@ -319,6 +320,14 @@ static void plViewStartDrag( QAbstractItemView *view, const Qt::DropActions & su
     drag->exec( supportedActions );
 }
 
+static void plViewDragMoveEvent( QAbstractItemView *view, QDragMoveEvent * event )
+{
+    if( event->keyboardModifiers() & Qt::ControlModifier &&
+        event->possibleActions() & Qt::CopyAction )
+        event->setDropAction( Qt::CopyAction );
+    else event->acceptProposedAction();
+}
+
 PlIconView::PlIconView( PLModel *model, QWidget *parent ) : QListView( parent )
 {
     PlIconViewItemDelegate *delegate = new PlIconViewItemDelegate( this );
@@ -344,6 +353,12 @@ void PlIconView::startDrag ( Qt::DropActions supportedActions )
     plViewStartDrag( this, supportedActions );
 }
 
+void PlIconView::dragMoveEvent ( QDragMoveEvent * event )
+{
+    plViewDragMoveEvent( this, event );
+    QAbstractItemView::dragMoveEvent( event );
+}
+
 PlListView::PlListView( PLModel *model, QWidget *parent ) : QListView( parent )
 {
     setModel( model );
@@ -364,8 +379,19 @@ void PlListView::startDrag ( Qt::DropActions supportedActions )
     plViewStartDrag( this, supportedActions );
 }
 
+void PlListView::dragMoveEvent ( QDragMoveEvent * event )
+{
+    plViewDragMoveEvent( this, event );
+    QAbstractItemView::dragMoveEvent( event );
+}
+
 void PlTreeView::startDrag ( Qt::DropActions supportedActions )
 {
     plViewStartDrag( this, supportedActions );
 }
 
+void PlTreeView::dragMoveEvent ( QDragMoveEvent * event )
+{
+    plViewDragMoveEvent( this, event );
+    QAbstractItemView::dragMoveEvent( event );
+}
diff --git a/modules/gui/qt4/components/playlist/icon_view.hpp b/modules/gui/qt4/components/playlist/icon_view.hpp
index b5cc433..9f53999 100644
--- a/modules/gui/qt4/components/playlist/icon_view.hpp
+++ b/modules/gui/qt4/components/playlist/icon_view.hpp
@@ -70,6 +70,7 @@ public:
     PlIconView( PLModel *model, QWidget *parent = 0 );
 private:
     void startDrag ( Qt::DropActions supportedActions );
+    void dragMoveEvent ( QDragMoveEvent * event );
 };
 
 class PlListView : public QListView
@@ -80,6 +81,7 @@ public:
     PlListView( PLModel *model, QWidget *parent = 0 );
 private:
     void startDrag ( Qt::DropActions supportedActions );
+    void dragMoveEvent ( QDragMoveEvent * event );
 };
 
 class PlTreeView : public QTreeView
@@ -88,6 +90,7 @@ class PlTreeView : public QTreeView
 
 private:
     void startDrag ( Qt::DropActions supportedActions );
+    void dragMoveEvent ( QDragMoveEvent * event );
 };
 
 #endif
diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp
index 82b3178..c3c960e 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.cpp
@@ -108,7 +108,7 @@ PLModel::~PLModel()
 
 Qt::DropActions PLModel::supportedDropActions() const
 {
-    return Qt::CopyAction; /* Why not Qt::MoveAction */
+    return Qt::CopyAction | Qt::MoveAction;
 }
 
 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
@@ -189,33 +189,13 @@ QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const
 bool PLModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
                            int row, int column, const QModelIndex &parent )
 {
+    bool copy = action == Qt::CopyAction;
+    if( !copy && action != Qt::MoveAction )
+        return true;
+
     const PlMimeData *plMimeData = qobject_cast<const PlMimeData*>( data );
     if( plMimeData )
     {
-        if( action == Qt::IgnoreAction )
-            return true;
-
-        PL_LOCK;
-        playlist_item_t *p_parent =
-            playlist_ItemGetById( p_playlist, itemId( parent ) );
-        if( !p_parent || p_parent->i_children == -1 )
-        {
-            PL_UNLOCK;
-            return false;
-        }
-
-        bool copy = false;
-        playlist_item_t *p_pl = p_playlist->p_playing;
-        playlist_item_t *p_ml = p_playlist->p_media_library;
-        if
-        (
-            row == -1 && (
-            ( p_pl && p_parent == p_pl ) ||
-            ( p_ml && p_parent == p_ml ) )
-        )
-            copy = true;
-        PL_UNLOCK;
-
         if( copy )
             dropAppendCopy( plMimeData, getItem( parent ) );
         else
diff --git a/modules/gui/qt4/components/playlist/selector.cpp b/modules/gui/qt4/components/playlist/selector.cpp
index 24bfa54..42e886e 100644
--- a/modules/gui/qt4/components/playlist/selector.cpp
+++ b/modules/gui/qt4/components/playlist/selector.cpp
@@ -372,6 +372,12 @@ bool PLSelector::dropMimeData ( QTreeWidgetItem * parent, int index,
     return true;
 }
 
+void PLSelector::dragMoveEvent ( QDragMoveEvent * event )
+{
+    event->setDropAction( Qt::CopyAction );
+    QAbstractItemView::dragMoveEvent( event );
+}
+
 void PLSelector::plItemAdded( int item, int parent )
 {
     if( parent != podcastsParentId ) return;
diff --git a/modules/gui/qt4/components/playlist/selector.hpp b/modules/gui/qt4/components/playlist/selector.hpp
index e9ea017..41d37b1 100644
--- a/modules/gui/qt4/components/playlist/selector.hpp
+++ b/modules/gui/qt4/components/playlist/selector.hpp
@@ -119,6 +119,7 @@ protected:
 private:
     QStringList mimeTypes () const;
     bool dropMimeData ( QTreeWidgetItem *, int, const QMimeData *, Qt::DropAction );
+    void dragMoveEvent ( QDragMoveEvent * event );
     void createItems();
     void drawBranches ( QPainter *, const QRect &, const QModelIndex & ) const;
     PLSelItem * addItem (



More information about the vlc-commits mailing list