From bb22f2970dd4978f7d2d6420dc1b96b4f1492b5b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Kempf <jb@videolan.org> Date: Wed, 5 Sep 2007 15:14:56 +0000 Subject: [PATCH] Qt4 - Right click on the header on the QTreeView for the playlist enables you to choose the columns you want to be shown. This removes also the code that was in the Model part since this is View Related. Ref #1282 (almost done). There is still segfaults on close of VLC after that menu is triggered. --- .../gui/qt4/components/playlist/panels.hpp | 2 + .../qt4/components/playlist/standardpanel.cpp | 62 +++++++++++++++---- modules/gui/qt4/playlist_model.cpp | 8 +-- modules/gui/qt4/playlist_model.hpp | 7 +++ 4 files changed, 63 insertions(+), 16 deletions(-) diff --git a/modules/gui/qt4/components/playlist/panels.hpp b/modules/gui/qt4/components/playlist/panels.hpp index a3410bcfa0bb..92213b0e185c 100644 --- a/modules/gui/qt4/components/playlist/panels.hpp +++ b/modules/gui/qt4/components/playlist/panels.hpp @@ -75,6 +75,7 @@ private: QPushButton *repeatButton , *randomButton,*addButton; ClickLineEdit *searchLine; int currentRootId; +QSignalMapper *ContextUpdateMapper; public slots: void removeItem( int ); virtual void setRoot( int ); @@ -88,6 +89,7 @@ private slots: void clearFilter(); void add(); void setCurrentRootId( int ); + void popupSelectColumn( QPoint ); }; #endif diff --git a/modules/gui/qt4/components/playlist/standardpanel.cpp b/modules/gui/qt4/components/playlist/standardpanel.cpp index bba41f86971a..a9f7aa092cde 100644 --- a/modules/gui/qt4/components/playlist/standardpanel.cpp +++ b/modules/gui/qt4/components/playlist/standardpanel.cpp @@ -50,27 +50,34 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, PLPanel( _parent, _p_intf ) { model = new PLModel( p_playlist, p_intf, p_root, -1, this ); + + /* Create and configure the QTreeView */ view = new QVLCTreeView( 0 ); view->setModel(model); view->setIconSize( QSize(20,20) ); view->setAlternatingRowColors( true ); - view->header()->resizeSection( 0, 230 ); - view->header()->resizeSection( 1, 170 ); - view->header()->setSortIndicatorShown( true ); - view->header()->setClickable( true ); - + view->setAnimated( true ); + view->setSortingEnabled( true ); view->setSelectionMode( QAbstractItemView::ExtendedSelection ); view->setDragEnabled( true ); view->setAcceptDrops( true ); view->setDropIndicatorShown( true ); view->setAutoScroll( true ); - + + view->header()->resizeSection( 0, 230 ); + view->header()->resizeSection( 1, 170 ); + view->header()->setSortIndicatorShown( true ); + view->header()->setClickable( true ); + view->header()->setContextMenuPolicy( Qt::CustomContextMenu ); + CONNECT( view, activated( const QModelIndex& ) , model,activateItem( const QModelIndex& ) ); CONNECT( view, rightClicked( QModelIndex , QPoint ), this, doPopup( QModelIndex, QPoint ) ); CONNECT( model, dataChanged( const QModelIndex&, const QModelIndex& ), this, handleExpansion( const QModelIndex& ) ); + CONNECT( view->header(), customContextMenuRequested( const QPoint & ), + this, popupSelectColumn( QPoint ) ); currentRootId = -1; CONNECT( parent, rootChanged(int), this, setCurrentRootId( int ) ); @@ -78,25 +85,29 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, QVBoxLayout *layout = new QVBoxLayout(); layout->setSpacing( 0 ); layout->setMargin( 0 ); + /* Buttons configuration */ QHBoxLayout *buttons = new QHBoxLayout(); - + addButton = new QPushButton( "+", this ); addButton->setMaximumWidth( 25 ); BUTTONACT( addButton, add() ); buttons->addWidget( addButton ); - repeatButton = new QPushButton( 0 ); buttons->addWidget( repeatButton ); + repeatButton = new QPushButton( this ); if( model->hasRepeat() ) repeatButton->setText( qtr( I_PL_REPEAT ) ); else if( model->hasLoop() ) repeatButton->setText( qtr( I_PL_LOOP ) ); else repeatButton->setText( qtr( I_PL_NOREPEAT ) ); BUTTONACT( repeatButton, toggleRepeat() ); + buttons->addWidget( repeatButton ); - randomButton = new QPushButton( 0 ); buttons->addWidget( randomButton ); + randomButton = new QPushButton( this ); randomButton->setText( model->hasRandom() ? qtr( I_PL_RANDOM ) : qtr( I_PL_NORANDOM) ); BUTTONACT( randomButton, toggleRandom() ); + buttons->addWidget( randomButton ); - QSpacerItem *spacer = new QSpacerItem( 10, 20 );buttons->addItem( spacer ); + QSpacerItem *spacer = new QSpacerItem( 10, 20 ); + buttons->addItem( spacer ); QLabel *filter = new QLabel( qtr(I_PL_SEARCH) + " " ); buttons->addWidget( filter ); @@ -106,8 +117,8 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, QPushButton *clear = new QPushButton( qfu( "CL") ); clear->setMaximumWidth( 30 ); - buttons->addWidget( clear ); BUTTONACT( clear, clearFilter() ); + buttons->addWidget( clear ); layout->addWidget( view ); layout->addLayout( buttons ); @@ -195,6 +206,35 @@ void StandardPLPanel::add() popup->popup( QCursor::pos() ); } +void StandardPLPanel::popupSelectColumn( QPoint ) +{ + ContextUpdateMapper = new QSignalMapper(this); + + QMenu *selectColMenu = new QMenu( qtr("Show columns") ); + +#define ADD_META_ACTION( meta ) { \ + QAction* option = selectColMenu->addAction( qfu(VLC_META_##meta) ); \ + option->setCheckable( true ); \ + option->setChecked( model->shownFlags() & VLC_META_ENGINE_##meta ); \ + ContextUpdateMapper->setMapping( option, VLC_META_ENGINE_##meta ); \ + CONNECT( option, triggered(), ContextUpdateMapper, map() ); \ + } + CONNECT( ContextUpdateMapper, mapped( int ), model, viewchanged( int ) ); + + ADD_META_ACTION( TITLE ); + ADD_META_ACTION( ARTIST ); + ADD_META_ACTION( DURATION ); + ADD_META_ACTION( COLLECTION ); + ADD_META_ACTION( GENRE ); + ADD_META_ACTION( SEQ_NUM ); + ADD_META_ACTION( RATING ); + ADD_META_ACTION( DESCRIPTION ); + +#undef ADD_META_ACTION + + selectColMenu->popup( QCursor::pos() ); + } + void StandardPLPanel::clearFilter() { searchLine->setText( "" ); diff --git a/modules/gui/qt4/playlist_model.cpp b/modules/gui/qt4/playlist_model.cpp index 16d53cb3a4af..0bbe46ff15cc 100644 --- a/modules/gui/qt4/playlist_model.cpp +++ b/modules/gui/qt4/playlist_model.cpp @@ -72,7 +72,6 @@ void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m) i_id = _i_id; i_input_id = _i_input_id; model = m; - if( parentItem == NULL ) { i_showflags = config_GetInt( model->p_intf , "qt-pl-showflags" ); @@ -289,7 +288,6 @@ PLModel::PLModel( playlist_t *_p_playlist, intf_thread_t *_p_intf, rebuild( p_root ); } - PLModel::~PLModel() { delCallbacks(); @@ -971,9 +969,9 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list ) menu->addAction( qfu(I_POP_SORT), this, SLOT( popupSort() ) ); menu->addAction( qfu(I_POP_ADD), this, SLOT( popupAdd() ) ); } - menu->addSeparator(); + // menu->addSeparator(); - ContextUpdateMapper = new QSignalMapper(this); + /*ContextUpdateMapper = new QSignalMapper(this); QMenu *selectColMenu = new QMenu( qtr("Show columns") ); @@ -996,7 +994,7 @@ void PLModel::popup( QModelIndex & index, QPoint &point, QModelIndexList list ) ADD_META_ACTION( DESCRIPTION ); #undef ADD_META_ACTION - menu->addMenu( selectColMenu ); + menu->addMenu( selectColMenu );*/ menu->popup( point ); } else diff --git a/modules/gui/qt4/playlist_model.hpp b/modules/gui/qt4/playlist_model.hpp index d8a87ea9f7bd..981acf2f33d1 100644 --- a/modules/gui/qt4/playlist_model.hpp +++ b/modules/gui/qt4/playlist_model.hpp @@ -66,6 +66,7 @@ protected: int i_id; int i_input_id; int i_showflags; + void updateview( void ); friend class PLModel; private: @@ -120,6 +121,7 @@ public: bool b_need_update; int i_items_to_append; + void rebuild(); void rebuild( playlist_item_t *); bool hasRandom(); bool hasLoop(); bool hasRepeat(); @@ -139,6 +141,11 @@ public: void sendArt( QString url ); void removeArt( ); + + int shownFlags() + { + return rootItem->i_showflags; + } private: void addCallbacks(); void delCallbacks(); -- GitLab