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