From ee454d5fbf0eb4d22feba57c85239af6c8ca88a0 Mon Sep 17 00:00:00 2001 From: Jakob Leben Date: Thu, 28 Jan 2010 21:17:47 +0100 Subject: [PATCH] Qt: prettier button with menu for playlist view switching --- .../gui/qt4/components/playlist/standardpanel.cpp | 65 ++++++++++++++-------- .../gui/qt4/components/playlist/standardpanel.hpp | 3 +- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/modules/gui/qt4/components/playlist/standardpanel.cpp b/modules/gui/qt4/components/playlist/standardpanel.cpp index d3e8e1f89f..e69eedfaad 100644 --- a/modules/gui/qt4/components/playlist/standardpanel.cpp +++ b/modules/gui/qt4/components/playlist/standardpanel.cpp @@ -97,25 +97,37 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, BUTTONACT( addButton, popupAdd() ); layout->addWidget( addButton, 0, 3 ); + /* Button to switch views */ QPushButton *viewButton = new QPushButton( this ); - viewButton->setIcon( QIcon( ":/buttons/playlist/playlist_add" ) ); + viewButton->setIcon( style()->standardIcon( QStyle::SP_FileDialogContentsView ) ); 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 */ getSettings()->beginGroup("Playlist"); int i_viewMode = getSettings()->value( "view-mode", TREE_VIEW ).toInt(); - if( i_viewMode == ICON_VIEW ) - { - createIconView(); - currentView = iconView; - } - else - { - createTreeView(); - currentView = treeView; - } + showView( i_viewMode ); getSettings()->endGroup(); @@ -348,27 +360,32 @@ void StandardPLPanel::createTreeView() 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 ) createIconView(); locationBar->setIndex( iconView->rootIndex() ); - treeView->hide(); + if( treeView ) treeView->hide(); iconView->show(); currentView = iconView; + break; } - else - { - if( treeView == NULL ) - createTreeView(); - - locationBar->setIndex( treeView->rootIndex() ); - iconView->hide(); - treeView->show(); - currentView = treeView; + default:; } } diff --git a/modules/gui/qt4/components/playlist/standardpanel.hpp b/modules/gui/qt4/components/playlist/standardpanel.hpp index 3cb5621a2c..58c118ac89 100644 --- a/modules/gui/qt4/components/playlist/standardpanel.hpp +++ b/modules/gui/qt4/components/playlist/standardpanel.hpp @@ -78,6 +78,7 @@ private: int currentRootId; QSignalMapper *selectColumnsSigMapper; + QSignalMapper *viewSelectionMapper; int last_activated_id; @@ -102,7 +103,7 @@ private slots: void popupSelectColumn( QPoint ); void popupPlView( const QPoint & ); void toggleColumnShown( int ); - void toggleView(); + void showView( int ); void activate( const QModelIndex & ); void handleInputChange( input_thread_t * ); }; -- 2.11.4.GIT