[vlc-devel] commit: Qt: prettier button with menu for playlist view switching ( Jakob Leben )

git version control git at videolan.org
Thu Jan 28 21:18:58 CET 2010


vlc | branch: master | Jakob Leben <jleben at videolan.org> | Thu Jan 28 21:17:47 2010 +0100| [ee454d5fbf0eb4d22feba57c85239af6c8ca88a0] | committer: Jakob Leben 

Qt: prettier button with menu for playlist view switching

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ee454d5fbf0eb4d22feba57c85239af6c8ca88a0
---

 .../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 d3e8e1f..e69eedf 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 3cb5621..58c118a 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 * );
 };




More information about the vlc-devel mailing list