X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fqt4%2Fcomponents%2Fplaylist%2Fplaylist.cpp;h=661f376375ddf3534a269c65fa6d1f5341e781fc;hb=a4f1bc2b0806c9eb5cf33f965c980b72f836bd6e;hp=144146f5b368e447bd2274a4240581f5c2ee5af4;hpb=f18a9358a25052dc4cbf764693ca20a06ee37aae;p=vlc diff --git a/modules/gui/qt4/components/playlist/playlist.cpp b/modules/gui/qt4/components/playlist/playlist.cpp index 144146f5b3..661f376375 100644 --- a/modules/gui/qt4/components/playlist/playlist.cpp +++ b/modules/gui/qt4/components/playlist/playlist.cpp @@ -26,26 +26,35 @@ # include "config.h" #endif -#include "components/playlist/standardpanel.hpp" -#include "components/playlist/selector.hpp" #include "components/playlist/playlist.hpp" -#include "components/playlist/playlist_model.hpp" +#include "components/playlist/standardpanel.hpp" /* MainView */ +#include "components/playlist/selector.hpp" /* PLSelector */ +#include "components/playlist/playlist_model.hpp" /* PLModel */ +#include "components/playlist/ml_model.hpp" /* MLModel */ +#include "components/interface_widgets.hpp" /* CoverArtLabel */ -#include "input_manager.hpp" /* art signal */ -#include "main_interface.hpp" /* DropEvent TODO remove this*/ +#include "util/searchlineedit.hpp" + +#include "input_manager.hpp" /* art signal */ +#include "main_interface.hpp" /* DropEvent TODO remove this*/ -#include #include +#include +#include +#include -#include /********************************************************************** * Playlist Widget. The embedded playlist **********************************************************************/ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par ) - : QSplitter( _par ), p_intf ( _p_i ) + : QWidget( _par ), p_intf ( _p_i ) { - setContentsMargins( 3, 3, 3, 3 ); + + setContentsMargins( 0, 3, 0, 3 ); + + QGridLayout *layout = new QGridLayout( this ); + layout->setMargin( 0 ); layout->setSpacing( 0 ); /******************* * Left * @@ -54,21 +63,18 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par ) leftSplitter = new QSplitter( Qt::Vertical, this ); /* Source Selector */ - selector = new PLSelector( this, p_intf ); + PLSelector *selector = new PLSelector( this, p_intf ); leftSplitter->addWidget( selector); /* Create a Container for the Art Label in order to have a beautiful resizing for the selector above it */ - QWidget *artContainer = new QWidget; - QHBoxLayout *artContLay = new QHBoxLayout( artContainer ); - artContLay->setMargin( 0 ); - artContLay->setSpacing( 0 ); + artContainer = new QStackedWidget; artContainer->setMaximumHeight( 128 ); /* Art label */ - art = new ArtLabel( artContainer, p_intf ); + CoverArtLabel *art = new CoverArtLabel( artContainer, p_intf ); art->setToolTip( qtr( "Double click to get media information" ) ); - artContLay->addWidget( art, 1 ); + artContainer->addWidget( art ); CONNECT( THEMIM->getIM(), artChanged( QString ), art, showArtUpdate( const QString& ) ); @@ -81,90 +87,113 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par ) /* Initialisation of the playlist */ playlist_t * p_playlist = THEPL; PL_LOCK; - playlist_item_t *p_root = THEPL->p_playing; + playlist_item_t *p_root = p_playlist->p_playing; PL_UNLOCK; - QWidget *rightPanel = new QWidget( this ); - QGridLayout *layout = new QGridLayout( rightPanel ); - layout->setSpacing( 0 ); layout->setMargin( 0 ); - setMinimumWidth( 300 ); + setMinimumWidth( 400 ); - PLModel *model = new PLModel( p_playlist, p_intf, p_root, this ); - mainView = new StandardPLPanel( this, p_intf, THEPL, p_root, selector ); + PLModel *model = PLModel::getPLModel( p_intf ); +#ifdef MEDIA_LIBRARY + MLModel *mlmodel = new MLModel( p_intf, this ); + mainView = new StandardPLPanel( this, p_intf, p_root, selector, model, mlmodel ); +#else + mainView = new StandardPLPanel( this, p_intf, p_root, selector, model, NULL ); +#endif /* Location Bar */ locationBar = new LocationBar( model ); locationBar->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred ); - layout->addWidget( locationBar, 0, 0 ); + layout->addWidget( locationBar, 0, 0, 1, 2 ); layout->setColumnStretch( 0, 5 ); CONNECT( locationBar, invoked( const QModelIndex & ), mainView, browseInto( const QModelIndex & ) ); + QHBoxLayout *topbarLayout = new QHBoxLayout(); + layout->addLayout( topbarLayout, 0, 1 ); + topbarLayout->setSpacing( 10 ); + + /* Button to clear playlist */ + QToolButton *clearPlaylistButton = new QToolButton( this ); + clearPlaylistButton->setIcon( style()->standardIcon( QStyle::SP_TrashIcon ) ); + clearPlaylistButton->setToolTip( qtr("Clear playlist") ); + topbarLayout->addWidget( clearPlaylistButton ); + CONNECT( clearPlaylistButton, clicked(), this, clearPlaylist() ); + /* Button to switch views */ QToolButton *viewButton = new QToolButton( this ); viewButton->setIcon( style()->standardIcon( QStyle::SP_FileDialogDetailedView ) ); viewButton->setToolTip( qtr("Change playlistview") ); - layout->addWidget( viewButton, 0, 1 ); + topbarLayout->addWidget( viewButton ); /* View selection menu */ - viewSelectionMapper = new QSignalMapper( this ); + QSignalMapper *viewSelectionMapper = new QSignalMapper( this ); CONNECT( viewSelectionMapper, mapped( int ), mainView, showView( int ) ); QActionGroup *actionGroup = new QActionGroup( this ); - for( int i = 0; i < StandardPLPanel::VIEW_COUNT; i++ ) + +#ifndef NDEBUG +# define MAX_VIEW StandardPLPanel::VIEW_COUNT +#else +# define MAX_VIEW StandardPLPanel::VIEW_COUNT - 1 +#endif + for( int i = 0; i < MAX_VIEW; i++ ) { viewActions[i] = actionGroup->addAction( viewNames[i] ); viewActions[i]->setCheckable( true ); viewSelectionMapper->setMapping( viewActions[i], i ); CONNECT( viewActions[i], triggered(), viewSelectionMapper, map() ); } + viewActions[0]->setChecked( true ); - CONNECT( viewButton, clicked(), mainView, cycleViews() ); - QMenu *viewMenu = new QMenu( this ); + QMenu *viewMenu = new QMenu( viewButton ); viewMenu->addActions( actionGroup->actions() ); viewButton->setMenu( viewMenu ); + CONNECT( viewButton, clicked(), mainView, cycleViews() ); /* Search */ searchEdit = new SearchLineEdit( this ); searchEdit->setMaximumWidth( 250 ); searchEdit->setMinimumWidth( 80 ); - layout->addWidget( searchEdit, 0, 2 ); - CONNECT( searchEdit, textEdited( const QString& ), + searchEdit->setToolTip( qtr("Search the playlist") ); + topbarLayout->addWidget( searchEdit ); + CONNECT( searchEdit, textChanged( const QString& ), mainView, search( const QString& ) ); CONNECT( searchEdit, searchDelayedChanged( const QString& ), mainView, searchDelayed( const QString & ) ); + CONNECT( mainView, viewChanged( const QModelIndex& ), this, changeView( const QModelIndex &) ); - layout->setColumnStretch( 2, 3 ); /* Connect the activation of the selector to a redefining of the PL */ - DCONNECT( selector, activated( playlist_item_t * ), - mainView, setRoot( playlist_item_t * ) ); + DCONNECT( selector, categoryActivated( playlist_item_t *, bool ), + mainView, setRootItem( playlist_item_t *, bool ) ); + mainView->setRootItem( p_root, false ); - mainView->setRoot( p_root ); - layout->addWidget( mainView, 1, 0, 1, -1 ); + /* */ + split = new PlaylistSplitter( this ); /* Add the two sides of the QSplitter */ - addWidget( leftSplitter ); - addWidget( rightPanel ); + split->addWidget( leftSplitter ); + split->addWidget( mainView ); QList sizeList; sizeList << 180 << 420 ; - setSizes( sizeList ); - //setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding ); - setStretchFactor( 0, 0 ); - setStretchFactor( 1, 3 ); + split->setSizes( sizeList ); + split->setStretchFactor( 0, 0 ); + split->setStretchFactor( 1, 3 ); + split->setCollapsible( 1, false ); leftSplitter->setMaximumWidth( 250 ); - setCollapsible( 1, false ); /* In case we want to keep the splitter information */ // components shall never write there setting to a fixed location, may infer // with other uses of the same component... getSettings()->beginGroup("Playlist"); - restoreState( getSettings()->value("splitterSizes").toByteArray()); + split->restoreState( getSettings()->value("splitterSizes").toByteArray()); leftSplitter->restoreState( getSettings()->value("leftSplitterGeometry").toByteArray() ); getSettings()->endGroup(); + layout->addWidget( split, 1, 0, 1, -1 ); + setAcceptDrops( true ); setWindowTitle( qtr( "Playlist" ) ); setWindowRole( "vlc-playlist" ); @@ -174,7 +203,7 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par ) PlaylistWidget::~PlaylistWidget() { getSettings()->beginGroup("Playlist"); - getSettings()->setValue( "splitterSizes", saveState() ); + getSettings()->setValue( "splitterSizes", split->saveState() ); getSettings()->setValue( "leftSplitterGeometry", leftSplitter->saveState() ); getSettings()->endGroup(); msg_Dbg( p_intf, "Playlist Destroyed" ); @@ -223,9 +252,23 @@ void PlaylistWidget::changeView( const QModelIndex& index ) { searchEdit->clear(); locationBar->setIndex( index ); + int i = mainView->currentViewIndex(); + viewActions[i]->setChecked(true); } +void PlaylistWidget::clearPlaylist() +{ + PLModel *model = PLModel::getPLModel( p_intf ); + if( model->rowCount() < 1 ) return; + QModelIndexList* l = new QModelIndexList(); + for( int i = 0; i < model->rowCount(); i++) + { + QModelIndex indexrecord = model->index( i, 0, QModelIndex() ); + l->append( indexrecord ); + } + model->doDelete(*l); +} #include #include #include @@ -253,9 +296,15 @@ void LocationBar::setIndex( const QModelIndex &index ) while( true ) { PLItem *item = model->getItem( i ); + QString text; - char *fb_name = input_item_GetTitleFbName( item->inputItem() ); - QString text = qfu(fb_name); + char *fb_name = input_item_GetTitle( item->inputItem() ); + if( EMPTY_STR( fb_name ) ) + { + free( fb_name ); + fb_name = input_item_GetName( item->inputItem() ); + } + text = qfu(fb_name); free(fb_name); QAbstractButton *btn = new LocationButton( text, first, !first, this ); @@ -356,7 +405,7 @@ QSize LocationBar::sizeHint() const LocationButton::LocationButton( const QString &text, bool bold, bool arrow, QWidget * parent ) - : b_arrow( arrow ), QPushButton( parent ) + : QPushButton( parent ), b_arrow( arrow ) { QFont font; font.setBold( bold ); @@ -366,7 +415,7 @@ LocationButton::LocationButton( const QString &text, bool bold, #define PADDING 4 -void LocationButton::paintEvent ( QPaintEvent * event ) +void LocationButton::paintEvent ( QPaintEvent * ) { QStyleOptionButton option; option.initFrom( this ); @@ -413,3 +462,26 @@ QSize LocationButton::sizeHint() const } #undef PADDING + +#ifdef Q_WS_MAC +QSplitterHandle *PlaylistSplitter::createHandle() +{ + return new SplitterHandle( orientation(), this ); +} + +SplitterHandle::SplitterHandle( Qt::Orientation orientation, QSplitter * parent ) + : QSplitterHandle( orientation, parent) +{ +}; + +QSize SplitterHandle::sizeHint() const +{ + return (orientation() == Qt::Horizontal) ? QSize( 1, height() ) : QSize( width(), 1 ); +} + +void SplitterHandle::paintEvent(QPaintEvent *event) +{ + QPainter painter( this ); + painter.fillRect( event->rect(), QColor(81, 81, 81) ); +} +#endif /* __APPLE__ */