]> git.sesse.net Git - vlc/commitdiff
Qt4: move the selector from View/Model to QTreeWidget
authorJean-Baptiste Kempf <jb@videolan.org>
Tue, 1 Sep 2009 22:46:34 +0000 (00:46 +0200)
committerJean-Baptiste Kempf <jb@videolan.org>
Sun, 6 Sep 2009 22:04:43 +0000 (00:04 +0200)
The idea behind this is to simplify the playlist_model and have a better SD control.

modules/gui/qt4/components/playlist/panels.hpp
modules/gui/qt4/components/playlist/playlist.cpp
modules/gui/qt4/components/playlist/playlist.hpp
modules/gui/qt4/components/playlist/selector.cpp
modules/gui/qt4/components/playlist/selector.hpp
modules/gui/qt4/components/playlist/standardpanel.cpp

index 4654b09e3f44a20476bddefd1c35ce64dd1cc4e9..d949c40ad23af15df642f82fc44cbe881033b681 100644 (file)
@@ -35,6 +35,8 @@
 #include <QWidget>
 #include <QString>
 
+#include <vlc_playlist.h>
+
 class QSignalMapper;
 class QTreeView;
 class PLModel;
@@ -56,6 +58,7 @@ protected:
     QFrame *parent;
 public slots:
     virtual void setRoot( int ) = 0;
+    virtual void setRoot( playlist_item_t * ) = 0;
 };
 
 
@@ -79,6 +82,7 @@ private:
 public slots:
     void removeItem( int );
     virtual void setRoot( int );
+    virtual void setRoot( playlist_item_t * );
 private slots:
     void deleteSelection();
     void handleExpansion( const QModelIndex& );
@@ -87,7 +91,7 @@ private slots:
     void gotoPlayingItem();
     void doPopup( QModelIndex index, QPoint point );
     void search( const QString& searchText );
-    void setCurrentRootId( int );
+    void setCurrentRootId( playlist_item_t * );
     void popupAdd();
     void popupSelectColumn( QPoint );
     void toggleColumnShown( int );
index 4ae5a301f822936c5cfe1a23ca863078d1fa075b..7851073a631c2f20fd2e71b8981e28adf69b7aa6 100644 (file)
@@ -77,20 +77,21 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) : p_intf ( _p_i )
     rightPanel = new StandardPLPanel( this, p_intf, THEPL, p_root );
 
     /* Connect the activation of the selector to a redefining of the PL */
-    CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
+    CONNECT( selector, activated( playlist_item_t * ),
+             rightPanel, setRoot( playlist_item_t * ) );
 
     /* Connect the activated() to the rootChanged() signal
        This will be used by StandardPLPanel to setCurrentRootId, that will
        change the label of the addButton  */
-    connect( selector, SIGNAL( activated( int ) ),
-             this, SIGNAL( rootChanged( int ) ) );
+    connect( selector, SIGNAL( activated( playlist_item_t * ) ),
+             this, SIGNAL( rootChanged( playlist_item_t * ) ) );
 
     /* Forward removal requests from the selector to the main panel */
-    CONNECT( qobject_cast<PLSelector *>( selector )->model,
+/*    CONNECT( qobject_cast<PLSelector *>( selector )->model,
              shouldRemove( int ),
-             qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
+             qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) ); */
 
-    emit rootChanged( p_root->i_id );
+    emit rootChanged( p_root );
 
     /* Add the two sides of the QSplitter */
     addWidget( leftW );
index ee3dad65dd4771193ae8fb8523c3508fda47cb5d..38270e6749f6da026cc9e64762c81b9c2c57e90e 100644 (file)
@@ -62,7 +62,7 @@ protected:
     virtual void closeEvent( QCloseEvent * );
 
 signals:
-    void rootChanged( int );
+    void rootChanged( playlist_item_t *);
 };
 
 class ArtLabel : public CoverArtLabel
index 22cad94f6be000d629566cb1e2c59c47c34246f9..40632214dd3c15762dfe8f1275e804096fd5c609 100644 (file)
 # include "config.h"
 #endif
 
+#include <assert.h>
+
 #include "components/playlist/selector.hpp"
 #include "qt4.hpp"
 
 #include <QVBoxLayout>
 #include <QHeaderView>
-#include <QTreeView>
+#include <QTreeWidget>
+
+#include <vlc_playlist.h>
 
 PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf ) : QWidget( p ), p_intf(_p_intf)
 {
-    model = new PLModel( THEPL, p_intf, THEPL->p_root_category, 1, this );
-    view = new QTreeView( 0 );
+//    model = new PLModel( THEPL, p_intf, THEPL->p_root_category, 1, this );
+    view = new QTreeWidget;
     view->setIconSize( QSize( 24,24 ) );
-    view->setAlternatingRowColors( true );
+//    view->setAlternatingRowColors( true );
     view->setIndentation( 0 );
     view->header()->hide();
-    view->setModel( model );
+//    view->setModel( model );
 
     view->setAcceptDrops(true);
     view->setDropIndicatorShown(true);
 
-    CONNECT( view, activated( const QModelIndex& ),
-             this, setSource( const QModelIndex& ) );
-    CONNECT( view, clicked( const QModelIndex& ),
-             this, setSource( const QModelIndex& ) );
+
+    createItems();
+    CONNECT( view, itemActivated( QTreeWidgetItem *, int ),
+             this, setSource( QTreeWidgetItem *) );
+    CONNECT( view, itemClicked( QTreeWidgetItem *, int ),
+             this, setSource( QTreeWidgetItem *) );
 
     QVBoxLayout *layout = new QVBoxLayout();
     layout->setSpacing( 0 ); layout->setMargin( 0 );
@@ -56,15 +62,38 @@ PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf ) : QWidget( p ), p_i
     setLayout( layout );
 
     /* select the first item */
