1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-11 16:44:05 +02:00

Added ContextView::setTrackView, allowing you to replace the TrackView with your own implementation of it.

This commit is contained in:
Christian Muehlhaeuser
2014-10-12 10:10:52 +02:00
parent f8fd06a2db
commit 188dea4991
2 changed files with 45 additions and 27 deletions

View File

@@ -43,26 +43,17 @@ using namespace Tomahawk;
ContextView::ContextView( QWidget* parent, const QString& caption ) ContextView::ContextView( QWidget* parent, const QString& caption )
: QWidget( parent ) : QWidget( parent )
, m_trackView( new TrackView() ) , m_trackView( new TrackView() )
, m_model( 0 )
, m_temporary( false ) , m_temporary( false )
{ {
// qRegisterMetaType< ContextViewMode >( "ContextViewMode" );
/* m_detailedView->setColumnHidden( PlayableModel::Age, true ); // Hide age column per default
m_detailedView->setColumnHidden( PlayableModel::Filesize, true ); // Hide filesize column per default
m_detailedView->setColumnHidden( PlayableModel::Composer, true ); // Hide composer column per default*/
TrackItemDelegate* del = new TrackItemDelegate( TrackItemDelegate::LovedTracks, m_trackView, m_trackView->proxyModel() ); TrackItemDelegate* del = new TrackItemDelegate( TrackItemDelegate::LovedTracks, m_trackView, m_trackView->proxyModel() );
m_trackView->setPlaylistItemDelegate( del ); m_trackView->setPlaylistItemDelegate( del );
m_trackView->proxyModel()->setStyle( PlayableProxyModel::Fancy ); m_trackView->proxyModel()->setStyle( PlayableProxyModel::Fancy );
TomahawkStyle::styleScrollBar( m_trackView->verticalScrollBar() ); TomahawkStyle::styleScrollBar( m_trackView->verticalScrollBar() );
setLayout( new QVBoxLayout() ); setLayout( new QVBoxLayout( this ) );
TomahawkUtils::unmarginLayout( layout() ); TomahawkUtils::unmarginLayout( layout() );
m_trackView->setStyleSheet( QString( "QTreeView { background-color: white; }" ) ); m_trackView->setStyleSheet( QString( "QTreeView { background-color: white; }" ) );
// m_gridView->setStyleSheet( QString( "QListView { background-color: white; }" ) );
m_captionLabel = new CaptionLabel( this ); m_captionLabel = new CaptionLabel( this );
setCaption( caption ); setCaption( caption );
@@ -72,7 +63,7 @@ ContextView::ContextView( QWidget* parent, const QString& caption )
vbox->setPalette( pal ); vbox->setPalette( pal );
vbox->setAutoFillBackground( true ); vbox->setAutoFillBackground( true );
QVBoxLayout* vboxl = new QVBoxLayout; QVBoxLayout* vboxl = new QVBoxLayout( this );
TomahawkUtils::unmarginLayout( vboxl ); TomahawkUtils::unmarginLayout( vboxl );
vboxl->setContentsMargins( 32, 32, 32, 32 ); vboxl->setContentsMargins( 32, 32, 32, 32 );
vboxl->setSpacing( 32 ); vboxl->setSpacing( 32 );
@@ -80,20 +71,19 @@ ContextView::ContextView( QWidget* parent, const QString& caption )
vbox->setLayout( vboxl ); vbox->setLayout( vboxl );
QWidget* hbox = new QWidget; QWidget* hbox = new QWidget;
QHBoxLayout* hboxl = new QHBoxLayout; QHBoxLayout* hboxl = new QHBoxLayout( this );
TomahawkUtils::unmarginLayout( hboxl ); TomahawkUtils::unmarginLayout( hboxl );
hboxl->setSpacing( 32 ); hboxl->setSpacing( 32 );
QVBoxLayout* vboxInner = new QVBoxLayout; m_innerLayout = new QVBoxLayout( this );
TomahawkUtils::unmarginLayout( vboxInner ); TomahawkUtils::unmarginLayout( m_innerLayout );
vboxInner->addWidget( m_trackView ); m_innerLayout->addWidget( m_trackView, 1 );
vboxInner->addStretch(); m_innerLayout->addStretch();
vboxInner->setStretchFactor( m_trackView, 1 );
TrackDetailView* detailView = new TrackDetailView; m_detailView = new TrackDetailView;
detailView->setPlaylistInterface( playlistInterface() ); m_detailView->setPlaylistInterface( playlistInterface() );
hboxl->addWidget( detailView ); hboxl->addWidget( m_detailView );
hboxl->addLayout( vboxInner ); hboxl->addLayout( m_innerLayout );
hbox->setLayout( hboxl ); hbox->setLayout( hboxl );
vboxl->addWidget( m_captionLabel ); vboxl->addWidget( m_captionLabel );
@@ -102,8 +92,8 @@ ContextView::ContextView( QWidget* parent, const QString& caption )
connect( m_captionLabel, SIGNAL( clicked() ), SIGNAL( closeClicked() ) ); connect( m_captionLabel, SIGNAL( clicked() ), SIGNAL( closeClicked() ) );
connect( m_trackView, SIGNAL( querySelected( Tomahawk::query_ptr ) ), SLOT( onQuerySelected( Tomahawk::query_ptr ) ) ); connect( m_trackView, SIGNAL( querySelected( Tomahawk::query_ptr ) ), SLOT( onQuerySelected( Tomahawk::query_ptr ) ) );
connect( m_trackView, SIGNAL( querySelected( Tomahawk::query_ptr ) ), detailView, SLOT( setQuery( Tomahawk::query_ptr ) ) ); connect( m_trackView, SIGNAL( querySelected( Tomahawk::query_ptr ) ), m_detailView, SLOT( setQuery( Tomahawk::query_ptr ) ) );
// connect( m_header, SIGNAL( filterTextChanged( QString ) ), SLOT( setFilter( QString ) ) ); connect( m_trackView, SIGNAL( modelChanged() ), SLOT( onModelChanged() ) );
TomahawkUtils::fixMargins( this ); TomahawkUtils::fixMargins( this );
} }
@@ -115,6 +105,31 @@ ContextView::~ContextView()
} }
void
ContextView::setTrackView( TrackView* view )
{
if ( m_trackView )
{
disconnect( m_trackView, SIGNAL( querySelected( Tomahawk::query_ptr ) ), this, SLOT( onQuerySelected( Tomahawk::query_ptr ) ) );
disconnect( m_trackView, SIGNAL( querySelected( Tomahawk::query_ptr ) ), m_detailView, SLOT( setQuery( Tomahawk::query_ptr ) ) );
disconnect( m_trackView, SIGNAL( modelChanged() ), this, SLOT( onModelChanged() ) );
m_innerLayout->removeWidget( m_trackView );
delete m_trackView;
}
m_trackView = view;
m_trackView->setStyleSheet( QString( "QTreeView { background-color: white; }" ) );
TomahawkStyle::styleScrollBar( m_trackView->verticalScrollBar() );
m_innerLayout->insertWidget( 0, view, 1 );
connect( m_trackView, SIGNAL( querySelected( Tomahawk::query_ptr ) ), SLOT( onQuerySelected( Tomahawk::query_ptr ) ) );
connect( m_trackView, SIGNAL( querySelected( Tomahawk::query_ptr ) ), m_detailView, SLOT( setQuery( Tomahawk::query_ptr ) ) );
connect( m_trackView, SIGNAL( modelChanged() ), SLOT( onModelChanged() ) );
}
void void
ContextView::setCaption( const QString& caption ) ContextView::setCaption( const QString& caption )
{ {
@@ -225,7 +240,7 @@ ContextView::setEmptyTip( const QString& tip )
void void
ContextView::onModelChanged() ContextView::onModelChanged()
{ {
if ( m_model->isReadOnly() ) if ( m_trackView->model()->isReadOnly() )
setEmptyTip( tr( "This playlist is currently empty." ) ); setEmptyTip( tr( "This playlist is currently empty." ) );
else else
setEmptyTip( tr( "This playlist is currently empty. Add some tracks to it and enjoy the music!" ) ); setEmptyTip( tr( "This playlist is currently empty. Add some tracks to it and enjoy the music!" ) );

View File

@@ -23,11 +23,11 @@
#include "PlaylistInterface.h" #include "PlaylistInterface.h"
#include "DllMacro.h" #include "DllMacro.h"
class QVBoxLayout;
class CaptionLabel; class CaptionLabel;
class GridView; class GridView;
class TrackView; class TrackView;
class PlayableModel; class TrackDetailView;
class PlaylistModel;
class DLLEXPORT ContextView : public QWidget, public Tomahawk::ViewPage class DLLEXPORT ContextView : public QWidget, public Tomahawk::ViewPage
{ {
@@ -50,6 +50,7 @@ public:
virtual bool isBeingPlayed() const; virtual bool isBeingPlayed() const;
void setTemporaryPage( bool b ); void setTemporaryPage( bool b );
void setTrackView( TrackView* view );
TrackView* trackView() const { return m_trackView; } TrackView* trackView() const { return m_trackView; }
void setCaption( const QString& caption ); void setCaption( const QString& caption );
@@ -76,7 +77,9 @@ private slots:
private: private:
CaptionLabel* m_captionLabel; CaptionLabel* m_captionLabel;
TrackView* m_trackView; TrackView* m_trackView;
PlayableModel* m_model; TrackDetailView* m_detailView;
QVBoxLayout* m_innerLayout;
QPixmap m_pixmap; QPixmap m_pixmap;
Tomahawk::query_ptr m_query; Tomahawk::query_ptr m_query;