From 4e7f747f01f2bb3df6e109b83161ed5af5fcd696 Mon Sep 17 00:00:00 2001 From: Francois Cartegnie <fcvlcdev@free.fr> Date: Wed, 18 Jul 2012 19:28:37 +0200 Subject: [PATCH] Qt: PLModel: Move Popup() creation out of the PLModel --- .../components/playlist/playlist_model.cpp | 129 ----------------- .../components/playlist/playlist_model.hpp | 17 +-- .../qt4/components/playlist/standardpanel.cpp | 135 +++++++++++++++++- .../qt4/components/playlist/standardpanel.hpp | 2 + .../gui/qt4/components/playlist/vlc_model.hpp | 12 +- 5 files changed, 150 insertions(+), 145 deletions(-) diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp index fc494422bd94..ca7b1e530ef2 100644 --- a/modules/gui/qt4/components/playlist/playlist_model.cpp +++ b/modules/gui/qt4/components/playlist/playlist_model.cpp @@ -1215,135 +1215,6 @@ void PLModel::actionSlot( QAction *action ) } } -/*********** Popup *********/ -bool PLModel::popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &selectionlist ) -{ - QModelIndexList callerAsList; - callerAsList << ( index.isValid() ? index : QModelIndex() ); - -#define ADD_MENU_ENTRY( icon, title, act, data ) \ - action = menu.addAction( icon, title ); \ - container.action = act; \ - container.indexes = data; \ - action->setData( QVariant::fromValue( container ) ) - - /* */ - QMenu menu; - QAction *action; - PLModel::actionsContainerType container; - - /* Play/Stream/Info static actions */ - if( index.isValid() ) - { - ADD_MENU_ENTRY( QIcon( ":/menu/play" ), qtr(I_POP_PLAY), - container.ACTION_PLAY, callerAsList ); - - ADD_MENU_ENTRY( QIcon( ":/menu/stream" ), qtr(I_POP_STREAM), - container.ACTION_STREAM, selectionlist ); - - ADD_MENU_ENTRY( QIcon(), qtr(I_POP_SAVE), - container.ACTION_SAVE, selectionlist ); - - ADD_MENU_ENTRY( QIcon( ":/menu/info" ), qtr(I_POP_INFO), - container.ACTION_INFO, callerAsList ); - - menu.addSeparator(); - - if( getURI( index ).startsWith( "file://" ) ) - { - ADD_MENU_ENTRY( QIcon( ":/type/folder-grey" ), qtr(I_POP_EXPLORE), - container.ACTION_EXPLORE, callerAsList ); - } - } - - /* In PL or ML, allow to add a file/folder */ - if( canEdit() ) - { - QIcon addIcon( ":/buttons/playlist/playlist_add" ); - - if( isTree() ) - { - ADD_MENU_ENTRY( addIcon, qtr(I_POP_NEWFOLDER), - container.ACTION_ADDNODE, callerAsList ); - } - - menu.addSeparator(); - if( isCurrentItem( rootIndex(), PLModel::IN_PLAYLIST ) ) - { - menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simplePLAppendDialog()) ); - menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) ); - menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( PLAppendDialog()) ); - } - else if( isCurrentItem( rootIndex(), PLModel::IN_MEDIALIBRARY ) ) - { - menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simpleMLAppendDialog()) ); - menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) ); - menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( MLAppendDialog() ) ); - } - } - - if( index.isValid() ) - { - if( !isCurrentItem( rootIndex(), PLModel::IN_PLAYLIST ) ) - { - ADD_MENU_ENTRY( QIcon(), qtr("Add to playlist"), - container.ACTION_ADDTOPLAYLIST, selectionlist ); - } - } - - menu.addSeparator(); - - /* Item removal */ - if( index.isValid() ) - { - ADD_MENU_ENTRY( QIcon( ":/buttons/playlist/playlist_remove" ), qtr(I_POP_DEL), - container.ACTION_REMOVE, selectionlist ); - } - - if( canEdit() ) { - menu.addAction( QIcon( ":/toolbar/clear" ), qtr("Clear playlist"), - this, SLOT( clearPlaylist() ) ); - } - - menu.addSeparator(); - - /* Playlist sorting */ - QMenu *sortingMenu = new QMenu( qtr( "Sort by" ) ); - /* Choose what columns to show in sorting menu, not sure if this should be configurable*/ - QList<int> sortingColumns; - sortingColumns << COLUMN_TITLE << COLUMN_ARTIST << COLUMN_ALBUM << COLUMN_TRACK_NUMBER << COLUMN_URI; - container.action = container.ACTION_SORT; - container.indexes = callerAsList; - foreach( int Column, sortingColumns ) - { - action = sortingMenu->addAction( qfu( psz_column_title( Column ) ) + " " + qtr("Ascending") ); - container.column = columnFromMeta(Column) + 1; - action->setData( QVariant::fromValue( container ) ); - - action = sortingMenu->addAction( qfu( psz_column_title( Column ) ) + " " + qtr("Descending") ); - container.column = -1 * (columnFromMeta(Column)+1); - action->setData( QVariant::fromValue( container ) ); - } - menu.addMenu( sortingMenu ); - - /* Zoom */ - QMenu *zoomMenu = new QMenu( qtr( "Display size" ) ); - zoomMenu->addAction( qtr( "Increase" ), this, SLOT( increaseZoom() ) ); - zoomMenu->addAction( qtr( "Decrease" ), this, SLOT( decreaseZoom() ) ); - menu.addMenu( zoomMenu ); - - CONNECT( &menu, triggered( QAction * ), this, actionSlot( QAction * ) ); - - /* Display and forward the result */ - if( !menu.isEmpty() ) - { - menu.exec( point ); return true; - } - else return false; - -#undef ADD_MENU_ENTRY -} - /* */ void PLModel::increaseZoom() { diff --git a/modules/gui/qt4/components/playlist/playlist_model.hpp b/modules/gui/qt4/components/playlist/playlist_model.hpp index 50032a293e94..97daba82995b 100644 --- a/modules/gui/qt4/components/playlist/playlist_model.hpp +++ b/modules/gui/qt4/components/playlist/playlist_model.hpp @@ -97,26 +97,19 @@ public: /* Lookups */ QModelIndex index( const int i_id, const int c ); - QModelIndex rootIndex() const; - bool isTree() const; - bool canEdit() const; + virtual QModelIndex rootIndex() const; + virtual bool isTree() const; + virtual bool canEdit() const; virtual QModelIndex currentIndex() const; int itemId( const QModelIndex &index ) const; - QString getURI( const QModelIndex &index ) const; + virtual QString getURI( const QModelIndex &index ) const; QString getTitle( const QModelIndex &index ) const; - enum playLocation - { - IN_PLAYLIST, - IN_MEDIALIBRARY - }; - bool isCurrentItem( const QModelIndex &index, playLocation where ) const; + virtual bool isCurrentItem( const QModelIndex &index, playLocation where ) const; /* */ void search( const QString& search_text, const QModelIndex & root, bool b_recursive ); void rebuild( playlist_item_t * p = NULL ); - /* Popup Actions */ - virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list ); virtual void doDelete( QModelIndexList selected ); signals: diff --git a/modules/gui/qt4/components/playlist/standardpanel.cpp b/modules/gui/qt4/components/playlist/standardpanel.cpp index d11d3cdd60d3..b07e8dc635ec 100644 --- a/modules/gui/qt4/components/playlist/standardpanel.cpp +++ b/modules/gui/qt4/components/playlist/standardpanel.cpp @@ -35,11 +35,12 @@ #include "components/playlist/selector.hpp" /* PLSelector */ #include "menus.hpp" /* Popup */ #include "input_manager.hpp" /* THEMIM */ +#include "dialogs_provider.hpp" /* THEDP */ #include <vlc_services_discovery.h> /* SD_CMD_SEARCH */ +#include <vlc_intf_strings.h> /* POP_ */ #include <QHeaderView> -#include <QModelIndexList> #include <QMenu> #include <QKeyEvent> #include <QWheelEvent> @@ -118,10 +119,140 @@ void StandardPLPanel::popupPlView( const QPoint &point ) QItemSelectionModel *selection = currentView->selectionModel(); QModelIndexList list = selection->selectedRows(); - if( !model->popup( index, globalPoint, list ) ) + if( !popup( index, globalPoint, list ) ) VLCMenuBar::PopupMenu( p_intf, true ); } +/*********** Popup *********/ +bool StandardPLPanel::popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &selectionlist ) +{ + VLCModel *model = qobject_cast<VLCModel*>(currentView->model()); + QModelIndexList callerAsList; + callerAsList << ( index.isValid() ? index : QModelIndex() ); + +#define ADD_MENU_ENTRY( icon, title, act, data ) \ + action = menu.addAction( icon, title ); \ + container.action = act; \ + container.indexes = data; \ + action->setData( QVariant::fromValue( container ) ) + + /* */ + QMenu menu; + QAction *action; + PLModel::actionsContainerType container; + + /* Play/Stream/Info static actions */ + if( index.isValid() ) + { + ADD_MENU_ENTRY( QIcon( ":/menu/play" ), qtr(I_POP_PLAY), + container.ACTION_PLAY, callerAsList ); + + ADD_MENU_ENTRY( QIcon( ":/menu/stream" ), qtr(I_POP_STREAM), + container.ACTION_STREAM, selectionlist ); + + ADD_MENU_ENTRY( QIcon(), qtr(I_POP_SAVE), + container.ACTION_SAVE, selectionlist ); + + ADD_MENU_ENTRY( QIcon( ":/menu/info" ), qtr(I_POP_INFO), + container.ACTION_INFO, callerAsList ); + + menu.addSeparator(); + + if( model->getURI( index ).startsWith( "file://" ) ) + { + ADD_MENU_ENTRY( QIcon( ":/type/folder-grey" ), qtr(I_POP_EXPLORE), + container.ACTION_EXPLORE, callerAsList ); + } + } + + /* In PL or ML, allow to add a file/folder */ + if( model->canEdit() ) + { + QIcon addIcon( ":/buttons/playlist/playlist_add" ); + + if( model->isTree() ) + { + ADD_MENU_ENTRY( addIcon, qtr(I_POP_NEWFOLDER), + container.ACTION_ADDNODE, callerAsList ); + } + + menu.addSeparator(); + if( model->isCurrentItem( model->rootIndex(), PLModel::IN_PLAYLIST ) ) + { + menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simplePLAppendDialog()) ); + menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) ); + menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( PLAppendDialog()) ); + } + else if( model->isCurrentItem( model->rootIndex(), PLModel::IN_MEDIALIBRARY ) ) + { + menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simpleMLAppendDialog()) ); + menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) ); + menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( MLAppendDialog() ) ); + } + } + + if( index.isValid() ) + { + if( !model->isCurrentItem( model->rootIndex(), PLModel::IN_PLAYLIST ) ) + { + ADD_MENU_ENTRY( QIcon(), qtr("Add to playlist"), + container.ACTION_ADDTOPLAYLIST, selectionlist ); + } + } + + menu.addSeparator(); + + /* Item removal */ + if( index.isValid() ) + { + ADD_MENU_ENTRY( QIcon( ":/buttons/playlist/playlist_remove" ), qtr(I_POP_DEL), + container.ACTION_REMOVE, selectionlist ); + } + + if( model->canEdit() ) { + menu.addAction( QIcon( ":/toolbar/clear" ), qtr("Clear playlist"), + model, SLOT( clearPlaylist() ) ); + } + + menu.addSeparator(); + + /* Playlist sorting */ + QMenu *sortingMenu = new QMenu( qtr( "Sort by" ) ); + /* Choose what columns to show in sorting menu, not sure if this should be configurable*/ + QList<int> sortingColumns; + sortingColumns << COLUMN_TITLE << COLUMN_ARTIST << COLUMN_ALBUM << COLUMN_TRACK_NUMBER << COLUMN_URI; + container.action = container.ACTION_SORT; + container.indexes = callerAsList; + foreach( int Column, sortingColumns ) + { + action = sortingMenu->addAction( qfu( psz_column_title( Column ) ) + " " + qtr("Ascending") ); + container.column = model->columnFromMeta(Column) + 1; + action->setData( QVariant::fromValue( container ) ); + + action = sortingMenu->addAction( qfu( psz_column_title( Column ) ) + " " + qtr("Descending") ); + container.column = -1 * (model->columnFromMeta(Column)+1); + action->setData( QVariant::fromValue( container ) ); + } + menu.addMenu( sortingMenu ); + + /* Zoom */ + QMenu *zoomMenu = new QMenu( qtr( "Display size" ) ); + zoomMenu->addAction( qtr( "Increase" ), model, SLOT( increaseZoom() ) ); + zoomMenu->addAction( qtr( "Decrease" ), model, SLOT( decreaseZoom() ) ); + menu.addMenu( zoomMenu ); + + CONNECT( &menu, triggered( QAction * ), model, actionSlot( QAction * ) ); + + /* Display and forward the result */ + if( !menu.isEmpty() ) + { + menu.exec( point ); return true; + } + else return false; + +#undef ADD_MENU_ENTRY +} + void StandardPLPanel::popupSelectColumn( QPoint ) { QMenu menu; diff --git a/modules/gui/qt4/components/playlist/standardpanel.hpp b/modules/gui/qt4/components/playlist/standardpanel.hpp index cb65ded74477..b9b35cd1e571 100644 --- a/modules/gui/qt4/components/playlist/standardpanel.hpp +++ b/modules/gui/qt4/components/playlist/standardpanel.hpp @@ -32,6 +32,7 @@ #include "components/playlist/playlist.hpp" #include <QWidget> +#include <QModelIndexList> #include <vlc_playlist.h> /* playlist_item_t */ @@ -74,6 +75,7 @@ protected: PLModel *model; MLModel *mlmodel; virtual void wheelEvent( QWheelEvent *e ); + bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &selectionlist ); private: intf_thread_t *p_intf; diff --git a/modules/gui/qt4/components/playlist/vlc_model.hpp b/modules/gui/qt4/components/playlist/vlc_model.hpp index 6de3ed8f15d7..3daf28a5c5d6 100644 --- a/modules/gui/qt4/components/playlist/vlc_model.hpp +++ b/modules/gui/qt4/components/playlist/vlc_model.hpp @@ -52,13 +52,21 @@ public: VLCModel( intf_thread_t *_p_intf, QObject *parent = 0 ); virtual int itemId( const QModelIndex & ) const = 0; virtual QModelIndex currentIndex() const = 0; - virtual bool popup( const QModelIndex & index, - const QPoint &point, const QModelIndexList &list ) = 0; virtual void doDelete( QModelIndexList ) = 0; virtual ~VLCModel(); static QString getMeta( const QModelIndex & index, int meta ); static QPixmap getArtPixmap( const QModelIndex & index, const QSize & size ); static QString getArtUrl( const QModelIndex & index ); + virtual QString getURI( const QModelIndex &index ) const = 0; + virtual QModelIndex rootIndex() const = 0; + virtual bool isTree() const = 0; + virtual bool canEdit() const = 0; + enum playLocation + { + IN_PLAYLIST, + IN_MEDIALIBRARY + }; + virtual bool isCurrentItem( const QModelIndex &index, playLocation where ) const = 0; struct actionsContainerType { -- GitLab