-    view->setCurrentIndex( model->index( 0, 0, QModelIndex() ) );
+//  view->setCurrentIndex( model->index( 0, 0, QModelIndex() ) );
 }
 
-void PLSelector::setSource( const QModelIndex &index )
+void PLSelector::setSource( QTreeWidgetItem *item )
 {
-    if( model )
-        emit activated( model->itemId( index ) );
+    if( item )
+    {
+        playlist_item_t *pl_item =
+                item->data( 0, Qt::UserRole ).value<playlist_item_t *>();
+        emit activated( pl_item );
+    }
 }
 
+void PLSelector::createItems()
+{
+    assert( view );
+    QTreeWidgetItem *pl = new QTreeWidgetItem( view );
+    pl->setText( 0, qtr( "Playlist" ) );
+    pl->setData( 0, Qt::UserRole, QVariant::fromValue( THEPL->p_local_category ) );
+/*    QTreeWidgetItem *empty = new QTreeWidgetItem( view );
+    empty->setFlags(Qt::NoItemFlags);
+*/
+    QTreeWidgetItem *lib = new QTreeWidgetItem( view );
+    lib->setText( 0, qtr( "Library" ) );
+    lib->setData( 0, Qt::UserRole, QVariant::fromValue( THEPL->p_ml_category ) );
+/*
+    QTreeWidgetItem *empty2 = new QTreeWidgetItem( view );
+    empty2->setFlags(Qt::NoItemFlags);*/
+
+
+
+}
 PLSelector::~PLSelector()
 {
 }
index 63a514e51a644f4f65e3b8dacc12c513c1c3724d..f496dd9dff098ae52661733c1452fa47a97fc063 100644 (file)
 #include "components/playlist/playlist_model.hpp"
 
 #include <QWidget>
+#include <QTreeWidgetItem>
 
-class QTreeView;
+class QTreeWidget;
 class PlaylistWidget;
 
+Q_DECLARE_METATYPE( playlist_item_t *);
 class PLSelector: public QWidget
 {
     Q_OBJECT;
@@ -46,11 +48,13 @@ protected:
     friend class PlaylistWidget;
 private:
     intf_thread_t *p_intf;
-    QTreeView *view;
+    QTreeWidget *view;
+    void createItems();
 private slots:
-    void setSource( const QModelIndex& );
+    void setSource( QTreeWidgetItem *item );
 signals:
     void activated( int );
+    void activated( playlist_item_t * );
     void shouldRemove( int );
 };
 
index d7cabd4a12536412af9877425decfdb6351c3716..5ecaf301a88f769008b30a62336257a8fe7e0df8 100644 (file)
@@ -107,7 +107,8 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
              this, handleExpansion( const QModelIndex& ) );
 
     currentRootId = -1;
-    CONNECT( parent, rootChanged( int ), this, setCurrentRootId( int ) );
+    CONNECT( parent, rootChanged( playlist_item_t * ),
+             this, setCurrentRootId( playlist_item_t * ) );
 
     /* Buttons configuration */
     QHBoxLayout *buttons = new QHBoxLayout;
@@ -219,19 +220,16 @@ void StandardPLPanel::handleExpansion( const QModelIndex& index )
     view->scrollTo( index );
 }
 
-void StandardPLPanel::setCurrentRootId( int _new )
+void StandardPLPanel::setCurrentRootId( playlist_item_t *p_item )
 {
-    currentRootId = _new;
-    if( currentRootId == THEPL->p_local_category->i_id ||
-        currentRootId == THEPL->p_local_onelevel->i_id  )
+    if( p_item == THEPL->p_local_category ||
+        p_item == THEPL->p_local_onelevel )
     {
         addButton->setEnabled( true );
         addButton->setToolTip( qtr(I_PL_ADDPL) );
     }
-    else if( ( THEPL->p_ml_category &&
-                        currentRootId == THEPL->p_ml_category->i_id ) ||
-             ( THEPL->p_ml_onelevel &&
-                        currentRootId == THEPL->p_ml_onelevel->i_id ) )
+    else if( ( THEPL->p_ml_category && p_item == THEPL->p_ml_category) ||
+             ( THEPL->p_ml_onelevel && p_item == THEPL->p_ml_onelevel ) )
     {
         addButton->setEnabled( true );
         addButton->setToolTip( qtr(I_PL_ADDML) );
@@ -310,6 +308,14 @@ void StandardPLPanel::setRoot( int i_root_id )
     playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id );
     assert( p_item );
     p_item = playlist_GetPreferredNode( THEPL, p_item );
+    setRoot( p_item );
+    QPL_UNLOCK;
+}
+
+void StandardPLPanel::setRoot( playlist_item_t *p_item )
+{
+    QPL_LOCK;
+    p_item = playlist_GetPreferredNode( THEPL, p_item );
     assert( p_item );
     QPL_UNLOCK;