From 8459ec5dda7360c78152738412db162209301481 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Tue, 12 Aug 2014 20:08:43 +0200 Subject: [PATCH] * Added ContextView, a wrapper for playlist and contextual detail view. To replace FlexibleView. --- src/libtomahawk/playlist/ContextView.cpp | 340 +++++++++++++++++++++++ src/libtomahawk/playlist/ContextView.h | 100 +++++++ 2 files changed, 440 insertions(+) create mode 100644 src/libtomahawk/playlist/ContextView.cpp create mode 100644 src/libtomahawk/playlist/ContextView.h diff --git a/src/libtomahawk/playlist/ContextView.cpp b/src/libtomahawk/playlist/ContextView.cpp new file mode 100644 index 000000000..144c1a0c6 --- /dev/null +++ b/src/libtomahawk/playlist/ContextView.cpp @@ -0,0 +1,340 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2014, Christian Muehlhaeuser + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "ContextView.h" + +#include +#include +#include + +#include "audio/AudioEngine.h" +#include "widgets/CaptionLabel.h" +#include "widgets/FilterHeader.h" +#include "playlist/ModeHeader.h" +#include "playlist/PlayableModel.h" +#include "playlist/PlaylistModel.h" +#include "playlist/TrackView.h" +#include "playlist/GridView.h" +#include "playlist/PlaylistLargeItemDelegate.h" +#include "playlist/TrackItemDelegate.h" +#include "playlist/TrackDetailView.h" +#include "PlayableProxyModelPlaylistInterface.h" +#include "utils/TomahawkStyle.h" +#include "utils/TomahawkUtilsGui.h" +#include "utils/ImageRegistry.h" +#include "utils/Closure.h" +#include "utils/Logger.h" + +using namespace Tomahawk; + + +ContextView::ContextView( QWidget* parent, const QString& caption, QWidget* extraHeader ) + : QWidget( parent ) +// , m_header( new FilterHeader( this ) ) +// , m_modeHeader( new ModeHeader( this ) ) + , m_trackView( new TrackView() ) + , m_model( 0 ) + , m_temporary( false ) +{ +// qRegisterMetaType< ContextViewMode >( "ContextViewMode" ); + +// m_header->setBackground( ImageRegistry::instance()->pixmap( RESPATH "images/playlist_background.png", QSize( 0, 0 ) ) ); + +// m_trackView->setPlaylistInterface( m_playlistInterface ); + +/* 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() ); + m_trackView->setPlaylistItemDelegate( del ); + m_trackView->proxyModel()->setStyle( PlayableProxyModel::Large ); + + setLayout( new QVBoxLayout() ); + TomahawkUtils::unmarginLayout( layout() ); + +/* QFrame* lineBelow = new QFrame( this ); + lineBelow->setStyleSheet( QString( "QFrame { border: 1px solid %1; }" ).arg( TomahawkStyle::HEADER_BACKGROUND.name() ) ); + lineBelow->setFrameShape( QFrame::HLine ); + lineBelow->setMaximumHeight( 1 ); + QFrame* lineBelow2 = new QFrame( this ); + lineBelow2->setStyleSheet( QString( "QFrame { border: 1px solid black; }" ) ); + lineBelow2->setFrameShape( QFrame::HLine ); + lineBelow2->setMaximumHeight( 1 );*/ + + m_trackView->setStyleSheet( QString( "QTreeView { background-color: white; }" ) ); +// m_gridView->setStyleSheet( QString( "QListView { background-color: white; }" ) ); + +// layout()->addWidget( m_header ); +// layout()->addWidget( m_modeHeader ); +// if ( extraHeader ) +// layout()->addWidget( extraHeader ); +// layout()->addWidget( lineBelow ); +// layout()->addWidget( lineBelow2 ); + + m_captionLabel = new CaptionLabel( this ); + setCaption( caption ); + + QWidget* vbox = new QWidget; + QPalette pal = vbox->palette(); + pal.setBrush( vbox->backgroundRole(), Qt::white ); + vbox->setPalette( pal ); + vbox->setAutoFillBackground( true ); + + QVBoxLayout* vboxl = new QVBoxLayout; + TomahawkUtils::unmarginLayout( vboxl ); + vboxl->setContentsMargins( 32, 32, 32, 32 ); + vboxl->setSpacing( 32 ); + + vbox->setLayout( vboxl ); + + QWidget* hbox = new QWidget; + QHBoxLayout* hboxl = new QHBoxLayout; + TomahawkUtils::unmarginLayout( hboxl ); + hboxl->setSpacing( 32 ); + + QVBoxLayout* vboxInner = new QVBoxLayout; + TomahawkUtils::unmarginLayout( vboxInner ); + vboxInner->addWidget( m_trackView ); + vboxInner->addStretch(); + vboxInner->setStretchFactor( m_trackView, 1 ); + + TrackDetailView* detailView = new TrackDetailView; + hboxl->addWidget( detailView ); + hboxl->addLayout( vboxInner ); + hbox->setLayout( hboxl ); + + vboxl->addWidget( m_captionLabel ); + vboxl->addWidget( hbox ); + layout()->addWidget( vbox ); + + 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 ) ), detailView, SLOT( setQuery( Tomahawk::query_ptr ) ) ); +// connect( m_header, SIGNAL( filterTextChanged( QString ) ), SLOT( setFilter( QString ) ) ); + +/* NewClosure( m_modeHeader, SIGNAL( flatClicked() ), const_cast< ContextView* >( this ), SLOT( setCurrentMode( ContextViewMode ) ), ContextView::Flat )->setAutoDelete( false ); + NewClosure( m_modeHeader, SIGNAL( detailedClicked() ), const_cast< ContextView* >( this ), SLOT( setCurrentMode( ContextViewMode ) ), ContextView::Detailed )->setAutoDelete( false ); + NewClosure( m_modeHeader, SIGNAL( gridClicked() ), const_cast< ContextView* >( this ), SLOT( setCurrentMode( ContextViewMode ) ), ContextView::Grid )->setAutoDelete( false );*/ +} + + +ContextView::~ContextView() +{ + tDebug() << Q_FUNC_INFO; +} + + +void +ContextView::setCaption( const QString& caption ) +{ + if ( caption.isEmpty() ) + m_captionLabel->setText( tr( "Playlist Details" ) ); + else + m_captionLabel->setText( caption ); +} + + +void +ContextView::onQuerySelected( const Tomahawk::query_ptr& query ) +{ + if ( query->track()->cover( QSize( 0, 0 ) ).isNull() ) + return; + + m_pixmap = query->track()->cover( QSize( 0, 0 ) ); + emit pixmapChanged( m_pixmap ); +} + + +void +ContextView::setGuid( const QString& guid ) +{ + m_trackView->setGuid( guid ); +} + + +void +ContextView::setTrackView( TrackView* view ) +{ +/* if ( m_trackView ) + { + m_stack->removeWidget( m_trackView ); + delete m_trackView; + } + +// view->setPlaylistInterface( m_playlistInterface ); + + m_trackView = view; + m_stack->addWidget( view );*/ +} + + +void +ContextView::setPlayableModel( PlayableModel* model ) +{ + if ( m_model ) + { + delete m_model; + } + + m_model = model; + + m_trackView->setPlayableModel( model ); + + m_trackView->setSortingEnabled( false ); + m_trackView->sortByColumn( -1 ); + m_trackView->proxyModel()->sort( -1 ); + + onModelChanged(); +} + + +void +ContextView::setPlaylistModel( PlaylistModel* model ) +{ + if ( m_model ) + { + disconnect( m_model, SIGNAL( changed() ), this, SLOT( onModelChanged() ) ); + } + + setPlayableModel( model ); + + connect( model, SIGNAL( changed() ), SLOT( onModelChanged() ), Qt::UniqueConnection ); +} + + +Tomahawk::playlistinterface_ptr +ContextView::playlistInterface() const +{ + return m_trackView->proxyModel()->playlistInterface(); +} + + +QString +ContextView::title() const +{ + return m_trackView->title(); +} + + +QString +ContextView::description() const +{ + return m_trackView->description(); +} + + +QPixmap +ContextView::pixmap() const +{ + return m_pixmap; +} + + +bool +ContextView::jumpToCurrentTrack() +{ + tDebug() << Q_FUNC_INFO; + + return m_trackView->jumpToCurrentTrack(); +} + + +bool +ContextView::setFilter( const QString& pattern ) +{ + ViewPage::setFilter( pattern ); + + m_trackView->setFilter( pattern ); + + return true; +} + + +void +ContextView::setEmptyTip( const QString& tip ) +{ + m_trackView->setEmptyTip( tip ); +} + + +void +ContextView::setPixmap( const QPixmap& pixmap ) +{ + m_pixmap = pixmap; +// m_header->setPixmap( pixmap ); +} + + +void +ContextView::onModelChanged() +{ +// m_header->setPixmap( m_pixmap ); +// m_header->setCaption( m_model->title() ); +// m_header->setDescription( m_model->description() ); + + if ( m_model->isReadOnly() ) + setEmptyTip( tr( "This playlist is currently empty." ) ); + else + setEmptyTip( tr( "This playlist is currently empty. Add some tracks to it and enjoy the music!" ) ); +} + + +void +ContextView::onWidgetDestroyed( QWidget* widget ) +{ + Q_UNUSED( widget ); + emit destroyed( this ); +} + + +bool +ContextView::isTemporaryPage() const +{ + return m_temporary; +} + + +void +ContextView::setTemporaryPage( bool b ) +{ + m_temporary = b; +} + + +bool +ContextView::isBeingPlayed() const +{ + if ( !playlistInterface() ) + return false; + + if ( playlistInterface() == AudioEngine::instance()->currentTrackPlaylist() ) + return true; + + if ( playlistInterface()->hasChildInterface( AudioEngine::instance()->currentTrackPlaylist() ) ) + return true; + + return false; +} + + +void +ContextView::setShowCloseButton( bool b ) +{ + m_captionLabel->setShowCloseButton( b ); +} diff --git a/src/libtomahawk/playlist/ContextView.h b/src/libtomahawk/playlist/ContextView.h new file mode 100644 index 000000000..8a1d5304f --- /dev/null +++ b/src/libtomahawk/playlist/ContextView.h @@ -0,0 +1,100 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2014, Christian Muehlhaeuser + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef CONTEXTVIEW_H +#define CONTEXTVIEW_H + +#include "ViewPage.h" +#include "PlaylistInterface.h" +#include "DllMacro.h" + +class QStackedWidget; + +class CaptionLabel; +class GridView; +class TrackView; +class PlayableModel; +class PlaylistModel; +class FilterHeader; +class ModeHeader; + +class DLLEXPORT ContextView : public QWidget, public Tomahawk::ViewPage +{ +Q_OBJECT + +public: + explicit ContextView( QWidget* parent = 0, const QString& caption = QString(), QWidget* extraHeader = 0 ); + ~ContextView(); + + virtual QWidget* widget() { return this; } + virtual Tomahawk::playlistinterface_ptr playlistInterface() const; + + virtual QString title() const; + virtual QString description() const; + virtual QPixmap pixmap() const; + + virtual bool showInfoBar() const { return false; } + virtual bool jumpToCurrentTrack(); + virtual bool isTemporaryPage() const; + virtual bool isBeingPlayed() const; + void setTemporaryPage( bool b ); + + TrackView* trackView() const { return m_trackView; } + + void setCaption( const QString& caption ); + + void setGuid( const QString& guid ); + + void setTrackView( TrackView* view ); + + void setPlayableModel( PlayableModel* model ); + void setPlaylistModel( PlaylistModel* model ); + + void setPixmap( const QPixmap& pixmap ); + void setEmptyTip( const QString& tip ); + +public slots: + virtual bool setFilter( const QString& pattern ); + void setShowCloseButton( bool b ); + +signals: + void closeClicked(); + void destroyed( QWidget* widget ); + void pixmapChanged( const QPixmap& pixmap ); + +private slots: + void onModelChanged(); + void onWidgetDestroyed( QWidget* widget ); + + void onQuerySelected( const Tomahawk::query_ptr& query ); + +private: + FilterHeader* m_header; + ModeHeader* m_modeHeader; + QPixmap m_pixmap; + CaptionLabel* m_captionLabel; + + TrackView* m_trackView; + + PlayableModel* m_model; + QStackedWidget* m_stack; + + bool m_temporary; +}; + +#endif // CONTEXTVIEW_H