X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fqt4%2Fcomponents%2Fplaylist%2Fplaylist_model.hpp;h=a1cf54070e17a39e9a88d83cfda232e09e60e781;hb=69863bd612acc31188fa55c713e0c9dc329eb909;hp=86ad09f3ae7f4de0c2f3542352aed93aef6dccf4;hpb=39d272d0ddcfed5024e7d4430b6ecf504aa41628;p=vlc diff --git a/modules/gui/qt4/components/playlist/playlist_model.hpp b/modules/gui/qt4/components/playlist/playlist_model.hpp index 86ad09f3ae..a1cf54070e 100644 --- a/modules/gui/qt4/components/playlist/playlist_model.hpp +++ b/modules/gui/qt4/components/playlist/playlist_model.hpp @@ -1,10 +1,11 @@ /***************************************************************************** * playlist_model.hpp : Model for a playlist tree **************************************************************************** - * Copyright (C) 2006 the VideoLAN team + * Copyright (C) 2006-2011 the VideoLAN team * $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,183 +29,184 @@ # include "config.h" #endif -#include #include #include +#include "vlc_model.hpp" +#include "playlist_item.hpp" -#include #include #include -#include #include +#include +#include +#include +#include -class PLModel; +class PLItem; +class PLSelector; +class PlMimeData; class QSignalMapper; -class PLItem +class PLModel : public VLCModel { - friend class PLModel; -public: - PLItem( int, int, PLItem *parent , PLModel * ); - PLItem( playlist_item_t *, PLItem *parent, PLModel * ); - ~PLItem(); + Q_OBJECT - int row() const; - void insertChild( PLItem *, int p, bool signal = true ); +public: + PLModel( playlist_t *, intf_thread_t *, + playlist_item_t *, QObject *parent = 0 ); + virtual ~PLModel(); - void appendChild( PLItem *item, bool signal = true ) + /* Qt4 main PLModel */ + static PLModel* getPLModel( intf_thread_t *p_intf ) { - insertChild( item, children.count(), signal ); - }; - void remove( PLItem *removed ); - - PLItem *child( int row ) { return children.value( row ); }; - int childCount() const { return children.count(); }; - QString columnString( int col ) { return item_col_strings.value( col ); }; - PLItem *parent() { return parentItem; }; - - void update( playlist_item_t *, bool ); -protected: - QList children; - QList item_col_strings; - bool b_current; - int i_type; - int i_id; - int i_input_id; - int i_showflags; - - void updateview(); -private: - void init( int, int, PLItem *, PLModel * ); - PLItem *parentItem; - PLModel *model; -}; + if(!p_intf->p_sys->pl_model ) + { + playlist_Lock( THEPL ); + playlist_item_t *p_root = THEPL->p_playing; + playlist_Unlock( THEPL ); + p_intf->p_sys->pl_model = new PLModel( THEPL, p_intf, p_root, NULL ); + } + + return p_intf->p_sys->pl_model; + } + + /*** QAbstractItemModel subclassing ***/ + + /* Data structure */ + virtual QVariant data( const QModelIndex &index, const int role ) const; + virtual QVariant headerData( int section, Qt::Orientation orientation, + int role = Qt::DisplayRole ) const; + virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const; + virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const; + virtual Qt::ItemFlags flags( const QModelIndex &index ) const; + virtual QModelIndex index( const int r, const int c, const QModelIndex &parent ) const; + virtual QModelIndex parent( const QModelIndex &index ) const; + + /* Drag and Drop */ + virtual Qt::DropActions supportedDropActions() const; + virtual QMimeData* mimeData( const QModelIndexList &indexes ) const; + virtual bool dropMimeData( const QMimeData *data, Qt::DropAction action, + int row, int column, const QModelIndex &target ); + virtual QStringList mimeTypes() const; -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; + /* Sort */ + virtual void sort( const int column, Qt::SortOrder order = Qt::AscendingOrder ); -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; -}; + /**** Custom ****/ -#include -#include + /* Lookups */ + QModelIndex index( const int i_id, const int c ); + virtual QModelIndex currentIndex() const; + int itemId( const QModelIndex &index ) const; -class PLModel : public QAbstractItemModel -{ - Q_OBJECT + /* */ + void search( const QString& search_text, const QModelIndex & root, bool b_recursive ); + void rebuild( playlist_item_t * p = NULL ); -friend class PLItem; + /* Popup Actions */ + virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list ); + virtual void doDelete( QModelIndexList selected ); -public: - PLModel( playlist_t *, intf_thread_t *, - playlist_item_t *, int, QObject *parent = 0 ); - ~PLModel(); + PLItem *getItem( const QModelIndex & index ) const + { + if( index.isValid() ) + return static_cast( index.internalPointer() ); + else return rootItem; + } - /* All types of lookups / QModel stuff */ - 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; - - 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 ); +signals: + void currentChanged( const QModelIndex& ); + void rootChanged(); - /* DnD handling */ - 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; +public slots: + virtual void activateItem( const QModelIndex &index ); - int shownFlags() { return rootItem->i_showflags; } private: - void addCallbacks(); - void delCallbacks(); - void customEvent( QEvent * ); - + /* 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 ); + /* Custom model private methods */ + /* Lookups */ + QStringList selectedURIs(); + QModelIndex index( PLItem *, const int c ) const; + bool isCurrent( const QModelIndex &index ) const; + bool isParent( const QModelIndex &index, const QModelIndex ¤t) const; + + /* Shallow actions (do not affect core playlist) */ + void updateTreeItem( PLItem * ); + void removeItem ( PLItem * ); + void removeItem( int ); + void recurseDelete( QList children, 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 * ); - 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 * ); + /* Deep actions (affect core playlist) */ + void dropAppendCopy( const PlMimeData * data, PLItem *target, int pos ); + void dropMove( const PlMimeData * data, PLItem *target, int new_pos ); - /* Actions */ - void recurseDelete( QList children, QModelIndexList *fullList ); - void doDeleteItem( PLItem *item, QModelIndexList *fullList ); + /* */ + void sort( const int i_root_id, const int column, Qt::SortOrder order ); /* Popup */ int i_popup_item, i_popup_parent; 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 ) 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 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 ); + + /* Zoom factor for font-size */ + int i_zoom; + private slots: void popupPlay(); void popupDel(); void popupInfo(); void popupStream(); void popupSave(); -#ifdef WIN32 void popupExplore(); -#endif - void viewchanged( int ); + void popupAddNode(); + void popupAddToPlaylist(); + 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 ); + void activateItem( playlist_item_t *p_item ); + void increaseZoom(); + void decreaseZoom(); +}; + +class PlMimeData : public QMimeData +{ + Q_OBJECT + +public: + PlMimeData() {} + ~PlMimeData(); + void appendItem( input_item_t *p_item ); + QList inputItems() const; + QStringList formats () const; + +private: + QList _inputItems; + QMimeData *_mimeData; }; #endif