QT4 playlist: even better DragNDrop policy
authorJakob Leben <jakob.leben@gmail.com>
Sun, 9 Aug 2009 18:31:40 +0000 (20:31 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Tue, 11 Aug 2009 15:41:55 +0000 (18:41 +0300)
Drop enabled only inside Playlist and Media player, not Podcast and
other Internet sources...

Signed-off-by: Rémi Denis-Courmont <remi@remlab.net>
modules/gui/qt4/components/playlist/playlist_model.cpp

index 2288e72..1d389ea 100644 (file)
@@ -115,18 +115,32 @@ Qt::DropActions PLModel::supportedDropActions() const
 
 Qt::ItemFlags PLModel::flags( const QModelIndex &index ) const
 {
-    Qt::ItemFlags defaultFlags = QAbstractItemModel::flags( index );
-    if( index.isValid() )
+    Qt::ItemFlags flags = QAbstractItemModel::flags( index );
+
+    PLItem *item = index.isValid() ?
+        static_cast<PLItem*>( index.internalPointer() ) :
+        rootItem;
+
+    int pl_input_id = p_playlist->p_local_category->p_input->i_id;
+    int ml_input_id = p_playlist->p_ml_category->p_input->i_id;
+
+    if( rootItem->i_id == p_playlist->p_root_onelevel->i_id
+          || rootItem->i_id == p_playlist->p_root_category->i_id )
+    {
+        if( item->i_input_id == pl_input_id
+            || item->i_input_id == ml_input_id )
+                flags |= Qt::ItemIsDropEnabled;
+    }
+    else
     {
-        PLItem *item = static_cast<PLItem*>( index.internalPointer() );
-        if ( item->b_is_node )
-            defaultFlags |= Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
-        else defaultFlags |= Qt::ItemIsDragEnabled;
-    }
-    else if ( rootItem->i_id != p_playlist->p_root_onelevel->i_id
-          && rootItem->i_id != p_playlist->p_root_category->i_id )
-              defaultFlags |= Qt::ItemIsDropEnabled;
-    return defaultFlags;
+        if ( item->b_is_node &&
+            ( rootItem->i_input_id == pl_input_id ||
+            rootItem->i_input_id == ml_input_id ) )
+                flags |= Qt::ItemIsDropEnabled;
+        flags |= Qt::ItemIsDragEnabled;
+    }
+
+    return flags;
 }
 
 /* A list of model indexes are a playlist */