Commit ee454d5f authored by Jakob Leben's avatar Jakob Leben

Qt: prettier button with menu for playlist view switching

parent f6b3f672
...@@ -97,25 +97,37 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, ...@@ -97,25 +97,37 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
BUTTONACT( addButton, popupAdd() ); BUTTONACT( addButton, popupAdd() );
layout->addWidget( addButton, 0, 3 ); layout->addWidget( addButton, 0, 3 );
/* Button to switch views */
QPushButton *viewButton = new QPushButton( this ); QPushButton *viewButton = new QPushButton( this );
viewButton->setIcon( QIcon( ":/buttons/playlist/playlist_add" ) ); viewButton->setIcon( style()->standardIcon( QStyle::SP_FileDialogContentsView ) );
layout->addWidget( viewButton, 0, 2 ); layout->addWidget( viewButton, 0, 2 );
BUTTONACT( viewButton, toggleView() );
/* View selection menu */
viewSelectionMapper = new QSignalMapper;
CONNECT( viewSelectionMapper, mapped( int ), this, showView( int ) );
QActionGroup *actionGroup = new QActionGroup( this );
QAction *action = actionGroup->addAction( "Detailed view" );
action->setCheckable( true );
viewSelectionMapper->setMapping( action, TREE_VIEW );
CONNECT( action, triggered(), viewSelectionMapper, map() );
action = actionGroup->addAction( "Icon view" );
action->setCheckable( true );
viewSelectionMapper->setMapping( action, ICON_VIEW );
CONNECT( action, triggered(), viewSelectionMapper, map() );
QMenu *viewMenu = new QMenu( this );
viewMenu->addActions( actionGroup->actions() );
viewButton->setMenu( viewMenu );
/* Saved Settings */ /* Saved Settings */
getSettings()->beginGroup("Playlist"); getSettings()->beginGroup("Playlist");
int i_viewMode = getSettings()->value( "view-mode", TREE_VIEW ).toInt(); int i_viewMode = getSettings()->value( "view-mode", TREE_VIEW ).toInt();
if( i_viewMode == ICON_VIEW ) showView( i_viewMode );
{
createIconView();
currentView = iconView;
}
else
{
createTreeView();
currentView = treeView;
}
getSettings()->endGroup(); getSettings()->endGroup();
...@@ -348,27 +360,32 @@ void StandardPLPanel::createTreeView() ...@@ -348,27 +360,32 @@ void StandardPLPanel::createTreeView()
layout->addWidget( treeView, 1, 0, 1, -1 ); layout->addWidget( treeView, 1, 0, 1, -1 );
} }
void StandardPLPanel::toggleView() void StandardPLPanel::showView( int i_view )
{ {
if( treeView && treeView->isVisible() ) switch( i_view )
{
case TREE_VIEW:
{
if( treeView == NULL )
createTreeView();
locationBar->setIndex( treeView->rootIndex() );
if( iconView ) iconView->hide();
treeView->show();
currentView = treeView;
break;
}
case ICON_VIEW:
{ {
if( iconView == NULL ) if( iconView == NULL )
createIconView(); createIconView();
locationBar->setIndex( iconView->rootIndex() ); locationBar->setIndex( iconView->rootIndex() );
treeView->hide(); if( treeView ) treeView->hide();
iconView->show(); iconView->show();
currentView = iconView; currentView = iconView;
break;
} }
else default:;
{
if( treeView == NULL )
createTreeView();
locationBar->setIndex( treeView->rootIndex() );
iconView->hide();
treeView->show();
currentView = treeView;
} }
} }
......
...@@ -78,6 +78,7 @@ private: ...@@ -78,6 +78,7 @@ private:
int currentRootId; int currentRootId;
QSignalMapper *selectColumnsSigMapper; QSignalMapper *selectColumnsSigMapper;
QSignalMapper *viewSelectionMapper;
int last_activated_id; int last_activated_id;
...@@ -102,7 +103,7 @@ private slots: ...@@ -102,7 +103,7 @@ private slots:
void popupSelectColumn( QPoint ); void popupSelectColumn( QPoint );
void popupPlView( const QPoint & ); void popupPlView( const QPoint & );
void toggleColumnShown( int ); void toggleColumnShown( int );
void toggleView(); void showView( int );
void activate( const QModelIndex & ); void activate( const QModelIndex & );
void handleInputChange( input_thread_t * ); void handleInputChange( input_thread_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