X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fqt4%2Fcomponents%2Fplaylist%2Fplaylist_model.hpp;h=f6343dfebae8adca8b79c2cc1c161926f3a287c3;hb=eb2da50b47b1af2d9b38a982579f34873d1bb081;hp=dd6ca2c51017f578a881ea67e2e3816b587f404b;hpb=c243a82ea99d0f3fd4bf42a41227cc07f95f4c10;p=vlc diff --git a/modules/gui/qt4/components/playlist/playlist_model.hpp b/modules/gui/qt4/components/playlist/playlist_model.hpp index dd6ca2c510..f6343dfeba 100644 --- a/modules/gui/qt4/components/playlist/playlist_model.hpp +++ b/modules/gui/qt4/components/playlist/playlist_model.hpp @@ -5,6 +5,7 @@ * $Id$ * * Authors: Clément Stenac + * Jakob Leben * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,9 +29,11 @@ # include "config.h" #endif -#include +#include "qt4.hpp" + #include #include + #include "playlist_item.hpp" #include @@ -40,131 +43,126 @@ #include #include #include - -class QSignalMapper; +#include class PLItem; - -#define DEPTH_PL -1 -#define DEPTH_SEL 1 - -static int ItemUpdate_Type = QEvent::User + 2; -static int ItemDelete_Type = QEvent::User + 3; -static int ItemAppend_Type = QEvent::User + 4; -static int PLUpdate_Type = QEvent::User + 5; - -class PLEvent : public QEvent -{ -public: - PLEvent( int type, int id ) : QEvent( (QEvent::Type)(type) ) - { i_id = id; p_add = NULL; }; - - PLEvent( playlist_add_t *a ) : QEvent( (QEvent::Type)(ItemAppend_Type) ) - { p_add = a; }; - - virtual ~PLEvent() {}; - - int i_id; - playlist_add_t *p_add; -}; - +class PLSelector; +class PlMimeData; class PLModel : public QAbstractItemModel { Q_OBJECT friend class PLItem; +friend class PLSelector; public: + enum { + IsCurrentRole = Qt::UserRole, + IsLeafNodeRole, + IsCurrentsParentNodeRole + }; + PLModel( playlist_t *, intf_thread_t *, - playlist_item_t *, int, QObject *parent = 0 ); + playlist_item_t *, QObject *parent = 0 ); ~PLModel(); - /* All types of lookups / QModel stuff */ + /*** QModel subclassing ***/ + + /* Data structure */ QVariant data( const QModelIndex &index, int role ) const; - Qt::ItemFlags flags( const QModelIndex &index ) const; QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; - QModelIndex index( int r, int c, const QModelIndex &parent ) const; - QModelIndex index( PLItem *, int c ) const; - int itemId( const QModelIndex &index ) const; - bool isCurrent( const QModelIndex &index ); - QModelIndex parent( const QModelIndex &index ) const; - int childrenCount( const QModelIndex &parent = QModelIndex() ) 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 parent( const QModelIndex &index ) const; - bool b_need_update; - int i_items_to_append; - - void rebuild(); void rebuild( playlist_item_t * ); - bool hasRandom(); bool hasLoop(); bool hasRepeat(); - - /* Actions made by the views */ - void popup( QModelIndex & index, QPoint &point, QModelIndexList list ); - void doDelete( QModelIndexList selected ); - void search( QString search ); - void sort( int column, Qt::SortOrder order ); - void removeItem( int ); - - /* DnD handling */ + /* Drag and Drop */ Qt::DropActions supportedDropActions() const; QMimeData* mimeData( const QModelIndexList &indexes ) const; bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &target ); QStringList mimeTypes() const; - int shownFlags() { return rootItem->i_showflags; } + /**** Custom ****/ -private: - void addCallbacks(); - void delCallbacks(); - void customEvent( QEvent * ); + /* Lookups */ + QStringList selectedURIs(); + QModelIndex index( PLItem *, int c ) const; + QModelIndex index( int i_id, int c ); + QModelIndex currentIndex(); + bool isParent( const QModelIndex &index, const QModelIndex ¤t) 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 */ + bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list ); + void doDelete( QModelIndexList selected ); + void search( const QString& search_text, const QModelIndex & root, bool b_recursive ); + 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 * ); + + inline PLItem *getItem( QModelIndex index ) const + { + if( index.isValid() ) + return static_cast( index.internalPointer() ); + else return rootItem; + } + +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]; - /* Update processing */ - void ProcessInputItemUpdate( int i_input_id ); - void ProcessItemRemoval( int i_id ); - void ProcessItemAppend( playlist_add_t *p_add ); - - void UpdateTreeItem( PLItem *, bool, bool force = false ); - void UpdateTreeItem( playlist_item_t *, PLItem *, bool, bool forc = false ); - void UpdateNodeChildren( PLItem * ); - void UpdateNodeChildren( playlist_item_t *, PLItem * ); - - /* Actions */ + /* Shallow actions (do not affect core playlist) */ + void updateTreeItem( PLItem * ); + void removeItem ( PLItem * ); + void removeItem( int ); void recurseDelete( QList children, QModelIndexList *fullList ); - void doDeleteItem( PLItem *item, QModelIndexList *fullList ); + void takeItem( PLItem * ); //will not delete item + void insertChildren( PLItem *node, QList& items, int i_pos ); + /* ...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; + int i_popup_item, i_popup_parent, i_popup_column; QModelIndexList current_selection; - QSignalMapper *ContextUpdateMapper; + QMenu *sortingMenu; + QSignalMapper *sortingMapper; /* Lookups */ - PLItem *FindById( PLItem *, int ); - PLItem *FindByInput( PLItem *, int ); - PLItem *FindInner( PLItem *, int , bool ); + PLItem *findById( PLItem *, int ); + PLItem *findByInput( PLItem *, int ); + PLItem *findInner( PLItem *, int , bool ); + bool canEdit() const; + PLItem *p_cached_item; PLItem *p_cached_item_bi; int i_cached_id; int i_cached_input_id; -signals: - void shouldRemove( int ); - -public slots: - void activateItem( const QModelIndex &index ); - void activateItem( playlist_item_t *p_item ); - void setRandom( bool ); - void setLoop( bool ); - void setRepeat( bool ); private slots: void popupPlay(); @@ -172,11 +170,29 @@ private slots: void popupInfo(); void popupStream(); void popupSave(); -#ifdef WIN32 void popupExplore(); -#endif + void popupAddNode(); + 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 inputItems() const; + QStringList formats () const; - void viewchanged( int ); +private: + QList _inputItems; + QMimeData *_mimeData; }; #endif