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

Qt: playlist code refactoring

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