]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/playlist/playlist_model.hpp
Qt4: compressor and Spatializer widget margin shouldn't be 0
[vlc] / modules / gui / qt4 / components / playlist / playlist_model.hpp
index 19f704b1e4ab345365820c832d30877c6cf54cff..11a582ea88a653c420be4d14df695e1573935d7a 100644 (file)
 #include <QSignalMapper>
 #include <QAbstractItemModel>
 #include <QVariant>
+#include <QAction>
 
-class QSignalMapper;
 class PLItem;
+class PLSelector;
+class PlMimeData;
 
 class PLModel : public QAbstractItemModel
 {
     Q_OBJECT
 
 friend class PLItem;
+friend class PLSelector;
 
 public:
     enum {
-      IsCurrentRole = Qt::UserRole
+      IsCurrentRole = Qt::UserRole,
+      IsLeafNodeRole,
+      IsCurrentsParentNodeRole
     };
 
     PLModel( playlist_t *, intf_thread_t *,
@@ -65,13 +70,13 @@ public:
     /*** QModel subclassing ***/
 
     /* Data structure */
-    QVariant data( const QModelIndex &index, int role ) const;
+    QVariant data( const QModelIndex &index, const int role ) const;
     QVariant headerData( int section, Qt::Orientation orientation,
                          int role = Qt::DisplayRole ) const;
     int rowCount( const QModelIndex &parent = QModelIndex() ) const;
     int columnCount( const QModelIndex &parent = QModelIndex() ) const;
     Qt::ItemFlags flags( const QModelIndex &index ) const;
-    QModelIndex index( int r, int c, const QModelIndex &parent ) const;
+    QModelIndex index( const int r, const int c, const QModelIndex &parent ) const;
     QModelIndex parent( const QModelIndex &index ) const;
 
     /* Drag and Drop */
@@ -85,19 +90,23 @@ public:
 
     /* Lookups */
     QStringList selectedURIs();
-    QModelIndex index( PLItem *, int c ) const;
-    QModelIndex index( int i_id, int c );
-    QModelIndex currentIndex();
+    QModelIndex index( PLItem *, const int c ) const;
+    QModelIndex index( const int i_id, const int c );
+    QModelIndex currentIndex() const;
+    bool isParent( const QModelIndex &index, const QModelIndex &current) const;
     bool isCurrent( const QModelIndex &index ) const;
     int itemId( const QModelIndex &index ) const;
+    static int columnFromMeta( int meta_column );
+    static int columnToMeta( int column );
 
     /* Actions */
-    void popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
+    bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
     void doDelete( QModelIndexList selected );
-    void search( const QString& search_text );
-    void sort( int column, Qt::SortOrder order );
-    void sort( int i_root_id, int column, Qt::SortOrder order );
-    void rebuild(); void rebuild( playlist_item_t *, bool b_first = false );
+    void search( const QString& search_text, const QModelIndex & root, bool b_recursive );
+    void sort( const int column, Qt::SortOrder order );
+    void sort( const int i_root_id, const int column, Qt::SortOrder order );
+    void rebuild();
+    void rebuild( playlist_item_t * );
 
     inline PLItem *getItem( QModelIndex index ) const
     {
@@ -106,55 +115,55 @@ public:
         else return rootItem;
     }
 
-private:
+signals:
+    void currentChanged( const QModelIndex& );
+    void rootChanged();
+
+public slots:
+    void activateItem( const QModelIndex &index );
+    void activateItem( playlist_item_t *p_item );
 
+private:
     /* General */
     PLItem *rootItem;
 
     playlist_t *p_playlist;
     intf_thread_t *p_intf;
-    int i_depth;
 
     static QIcon icons[ITEM_TYPE_NUMBER];
 
-    /* Actions */
-    void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
+    /* Shallow actions (do not affect core playlist) */
     void updateTreeItem( PLItem * );
     void removeItem ( PLItem * );
     void removeItem( int );
+    void recurseDelete( QList<PLItem*> children, QModelIndexList *fullList );
     void takeItem( PLItem * ); //will not delete item
     void insertChildren( PLItem *node, QList<PLItem*>& items, int i_pos );
-    void dropAppendCopy( QByteArray& data, PLItem *target );
-    void dropMove( QByteArray& data, PLItem *target, int new_pos );
-    /* The following actions will not signal the view! */
+    /* ...of which  the following will not update the views */
     void updateChildren( PLItem * );
     void updateChildren( playlist_item_t *, PLItem * );
 
+    /* Deep actions (affect core playlist) */
+    void dropAppendCopy( const PlMimeData * data, PLItem *target, int pos );
+    void dropMove( const PlMimeData * data, PLItem *target, int new_pos );
+
     /* Popup */
     int i_popup_item, i_popup_parent, i_popup_column;
     QModelIndexList current_selection;
+    QMenu *sortingMenu;
+    QSignalMapper *sortingMapper;
 
     /* Lookups */
-    PLItem *findById( PLItem *, int );
-    PLItem *findByInput( PLItem *, int );
-    PLItem *findInner( PLItem *, int , bool );
-
-    int columnFromMeta( int meta_column ) const;
-    int columnToMeta( int column ) const;
+    PLItem *findById( PLItem *, int ) const;
+    PLItem *findByInput( PLItem *, int ) const;
+    PLItem *findInner(PLItem *, int , bool ) const;
     bool canEdit() const;
+
     PLItem *p_cached_item;
     PLItem *p_cached_item_bi;
     int i_cached_id;
     int i_cached_input_id;
 
-signals:
-    void currentChanged( const QModelIndex& );
-    void rootChanged();
-
-public slots:
-    void activateItem( const QModelIndex &index );
-    void activateItem( playlist_item_t *p_item );
-
 private slots:
     void popupPlay();
     void popupDel();
@@ -163,12 +172,27 @@ private slots:
     void popupSave();
     void popupExplore();
     void popupAddNode();
-    void popupSortAsc();
-    void popupSortDesc();
+    void popupSort( int column );
     void processInputItemUpdate( input_item_t *);
     void processInputItemUpdate( input_thread_t* p_input );
     void processItemRemoval( int i_id );
     void processItemAppend( int item, int parent );
 };
 
+class PlMimeData : public QMimeData
+{
+    Q_OBJECT
+
+public:
+    PlMimeData();
+    ~PlMimeData();
+    void appendItem( input_item_t *p_item );
+    QList<input_item_t*> inputItems() const;
+    QStringList formats () const;
+
+private:
+    QList<input_item_t*> _inputItems;
+    QMimeData *_mimeData;
+};
+
 #endif