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

Qt: Playlist, code simplification and factorisation

Remove friendship
Factorisation of CoverArt
Reduction of class footprints
virtual and protected correctness
Forward declaration when possible
parent d90dc446
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
#include "components/controller.hpp" #include "components/controller.hpp"
#include "components/controller_widget.hpp" #include "components/controller_widget.hpp"
#include "dialogs_provider.hpp"
#include "components/info_panels.hpp"
#include <QWidget> #include <QWidget>
#include <QFrame> #include <QFrame>
...@@ -201,6 +203,15 @@ public: ...@@ -201,6 +203,15 @@ public:
CoverArtLabel( QWidget *parent, intf_thread_t * ); CoverArtLabel( QWidget *parent, intf_thread_t * );
virtual ~CoverArtLabel(); virtual ~CoverArtLabel();
protected:
virtual void mouseDoubleClickEvent( QMouseEvent *event )
{
if( qobject_cast<MetaPanel *>(this->window()) == NULL )
{
THEDP->mediaInfoDialog();
}
event->accept();
}
private: private:
intf_thread_t *p_intf; intf_thread_t *p_intf;
......
...@@ -26,18 +26,18 @@ ...@@ -26,18 +26,18 @@
# include "config.h" # include "config.h"
#endif #endif
#include "components/playlist/standardpanel.hpp"
#include "components/playlist/selector.hpp"
#include "components/playlist/playlist.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/interface_widgets.hpp" /* CoverArtLabel */
#include "input_manager.hpp" /* art signal */ #include "input_manager.hpp" /* art signal */
#include "main_interface.hpp" /* DropEvent TODO remove this*/ #include "main_interface.hpp" /* DropEvent TODO remove this*/
#include <QGroupBox>
#include <QMenu> #include <QMenu>
#include <QSignalMapper>
#include <iostream>
/********************************************************************** /**********************************************************************
* Playlist Widget. The embedded playlist * Playlist Widget. The embedded playlist
**********************************************************************/ **********************************************************************/
...@@ -54,7 +54,7 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par ) ...@@ -54,7 +54,7 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par )
leftSplitter = new QSplitter( Qt::Vertical, this ); leftSplitter = new QSplitter( Qt::Vertical, this );
/* Source Selector */ /* Source Selector */
selector = new PLSelector( this, p_intf ); PLSelector *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
...@@ -66,7 +66,7 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par ) ...@@ -66,7 +66,7 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par )
artContainer->setMaximumHeight( 128 ); artContainer->setMaximumHeight( 128 );
/* Art label */ /* Art label */
art = new ArtLabel( artContainer, p_intf ); CoverArtLabel *art = new CoverArtLabel( 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 ); artContLay->addWidget( art, 1 );
...@@ -107,10 +107,11 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par ) ...@@ -107,10 +107,11 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par )
layout->addWidget( viewButton, 0, 1 ); layout->addWidget( viewButton, 0, 1 );
/* View selection menu */ /* View selection menu */
viewSelectionMapper = new QSignalMapper( this ); QSignalMapper *viewSelectionMapper = new QSignalMapper( this );
CONNECT( viewSelectionMapper, mapped( int ), mainView, showView( int ) ); CONNECT( viewSelectionMapper, mapped( int ), mainView, showView( int ) );
QActionGroup *actionGroup = new QActionGroup( this ); QActionGroup *actionGroup = new QActionGroup( this );
QAction *viewActions[StandardPLPanel::VIEW_COUNT];
for( int i = 0; i < StandardPLPanel::VIEW_COUNT; i++ ) for( int i = 0; i < StandardPLPanel::VIEW_COUNT; i++ )
{ {
viewActions[i] = actionGroup->addAction( viewNames[i] ); viewActions[i] = actionGroup->addAction( viewNames[i] );
...@@ -119,10 +120,10 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par ) ...@@ -119,10 +120,10 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par )
CONNECT( viewActions[i], triggered(), viewSelectionMapper, map() ); CONNECT( viewActions[i], triggered(), viewSelectionMapper, map() );
} }
CONNECT( viewButton, clicked(), mainView, cycleViews() ); QMenu *viewMenu = new QMenu( viewButton );
QMenu *viewMenu = new QMenu( this );
viewMenu->addActions( actionGroup->actions() ); viewMenu->addActions( actionGroup->actions() );
viewButton->setMenu( viewMenu ); viewButton->setMenu( viewMenu );
CONNECT( viewButton, clicked(), mainView, cycleViews() );
/* Search */ /* Search */
searchEdit = new SearchLineEdit( this ); searchEdit = new SearchLineEdit( this );
...@@ -141,7 +142,6 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par ) ...@@ -141,7 +142,6 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par )
DCONNECT( selector, activated( playlist_item_t * ), DCONNECT( selector, activated( playlist_item_t * ),
mainView, setRoot( playlist_item_t * ) ); mainView, setRoot( playlist_item_t * ) );
mainView->setRoot( p_root );
layout->addWidget( mainView, 1, 0, 1, -1 ); layout->addWidget( mainView, 1, 0, 1, -1 );
/* Add the two sides of the QSplitter */ /* Add the two sides of the QSplitter */
......
...@@ -32,60 +32,41 @@ ...@@ -32,60 +32,41 @@
#include "qt4.hpp" #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 <vlc_playlist.h>
#include <QSplitter> #include <QSplitter>
#include <QPushButton>
class PLSelector;
class QPushButton;
class StandardPLPanel; class StandardPLPanel;
class LocationBar;
class QSignalMapper;
class SearchLineEdit;
class QModelIndex;
static const QString viewNames[] = { qtr( "Detailed View" ), static const QString viewNames[] = { qtr( "Detailed View" ),
qtr( "Icon View" ), qtr( "Icon View" ),
qtr( "List View" ) }; qtr( "List View" ) };
class ArtLabel : public CoverArtLabel
{
public:
ArtLabel( QWidget *parent, intf_thread_t *intf )
: CoverArtLabel( parent, intf ) {}
virtual void mouseDoubleClickEvent( QMouseEvent *event )
{
THEDP->mediaInfoDialog();
event->accept();
}
};
class LocationBar;
class PlaylistWidget : public QSplitter class PlaylistWidget : public QSplitter
{ {
Q_OBJECT Q_OBJECT
public: public:
PlaylistWidget( intf_thread_t *_p_i, QWidget * ); PlaylistWidget( intf_thread_t *_p_i, QWidget * );
virtual ~PlaylistWidget(); virtual ~PlaylistWidget();
void forceHide(); void forceHide();
void forceShow(); void forceShow();
private:
PLSelector *selector;
ArtLabel *art;
QPushButton *addButton; private:
QSplitter *leftSplitter; QSplitter *leftSplitter;
QSignalMapper *viewSelectionMapper;
QAction *viewActions[3];
StandardPLPanel *mainView; StandardPLPanel *mainView;
LocationBar *locationBar; LocationBar *locationBar;
SearchLineEdit *searchEdit; SearchLineEdit *searchEdit;
protected:
intf_thread_t *p_intf; intf_thread_t *p_intf;
protected:
virtual void dropEvent( QDropEvent *); virtual void dropEvent( QDropEvent *);
virtual void dragEnterEvent( QDragEnterEvent * ); virtual void dragEnterEvent( QDragEnterEvent * );
virtual void closeEvent( QCloseEvent * ); virtual void closeEvent( QCloseEvent * );
...@@ -98,39 +79,43 @@ class LocationButton : public QPushButton ...@@ -98,39 +79,43 @@ class LocationButton : public QPushButton
{ {
public: public:
LocationButton( const QString &, bool bold, bool arrow, QWidget * parent = NULL ); LocationButton( const QString &, bool bold, bool arrow, QWidget * parent = NULL );
QSize sizeHint() const; virtual QSize sizeHint() const;
protected:
virtual void paintEvent ( QPaintEvent * event );
private: private:
void paintEvent ( QPaintEvent * event );
QFontMetrics *metrics;
bool b_arrow; bool b_arrow;
}; };
class PLModel; class PLModel;
class QHBoxLayout;
class LocationBar : public QWidget class LocationBar : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
LocationBar( PLModel * ); LocationBar( PLModel * );
void setIndex( const QModelIndex & ); void setIndex( const QModelIndex & );
QSize sizeHint() const; virtual QSize sizeHint() const;
signals: protected:
void invoked( const QModelIndex & ); virtual void resizeEvent ( QResizeEvent * event );
public slots:
void setRootIndex();
private slots:
void invoke( int i_item_id );
private: private:
void layOut( const QSize& size ); void layOut( const QSize& size );
void resizeEvent ( QResizeEvent * event );
PLModel *model; PLModel *model;
QSignalMapper *mapper; QSignalMapper *mapper;
QHBoxLayout *box;
QList<QWidget*> buttons; QList<QWidget*> buttons;
QList<QAction*> actions; QList<QAction*> actions;
LocationButton *btnMore; LocationButton *btnMore;
QMenu *menuMore; QMenu *menuMore;
QList<int> widths; QList<int> widths;
public slots:
void setRootIndex();
private slots:
void invoke( int i_item_id );
signals:
void invoked( const QModelIndex & );
}; };
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include <QList> #include <QList>
class PLItem class PLItem
{ {
friend class PLModel; friend class PLModel;
......
...@@ -28,26 +28,27 @@ ...@@ -28,26 +28,27 @@
#endif #endif
#include "qt4.hpp" #include "qt4.hpp"
#include "dialogs_provider.hpp"
#include "components/playlist/playlist_model.hpp" #include "components/playlist/playlist_model.hpp"
#include "dialogs/mediainfo.hpp" #include "dialogs_provider.hpp" /* THEDP */
#include "dialogs/playlist.hpp" #include "input_manager.hpp" /* THEMIM */
#include "dialogs/mediainfo.hpp" /* MediaInfo Dialog */
#include "dialogs/playlist.hpp" /* Playlist Dialog */
#include <vlc_intf_strings.h> #include <vlc_intf_strings.h>
#include "pixmaps/types/type_unknown.xpm" #include "pixmaps/types/type_unknown.xpm"
#include "sorting.h"
#include <assert.h> #include <assert.h>
#include <QIcon> #include <QIcon>
#include <QFont> #include <QFont>
#include <QMenu> #include <QMenu>
#include <QApplication>
#include <QSettings>
#include <QUrl> #include <QUrl>
#include <QFileInfo> #include <QFileInfo>
#include <QDesktopServices> #include <QDesktopServices>
#include <QInputDialog> #include <QInputDialog>
#include <QSignalMapper>
#include "sorting.h"
#define I_NEW_DIR \ #define I_NEW_DIR \
I_DIR_OR_FOLDER( N_("Create Directory"), N_( "Create Folder" ) ) I_DIR_OR_FOLDER( N_("Create Directory"), N_( "Create Folder" ) )
......
...@@ -36,26 +36,20 @@ ...@@ -36,26 +36,20 @@
#include "playlist_item.hpp" #include "playlist_item.hpp"
#include <QModelIndex>
#include <QObject>
#include <QEvent>
#include <QMimeData> #include <QMimeData>
#include <QSignalMapper>
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QVariant> #include <QVariant>
#include <QAction> #include <QModelIndex>
class PLItem; class PLItem;
class PLSelector; class PLSelector;
class PlMimeData; class PlMimeData;
class QSignalMapper;
class PLModel : public QAbstractItemModel class PLModel : public QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
friend class PLItem;
friend class PLSelector;
public: public:
enum { enum {
IsCurrentRole = Qt::UserRole, IsCurrentRole = Qt::UserRole,
......
...@@ -81,7 +81,7 @@ public: ...@@ -81,7 +81,7 @@ public:
PLSelItem( QTreeWidgetItem*, const QString& ); PLSelItem( QTreeWidgetItem*, const QString& );
void setText( const QString& text ) { lbl->setText( text ); } void setText( const QString& text ) { lbl->setText( text ); }
const QString text() { return lbl->text(); } QString text() const { return lbl->text(); }
void addAction( ItemAction, const QString& toolTip = 0 ); void addAction( ItemAction, const QString& toolTip = 0 );
QTreeWidgetItem *treeItem() { return qitem; } QTreeWidgetItem *treeItem() { return qitem; }
...@@ -101,9 +101,9 @@ private: ...@@ -101,9 +101,9 @@ private:
inline void leaveEvent( QEvent* ){ hideAction(); } inline void leaveEvent( QEvent* ){ hideAction(); }
QTreeWidgetItem* qitem; QTreeWidgetItem* qitem;
QVLCFramelessButton *lblAction; QVLCFramelessButton* lblAction;
QLabel *lbl; QLabel* lbl;
QHBoxLayout *layout; QHBoxLayout* layout;
}; };
Q_DECLARE_METATYPE( playlist_item_t *); Q_DECLARE_METATYPE( playlist_item_t *);
...@@ -116,8 +116,12 @@ public: ...@@ -116,8 +116,12 @@ public:
virtual ~PLSelector(); virtual ~PLSelector();
void getCurrentSelectedItem( int *type, QString *name ); void getCurrentSelectedItem( int *type, QString *name );
protected: protected:
friend class PlaylistWidget; virtual void drawBranches ( QPainter *, const QRect &, const QModelIndex & ) const;
virtual void dragMoveEvent ( QDragMoveEvent * event );
virtual bool dropMimeData ( QTreeWidgetItem *, int, const QMimeData *, Qt::DropAction );
virtual QStringList mimeTypes () const;
private: private:
void createItems(); void createItems();
...@@ -126,11 +130,6 @@ private: ...@@ -126,11 +130,6 @@ private:
PLSelItem * addPodcastItem( playlist_item_t *p_item ); PLSelItem * addPodcastItem( playlist_item_t *p_item );
inline PLSelItem * itemWidget( QTreeWidgetItem * ); inline PLSelItem * itemWidget( QTreeWidgetItem * );
void drawBranches ( QPainter *, const QRect &, const QModelIndex & ) const;
QStringList mimeTypes () const;
bool dropMimeData ( QTreeWidgetItem *, int, const QMimeData *, Qt::DropAction );
void dragMoveEvent ( QDragMoveEvent * event );
intf_thread_t *p_intf; intf_thread_t *p_intf;
QTreeWidgetItem *podcastsParent; QTreeWidgetItem *podcastsParent;
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include <QToolButton> #include <QToolButton>
#include <QFontMetrics> #include <QFontMetrics>
#include <QStackedLayout> #include <QStackedLayout>
#include <QSignalMapper>
#include <assert.h> #include <assert.h>
...@@ -65,7 +66,7 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, ...@@ -65,7 +66,7 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
QWidget( _parent ), p_intf( _p_intf ), QWidget( _parent ), p_intf( _p_intf ),
p_selector( _p_selector ) p_selector( _p_selector )
{ {
layout = new QGridLayout( this ); QGridLayout *layout = new QGridLayout( this );
layout->setSpacing( 0 ); layout->setMargin( 0 ); layout->setSpacing( 0 ); layout->setMargin( 0 );
setMinimumWidth( 300 ); setMinimumWidth( 300 );
...@@ -95,6 +96,8 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, ...@@ -95,6 +96,8 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
CONNECT( model, currentChanged( const QModelIndex& ), CONNECT( model, currentChanged( const QModelIndex& ),
this, handleExpansion( const QModelIndex& ) ); this, handleExpansion( const QModelIndex& ) );
CONNECT( model, rootChanged(), this, handleRootChange() ); CONNECT( model, rootChanged(), this, handleRootChange() );
setRoot( p_root );
} }
StandardPLPanel::~StandardPLPanel() StandardPLPanel::~StandardPLPanel()
......
...@@ -31,26 +31,24 @@ ...@@ -31,26 +31,24 @@
#include "qt4.hpp" #include "qt4.hpp"
#include "components/playlist/playlist.hpp" #include "components/playlist/playlist.hpp"
#include <QModelIndex>
#include <QWidget> #include <QWidget>
#include <QString>
#include <QToolBar>
#include <vlc_playlist.h> #include <vlc_playlist.h> /* playlist_item_t */
class QSignalMapper; class QSignalMapper;
class QTreeView;
class QListView;
class PLModel; class PLModel;
class QPushButton;
class QKeyEvent; class QKeyEvent;
class QWheelEvent; class QWheelEvent;
class QStackedLayout; class QStackedLayout;
class QModelIndex;
class QAbstractItemView;
class QTreeView;
class PlIconView; class PlIconView;
class PlListView; class PlListView;
class LocationBar; class LocationBar;
class PLSelector; class PLSelector;
class QAbstractItemView;
class PlaylistWidget; class PlaylistWidget;
class StandardPLPanel: public QWidget class StandardPLPanel: public QWidget
...@@ -61,29 +59,26 @@ public: ...@@ -61,29 +59,26 @@ public:
StandardPLPanel( PlaylistWidget *, intf_thread_t *, StandardPLPanel( PlaylistWidget *, intf_thread_t *,
playlist_t *, playlist_item_t *, PLSelector *, PLModel * ); playlist_t *, playlist_item_t *, PLSelector *, PLModel * );
virtual ~StandardPLPanel(); virtual ~StandardPLPanel();
protected:
friend class PlaylistWidget;
PLModel *model; enum { TREE_VIEW = 0,
private:
enum {
TREE_VIEW = 0,
ICON_VIEW, ICON_VIEW,
LIST_VIEW, LIST_VIEW,
VIEW_COUNT };
VIEW_COUNT protected:
};
PLModel *model;
virtual void wheelEvent( QWheelEvent *e );
private:
intf_thread_t *p_intf; intf_thread_t *p_intf;
QWidget *parent;
QGridLayout *layout;
PLSelector *p_selector; PLSelector *p_selector;
QTreeView *treeView; QTreeView *treeView;
PlIconView *iconView; PlIconView *iconView;
PlListView *listView; PlListView *listView;
QAbstractItemView *currentView; QAbstractItemView *currentView;
QStackedLayout *viewStack; QStackedLayout *viewStack;
int currentRootId; int currentRootId;
...@@ -95,7 +90,6 @@ private: ...@@ -95,7 +90,6 @@ private:
void createTreeView(); void createTreeView();
void createIconView(); void createIconView();
void createListView(); void createListView();
void wheelEvent( QWheelEvent *e );
bool eventFilter ( QObject * watched, QEvent * event ); bool eventFilter ( QObject * watched, QEvent * event );
public slots: public slots:
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "menus.hpp" #include "menus.hpp"
#include "recents.hpp" #include "recents.hpp"
#include "util/qt_dirs.hpp" #include "util/qt_dirs.hpp"
#include "main_interface.hpp"
/* The dialogs */ /* The dialogs */
#include "dialogs/playlist.hpp" #include "dialogs/playlist.hpp"
......
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