Commit 7c1fe483 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Qt: put CreateTreeView and createIconView in their own functions

parent 0f03fef4
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
# include "config.h" # include "config.h"
#endif #endif
#include "qt4.hpp"
#include "dialogs_provider.hpp" #include "dialogs_provider.hpp"
#include "components/playlist/playlist_model.hpp" #include "components/playlist/playlist_model.hpp"
...@@ -61,55 +60,19 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, ...@@ -61,55 +60,19 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
model = new PLModel( p_playlist, p_intf, p_root, this ); model = new PLModel( p_playlist, p_intf, p_root, this );
/* Create and configure the QTreeView */
treeView = new QTreeView;
treeView->setModel( model );
iconView = NULL; iconView = NULL;
treeView = NULL;
treeView->setIconSize( QSize( 20, 20 ) );
treeView->setAlternatingRowColors( true );
treeView->setAnimated( true );
treeView->setUniformRowHeights( true );
treeView->setSortingEnabled( true );
treeView->header()->setSortIndicator( -1 , Qt::AscendingOrder );
treeView->header()->setSortIndicatorShown( true );
treeView->header()->setClickable( true );
treeView->header()->setContextMenuPolicy( Qt::CustomContextMenu );
treeView->setSelectionBehavior( QAbstractItemView::SelectRows );
treeView->setSelectionMode( QAbstractItemView::ExtendedSelection );
treeView->setDragEnabled( true );
treeView->setAcceptDrops( true );
treeView->setDropIndicatorShown( true );
treeView->setContextMenuPolicy( Qt::CustomContextMenu );
/* Saved Settings */ /* Saved Settings */
getSettings()->beginGroup("Playlist"); getSettings()->beginGroup("Playlist");
if( getSettings()->contains( "headerStateV2" ) )
{ int i_viewMode = getSettings()->value( "view-mode", TREE_VIEW ).toInt();
treeView->header()->restoreState( if( i_viewMode == ICON_VIEW )
getSettings()->value( "headerStateV2" ).toByteArray() ); iconView = new PlIconView( model, this );
}
else else
{ createTreeView();
for( int m = 1, c = 0; m != COLUMN_END; m <<= 1, c++ )
{
treeView->setColumnHidden( c, !( m & COLUMN_DEFAULT ) );
if( m == COLUMN_TITLE ) treeView->header()->resizeSection( c, 200 );
else if( m == COLUMN_DURATION ) treeView->header()->resizeSection( c, 80 );
}
}
getSettings()->endGroup();
/* Connections for the TreeView */ getSettings()->endGroup();
CONNECT( treeView, activated( const QModelIndex& ),
model,activateItem( const QModelIndex& ) );
CONNECT( treeView->header(), customContextMenuRequested( const QPoint & ),
this, popupSelectColumn( QPoint ) );
CONNECT( treeView, customContextMenuRequested( const QPoint & ),
this, popupPlView( const QPoint & ) );
CONNECT( model, currentChanged( const QModelIndex& ),
this, handleExpansion( const QModelIndex& ) );
currentRootId = -1; currentRootId = -1;
...@@ -142,30 +105,26 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, ...@@ -142,30 +105,26 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
viewButton->setIcon( QIcon( ":/buttons/playlist/playlist_add" ) ); viewButton->setIcon( QIcon( ":/buttons/playlist/playlist_add" ) );
layout->addWidget( viewButton, 0, 2 ); layout->addWidget( viewButton, 0, 2 );
BUTTONACT( viewButton, toggleView() ); BUTTONACT( viewButton, toggleView() );
/* Finish the layout */
layout->addWidget( treeView, 1, 0, 1, -1 );
selectColumnsSigMapper = new QSignalMapper( this );
CONNECT( selectColumnsSigMapper, mapped( int ),
this, toggleColumnShown( int ) );
} }
StandardPLPanel::~StandardPLPanel() StandardPLPanel::~StandardPLPanel()
{ {
getSettings()->beginGroup("Playlist"); getSettings()->beginGroup("Playlist");
getSettings()->setValue( "headerStateV2", treeView->header()->saveState() ); if( treeView )
getSettings()->setValue( "headerStateV2", treeView->header()->saveState() );
getSettings()->endGroup(); getSettings()->endGroup();
} }
/* Unused anymore, but might be useful, like in right-click menu */ /* Unused anymore, but might be useful, like in right-click menu */
void StandardPLPanel::gotoPlayingItem() void StandardPLPanel::gotoPlayingItem()
{ {
treeView->scrollTo( model->currentIndex() ); if( treeView )
treeView->scrollTo( model->currentIndex() );
} }
void StandardPLPanel::handleExpansion( const QModelIndex& index ) void StandardPLPanel::handleExpansion( const QModelIndex& index )
{ {
assert( treeView );
treeView->scrollTo( index ); treeView->scrollTo( index );
} }
...@@ -197,6 +156,7 @@ void StandardPLPanel::popupAdd() ...@@ -197,6 +156,7 @@ void StandardPLPanel::popupAdd()
void StandardPLPanel::popupSelectColumn( QPoint pos ) void StandardPLPanel::popupSelectColumn( QPoint pos )
{ {
QMenu menu; QMenu menu;
assert( treeView );
/* We do not offer the option to hide index 0 column, or /* We do not offer the option to hide index 0 column, or
* QTreeView will behave weird */ * QTreeView will behave weird */
...@@ -216,8 +176,9 @@ void StandardPLPanel::popupSelectColumn( QPoint pos ) ...@@ -216,8 +176,9 @@ void StandardPLPanel::popupSelectColumn( QPoint pos )
void StandardPLPanel::popupPlView( const QPoint &point ) void StandardPLPanel::popupPlView( const QPoint &point )
{ {
QAbstractItemView *aView; QAbstractItemView *aView;
if ( treeView->isVisible() ) aView = treeView; if ( treeView && treeView->isVisible() ) aView = treeView;
else aView = iconView; else if( iconView && iconView->isVisible() ) aView = iconView;
else return;
QModelIndex index = aView->indexAt( point ); QModelIndex index = aView->indexAt( point );
QPoint globalPoint = aView->viewport()->mapToGlobal( point ); QPoint globalPoint = aView->viewport()->mapToGlobal( point );
...@@ -297,23 +258,87 @@ void StandardPLPanel::keyPressEvent( QKeyEvent *e ) ...@@ -297,23 +258,87 @@ void StandardPLPanel::keyPressEvent( QKeyEvent *e )
void StandardPLPanel::deleteSelection() void StandardPLPanel::deleteSelection()
{ {
//FIXME
if( !treeView ) return;
QItemSelectionModel *selection = treeView->selectionModel(); QItemSelectionModel *selection = treeView->selectionModel();
QModelIndexList list = selection->selectedIndexes(); QModelIndexList list = selection->selectedIndexes();
model->doDelete( list ); model->doDelete( list );
} }
void StandardPLPanel::createIconView()
{
iconView = new PlIconView( model, this );
iconView->setContextMenuPolicy( Qt::CustomContextMenu );
CONNECT( iconView, customContextMenuRequested( const QPoint & ),
this, popupPlView( const QPoint & ) );
layout->addWidget( iconView, 1, 0, 1, -1 );
}
void StandardPLPanel::createTreeView()
{
/* Create and configure the QTreeView */
treeView = new QTreeView;
treeView->setModel( model );
treeView->setIconSize( QSize( 20, 20 ) );
treeView->setAlternatingRowColors( true );
treeView->setAnimated( true );
treeView->setUniformRowHeights( true );
treeView->setSortingEnabled( true );
treeView->header()->setSortIndicator( -1 , Qt::AscendingOrder );
treeView->header()->setSortIndicatorShown( true );
treeView->header()->setClickable( true );
treeView->header()->setContextMenuPolicy( Qt::CustomContextMenu );
treeView->setSelectionBehavior( QAbstractItemView::SelectRows );
treeView->setSelectionMode( QAbstractItemView::ExtendedSelection );
treeView->setDragEnabled( true );
treeView->setAcceptDrops( true );
treeView->setDropIndicatorShown( true );
treeView->setContextMenuPolicy( Qt::CustomContextMenu );
if( getSettings()->contains( "headerStateV2" ) )
{
treeView->header()->restoreState(
getSettings()->value( "headerStateV2" ).toByteArray() );
}
else
{
for( int m = 1, c = 0; m != COLUMN_END; m <<= 1, c++ )
{
treeView->setClumnHidden( c, !( m & COLUMN_DEFAULT ) );
if( m == COLUMN_TITLE ) treeView->header()->resizeSection( c, 200 );
else if( m == COLUMN_DURATION ) treeView->header()->resizeSection( c, 80 );
}
}
/* Connections for the TreeView */
CONNECT( treeView, activated( const QModelIndex& ),
model,activateItem( const QModelIndex& ) );
CONNECT( treeView->header(), customContextMenuRequested( const QPoint & ),
this, popupSelectColumn( QPoint ) );
CONNECT( treeView, customContextMenuRequested( const QPoint & ),
this, popupPlView( const QPoint & ) );
CONNECT( model, currentChanged( const QModelIndex& ),
this, handleExpansion( const QModelIndex& ) );
/* SignalMapper for columns */
selectColumnsSigMapper = new QSignalMapper( this );
CONNECT( selectColumnsSigMapper, mapped( int ),
this, toggleColumnShown( int ) );
/* Finish the layout */
layout->addWidget( treeView, 1, 0, 1, -1 );
}
void StandardPLPanel::toggleView() void StandardPLPanel::toggleView()
{ {
if( treeView && treeView->isVisible() ) if( treeView && treeView->isVisible() )
{ {
if( iconView == NULL ) if( iconView == NULL )
{ createIconView();
iconView = new PlIconView( model, this );
layout->addWidget( iconView, 1, 0, 1, -1 );
iconView->setContextMenuPolicy( Qt::CustomContextMenu );
CONNECT( iconView, customContextMenuRequested( const QPoint & ),
this, popupPlView( const QPoint & ) );
}
treeView->hide(); treeView->hide();
iconView->show(); iconView->show();
} }
......
...@@ -75,6 +75,15 @@ private: ...@@ -75,6 +75,15 @@ private:
int currentRootId; int currentRootId;
QSignalMapper *selectColumnsSigMapper; QSignalMapper *selectColumnsSigMapper;
enum {
TREE_VIEW = 0,
ICON_VIEW,
COVER_VIEW,
};
void createTreeView();
void createIconView();
public slots: public slots:
void removeItem( int ); void removeItem( int );
virtual void setRoot( playlist_item_t * ); virtual void setRoot( playlist_item_t * );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment