]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/playlist/playlist_model.hpp
Qt: remove the zoom slider and put it on the menu
[vlc] / modules / gui / qt4 / components / playlist / playlist_model.hpp
index ca18f0f03c22fcae1794d5a16ef9c0c5ac0a69a6..a1cf54070e17a39e9a88d83cfda232e09e60e781 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * 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 <zorglub@videolan.org>
 # include "config.h"
 #endif
 
-#include "qt4.hpp"
-
 #include <vlc_input.h>
 #include <vlc_playlist.h>
-
+#include "vlc_model.hpp"
 #include "playlist_item.hpp"
 
-#include <QModelIndex>
 #include <QObject>
 #include <QEvent>
-#include <QMimeData>
 #include <QSignalMapper>
+#include <QMimeData>
 #include <QAbstractItemModel>
 #include <QVariant>
-#include <QAction>
+#include <QModelIndex>
 
 class PLItem;
 class PLSelector;
 class PlMimeData;
+class QSignalMapper;
 
-class PLModel : public QAbstractItemModel
+class PLModel : public VLCModel
 {
     Q_OBJECT
 
-friend class PLItem;
-friend class PLSelector;
-
 public:
-    enum {
-      IsCurrentRole = Qt::UserRole,
-      IsLeafNodeRole,
-      IsCurrentsParentNodeRole
-    };
-
     PLModel( playlist_t *, intf_thread_t *,
              playlist_item_t *, QObject *parent = 0 );
-    ~PLModel();
+    virtual ~PLModel();
+
+    /* Qt4 main PLModel */
+    static PLModel* getPLModel( intf_thread_t *p_intf )
+    {
+        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;
+    }
 
-    /*** QModel subclassing ***/
+    /*** QAbstractItemModel subclassing ***/
 
     /* Data structure */
-    QVariant data( const QModelIndex &index, int role ) const;
-    QVariant headerData( int section, Qt::Orientation orientation,
+    virtual QVariant data( const QModelIndex &index, const int role ) const;
+    virtual 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 parent( const QModelIndex &index ) 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 */
-    Qt::DropActions supportedDropActions() const;
-    QMimeData* mimeData( const QModelIndexList &indexes ) const;
-    bool dropMimeData( const QMimeData *data, Qt::DropAction action,
+    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 );
-    QStringList mimeTypes() const;
+    virtual QStringList mimeTypes() const;
+
+    /* Sort */
+    virtual void sort( const int column, Qt::SortOrder order = Qt::AscendingOrder );
 
     /**** Custom ****/
 
     /* Lookups */
-    QStringList selectedURIs();
-    QModelIndex index( PLItem *, int c ) const;
-    QModelIndex index( int i_id, int c );
-    QModelIndex currentIndex() const;
-    bool isParent( const QModelIndex &index, const QModelIndex &current) const;
-    bool isCurrent( const QModelIndex &index ) const;
+    QModelIndex index( const int i_id, const int c );
+    virtual QModelIndex currentIndex() 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 * );
+    void rebuild( playlist_item_t * p = NULL );
+
+    /* Popup Actions */
+    virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
+    virtual void doDelete( QModelIndexList selected );
 
-    inline PLItem *getItem( QModelIndex index ) const
+    PLItem *getItem( const QModelIndex & index ) const
     {
         if( index.isValid() )
             return static_cast<PLItem*>( index.internalPointer() );
@@ -120,18 +119,23 @@ signals:
     void rootChanged();
 
 public slots:
-    void activateItem( const QModelIndex &index );
-    void activateItem( playlist_item_t *p_item );
+    virtual void activateItem( const QModelIndex &index );
 
 private:
     /* General */
     PLItem *rootItem;
 
     playlist_t *p_playlist;
-    intf_thread_t *p_intf;
 
     static QIcon icons[ITEM_TYPE_NUMBER];
 
+    /* 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 &current) const;
+
     /* Shallow actions (do not affect core playlist) */
     void updateTreeItem( PLItem * );
     void removeItem ( PLItem * );
@@ -147,8 +151,11 @@ private:
     void dropAppendCopy( const PlMimeData * data, PLItem *target, int pos );
     void dropMove( const PlMimeData * data, PLItem *target, int new_pos );
 
+    /* */
+    void sort( const int i_root_id, const int column, Qt::SortOrder order );
+
     /* Popup */
-    int i_popup_item, i_popup_parent, i_popup_column;
+    int i_popup_item, i_popup_parent;
     QModelIndexList current_selection;
     QMenu *sortingMenu;
     QSignalMapper *sortingMapper;
@@ -164,6 +171,9 @@ private:
     int i_cached_id;
     int i_cached_input_id;
 
+    /* Zoom factor for font-size */
+    int i_zoom;
+
 private slots:
     void popupPlay();
     void popupDel();
@@ -172,11 +182,15 @@ private slots:
     void popupSave();
     void popupExplore();
     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
@@ -184,7 +198,7 @@ class PlMimeData : public QMimeData
     Q_OBJECT
 
 public:
-    PlMimeData();
+    PlMimeData() {}
     ~PlMimeData();
     void appendItem( input_item_t *p_item );
     QList<input_item_t*> inputItems() const;