Commit f18a9358 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Qt: playlist code refactoring

parent da1239a1
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "main_interface.hpp" /* DropEvent TODO remove this*/ #include "main_interface.hpp" /* DropEvent TODO remove this*/
#include <QGroupBox> #include <QGroupBox>
#include <QMenu>
#include <iostream> #include <iostream>
/********************************************************************** /**********************************************************************
...@@ -46,12 +47,14 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par ) ...@@ -46,12 +47,14 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par )
{ {
setContentsMargins( 3, 3, 3, 3 ); setContentsMargins( 3, 3, 3, 3 );
/* We use a QSplitter for the left part*/ /*******************
* Left *
*******************/
/* We use a QSplitter for the left part */
leftSplitter = new QSplitter( Qt::Vertical, this ); leftSplitter = new QSplitter( Qt::Vertical, this );
/* Source Selector */ /* Source Selector */
selector = new PLSelector( this, p_intf ); selector = new PLSelector( this, p_intf );
leftSplitter->addWidget( selector); leftSplitter->addWidget( selector);
/* Create a Container for the Art Label /* Create a Container for the Art Label
...@@ -65,27 +68,81 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par ) ...@@ -65,27 +68,81 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par )
/* Art label */ /* Art label */
art = new ArtLabel( artContainer, p_intf ); art = new ArtLabel( artContainer, p_intf );
art->setToolTip( qtr( "Double click to get media information" ) ); art->setToolTip( qtr( "Double click to get media information" ) );
artContLay->addWidget( art, 1 );
CONNECT( THEMIM->getIM(), artChanged( QString ), CONNECT( THEMIM->getIM(), artChanged( QString ),
art, showArtUpdate( const QString& ) ); art, showArtUpdate( const QString& ) );
artContLay->addWidget( art, 1 );
leftSplitter->addWidget( artContainer ); leftSplitter->addWidget( artContainer );
/*******************
* Right *
*******************/
/* Initialisation of the playlist */ /* Initialisation of the playlist */
playlist_t * p_playlist = THEPL; playlist_t * p_playlist = THEPL;
PL_LOCK; PL_LOCK;
playlist_item_t *p_root = THEPL->p_playing; playlist_item_t *p_root = THEPL->p_playing;
PL_UNLOCK; PL_UNLOCK;
rightPanel = new StandardPLPanel( this, p_intf, THEPL, p_root, selector ); QWidget *rightPanel = new QWidget( this );
QGridLayout *layout = new QGridLayout( rightPanel );
layout->setSpacing( 0 ); layout->setMargin( 0 );
setMinimumWidth( 300 );
PLModel *model = new PLModel( p_playlist, p_intf, p_root, this );
mainView = new StandardPLPanel( this, p_intf, THEPL, p_root, selector );
/* Location Bar */
locationBar = new LocationBar( model );
locationBar->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred );
layout->addWidget( locationBar, 0, 0 );
layout->setColumnStretch( 0, 5 );
CONNECT( locationBar, invoked( const QModelIndex & ),
mainView, browseInto( const QModelIndex & ) );
/* 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 );
/* View selection menu */
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++ )
{
viewActions[i] = actionGroup->addAction( viewNames[i] );
viewActions[i]->setCheckable( true );
viewSelectionMapper->setMapping( viewActions[i], i );
CONNECT( viewActions[i], triggered(), viewSelectionMapper, map() );
}
CONNECT( viewButton, clicked(), mainView, cycleViews() );
QMenu *viewMenu = new QMenu( this );
viewMenu->addActions( actionGroup->actions() );
viewButton->setMenu( viewMenu );
/* Search */
searchEdit = new SearchLineEdit( this );
searchEdit->setMaximumWidth( 250 );
searchEdit->setMinimumWidth( 80 );
layout->addWidget( searchEdit, 0, 2 );
CONNECT( searchEdit, textEdited( 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 */ /* Connect the activation of the selector to a redefining of the PL */
DCONNECT( selector, activated( playlist_item_t * ), DCONNECT( selector, activated( playlist_item_t * ),
rightPanel, setRoot( playlist_item_t * ) ); mainView, setRoot( playlist_item_t * ) );
rightPanel->setRoot( p_root ); mainView->setRoot( p_root );
layout->addWidget( mainView, 1, 0, 1, -1 );
/* Add the two sides of the QSplitter */ /* Add the two sides of the QSplitter */
addWidget( leftSplitter ); addWidget( leftSplitter );
...@@ -151,17 +208,23 @@ void PlaylistWidget::closeEvent( QCloseEvent *event ) ...@@ -151,17 +208,23 @@ void PlaylistWidget::closeEvent( QCloseEvent *event )
void PlaylistWidget::forceHide() void PlaylistWidget::forceHide()
{ {
leftSplitter->hide(); leftSplitter->hide();
rightPanel->hide(); mainView->hide();
updateGeometry(); updateGeometry();
} }
void PlaylistWidget::forceShow() void PlaylistWidget::forceShow()
{ {
leftSplitter->show(); leftSplitter->show();
rightPanel->show(); mainView->show();
updateGeometry(); updateGeometry();
} }
void PlaylistWidget::changeView( const QModelIndex& index )
{
searchEdit->clear();
locationBar->setIndex( index );
}
#include <QSignalMapper> #include <QSignalMapper>
#include <QMenu> #include <QMenu>
......
...@@ -33,14 +33,22 @@ ...@@ -33,14 +33,22 @@
#include "qt4.hpp" #include "qt4.hpp"
#include "dialogs_provider.hpp" /* Media Info from ArtLabel */ #include "dialogs_provider.hpp" /* Media Info from ArtLabel */
#include "components/playlist/standardpanel.hpp" /* CoverArt */
#include "components/interface_widgets.hpp" /* CoverArt */ #include "components/interface_widgets.hpp" /* CoverArt */
//#include <vlc_playlist.h> //#include <vlc_playlist.h>
#include <QSplitter> #include <QSplitter>
class PLSelector; class PLSelector;
class StandardPLPanel;
class QPushButton; class QPushButton;
class StandardPLPanel;
static const QString viewNames[] = { qtr( "Detailed View" ),
qtr( "Icon View" ),
qtr( "List View" ) };
class ArtLabel : public CoverArtLabel class ArtLabel : public CoverArtLabel
{ {
...@@ -55,6 +63,7 @@ public: ...@@ -55,6 +63,7 @@ public:
} }
}; };
class LocationBar;
class PlaylistWidget : public QSplitter class PlaylistWidget : public QSplitter
{ {
Q_OBJECT Q_OBJECT
...@@ -66,15 +75,23 @@ public: ...@@ -66,15 +75,23 @@ public:
private: private:
PLSelector *selector; PLSelector *selector;
ArtLabel *art; ArtLabel *art;
StandardPLPanel *rightPanel;
QPushButton *addButton; QPushButton *addButton;
QSplitter *leftSplitter; QSplitter *leftSplitter;
QSignalMapper *viewSelectionMapper;
QAction *viewActions[3];
StandardPLPanel *mainView;
LocationBar *locationBar;
SearchLineEdit *searchEdit;
protected: protected:
intf_thread_t *p_intf; intf_thread_t *p_intf;
virtual void dropEvent( QDropEvent *); virtual void dropEvent( QDropEvent *);
virtual void dragEnterEvent( QDragEnterEvent * ); virtual void dragEnterEvent( QDragEnterEvent * );
virtual void closeEvent( QCloseEvent * ); virtual void closeEvent( QCloseEvent * );
private slots:
void changeView( const QModelIndex& index );
}; };
class LocationButton : public QPushButton class LocationButton : public QPushButton
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "components/playlist/selector.hpp" #include "components/playlist/selector.hpp"
#include "util/customwidgets.hpp" #include "util/customwidgets.hpp"
#include "menus.hpp" #include "menus.hpp"
#include "input_manager.hpp"
#include <vlc_intf_strings.h> #include <vlc_intf_strings.h>
...@@ -52,9 +53,6 @@ ...@@ -52,9 +53,6 @@
#include "sorting.h" #include "sorting.h"
static const QString viewNames[] = { qtr( "Detailed View" ),
qtr( "Icon View" ),
qtr( "List View" ) };
StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
intf_thread_t *_p_intf, intf_thread_t *_p_intf,
...@@ -79,49 +77,6 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, ...@@ -79,49 +77,6 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
currentRootIndexId = -1; currentRootIndexId = -1;
lastActivatedId = -1; lastActivatedId = -1;
locationBar = new LocationBar( model );
locationBar->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred );
layout->addWidget( locationBar, 0, 0 );
layout->setColumnStretch( 0, 5 );
CONNECT( locationBar, invoked( const QModelIndex & ),
this, browseInto( const QModelIndex & ) );
searchEdit = new SearchLineEdit( this );
searchEdit->setMaximumWidth( 250 );
searchEdit->setMinimumWidth( 80 );
layout->addWidget( searchEdit, 0, 2 );
CONNECT( searchEdit, textEdited( const QString& ),
this, search( const QString& ) );
CONNECT( searchEdit, editingFinished(),
this, searchDelayed() );
layout->setColumnStretch( 2, 3 );
/* 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 );
/* View selection menu */
viewSelectionMapper = new QSignalMapper( this );
CONNECT( viewSelectionMapper, mapped( int ), this, showView( int ) );
QActionGroup *actionGroup = new QActionGroup( this );
for( int i = 0; i < VIEW_COUNT; i++ )
{
viewActions[i] = actionGroup->addAction( viewNames[i] );
viewActions[i]->setCheckable( true );
viewSelectionMapper->setMapping( viewActions[i], i );
CONNECT( viewActions[i], triggered(), viewSelectionMapper, map() );
}
BUTTONACT( viewButton, cycleViews() );
QMenu *viewMenu = new QMenu( this );
viewMenu->addActions( actionGroup->actions() );
viewButton->setMenu( viewMenu );
/* Saved Settings */ /* Saved Settings */
getSettings()->beginGroup("Playlist"); getSettings()->beginGroup("Playlist");
...@@ -223,7 +178,7 @@ void StandardPLPanel::search( const QString& searchText ) ...@@ -223,7 +178,7 @@ void StandardPLPanel::search( const QString& searchText )
} }
} }
void StandardPLPanel::searchDelayed() void StandardPLPanel::searchDelayed( const QString& searchText )
{ {
int type; int type;
QString name; QString name;
...@@ -231,8 +186,8 @@ void StandardPLPanel::searchDelayed() ...@@ -231,8 +186,8 @@ void StandardPLPanel::searchDelayed()
if( type == SD_TYPE ) if( type == SD_TYPE )
{ {
if( !name.isEmpty() && !searchEdit->text().isEmpty() ) if( !name.isEmpty() && !searchText.isEmpty() )
playlist_QueryServicesDiscovery( THEPL, qtu(name), qtu(searchEdit->text() ) ); playlist_QueryServicesDiscovery( THEPL, qtu( name ), qtu( searchText ) );
} }
} }
...@@ -251,8 +206,7 @@ void StandardPLPanel::browseInto( const QModelIndex &index ) ...@@ -251,8 +206,7 @@ void StandardPLPanel::browseInto( const QModelIndex &index )
currentView->setRootIndex( index ); currentView->setRootIndex( index );
} }
locationBar->setIndex( index ); emit viewChanged( index );
searchEdit->clear();
} }
void StandardPLPanel::browseInto( ) void StandardPLPanel::browseInto( )
...@@ -406,7 +360,7 @@ void StandardPLPanel::showView( int i_view ) ...@@ -406,7 +360,7 @@ void StandardPLPanel::showView( int i_view )
} }
viewStack->setCurrentWidget( currentView ); viewStack->setCurrentWidget( currentView );
viewActions[i_view]->setChecked( true ); //viewActions[i_view]->setChecked( true );
browseInto(); browseInto();
gotoPlayingItem(); gotoPlayingItem();
} }
...@@ -466,6 +420,4 @@ void StandardPLPanel::browseInto( input_item_t *p_input ) ...@@ -466,6 +420,4 @@ void StandardPLPanel::browseInto( input_item_t *p_input )
lastActivatedId = -1; lastActivatedId = -1;
} }
...@@ -49,6 +49,9 @@ class QStackedLayout; ...@@ -49,6 +49,9 @@ class QStackedLayout;
class PlIconView; class PlIconView;
class PlListView; class PlListView;
class LocationBar; class LocationBar;
class PLSelector;
class QAbstractItemView;
class PlaylistWidget;
class StandardPLPanel: public QWidget class StandardPLPanel: public QWidget
{ {
...@@ -74,10 +77,7 @@ private: ...@@ -74,10 +77,7 @@ private:
intf_thread_t *p_intf; intf_thread_t *p_intf;
QWidget *parent; QWidget *parent;
QLabel *title;
QGridLayout *layout; QGridLayout *layout;
LocationBar *locationBar;
SearchLineEdit *searchEdit;
PLSelector *p_selector; PLSelector *p_selector;
QTreeView *treeView; QTreeView *treeView;
...@@ -86,11 +86,8 @@ private: ...@@ -86,11 +86,8 @@ private:
QAbstractItemView *currentView; QAbstractItemView *currentView;
QStackedLayout *viewStack; QStackedLayout *viewStack;
QAction *viewActions[ VIEW_COUNT ];
QAction *iconViewAction, *treeViewAction;
int currentRootId; int currentRootId;
QSignalMapper *selectColumnsSigMapper; QSignalMapper *selectColumnsSigMapper;
QSignalMapper *viewSelectionMapper;
int lastActivatedId; int lastActivatedId;
int currentRootIndexId; int currentRootIndexId;
...@@ -105,20 +102,28 @@ public slots: ...@@ -105,20 +102,28 @@ public slots:
void setRoot( playlist_item_t * ); void setRoot( playlist_item_t * );
void browseInto( const QModelIndex& ); void browseInto( const QModelIndex& );
void browseInto( ); void browseInto( );
private slots: private slots:
void deleteSelection(); void deleteSelection();
void handleExpansion( const QModelIndex& ); void handleExpansion( const QModelIndex& );
void handleRootChange(); void handleRootChange();
void activate( const QModelIndex & );
void browseInto( input_item_t * );
void gotoPlayingItem(); void gotoPlayingItem();
void search( const QString& searchText ); void search( const QString& searchText );
void searchDelayed(); void searchDelayed( const QString& searchText );
void popupSelectColumn( QPoint );
void popupPlView( const QPoint & ); void popupPlView( const QPoint & );
void popupSelectColumn( QPoint );
void toggleColumnShown( int ); void toggleColumnShown( int );
void showView( int ); void showView( int );
void cycleViews(); void cycleViews();
void activate( const QModelIndex & );
void browseInto( input_item_t * ); signals:
void viewChanged( const QModelIndex& );
}; };
#endif #endif
...@@ -148,6 +148,10 @@ SearchLineEdit::SearchLineEdit( QWidget *parent ) : QLineEdit( parent ) ...@@ -148,6 +148,10 @@ SearchLineEdit::SearchLineEdit( QWidget *parent ) : QLineEdit( parent )
CONNECT( this, textEdited( const QString& ), CONNECT( this, textEdited( const QString& ),
this, updateText( const QString& ) ); this, updateText( const QString& ) );
CONNECT( this, editingFinished(),
this, searchEditingFinished() );
} }
void SearchLineEdit::clear() void SearchLineEdit::clear()
...@@ -208,6 +212,11 @@ void SearchLineEdit::paintEvent( QPaintEvent *event ) ...@@ -208,6 +212,11 @@ void SearchLineEdit::paintEvent( QPaintEvent *event )
painter.drawText( rect, Qt::AlignLeft | Qt::AlignVCenter, qtr( I_PL_FILTER ) ); painter.drawText( rect, Qt::AlignLeft | Qt::AlignVCenter, qtr( I_PL_FILTER ) );
} }
void SearchLineEdit::searchEditingFinished()
{
emit searchDelayedChanged( text() );
}
QVLCElidingLabel::QVLCElidingLabel( const QString &s, Qt::TextElideMode mode, QWidget * parent ) QVLCElidingLabel::QVLCElidingLabel( const QString &s, Qt::TextElideMode mode, QWidget * parent )
: elideMode( mode ), QLabel( s, parent ) : elideMode( mode ), QLabel( s, parent )
......
...@@ -89,6 +89,10 @@ public slots: ...@@ -89,6 +89,10 @@ public slots:
private slots: private slots:
void updateText( const QString& ); void updateText( const QString& );
void searchEditingFinished();
signals:
void searchDelayedChanged( const QString& );
}; };
class QVLCElidingLabel : public QLabel class QVLCElidingLabel : public QLabel
......
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