From 27df8fd3dc13bce7643c44ce37284bab3c319a4a Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 2 Jul 2012 23:04:46 +0200 Subject: [PATCH 1/5] * Added FlexibleView widget. --- src/libtomahawk/CMakeLists.txt | 1 + src/libtomahawk/playlist/FlexibleView.cpp | 237 ++++++++++++++++++++++ src/libtomahawk/playlist/FlexibleView.h | 83 ++++++++ 3 files changed, 321 insertions(+) create mode 100644 src/libtomahawk/playlist/FlexibleView.cpp create mode 100644 src/libtomahawk/playlist/FlexibleView.h diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 62e6ce9b2..96e08a322 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -48,6 +48,7 @@ set( libGuiSources infobar/InfoBar.cpp + playlist/FlexibleView.cpp playlist/TreeModel.cpp playlist/TreeProxyModel.cpp playlist/TreeProxyModelPlaylistInterface.cpp diff --git a/src/libtomahawk/playlist/FlexibleView.cpp b/src/libtomahawk/playlist/FlexibleView.cpp new file mode 100644 index 000000000..73d5b8474 --- /dev/null +++ b/src/libtomahawk/playlist/FlexibleView.cpp @@ -0,0 +1,237 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2012, 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 "FlexibleView.h" + +#include +#include +#include + +#include "playlist/PlayableModel.h" +#include "playlist/TrackView.h" +#include "playlist/GridView.h" +#include "playlist/PlaylistLargeItemDelegate.h" +#include "utils/Closure.h" +#include "utils/TomahawkUtilsGui.h" +#include "utils/Logger.h" + +using namespace Tomahawk; + + +FlexibleView::FlexibleView( QWidget* parent ) + : QWidget( parent ) + , m_trackView( new TrackView() ) + , m_detailedView( new TrackView() ) + , m_gridView( new GridView() ) + , m_model( 0 ) +{ + qRegisterMetaType< FlexibleViewMode >( "FlexibleViewMode" ); + + PlaylistLargeItemDelegate* del = new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::LovedTracks, m_trackView, m_trackView->proxyModel() ); + connect( del, SIGNAL( updateIndex( QModelIndex ) ), m_trackView, SLOT( update( QModelIndex ) ) ); + m_trackView->setItemDelegate( del ); + m_trackView->proxyModel()->setStyle( PlayableProxyModel::Large ); + + m_stack = new QStackedWidget(); + setLayout( new QVBoxLayout() ); + TomahawkUtils::unmarginLayout( layout() ); + + QWidget* modeBar = new QWidget(); + modeBar->setLayout( new QHBoxLayout() ); + TomahawkUtils::unmarginLayout( modeBar->layout() ); + + QWidget* modeWidget = new QWidget(); + modeWidget->setLayout( new QHBoxLayout() ); + modeWidget->setFixedSize( QSize( 87, 30 ) ); + TomahawkUtils::unmarginLayout( modeWidget->layout() ); + + QRadioButton* radioNormal = new QRadioButton(); + radioNormal->setObjectName( "radioNormal" ); + QRadioButton* radioDetailed = new QRadioButton(); + radioDetailed->setObjectName( "radioDetailed" ); + QRadioButton* radioCloud = new QRadioButton(); + radioCloud->setObjectName( "radioCloud" ); + + radioNormal->setFocusPolicy( Qt::NoFocus ); + radioDetailed->setFocusPolicy( Qt::NoFocus ); + radioCloud->setFocusPolicy( Qt::NoFocus ); + + QFile f( RESPATH "stylesheets/topbar-radiobuttons.css" ); + f.open( QFile::ReadOnly ); + QString css = QString::fromAscii( f.readAll() ); + f.close(); + + modeWidget->setStyleSheet( css ); + modeWidget->layout()->addWidget( radioNormal ); + modeWidget->layout()->addWidget( radioDetailed ); + modeWidget->layout()->addWidget( radioCloud ); + modeWidget->layout()->addItem( new QSpacerItem( 1, 1, QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + modeBar->layout()->addItem( new QSpacerItem( 1, 1, QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + modeBar->layout()->addWidget( modeWidget ); + modeBar->layout()->addItem( new QSpacerItem( 1, 1, QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + layout()->addWidget( modeBar ); + layout()->addWidget( m_stack ); + + m_stack->addWidget( m_trackView ); + m_stack->addWidget( m_detailedView ); + m_stack->addWidget( m_gridView ); + + radioNormal->setChecked( true ); + setCurrentMode( Flat ); + + NewClosure( radioNormal, SIGNAL( clicked() ), const_cast< FlexibleView* >( this ), SLOT( setCurrentMode( FlexibleViewMode ) ), Flat )->setAutoDelete( false ); + NewClosure( radioDetailed, SIGNAL( clicked() ), const_cast< FlexibleView* >( this ), SLOT( setCurrentMode( FlexibleViewMode ) ), Detailed )->setAutoDelete( false ); + NewClosure( radioCloud, SIGNAL( clicked() ), const_cast< FlexibleView* >( this ), SLOT( setCurrentMode( FlexibleViewMode ) ), Grid )->setAutoDelete( false ); +} + + +FlexibleView::~FlexibleView() +{ + tDebug() << Q_FUNC_INFO; +} + + +void +FlexibleView::setTrackView( TrackView* view ) +{ + if ( m_trackView ) + { + delete m_trackView; + } + + m_trackView = view; + m_stack->addWidget( view ); +} + + +void +FlexibleView::setDetailedView( TrackView* view ) +{ + if ( m_detailedView ) + { + delete m_detailedView; + } + + m_detailedView = view; + m_stack->addWidget( view ); +} + + +void +FlexibleView::setGridView( GridView* view ) +{ + if ( m_gridView ) + { + delete m_gridView; + } + + m_gridView = view; + m_stack->addWidget( view ); +} + + +void +FlexibleView::setPlayableModel( PlayableModel* model ) +{ + if ( m_model ) + { + delete m_model; + } + + m_model = model; + + m_trackView->setPlayableModel( model ); + m_detailedView->setPlayableModel( model ); + m_gridView->setPlayableModel( model ); + + m_trackView->setSortingEnabled( false ); + m_trackView->sortByColumn( -1 ); + m_trackView->proxyModel()->sort( -1 ); + m_detailedView->proxyModel()->sort( -1 ); + m_gridView->proxyModel()->sort( -1 ); +} + + +void +FlexibleView::setCurrentMode( FlexibleViewMode mode ) +{ + m_mode = mode; + + switch ( mode ) + { + case Flat: + { + m_stack->setCurrentWidget( m_trackView ); + break; + } + + case Detailed: + { + m_stack->setCurrentWidget( m_detailedView ); + break; + } + + case Grid: + { + m_stack->setCurrentWidget( m_gridView ); + break; + } + } + + emit modeChanged( mode ); +} + + +Tomahawk::playlistinterface_ptr +FlexibleView::playlistInterface() const +{ + return m_trackView->playlistInterface(); +} + + +QString +FlexibleView::title() const +{ + return m_trackView->title(); +} + + +QString +FlexibleView::description() const +{ + return m_trackView->description(); +} + + +QPixmap +FlexibleView::pixmap() const +{ + return m_trackView->pixmap(); +} + + +bool +FlexibleView::jumpToCurrentTrack() +{ + m_trackView->jumpToCurrentTrack(); + m_detailedView->jumpToCurrentTrack(); + m_gridView->jumpToCurrentTrack(); + return true; +} diff --git a/src/libtomahawk/playlist/FlexibleView.h b/src/libtomahawk/playlist/FlexibleView.h new file mode 100644 index 000000000..838842c46 --- /dev/null +++ b/src/libtomahawk/playlist/FlexibleView.h @@ -0,0 +1,83 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2012, 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 FLEXIBLEVIEW_H +#define FLEXIBLEVIEW_H + +#include "ViewPage.h" +#include "PlaylistInterface.h" +#include "DllMacro.h" + +class QStackedWidget; + +class GridView; +class TrackView; +class PlayableModel; + +class DLLEXPORT FlexibleView : public QWidget, public Tomahawk::ViewPage +{ +Q_OBJECT + +public: + enum FlexibleViewMode + { Flat = 0, Detailed = 1, Grid = 2 }; + + explicit FlexibleView( QWidget* parent = 0 ); + ~FlexibleView(); + + 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 showStatsBar() const { return false; } + virtual bool showFilter() const { return true; } + +// virtual void setShowModes( bool b ) { m_showModes = b; } + virtual bool showModes() const { return false; } + + virtual bool jumpToCurrentTrack(); + + void setTrackView( TrackView* view ); + void setDetailedView( TrackView* view ); + void setGridView( GridView* view ); + + void setPlayableModel( PlayableModel* model ); + +public slots: + void setCurrentMode( FlexibleViewMode mode ); + +signals: + void modeChanged( FlexibleViewMode mode ); + +private: + TrackView* m_trackView; + TrackView* m_detailedView; + GridView* m_gridView; + + PlayableModel* m_model; + QStackedWidget* m_stack; + + FlexibleViewMode m_mode; +}; + +Q_DECLARE_METATYPE( FlexibleView::FlexibleViewMode ); + +#endif // FLEXIBLEVIEW_H From 1860d7732ab22d302ab7abf0381c7eef5dcd7b10 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 2 Jul 2012 23:08:07 +0200 Subject: [PATCH 2/5] * Moved style/view specific model stuff into PlayableProxyModel. --- src/libtomahawk/playlist/PlayableModel.cpp | 106 +--------------- src/libtomahawk/playlist/PlayableModel.h | 19 --- .../playlist/PlayableProxyModel.cpp | 117 ++++++++++++++++++ src/libtomahawk/playlist/PlayableProxyModel.h | 20 +++ 4 files changed, 143 insertions(+), 119 deletions(-) diff --git a/src/libtomahawk/playlist/PlayableModel.cpp b/src/libtomahawk/playlist/PlayableModel.cpp index c108a49d9..0af16f581 100644 --- a/src/libtomahawk/playlist/PlayableModel.cpp +++ b/src/libtomahawk/playlist/PlayableModel.cpp @@ -41,7 +41,6 @@ PlayableModel::PlayableModel( QObject* parent, bool loading ) : QAbstractItemModel( parent ) , m_rootItem( new PlayableItem( 0, this ) ) , m_readOnly( true ) - , m_style( Detailed ) , m_loading( loading ) { connect( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), SLOT( onPlaybackStarted( Tomahawk::result_ptr ) ), Qt::DirectConnection ); @@ -49,9 +48,6 @@ PlayableModel::PlayableModel( QObject* parent, bool loading ) m_header << tr( "Artist" ) << tr( "Title" ) << tr( "Composer" ) << tr( "Album" ) << tr( "Track" ) << tr( "Duration" ) << tr( "Bitrate" ) << tr( "Age" ) << tr( "Year" ) << tr( "Size" ) << tr( "Origin" ) << tr( "Score" ) << tr( "Name" ); - - m_headerStyle[ Detailed ] << Artist << Track << Composer << Album << AlbumPos << Duration << Bitrate << Age << Year << Filesize << Origin << Score; - m_headerStyle[ Collection ] << Name << Composer << Duration << Bitrate << Age << Year << Filesize << Origin; } @@ -94,23 +90,7 @@ PlayableModel::columnCount( const QModelIndex& parent ) const { Q_UNUSED( parent ); - switch ( m_style ) - { - case Short: - case ShortWithAvatars: - case Large: - return 1; - break; - - case Collection: - return 8; - break; - - case Detailed: - default: - return 12; - break; - } + return 12; } @@ -183,10 +163,7 @@ PlayableModel::queryData( const query_ptr& query, int column, int role ) const if ( role != Qt::DisplayRole ) // && role != Qt::ToolTipRole ) return QVariant(); - if ( !m_headerStyle.contains( m_style ) ) - return query->track(); - - switch( m_headerStyle[ m_style ].at( column ) ) + switch ( column ) { case Artist: return query->artist(); @@ -229,7 +206,7 @@ PlayableModel::queryData( const query_ptr& query, int column, int role ) const } if ( query->numResults() ) { - switch( m_headerStyle[ m_style ].at( column ) ) + switch ( column ) { case Bitrate: if ( query->results().first()->bitrate() > 0 ) @@ -283,16 +260,6 @@ PlayableModel::data( const QModelIndex& index, int role ) const return QVariant( columnAlignment( index.column() ) ); } - if ( role == StyleRole ) - { - return m_style; - } - - if ( role == Qt::SizeHintRole && !m_itemSize.isEmpty() ) - { - return m_itemSize; - } - if ( !entry->query().isNull() ) { return queryData( entry->query()->displayQuery(), index.column(), role ); @@ -317,10 +284,8 @@ PlayableModel::headerData( int section, Qt::Orientation orientation, int role ) if ( role == Qt::DisplayRole && section >= 0 ) { - if ( m_headerStyle.contains( m_style ) ) - { - return m_header.at( m_headerStyle[ m_style ].at( section ) ); - } + if ( section < m_header.count() ) + return m_header.at( section ); else return tr( "Name" ); } @@ -334,28 +299,6 @@ PlayableModel::headerData( int section, Qt::Orientation orientation, int role ) } -void -PlayableModel::updateDetailedInfo( const QModelIndex& index ) -{ - if ( style() != PlayableModel::Short && style() != PlayableModel::Large ) - return; - - PlayableItem* item = itemFromIndex( index ); - if ( item->query().isNull() ) - return; - - if ( style() == PlayableModel::Short || style() == PlayableModel::Large ) - { - item->query()->cover( QSize( 0, 0 ) ); - } - - if ( style() == PlayableModel::Large ) - { - item->query()->loadSocialActions(); - } -} - - void PlayableModel::setCurrentItem( const QModelIndex& index ) { @@ -717,47 +660,10 @@ PlayableModel::ensureResolved() } -void -PlayableModel::setStyle( PlayableModel::PlayableItemStyle style ) -{ - m_style = style; -} - - -QList< double > -PlayableModel::columnWeights() const -{ - QList< double > w; - - switch ( m_style ) - { - case Short: - case ShortWithAvatars: - case Large: - w << 1.0; - break; - - case Collection: - w << 0.42 << 0.12 << 0.07 << 0.07 << 0.07 << 0.07 << 0.07; // << 0.11; - break; - - case Detailed: - default: - w << 0.16 << 0.16 << 0.14 << 0.12 << 0.05 << 0.05 << 0.05 << 0.05 << 0.05 << 0.05 << 0.09; // << 0.03; - break; - } - - return w; -} - - Qt::Alignment PlayableModel::columnAlignment( int column ) const { - if ( !m_headerStyle.contains( m_style ) ) - return Qt::AlignLeft; - - switch( m_headerStyle[ m_style ].at( column ) ) + switch ( column ) { case Age: case AlbumPos: diff --git a/src/libtomahawk/playlist/PlayableModel.h b/src/libtomahawk/playlist/PlayableModel.h index 04ee5a20e..deacf8720 100644 --- a/src/libtomahawk/playlist/PlayableModel.h +++ b/src/libtomahawk/playlist/PlayableModel.h @@ -38,12 +38,6 @@ class DLLEXPORT PlayableModel : public QAbstractItemModel Q_OBJECT public: - enum PlayableItemStyle - { Detailed = 0, Short = 1, ShortWithAvatars = 2, Large = 3, Collection = 4 }; - - enum PlayableModelRole - { StyleRole = Qt::UserRole + 1 }; - enum Columns { Artist = 0, Track = 1, @@ -63,9 +57,6 @@ public: explicit PlayableModel( QObject* parent = 0, bool loading = true ); virtual ~PlayableModel(); - PlayableModel::PlayableItemStyle style() const { return m_style; } - void setStyle( PlayableModel::PlayableItemStyle style ); - virtual QModelIndex index( int row, int column, const QModelIndex& parent ) const; virtual QModelIndex parent( const QModelIndex& child ) const; @@ -87,8 +78,6 @@ public: virtual int columnCount( const QModelIndex& parent = QModelIndex() ) const; virtual bool hasChildren( const QModelIndex& parent ) const; - QList< double > columnWeights() const; - virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const; virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) const; @@ -113,11 +102,6 @@ public: /// Returns a flat list of all tracks in this model QList< Tomahawk::query_ptr > queries() const; - void updateDetailedInfo( const QModelIndex& index ); - - QSize itemSize() const { return m_itemSize; } - void setItemSize( const QSize& size ) { m_itemSize = size; } - void startLoading(); void finishLoading(); @@ -176,7 +160,6 @@ private: PlayableItem* m_rootItem; QPersistentModelIndex m_currentIndex; Tomahawk::QID m_currentUuid; - QSize m_itemSize; bool m_readOnly; @@ -184,10 +167,8 @@ private: QString m_description; QPixmap m_icon; - QHash< PlayableItemStyle, QList > m_headerStyle; QStringList m_header; - PlayableItemStyle m_style; bool m_loading; }; diff --git a/src/libtomahawk/playlist/PlayableProxyModel.cpp b/src/libtomahawk/playlist/PlayableProxyModel.cpp index 5efe43514..b281a2d9b 100644 --- a/src/libtomahawk/playlist/PlayableProxyModel.cpp +++ b/src/libtomahawk/playlist/PlayableProxyModel.cpp @@ -36,12 +36,16 @@ PlayableProxyModel::PlayableProxyModel( QObject* parent ) , m_showOfflineResults( true ) , m_hideDupeItems( false ) , m_maxVisibleItems( -1 ) + , m_style( Detailed ) { setFilterCaseSensitivity( Qt::CaseInsensitive ); setSortCaseSensitivity( Qt::CaseInsensitive ); setDynamicSortFilter( true ); setSourcePlayableModel( 0 ); + + m_headerStyle[ Detailed ] << PlayableModel::Artist << PlayableModel::Track << PlayableModel::Composer << PlayableModel::Album << PlayableModel::AlbumPos << PlayableModel::Duration << PlayableModel::Bitrate << PlayableModel::Age << PlayableModel::Year << PlayableModel::Filesize << PlayableModel::Origin << PlayableModel::Score; + m_headerStyle[ Collection ] << PlayableModel::Name << PlayableModel::Composer << PlayableModel::Duration << PlayableModel::Bitrate << PlayableModel::Age << PlayableModel::Year << PlayableModel::Filesize << PlayableModel::Origin; } @@ -461,3 +465,116 @@ PlayableProxyModel::playlistInterface() return m_playlistInterface; } + + +int +PlayableProxyModel::columnCount( const QModelIndex& parent ) const +{ + Q_UNUSED( parent ); + + switch ( m_style ) + { + case Short: + case ShortWithAvatars: + case Large: + return 1; + break; + + case Collection: + return 8; + break; + + case Detailed: + default: + return 12; + break; + } +} + + +QVariant +PlayableProxyModel::data( const QModelIndex& index, int role ) const +{ + if ( role == StyleRole ) + { + return m_style; + } + + if ( !sourceModel() ) + return QVariant(); + if ( !m_headerStyle.contains( m_style ) ) + return QVariant(); + + PlayableModel::Columns col = m_headerStyle[ m_style ].at( index.column() ); + QModelIndex sourceIdx = mapToSource( index ); + QModelIndex idx = sourceModel()->index( sourceIdx.row(), (int)col, sourceIdx.parent() ); + + return idx.data( role ); +} + + +QVariant +PlayableProxyModel::headerData( int section, Qt::Orientation orientation, int role ) const +{ + if ( !sourceModel() ) + return QVariant(); + if ( !m_headerStyle.contains( m_style ) ) + return QVariant(); + + if ( section < m_headerStyle[ m_style ].count() ) + { + PlayableModel::Columns col = m_headerStyle[ m_style ].at( section ); + return sourceModel()->headerData( (int)col, orientation, role ); + } + else + return sourceModel()->headerData( 255, orientation, role ); +} + + +QList< double > +PlayableProxyModel::columnWeights() const +{ + QList< double > w; + + switch ( m_style ) + { + case Short: + case ShortWithAvatars: + case Large: + w << 1.0; + break; + + case Collection: + w << 0.42 << 0.12 << 0.07 << 0.07 << 0.07 << 0.07 << 0.07; // << 0.11; + break; + + case Detailed: + default: + w << 0.16 << 0.16 << 0.14 << 0.12 << 0.05 << 0.05 << 0.05 << 0.05 << 0.05 << 0.05 << 0.09; // << 0.03; + break; + } + + return w; +} + + +void +PlayableProxyModel::updateDetailedInfo( const QModelIndex& index ) +{ + if ( style() != PlayableProxyModel::Short && style() != PlayableProxyModel::Large ) + return; + + PlayableItem* item = itemFromIndex( mapToSource( index ) ); + if ( item->query().isNull() ) + return; + + if ( style() == PlayableProxyModel::Short || style() == PlayableProxyModel::Large ) + { + item->query()->cover( QSize( 0, 0 ) ); + } + + if ( style() == PlayableProxyModel::Large ) + { + item->query()->loadSocialActions(); + } +} diff --git a/src/libtomahawk/playlist/PlayableProxyModel.h b/src/libtomahawk/playlist/PlayableProxyModel.h index dd4cf0d9d..79b496317 100644 --- a/src/libtomahawk/playlist/PlayableProxyModel.h +++ b/src/libtomahawk/playlist/PlayableProxyModel.h @@ -32,6 +32,12 @@ class DLLEXPORT PlayableProxyModel : public QSortFilterProxyModel Q_OBJECT public: + enum PlayableItemStyle + { Detailed = 0, Short = 1, ShortWithAvatars = 2, Large = 3, Collection = 4 }; + + enum PlayableProxyModelRole + { StyleRole = Qt::UserRole + 1 }; + explicit PlayableProxyModel ( QObject* parent = 0 ); virtual ~PlayableProxyModel() {} @@ -41,6 +47,9 @@ public: virtual bool isLoading() const; + PlayableProxyModel::PlayableItemStyle style() const { return m_style; } + void setStyle( PlayableProxyModel::PlayableItemStyle style ) { m_style = style; } + virtual QPersistentModelIndex currentIndex() const { return mapFromSource( m_model->currentItem() ); } virtual void setCurrentIndex( const QModelIndex& index ) { m_model->setCurrentItem( mapToSource( index ) ); } @@ -63,6 +72,14 @@ public: virtual Tomahawk::playlistinterface_ptr playlistInterface(); + QList< double > columnWeights() const; + + virtual int columnCount( const QModelIndex& parent = QModelIndex() ) const; + virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const; + virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) const; + + void updateDetailedInfo( const QModelIndex& index ); + signals: void filterChanged( const QString& filter ); @@ -86,6 +103,9 @@ private: bool m_showOfflineResults; bool m_hideDupeItems; int m_maxVisibleItems; + + QHash< PlayableItemStyle, QList > m_headerStyle; + PlayableItemStyle m_style; }; #endif // TRACKPROXYMODEL_H From bd629e6178f273c8e7d1fea48473ff7595fa8e9d Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 2 Jul 2012 23:10:24 +0200 Subject: [PATCH 3/5] * Moved itemSize from model to delegate. --- src/libtomahawk/playlist/GridItemDelegate.cpp | 11 ++++++++--- src/libtomahawk/playlist/GridItemDelegate.h | 4 ++++ src/libtomahawk/playlist/GridView.cpp | 6 +++--- src/libtomahawk/playlist/GridView.h | 3 ++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/libtomahawk/playlist/GridItemDelegate.cpp b/src/libtomahawk/playlist/GridItemDelegate.cpp index f64aee9f1..66472f2d6 100644 --- a/src/libtomahawk/playlist/GridItemDelegate.cpp +++ b/src/libtomahawk/playlist/GridItemDelegate.cpp @@ -64,8 +64,13 @@ GridItemDelegate::GridItemDelegate( QAbstractItemView* parent, PlayableProxyMode QSize GridItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const { - QSize size = QStyledItemDelegate::sizeHint( option, index ); - return size; + if ( m_itemSize.isNull() ) + { + QSize size = QStyledItemDelegate::sizeHint( option, index ); + return size; + } + else + return m_itemSize; } @@ -363,7 +368,7 @@ GridItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const Q // reset mouse cursor. we switch to a pointing hand cursor when hovering an artist name m_view->setCursor( Qt::ArrowCursor ); - + if ( hoveringArtist ) { diff --git a/src/libtomahawk/playlist/GridItemDelegate.h b/src/libtomahawk/playlist/GridItemDelegate.h index 89474a91b..7409f0fdd 100644 --- a/src/libtomahawk/playlist/GridItemDelegate.h +++ b/src/libtomahawk/playlist/GridItemDelegate.h @@ -41,6 +41,9 @@ Q_OBJECT public: GridItemDelegate( QAbstractItemView* parent = 0, PlayableProxyModel* proxy = 0 ); + QSize itemSize() const { return m_itemSize; } + void setItemSize( const QSize& size ) { m_itemSize = size; } + protected: void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; @@ -70,6 +73,7 @@ private: QAbstractItemView* m_view; PlayableProxyModel* m_model; + QSize m_itemSize; mutable QHash< QPersistentModelIndex, QRect > m_artistNameRects; mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_covers; diff --git a/src/libtomahawk/playlist/GridView.cpp b/src/libtomahawk/playlist/GridView.cpp index 7726c2478..912db36e0 100644 --- a/src/libtomahawk/playlist/GridView.cpp +++ b/src/libtomahawk/playlist/GridView.cpp @@ -229,7 +229,7 @@ GridView::verifySize() const int overlapRows = m_model->rowCount( QModelIndex() ) % itemsPerRow; const int rows = floor( (double)m_model->rowCount( QModelIndex() ) / (double)itemsPerRow ); - const int newHeight = rows * m_model->itemSize().height(); + const int newHeight = rows * m_delegate->itemSize().height(); if ( newHeight > 0 ) setFixedHeight( newHeight ); @@ -257,8 +257,8 @@ GridView::layoutItems() const int remSpace = rectWidth - ( itemsPerRow * itemWidth ); const int extraSpace = remSpace / itemsPerRow; const int newItemWidth = itemWidth + extraSpace; - - m_model->setItemSize( QSize( newItemWidth, newItemWidth ) ); + + m_delegate->setItemSize( QSize( newItemWidth, newItemWidth ) ); verifySize(); if ( !m_inited ) diff --git a/src/libtomahawk/playlist/GridView.h b/src/libtomahawk/playlist/GridView.h index 4326f84ed..e3cbd7a5c 100644 --- a/src/libtomahawk/playlist/GridView.h +++ b/src/libtomahawk/playlist/GridView.h @@ -50,6 +50,7 @@ public: PlayableModel* model() const { return m_model; } PlayableProxyModel* proxyModel() const { return m_proxyModel; } + GridItemDelegate* delegate() const { return m_delegate; } bool autoFitItems() const { return m_autoFitItems; } void setAutoFitItems( bool b ) { m_autoFitItems = b; } @@ -111,7 +112,7 @@ private: bool m_inited; bool m_autoFitItems; bool m_autoResize; - + QRect m_paintRect; }; From 01fb91ac59095581602d0188c7edce4ca87c7fe9 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 2 Jul 2012 23:10:36 +0200 Subject: [PATCH 4/5] * Use new model/view API. --- .../context/pages/RelatedArtistsContext.cpp | 2 +- .../context/pages/TopTracksContext.cpp | 2 +- .../playlist/CustomPlaylistView.cpp | 2 +- .../playlist/PlaylistItemDelegate.cpp | 12 ++++++------ src/libtomahawk/playlist/PlaylistView.cpp | 6 +++--- src/libtomahawk/playlist/QueueView.cpp | 2 +- src/libtomahawk/playlist/TrackView.cpp | 18 +++++++++--------- src/libtomahawk/playlist/TreeModel.cpp | 3 +-- src/libtomahawk/playlist/TreeView.cpp | 10 +++++----- .../widgets/SocialPlaylistWidget.cpp | 2 +- src/libtomahawk/widgets/WelcomeWidget.cpp | 2 +- src/libtomahawk/widgets/WhatsHotWidget.cpp | 4 ++-- .../widgets/infowidgets/ArtistInfoWidget.cpp | 7 ++++--- .../widgets/infowidgets/SourceInfoWidget.cpp | 4 ++-- src/sourcetree/items/SourceItem.cpp | 4 ++-- 15 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/libtomahawk/context/pages/RelatedArtistsContext.cpp b/src/libtomahawk/context/pages/RelatedArtistsContext.cpp index f3a7edd4a..40dee1281 100644 --- a/src/libtomahawk/context/pages/RelatedArtistsContext.cpp +++ b/src/libtomahawk/context/pages/RelatedArtistsContext.cpp @@ -35,7 +35,7 @@ RelatedArtistsContext::RelatedArtistsContext() m_relatedView->setGuid( "RelatedArtistsContext" ); m_relatedView->setUpdatesContextView( false ); m_relatedModel = new TreeModel( m_relatedView ); - m_relatedModel->setStyle( TreeModel::Large ); + m_relatedView->proxyModel()->setStyle( PlayableProxyModel::Large ); m_relatedView->setTreeModel( m_relatedModel ); m_relatedView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); m_relatedView->setSortingEnabled( false ); diff --git a/src/libtomahawk/context/pages/TopTracksContext.cpp b/src/libtomahawk/context/pages/TopTracksContext.cpp index b9dff8d3b..c07415c24 100644 --- a/src/libtomahawk/context/pages/TopTracksContext.cpp +++ b/src/libtomahawk/context/pages/TopTracksContext.cpp @@ -33,7 +33,7 @@ TopTracksContext::TopTracksContext() m_topHitsView->setGuid( "TopTracksContext" ); m_topHitsView->setUpdatesContextView( false ); m_topHitsModel = new PlaylistModel( m_topHitsView ); - m_topHitsModel->setStyle( PlayableModel::Short ); + m_topHitsView->proxyModel()->setStyle( PlayableProxyModel::Short ); m_topHitsView->setPlaylistModel( m_topHitsModel ); m_topHitsView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); diff --git a/src/libtomahawk/playlist/CustomPlaylistView.cpp b/src/libtomahawk/playlist/CustomPlaylistView.cpp index 8ae04bbd0..045967a05 100644 --- a/src/libtomahawk/playlist/CustomPlaylistView.cpp +++ b/src/libtomahawk/playlist/CustomPlaylistView.cpp @@ -34,7 +34,7 @@ CustomPlaylistView::CustomPlaylistView( CustomPlaylistView::PlaylistType type, c , m_model( new PlaylistModel( this ) ) { // Generate the tracks, add them to the playlist - m_model->setStyle( PlayableModel::Large ); + proxyModel()->setStyle( PlayableProxyModel::Large ); setPlaylistModel( m_model ); generateTracks(); diff --git a/src/libtomahawk/playlist/PlaylistItemDelegate.cpp b/src/libtomahawk/playlist/PlaylistItemDelegate.cpp index cc2eec100..2ddf88f98 100644 --- a/src/libtomahawk/playlist/PlaylistItemDelegate.cpp +++ b/src/libtomahawk/playlist/PlaylistItemDelegate.cpp @@ -67,8 +67,8 @@ PlaylistItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModel if ( index.isValid() ) { - int style = index.data( PlayableModel::StyleRole ).toInt(); - if ( style == PlayableModel::Short || style == PlayableModel::ShortWithAvatars ) + int style = index.data( PlayableProxyModel::StyleRole ).toInt(); + if ( style == PlayableProxyModel::Short || style == PlayableProxyModel::ShortWithAvatars ) { int rowHeight = option.fontMetrics.height() + 8; size.setHeight( rowHeight * 2 ); @@ -101,17 +101,17 @@ PlaylistItemDelegate::prepareStyleOption( QStyleOptionViewItemV4* option, const void PlaylistItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { - int style = index.data( PlayableModel::StyleRole ).toInt(); + int style = index.data( PlayableProxyModel::StyleRole ).toInt(); switch ( style ) { - case PlayableModel::Detailed: + case PlayableProxyModel::Detailed: paintDetailed( painter, option, index ); break; - case PlayableModel::Short: + case PlayableProxyModel::Short: paintShort( painter, option, index ); break; - case PlayableModel::ShortWithAvatars: + case PlayableProxyModel::ShortWithAvatars: paintShort( painter, option, index, true ); break; } diff --git a/src/libtomahawk/playlist/PlaylistView.cpp b/src/libtomahawk/playlist/PlaylistView.cpp index 5b7fdff59..3453b8709 100644 --- a/src/libtomahawk/playlist/PlaylistView.cpp +++ b/src/libtomahawk/playlist/PlaylistView.cpp @@ -62,15 +62,15 @@ PlaylistView::setPlaylistModel( PlaylistModel* model ) setColumnHidden( PlayableModel::Age, true ); // Hide age column per default setColumnHidden( PlayableModel::Composer, true ); // Hide composer column per default - if ( guid().isEmpty() ) + if ( guid().isEmpty() && proxyModel()->columnCount() > 1 ) { if ( !m_model->playlist().isNull() ) { - setGuid( QString( "playlistview/%1/%2" ).arg( m_model->columnCount() ).arg( m_model->playlist()->guid() ) ); + setGuid( QString( "playlistview/%1/%2" ).arg( proxyModel()->columnCount() ).arg( m_model->playlist()->guid() ) ); } else { - setGuid( QString( "playlistview/%1" ).arg( m_model->columnCount() ) ); + setGuid( QString( "playlistview/%1" ).arg( proxyModel()->columnCount() ) ); } } diff --git a/src/libtomahawk/playlist/QueueView.cpp b/src/libtomahawk/playlist/QueueView.cpp index e939e2b6d..df60a7705 100644 --- a/src/libtomahawk/playlist/QueueView.cpp +++ b/src/libtomahawk/playlist/QueueView.cpp @@ -47,7 +47,7 @@ QueueView::QueueView( AnimatedSplitter* parent ) ui->queue->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Ignored ); PlaylistModel* queueModel = new PlaylistModel( this ); - queueModel->setStyle( PlaylistModel::Short ); + ui->queue->proxyModel()->setStyle( PlayableProxyModel::Short ); queueModel->finishLoading(); ui->queue->setPlaylistModel( queueModel ); queueModel->setReadOnly( false ); diff --git a/src/libtomahawk/playlist/TrackView.cpp b/src/libtomahawk/playlist/TrackView.cpp index 908f0a9fb..2d655bbde 100644 --- a/src/libtomahawk/playlist/TrackView.cpp +++ b/src/libtomahawk/playlist/TrackView.cpp @@ -153,13 +153,13 @@ TrackView::setPlayableModel( PlayableModel* model ) connect( m_proxyModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( onViewChanged() ) ); setAcceptDrops( true ); - m_header->setDefaultColumnWeights( model->columnWeights() ); + m_header->setDefaultColumnWeights( m_proxyModel->columnWeights() ); - switch( model->style() ) + switch( m_proxyModel->style() ) { - case PlayableModel::Short: - case PlayableModel::ShortWithAvatars: - case PlayableModel::Large: + case PlayableProxyModel::Short: + case PlayableProxyModel::ShortWithAvatars: + case PlayableProxyModel::Large: setHeaderHidden( true ); setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); break; @@ -184,7 +184,7 @@ TrackView::setEmptyTip( const QString& tip ) void TrackView::onViewChanged() { - if ( m_model->style() != PlayableModel::Short && m_model->style() != PlayableModel::Large ) // eventual FIXME? + if ( m_proxyModel->style() != PlayableProxyModel::Short && m_proxyModel->style() != PlayableProxyModel::Large ) // eventual FIXME? return; if ( m_timer.isActive() ) @@ -217,7 +217,7 @@ TrackView::onScrollTimeout() for ( int i = left.row(); i <= max; i++ ) { - m_model->updateDetailedInfo( m_proxyModel->mapToSource( m_proxyModel->index( i, 0 ) ) ); + m_proxyModel->updateDetailedInfo( m_proxyModel->index( i, 0 ) ); } } @@ -621,7 +621,7 @@ TrackView::updateHoverIndex( const QPoint& pos ) repaint(); } - if ( !m_model || m_model->style() != PlayableModel::Detailed ) + if ( !m_model || m_proxyModel->style() != PlayableProxyModel::Detailed ) return; if ( idx.column() == PlayableModel::Artist || idx.column() == PlayableModel::Album || idx.column() == PlayableModel::Track ) @@ -673,7 +673,7 @@ TrackView::mousePressEvent( QMouseEvent* event ) { QTreeView::mousePressEvent( event ); - if ( !m_model || m_model->style() != PlayableModel::Detailed ) + if ( !m_model || m_proxyModel->style() != PlayableProxyModel::Detailed ) return; QModelIndex idx = indexAt( event->pos() ); diff --git a/src/libtomahawk/playlist/TreeModel.cpp b/src/libtomahawk/playlist/TreeModel.cpp index 7066a2085..fd848d292 100644 --- a/src/libtomahawk/playlist/TreeModel.cpp +++ b/src/libtomahawk/playlist/TreeModel.cpp @@ -41,7 +41,6 @@ TreeModel::TreeModel( QObject* parent ) : PlayableModel( parent ) , m_mode( DatabaseMode ) { - setStyle( Collection ); setIcon( QPixmap( RESPATH "images/music-icon.png" ) ); connect( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), SLOT( onPlaybackStarted( Tomahawk::result_ptr ) ), Qt::DirectConnection ); @@ -172,7 +171,7 @@ TreeModel::fetchAlbums( const artist_ptr& artist ) connect( artist.data(), SIGNAL( albumsAdded( QList, Tomahawk::ModelMode ) ), SLOT( onAlbumsFound( QList, Tomahawk::ModelMode ) ), Qt::UniqueConnection ); - + const QModelIndex parent = indexFromArtist( artist ); addAlbums( parent, artist->albums( m_mode, m_collection ) ); } diff --git a/src/libtomahawk/playlist/TreeView.cpp b/src/libtomahawk/playlist/TreeView.cpp index a0fc559ae..16755e5d6 100644 --- a/src/libtomahawk/playlist/TreeView.cpp +++ b/src/libtomahawk/playlist/TreeView.cpp @@ -145,8 +145,8 @@ TreeView::setTreeModel( TreeModel* model ) guid(); // this will set the guid on the header - m_header->setDefaultColumnWeights( model->columnWeights() ); - if ( model->style() == PlayableModel::Large ) + m_header->setDefaultColumnWeights( m_proxyModel->columnWeights() ); + if ( m_proxyModel->style() == PlayableProxyModel::Large ) { setHeaderHidden( true ); setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); @@ -158,7 +158,7 @@ TreeView::setTreeModel( TreeModel* model ) } emit modelChanged(); - + /* setColumnHidden( PlayableModel::Score, true ); // Hide score column per default setColumnHidden( PlayableModel::Origin, true ); // Hide origin column per default setColumnHidden( PlayableModel::Composer, true ); //Hide composer column per default @@ -439,7 +439,7 @@ TreeView::updateHoverIndex( const QPoint& pos ) repaint(); } - if ( !m_model || m_model->style() != PlayableModel::Collection ) + if ( !m_model || m_proxyModel->style() != PlayableProxyModel::Collection ) return; PlayableItem* item = proxyModel()->itemFromIndex( proxyModel()->mapToSource( idx ) ); @@ -492,7 +492,7 @@ TreeView::mousePressEvent( QMouseEvent* event ) { QTreeView::mousePressEvent( event ); - if ( !m_model || m_model->style() != PlayableModel::Collection ) + if ( !m_model || m_proxyModel->style() != PlayableProxyModel::Collection ) return; QModelIndex idx = indexAt( event->pos() ); diff --git a/src/libtomahawk/widgets/SocialPlaylistWidget.cpp b/src/libtomahawk/widgets/SocialPlaylistWidget.cpp index a7876d4a9..99c5c4d8d 100644 --- a/src/libtomahawk/widgets/SocialPlaylistWidget.cpp +++ b/src/libtomahawk/widgets/SocialPlaylistWidget.cpp @@ -69,7 +69,7 @@ SocialPlaylistWidget::SocialPlaylistWidget ( QWidget* parent ) m_topForeignTracksModel = new PlaylistModel( ui->newTracksView ); ui->newTracksView->setPlaylistModel( m_topForeignTracksModel ); - m_topForeignTracksModel->setStyle( PlayableModel::Short ); + ui->newTracksView->proxyModel()->setStyle( PlayableProxyModel::Short ); ui->newTracksView->overlay()->setEnabled( false ); m_popularNewAlbumsModel = new PlayableModel( ui->newAlbumsView ); diff --git a/src/libtomahawk/widgets/WelcomeWidget.cpp b/src/libtomahawk/widgets/WelcomeWidget.cpp index 5d9b88fce..7456233d2 100644 --- a/src/libtomahawk/widgets/WelcomeWidget.cpp +++ b/src/libtomahawk/widgets/WelcomeWidget.cpp @@ -69,7 +69,7 @@ WelcomeWidget::WelcomeWidget( QWidget* parent ) updatePlaylists(); m_tracksModel = new RecentlyPlayedModel( ui->tracksView ); - m_tracksModel->setStyle( PlayableModel::ShortWithAvatars ); + ui->tracksView->proxyModel()->setStyle( PlayableProxyModel::ShortWithAvatars ); ui->tracksView->overlay()->setEnabled( false ); ui->tracksView->setPlaylistModel( m_tracksModel ); m_tracksModel->setSource( source_ptr() ); diff --git a/src/libtomahawk/widgets/WhatsHotWidget.cpp b/src/libtomahawk/widgets/WhatsHotWidget.cpp index 2c6deff51..8dba1e009 100644 --- a/src/libtomahawk/widgets/WhatsHotWidget.cpp +++ b/src/libtomahawk/widgets/WhatsHotWidget.cpp @@ -262,7 +262,6 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat TreeModel* artistsModel = new TreeModel( ui->artistsViewLeft ); artistsModel->setMode( InfoSystemMode ); - artistsModel->setStyle( PlayableModel::Collection ); artistsModel->startLoading(); m_artistModels[ chartId ] = artistsModel; @@ -293,7 +292,6 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat connect( loader, SIGNAL( tracks( Tomahawk::ChartDataLoader*, QList< Tomahawk::query_ptr > ) ), this, SLOT( chartTracksLoaded( Tomahawk::ChartDataLoader*, QList< Tomahawk::query_ptr > ) ) ); PlaylistModel* trackModel = new PlaylistModel( ui->tracksViewLeft ); - trackModel->setStyle( PlayableModel::Large ); trackModel->startLoading(); m_trackModels[ chartId ] = trackModel; @@ -463,6 +461,7 @@ WhatsHotWidget::setLeftViewAlbums( PlayableModel* model ) void WhatsHotWidget::setLeftViewArtists( TreeModel* model ) { + ui->artistsViewLeft->proxyModel()->setStyle( PlayableProxyModel::Collection ); ui->artistsViewLeft->setTreeModel( model ); ui->artistsViewLeft->proxyModel()->sort( -1 ); // disable sorting, must be called after artistsViewLeft->setTreeModel ui->stackLeft->setCurrentIndex( 1 ); @@ -472,6 +471,7 @@ WhatsHotWidget::setLeftViewArtists( TreeModel* model ) void WhatsHotWidget::setLeftViewTracks( PlaylistModel* model ) { + ui->tracksViewLeft->proxyModel()->setStyle( PlayableProxyModel::Large ); ui->tracksViewLeft->setPlaylistModel( model ); ui->tracksViewLeft->proxyModel()->sort( -1 ); ui->stackLeft->setCurrentIndex( 0 ); diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp index 645bdaace..9227dbe13 100644 --- a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp @@ -25,6 +25,7 @@ #include #include "audio/AudioEngine.h" +#include "playlist/GridItemDelegate.h" #include "playlist/PlayableModel.h" #include "playlist/TreeModel.h" #include "playlist/PlaylistModel.h" @@ -73,7 +74,7 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget* ui->topHits->setEmptyTip( tr( "Sorry, we could not find any related artists!" ) ); m_topHitsModel = new PlaylistModel( ui->topHits ); - m_topHitsModel->setStyle( PlayableModel::Short ); + ui->topHits->proxyModel()->setStyle( PlayableProxyModel::Short ); ui->topHits->setPlayableModel( m_topHitsModel ); ui->topHits->setSortingEnabled( false ); ui->topHits->setEmptyTip( tr( "Sorry, we could not find any top hits for this artist!" ) ); @@ -82,13 +83,13 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget* ui->relatedArtists->setWrapping( false ); ui->relatedArtists->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); ui->relatedArtists->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded ); - m_relatedModel->setItemSize( QSize( 170, 170 ) ); + ui->relatedArtists->delegate()->setItemSize( QSize( 170, 170 ) ); ui->albums->setAutoFitItems( false ); ui->albums->setWrapping( false ); ui->albums->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); ui->albums->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded ); - m_albumsModel->setItemSize( QSize( 170, 170 ) ); + ui->albums->delegate()->setItemSize( QSize( 170, 170 ) ); ui->albums->proxyModel()->setHideDupeItems( true ); ui->topHits->setFrameShape( QFrame::StyledPanel ); diff --git a/src/libtomahawk/widgets/infowidgets/SourceInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/SourceInfoWidget.cpp index fd15f3d54..421d122f8 100644 --- a/src/libtomahawk/widgets/infowidgets/SourceInfoWidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/SourceInfoWidget.cpp @@ -50,13 +50,13 @@ SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget* ui->splitter->setStretchFactor( 1, 1 ); m_recentTracksModel = new RecentlyAddedModel( ui->recentCollectionView ); - m_recentTracksModel->setStyle( PlayableModel::Short ); + ui->recentCollectionView->proxyModel()->setStyle( PlayableProxyModel::Short ); ui->recentCollectionView->setPlayableModel( m_recentTracksModel ); ui->recentCollectionView->sortByColumn( PlayableModel::Age, Qt::DescendingOrder ); m_recentTracksModel->setSource( source ); m_historyModel = new RecentlyPlayedModel( ui->historyView ); - m_historyModel->setStyle( PlayableModel::Short ); + ui->historyView->proxyModel()->setStyle( PlayableProxyModel::Short ); ui->historyView->setPlaylistModel( m_historyModel ); m_historyModel->setSource( source ); diff --git a/src/sourcetree/items/SourceItem.cpp b/src/sourcetree/items/SourceItem.cpp index 5cf8df283..8275f9f81 100644 --- a/src/sourcetree/items/SourceItem.cpp +++ b/src/sourcetree/items/SourceItem.cpp @@ -513,7 +513,7 @@ SourceItem::latestAdditionsClicked() cv->setAttribute( Qt::WA_MacShowFocusRect, 0 ); RecentlyAddedModel* raModel = new RecentlyAddedModel( cv ); - raModel->setStyle( PlayableModel::Large ); + cv->proxyModel()->setStyle( PlayableProxyModel::Large ); raModel->setTitle( tr( "Latest Additions" ) ); if ( m_source->isLocal() ) @@ -556,7 +556,7 @@ SourceItem::recentPlaysClicked() pv->setAttribute( Qt::WA_MacShowFocusRect, 0 ); RecentlyPlayedModel* raModel = new RecentlyPlayedModel( pv ); - raModel->setStyle( PlayableModel::Large ); + pv->proxyModel()->setStyle( PlayableProxyModel::Large ); raModel->setTitle( tr( "Recently Played Tracks" ) ); if ( m_source->isLocal() ) From 1761f7af0c1f17602693153a7849e7bddf0de833 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 2 Jul 2012 23:11:11 +0200 Subject: [PATCH 5/5] * Playlists are now displayed as FlexibleViews. --- src/libtomahawk/ViewManager.cpp | 39 +++++++++++++++++++++------------ src/libtomahawk/ViewManager.h | 9 ++++---- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/libtomahawk/ViewManager.cpp b/src/libtomahawk/ViewManager.cpp index a010b16fb..444346cea 100644 --- a/src/libtomahawk/ViewManager.cpp +++ b/src/libtomahawk/ViewManager.cpp @@ -27,6 +27,7 @@ #include "infobar/InfoBar.h" #include "topbar/TopBar.h" +#include "FlexibleView.h" #include "TreeModel.h" #include "PlaylistModel.h" #include "PlaylistView.h" @@ -94,6 +95,7 @@ ViewManager::ViewManager( QObject* parent ) m_widget->layout()->addWidget( m_contextWidget ); m_superCollectionView = new TreeView(); + m_superCollectionView->proxyModel()->setStyle( PlayableProxyModel::Collection ); m_superCollectionModel = new TreeModel( m_superCollectionView ); m_superCollectionView->setTreeModel( m_superCollectionModel ); m_superCollectionView->setShowModes( false ); @@ -137,16 +139,20 @@ ViewManager::~ViewManager() } -PlaylistView* -ViewManager::createPageForPlaylist( const playlist_ptr& pl ) +FlexibleView* +ViewManager::createPageForPlaylist( const playlist_ptr& playlist ) { - PlaylistView* view = new PlaylistView(); + FlexibleView* view = new FlexibleView(); PlaylistModel* model = new PlaylistModel(); - view->setPlaylistModel( model ); - model->loadPlaylist( pl ); - pl->resolve(); + view->setPlayableModel( model ); + + PlaylistView* pv = new PlaylistView(); + pv->setPlaylistModel( model ); + view->setDetailedView( pv ); + + model->loadPlaylist( playlist ); + playlist->resolve(); - m_playlistViews.insert( pl, view ); return view; } @@ -170,11 +176,12 @@ ViewManager::playlistForPage( ViewPage* page ) const Tomahawk::ViewPage* ViewManager::show( const Tomahawk::playlist_ptr& playlist ) { - PlaylistView* view; + FlexibleView* view; if ( !m_playlistViews.contains( playlist ) || m_playlistViews.value( playlist ).isNull() ) { view = createPageForPlaylist( playlist ); + m_playlistViews.insert( playlist, view ); } else { @@ -182,7 +189,6 @@ ViewManager::show( const Tomahawk::playlist_ptr& playlist ) } setPage( view ); - emit numSourcesChanged( SourceList::instance()->count() ); return view; @@ -303,6 +309,7 @@ ViewManager::show( const Tomahawk::collection_ptr& collection ) if ( !m_treeViews.contains( collection ) || m_treeViews.value( collection ).isNull() ) { view = new TreeView(); + view->proxyModel()->setStyle( PlayableProxyModel::Collection ); TreeModel* model = new TreeModel(); view->setTreeModel( model ); @@ -486,7 +493,7 @@ ViewManager::showRecentPlaysPage() RecentlyPlayedModel* raModel = new RecentlyPlayedModel( pv ); raModel->setTitle( tr( "Recently Played Tracks" ) ); raModel->setDescription( tr( "Recently played tracks from all your friends" ) ); - raModel->setStyle( PlayableModel::Large ); + pv->proxyModel()->setStyle( PlayableProxyModel::Large ); PlaylistLargeItemDelegate* del = new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::RecentlyPlayed, pv, pv->proxyModel() ); connect( del, SIGNAL( updateIndex( QModelIndex ) ), pv, SLOT( update( QModelIndex ) ) ); @@ -737,12 +744,16 @@ ViewManager::saveCurrentPlaylistSettings() TomahawkSettings* s = TomahawkSettings::instance(); Tomahawk::playlist_ptr pl = playlistForInterface( currentPlaylistInterface() ); - if ( !pl.isNull() ) { + if ( !pl.isNull() ) + { s->setShuffleState( pl->guid(), currentPlaylistInterface()->shuffled() ); s->setRepeatMode( pl->guid(), currentPlaylistInterface()->repeatMode() ); - } else { + } + else + { Tomahawk::dynplaylist_ptr dynPl = dynamicPlaylistForInterface( currentPlaylistInterface() ); - if ( !dynPl.isNull() ) { + if ( !dynPl.isNull() ) + { s->setShuffleState( dynPl->guid(), currentPlaylistInterface()->shuffled() ); s->setRepeatMode( dynPl->guid(), currentPlaylistInterface()->repeatMode() ); } @@ -977,7 +988,7 @@ ViewManager::currentPage() const Tomahawk::playlist_ptr ViewManager::playlistForInterface( Tomahawk::playlistinterface_ptr interface ) const { - foreach ( QWeakPointer view, m_playlistViews.values() ) + foreach ( QWeakPointer view, m_playlistViews.values() ) { if ( !view.isNull() && view.data()->playlistInterface() == interface ) { diff --git a/src/libtomahawk/ViewManager.h b/src/libtomahawk/ViewManager.h index d4fefe1bf..1f6e7f2b4 100644 --- a/src/libtomahawk/ViewManager.h +++ b/src/libtomahawk/ViewManager.h @@ -40,6 +40,7 @@ class ArtistInfoWidget; class TreeView; class CollectionModel; class ContextWidget; +class FlexibleView; class PlaylistModel; class PlaylistView; class TrackProxyModel; @@ -104,7 +105,7 @@ public: // only use this is you need to create a playlist and show it directly and want it to be // linked to the sidebar. call it right after creating the playlist - PlaylistView* createPageForPlaylist( const Tomahawk::playlist_ptr& pl ); + FlexibleView* createPageForPlaylist( const Tomahawk::playlist_ptr& playlist ); bool isTomahawkLoaded() const { return m_loaded; } @@ -132,7 +133,7 @@ signals: void hideQueueRequested(); void tomahawkLoaded(); - + void historyBackAvailable( bool avail ); void historyForwardAvailable( bool avail ); @@ -156,7 +157,7 @@ public slots: void historyBack(); void historyForward(); - + QList< Tomahawk::ViewPage* > historyPages() const; void destroyPage( Tomahawk::ViewPage* page ); @@ -220,7 +221,7 @@ private: QHash< Tomahawk::artist_ptr, QWeakPointer > m_artistViews; QHash< Tomahawk::album_ptr, QWeakPointer > m_albumViews; QHash< Tomahawk::query_ptr, QWeakPointer > m_trackViews; - QHash< Tomahawk::playlist_ptr, QWeakPointer > m_playlistViews; + QHash< Tomahawk::playlist_ptr, QWeakPointer > m_playlistViews; QHash< Tomahawk::source_ptr, QWeakPointer > m_sourceViews; QList m_pageHistoryBack;