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

* Added PlaylistLargeItemDelegate. Loved, latest & recent tracks use it.

This commit is contained in:
Christian Muehlhaeuser
2012-03-17 06:55:49 +01:00
parent bd098e3ff2
commit 3e11945c02
14 changed files with 435 additions and 52 deletions

View File

@@ -79,6 +79,7 @@ set( libGuiSources
playlist/ViewHeader.cpp playlist/ViewHeader.cpp
playlist/RecentlyAddedModel.cpp playlist/RecentlyAddedModel.cpp
playlist/RecentlyPlayedModel.cpp playlist/RecentlyPlayedModel.cpp
playlist/PlaylistLargeItemDelegate.cpp
playlist/dynamic/DynamicPlaylist.cpp playlist/dynamic/DynamicPlaylist.cpp
playlist/dynamic/DynamicView.cpp playlist/dynamic/DynamicView.cpp

View File

@@ -65,8 +65,9 @@ DatabaseCommand_LoadSocialActions::exec( DatabaseImpl* dbi )
action.action = query.value( 0 ); // action action.action = query.value( 0 ); // action
action.value = query.value( 1 ); // comment action.value = query.value( 1 ); // comment
action.timestamp = query.value( 2 ); // timestamp action.timestamp = query.value( 2 ); // timestamp
action.source = query.value( 3 ); // source action.source = SourceList::instance()->get( query.value( 3 ).toInt() ); // source
if ( !action.source.isNull() )
allSocialActions.append( action ); allSocialActions.append( action );
} }

View File

@@ -0,0 +1,228 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "PlaylistLargeItemDelegate.h"
#include <QApplication>
#include <QPainter>
#include "query.h"
#include "result.h"
#include "artist.h"
#include "source.h"
#include "sourcelist.h"
#include "trackmodel.h"
#include "trackmodelitem.h"
#include "trackproxymodel.h"
#include "trackview.h"
#include "trackheader.h"
#include "utils/tomahawkutilsgui.h"
#include "utils/logger.h"
using namespace Tomahawk;
PlaylistLargeItemDelegate::PlaylistLargeItemDelegate( TrackView* parent, TrackProxyModel* proxy )
: QStyledItemDelegate( (QObject*)parent )
, m_view( parent )
, m_model( proxy )
{
m_topOption = QTextOption( Qt::AlignTop );
m_topOption.setWrapMode( QTextOption::NoWrap );
m_centerRightOption = QTextOption( Qt::AlignVCenter | Qt::AlignRight );
m_centerRightOption.setWrapMode( QTextOption::NoWrap );
m_bottomOption = QTextOption( Qt::AlignBottom );
m_bottomOption.setWrapMode( QTextOption::NoWrap );
}
QSize
PlaylistLargeItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
QSize size = QStyledItemDelegate::sizeHint( option, index );
if ( index.isValid() )
{
int rowHeight = option.fontMetrics.height() + 8;
size.setHeight( rowHeight * 3 );
}
return size;
}
QWidget*
PlaylistLargeItemDelegate::createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
Q_UNUSED( parent );
Q_UNUSED( option );
Q_UNUSED( index );
return 0;
}
void
PlaylistLargeItemDelegate::prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, TrackModelItem* item ) const
{
initStyleOption( option, index );
if ( item->isPlaying() )
{
option->palette.setColor( QPalette::Highlight, option->palette.color( QPalette::Mid ) );
option->state |= QStyle::State_Selected;
}
if ( option->state & QStyle::State_Selected )
{
option->palette.setColor( QPalette::Text, option->palette.color( QPalette::HighlightedText ) );
}
else
{
float opacity = 0.0;
if ( item->query()->results().count() )
opacity = item->query()->results().first()->score();
opacity = qMax( (float)0.3, opacity );
QColor textColor = TomahawkUtils::alphaBlend( option->palette.color( QPalette::Text ), option->palette.color( QPalette::BrightText ), opacity );
option->palette.setColor( QPalette::Text, textColor );
}
}
void
PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
TrackModelItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) );
Q_ASSERT( item );
QStyleOptionViewItemV4 opt = option;
prepareStyleOption( &opt, index, item );
opt.text.clear();
qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter );
if ( m_view->header()->visualIndex( index.column() ) > 0 )
return;
QPixmap pixmap, avatar;
QString artist, track, upperText, lowerText;
source_ptr source = item->query()->playedBy().first;
unsigned int duration = 0;
if ( item->query()->results().count() )
{
artist = item->query()->results().first()->artist()->name();
track = item->query()->results().first()->track();
duration = item->query()->results().first()->duration();
}
else
{
artist = item->query()->artist();
track = item->query()->track();
}
lowerText = item->query()->socialActionDescription( "Love" );
if ( source.isNull() )
{
}
else
{
upperText = QString( "%1 - %2" ).arg( artist ).arg( track );
QString playtime = TomahawkUtils::ageToString( QDateTime::fromTime_t( item->query()->playedBy().second ), true );
if ( source == SourceList::instance()->getLocal() )
lowerText = QString( tr( "played %1 by you" ) ).arg( playtime );
else
lowerText = QString( tr( "played %1 by %2" ) ).arg( playtime ).arg( source->friendlyName() );
}
painter->save();
{
QRect r = opt.rect.adjusted( 3, 6, 0, -6 );
// Paint Now Playing Speaker Icon
if ( item->isPlaying() )
{
QPixmap nowPlayingIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeaker );
QRect npr = r.adjusted( 3, r.height() / 2 - nowPlayingIcon.height() / 2, 18 - r.width(), -r.height() / 2 + nowPlayingIcon.height() / 2 );
nowPlayingIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeaker, TomahawkUtils::Original, npr.size() );
painter->drawPixmap( npr, nowPlayingIcon );
r.adjust( 22, 0, 0, 0 );
}
painter->setPen( opt.palette.text().color() );
QSize avatarSize( 32, 32 );
QRect pixmapRect = r.adjusted( 6, 0, -option.rect.width() + option.rect.height() - 6 + r.left(), 0 );
QRect avatarRect = r.adjusted( option.rect.width() - r.left() - 12 - avatarSize.width(), ( option.rect.height() - avatarSize.height() ) / 2 - 5, 0, 0 );
avatarRect.setSize( avatarSize );
if ( source )
avatar = source->avatar( Source::FancyStyle, avatarRect.size() );
pixmap = item->query()->cover( pixmapRect.size(), false );
if ( !pixmap )
{
pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultTrackImage, TomahawkUtils::ScaledCover, pixmapRect.size() );
}
painter->drawPixmap( pixmapRect, pixmap );
if ( !avatar.isNull() )
painter->drawPixmap( avatarRect, avatar );
QFont boldFont = opt.font;
boldFont.setPixelSize( 15 );
boldFont.setWeight( 99 );
QFont smallBoldFont = opt.font;
smallBoldFont.setPixelSize( 12 );
smallBoldFont.setBold( true );
smallBoldFont.setWeight( 80 );
r.adjust( pixmapRect.width() + 12, 1, -28 - avatar.width(), 0 );
QRect leftRect = r.adjusted( 0, 0, -r.width() / 2 - 4, 0 );
QRect rightRect = r.adjusted( r.width() / 2 + 4, 0, 0, 0 );
painter->setFont( boldFont );
QString text = painter->fontMetrics().elidedText( artist, Qt::ElideRight, leftRect.width() );
painter->drawText( leftRect, text, m_topOption );
painter->setFont( smallBoldFont );
text = painter->fontMetrics().elidedText( track, Qt::ElideRight, leftRect.width() );
painter->drawText( leftRect.adjusted( 0, 19, 0, 0 ), text, m_topOption );
painter->setFont( opt.font );
text = painter->fontMetrics().elidedText( lowerText, Qt::ElideRight, leftRect.width() );
painter->drawText( leftRect, text, m_bottomOption );
if ( duration > 0 )
{
painter->setFont( smallBoldFont );
text = painter->fontMetrics().elidedText( TomahawkUtils::timeToString( duration ), Qt::ElideRight, rightRect.width() );
painter->drawText( rightRect, text, m_centerRightOption );
}
}
painter->restore();
}

View File

@@ -0,0 +1,55 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef PLAYLISTLARGEITEMDELEGATE_H
#define PLAYLISTLARGEITEMDELEGATE_H
#include <QStyledItemDelegate>
#include <QTextOption>
#include "dllmacro.h"
class TrackModel;
class TrackModelItem;
class TrackProxyModel;
class TrackView;
class DLLEXPORT PlaylistLargeItemDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
PlaylistLargeItemDelegate( TrackView* parent = 0, TrackProxyModel* proxy = 0 );
protected:
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
private:
void prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, TrackModelItem* item ) const;
QTextOption m_topOption;
QTextOption m_centerRightOption;
QTextOption m_bottomOption;
TrackView* m_view;
TrackProxyModel* m_model;
};
#endif // PLAYLISTLARGEITEMDELEGATE_H

View File

@@ -37,6 +37,7 @@ CustomPlaylistView::CustomPlaylistView( CustomPlaylistView::PlaylistType type, c
setFrameShape( QFrame::NoFrame ); setFrameShape( QFrame::NoFrame );
setAttribute( Qt::WA_MacShowFocusRect, 0 ); setAttribute( Qt::WA_MacShowFocusRect, 0 );
m_model->setStyle( TrackModel::Large );
setPlaylistModel( m_model ); setPlaylistModel( m_model );
generateTracks(); generateTracks();

View File

@@ -88,6 +88,7 @@ TrackModel::columnCount( const QModelIndex& parent ) const
{ {
case Short: case Short:
case ShortWithAvatars: case ShortWithAvatars:
case Large:
return 1; return 1;
break; break;
@@ -259,14 +260,24 @@ TrackModel::headerData( int section, Qt::Orientation orientation, int role ) con
void void
TrackModel::getCover( const QModelIndex& index ) TrackModel::updateDetailedInfo( const QModelIndex& index )
{ {
if ( style() != TrackModel::Short ) if ( style() != TrackModel::Short && style() != TrackModel::Large )
return; return;
TrackModelItem* item = itemFromIndex( index ); TrackModelItem* item = itemFromIndex( index );
if ( !item->query().isNull() ) if ( item->query().isNull() )
return;
if ( style() == TrackModel::Short || style() == TrackModel::Large )
{
item->query()->cover( QSize( 0, 0 ) ); item->query()->cover( QSize( 0, 0 ) );
}
if ( style() == TrackModel::Large )
{
item->query()->loadSocialActions();
}
} }

View File

@@ -36,7 +36,7 @@ Q_OBJECT
public: public:
enum TrackItemStyle enum TrackItemStyle
{ Detailed = 0, Short = 1, ShortWithAvatars = 2 }; { Detailed = 0, Short = 1, ShortWithAvatars = 2, Large = 3 };
enum TrackModelRole enum TrackModelRole
{ StyleRole = Qt::UserRole + 1 }; { StyleRole = Qt::UserRole + 1 };
@@ -98,7 +98,7 @@ public:
/// Returns a flat list of all tracks in this model /// Returns a flat list of all tracks in this model
QList< Tomahawk::query_ptr > queries() const; QList< Tomahawk::query_ptr > queries() const;
void getCover( const QModelIndex& index ); void updateDetailedInfo( const QModelIndex& index );
signals: signals:
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode ); void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );

View File

@@ -1,3 +1,4 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
@@ -115,4 +116,5 @@ TrackModelItem::setupItem( const Tomahawk::query_ptr& query, TrackModelItem* par
connect( query.data(), SIGNAL( resultsRemoved( Tomahawk::result_ptr ) ), SIGNAL( dataChanged() ) ); connect( query.data(), SIGNAL( resultsRemoved( Tomahawk::result_ptr ) ), SIGNAL( dataChanged() ) );
connect( query.data(), SIGNAL( resultsChanged() ), SIGNAL( dataChanged() ) ); connect( query.data(), SIGNAL( resultsChanged() ), SIGNAL( dataChanged() ) );
connect( query.data(), SIGNAL( updated() ), SIGNAL( dataChanged() ) ); connect( query.data(), SIGNAL( updated() ), SIGNAL( dataChanged() ) );
connect( query.data(), SIGNAL( socialActionsLoaded() ), SIGNAL( dataChanged() ) );
} }

View File

@@ -147,13 +147,16 @@ TrackView::setTrackModel( TrackModel* model )
setAcceptDrops( true ); setAcceptDrops( true );
if ( model->style() == TrackModel::Short || model->style() == TrackModel::ShortWithAvatars ) switch( model->style() )
{ {
case TrackModel::Short:
case TrackModel::ShortWithAvatars:
case TrackModel::Large:
setHeaderHidden( true ); setHeaderHidden( true );
setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
} break;
else
{ default:
setHeaderHidden( false ); setHeaderHidden( false );
setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded ); setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
} }
@@ -163,7 +166,7 @@ TrackView::setTrackModel( TrackModel* model )
void void
TrackView::onViewChanged() TrackView::onViewChanged()
{ {
if ( m_model->style() != TrackModel::Short ) // eventual FIXME? if ( m_model->style() != TrackModel::Short && m_model->style() != TrackModel::Large ) // eventual FIXME?
return; return;
if ( m_timer.isActive() ) if ( m_timer.isActive() )
@@ -196,7 +199,7 @@ TrackView::onScrollTimeout()
for ( int i = left.row(); i <= max; i++ ) for ( int i = left.row(); i <= max; i++ )
{ {
m_model->getCover( m_proxyModel->mapToSource( m_proxyModel->index( i, 0 ) ) ); m_model->updateDetailedInfo( m_proxyModel->mapToSource( m_proxyModel->index( i, 0 ) ) );
} }
} }
@@ -519,7 +522,7 @@ TrackView::updateHoverIndex( const QPoint& pos )
repaint(); repaint();
} }
if ( !m_model || m_model->style() == TrackModel::Short || m_model->style() == TrackModel::ShortWithAvatars ) if ( !m_model || m_model->style() != TrackModel::Detailed )
return; return;
if ( idx.column() == TrackModel::Artist || idx.column() == TrackModel::Album ) if ( idx.column() == TrackModel::Artist || idx.column() == TrackModel::Album )

View File

@@ -521,7 +521,7 @@ Query::setAllSocialActions( const QList< SocialAction >& socialActions )
QList< SocialAction > QList< SocialAction >
Query::allSocialActions() Query::allSocialActions() const
{ {
return m_allSocialActions; return m_allSocialActions;
} }
@@ -537,7 +537,7 @@ Query::parseSocialActions()
{ {
Tomahawk::SocialAction socialAction; Tomahawk::SocialAction socialAction;
socialAction = it.next(); socialAction = it.next();
if ( socialAction.timestamp.toUInt() > highestTimestamp && socialAction.source.toInt() == SourceList::instance()->getLocal()->id() ) if ( socialAction.timestamp.toUInt() > highestTimestamp && socialAction.source->id() == SourceList::instance()->getLocal()->id() )
{ {
m_currentSocialActions[ socialAction.action.toString() ] = socialAction.value.toBool(); m_currentSocialActions[ socialAction.action.toString() ] = socialAction.value.toBool();
} }
@@ -584,6 +584,67 @@ Query::setLoved( bool loved )
} }
QString
Query::socialActionDescription( const QString& action ) const
{
QString desc;
QList< Tomahawk::SocialAction > socialActions = allSocialActions();
QStringList actionSources;
int loveTotal = 0;
foreach ( const Tomahawk::SocialAction& sa, socialActions )
{
if ( sa.action == action )
{
if ( actionSources.contains( sa.source->friendlyName() ) )
continue;
actionSources << sa.source->friendlyName();
loveTotal++;
}
}
actionSources.clear();
int loveCounter = 0;
foreach ( const Tomahawk::SocialAction& sa, socialActions )
{
if ( sa.action == action )
{
if ( actionSources.contains( sa.source->friendlyName() ) )
continue;
actionSources << sa.source->friendlyName();
if ( ++loveCounter > 3 )
continue;
else if ( loveCounter > 1 )
{
if ( loveCounter == loveTotal )
desc += tr( " and " );
else
desc += ", ";
}
if ( sa.source->isLocal() )
{
if ( loveCounter == 1 )
desc += tr( "You" );
else
desc += tr( "you" );
}
else
desc += sa.source->friendlyName();
}
}
if ( loveCounter > 0 )
{
if ( loveCounter > 3 )
desc += " " + tr( "and %1 others" ).arg( loveCounter - 3 );
desc += " " + tr( "loved this track" ); //FIXME: more action descs required
}
return desc;
}
#ifndef ENABLE_HEADLESS #ifndef ENABLE_HEADLESS
QPixmap QPixmap
Query::cover( const QSize& size, bool forceLoad ) const Query::cover( const QSize& size, bool forceLoad ) const

View File

@@ -114,8 +114,9 @@ public:
bool loved(); bool loved();
void loadSocialActions(); void loadSocialActions();
QList< Tomahawk::SocialAction > allSocialActions(); QList< Tomahawk::SocialAction > allSocialActions() const;
void setAllSocialActions( const QList< Tomahawk::SocialAction >& socialActions ); void setAllSocialActions( const QList< Tomahawk::SocialAction >& socialActions );
QString socialActionDescription( const QString& action ) const;
QWeakPointer< Tomahawk::Query > weakRef() { return m_ownRef; } QWeakPointer< Tomahawk::Query > weakRef() { return m_ownRef; }
void setWeakRef( QWeakPointer< Tomahawk::Query > weakRef ) { m_ownRef = weakRef; } void setWeakRef( QWeakPointer< Tomahawk::Query > weakRef ) { m_ownRef = weakRef; }

View File

@@ -41,7 +41,7 @@ struct SocialAction
QVariant action; QVariant action;
QVariant value; QVariant value;
QVariant timestamp; QVariant timestamp;
QVariant source; Tomahawk::source_ptr source;
}; };

View File

@@ -41,6 +41,7 @@
#include "tomahawksettings.h" #include "tomahawksettings.h"
#include "customplaylistview.h" #include "customplaylistview.h"
#include "PlaylistLargeItemDelegate.h"
#include "dynamic/widgets/DynamicWidget.h" #include "dynamic/widgets/DynamicWidget.h"
#include "widgets/welcomewidget.h" #include "widgets/welcomewidget.h"
@@ -437,7 +438,12 @@ Tomahawk::ViewPage*
ViewManager::showTopLovedPage() ViewManager::showTopLovedPage()
{ {
if ( !m_topLovedWidget ) if ( !m_topLovedWidget )
m_topLovedWidget = new CustomPlaylistView( CustomPlaylistView::TopLovedTracks, source_ptr(), m_widget ); {
CustomPlaylistView* view = new CustomPlaylistView( CustomPlaylistView::TopLovedTracks, source_ptr(), m_widget );
view->setItemDelegate( new PlaylistLargeItemDelegate( view, view->proxyModel() ) );
m_topLovedWidget = view;
}
return show( m_topLovedWidget ); return show( m_topLovedWidget );
} }

View File

@@ -31,6 +31,7 @@
#include "playlist/playlistview.h" #include "playlist/playlistview.h"
#include "playlist/RecentlyAddedModel.h" #include "playlist/RecentlyAddedModel.h"
#include "playlist/RecentlyPlayedModel.h" #include "playlist/RecentlyPlayedModel.h"
#include "playlist/PlaylistLargeItemDelegate.h"
#include "source.h" #include "source.h"
#include "sourcelist.h" #include "sourcelist.h"
@@ -103,7 +104,7 @@ SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahaw
onStationsAdded( stations ); onStationsAdded( stations );
} }
if( ViewManager::instance()->pageForCollection( source->collection() ) ) if ( ViewManager::instance()->pageForCollection( source->collection() ) )
model()->linkSourceItemToPage( this, ViewManager::instance()->pageForCollection( source->collection() ) ); model()->linkSourceItemToPage( this, ViewManager::instance()->pageForCollection( source->collection() ) );
m_defaultAvatar = TomahawkUtils::createAvatarFrame( QPixmap( RESPATH "images/user-avatar.png" ) ); m_defaultAvatar = TomahawkUtils::createAvatarFrame( QPixmap( RESPATH "images/user-avatar.png" ) );
@@ -301,7 +302,7 @@ SourceItem::playlistDeletedInternal( SourceTreeItem* parent, const T& p )
for( int i = 0; i < curCount; i++ ) for( int i = 0; i < curCount; i++ )
{ {
PlaylistItem* pl = qobject_cast< PlaylistItem* >( parent->children().at( i ) ); PlaylistItem* pl = qobject_cast< PlaylistItem* >( parent->children().at( i ) );
if( pl && pl->playlist() == p ) if ( pl && pl->playlist() == p )
{ {
parent->beginRowsRemoved( i, i ); parent->beginRowsRemoved( i, i );
parent->removeChild( pl ); parent->removeChild( pl );
@@ -312,20 +313,20 @@ SourceItem::playlistDeletedInternal( SourceTreeItem* parent, const T& p )
} }
} }
if( ( parent == m_playlists || parent == m_stations ) && if ( ( parent == m_playlists || parent == m_stations ) &&
parent->children().isEmpty() && parent->parent() ) // Don't leave an empty Playlist or Station category parent->children().isEmpty() && parent->parent() ) // Don't leave an empty Playlist or Station category
{ {
int idx = parent->parent()->children().indexOf( parent ); int idx = parent->parent()->children().indexOf( parent );
if( idx < 0 ) if ( idx < 0 )
return; return;
parent->parent()->beginRowsRemoved( idx, idx ); parent->parent()->beginRowsRemoved( idx, idx );
parent->parent()->removeChild( parent ); parent->parent()->removeChild( parent );
parent->parent()->endRowsRemoved(); parent->parent()->endRowsRemoved();
if( parent == m_playlists ) if ( parent == m_playlists )
m_playlists = 0; m_playlists = 0;
else if( parent == m_stations ) else if ( parent == m_stations )
m_stations = 0; m_stations = 0;
delete parent; delete parent;
} }
@@ -335,12 +336,10 @@ SourceItem::playlistDeletedInternal( SourceTreeItem* parent, const T& p )
void void
SourceItem::onPlaylistsAdded( const QList< playlist_ptr >& playlists ) SourceItem::onPlaylistsAdded( const QList< playlist_ptr >& playlists )
{ {
// qDebug() << Q_FUNC_INFO << m_source->friendlyName() << playlists.count(); if ( playlists.isEmpty() )
if( playlists.isEmpty() )
return; return;
if( !m_playlists ) if ( !m_playlists )
{ {
// add the category too // add the category too
int cur = children().count(); int cur = children().count();
@@ -354,14 +353,13 @@ SourceItem::onPlaylistsAdded( const QList< playlist_ptr >& playlists )
int from = m_playlists->children().count() - addOffset; int from = m_playlists->children().count() - addOffset;
m_playlists->beginRowsAdded( from, from + playlists.count() - 1 ); m_playlists->beginRowsAdded( from, from + playlists.count() - 1 );
foreach( const playlist_ptr& p, playlists ) foreach ( const playlist_ptr& p, playlists )
{ {
PlaylistItem* plItem = new PlaylistItem( model(), m_playlists, p, m_playlists->children().count() - addOffset ); PlaylistItem* plItem = new PlaylistItem( model(), m_playlists, p, m_playlists->children().count() - addOffset );
// qDebug() << "Playlist added:" << p->title() << p->creator() << p->info();
p->loadRevision(); p->loadRevision();
items << plItem; items << plItem;
if( m_source->isLocal() ) if ( m_source->isLocal() )
connect( p.data(), SIGNAL( aboutToBeDeleted( Tomahawk::playlist_ptr ) ), connect( p.data(), SIGNAL( aboutToBeDeleted( Tomahawk::playlist_ptr ) ),
SLOT( onPlaylistDeleted( Tomahawk::playlist_ptr ) ), Qt::QueuedConnection ); SLOT( onPlaylistDeleted( Tomahawk::playlist_ptr ) ), Qt::QueuedConnection );
else else
@@ -383,10 +381,10 @@ SourceItem::onPlaylistDeleted( const playlist_ptr& playlist )
void void
SourceItem::onAutoPlaylistsAdded( const QList< dynplaylist_ptr >& playlists ) SourceItem::onAutoPlaylistsAdded( const QList< dynplaylist_ptr >& playlists )
{ {
if( playlists.isEmpty() ) if ( playlists.isEmpty() )
return; return;
if( !m_playlists ) if ( !m_playlists )
{ {
// add the category too // add the category too
int cur = children().count(); int cur = children().count();
@@ -402,8 +400,8 @@ SourceItem::onAutoPlaylistsAdded( const QList< dynplaylist_ptr >& playlists )
void void
SourceItem::onAutoPlaylistDeleted( const dynplaylist_ptr& playlist ) SourceItem::onAutoPlaylistDeleted( const dynplaylist_ptr& playlist )
{ {
if( !m_playlists ) if ( !m_playlists )
qDebug() << "NO playlist category item for a deleting playlist.."; qDebug() << "NO playlist category item for a deleting playlist...";
playlistDeletedInternal( m_playlists, playlist ); playlistDeletedInternal( m_playlists, playlist );
} }
@@ -412,10 +410,10 @@ SourceItem::onAutoPlaylistDeleted( const dynplaylist_ptr& playlist )
void void
SourceItem::onStationsAdded( const QList< dynplaylist_ptr >& stations ) SourceItem::onStationsAdded( const QList< dynplaylist_ptr >& stations )
{ {
if( stations.isEmpty() ) if ( stations.isEmpty() )
return; return;
if( !m_stations ) if ( !m_stations )
{ {
// add the category too // add the category too
int cur = children().count(); int cur = children().count();
@@ -445,7 +443,7 @@ SourceItem::requestExpanding()
ViewPage* ViewPage*
SourceItem::sourceInfoClicked() SourceItem::sourceInfoClicked()
{ {
if( m_source.isNull() ) if ( m_source.isNull() )
return 0; return 0;
m_sourceInfoPage = ViewManager::instance()->show( m_source ); m_sourceInfoPage = ViewManager::instance()->show( m_source );
@@ -463,7 +461,7 @@ SourceItem::getSourceInfoPage() const
ViewPage* ViewPage*
SourceItem::collectionClicked() SourceItem::collectionClicked()
{ {
if( m_source.isNull() ) if ( m_source.isNull() )
return 0; return 0;
m_collectionPage = ViewManager::instance()->show( m_source->collection() ); m_collectionPage = ViewManager::instance()->show( m_source->collection() );
@@ -503,7 +501,12 @@ ViewPage*
SourceItem::lovedTracksClicked() SourceItem::lovedTracksClicked()
{ {
if ( !m_lovedTracksPage ) if ( !m_lovedTracksPage )
m_lovedTracksPage = new CustomPlaylistView( m_source.isNull() ? CustomPlaylistView::TopLovedTracks : CustomPlaylistView::SourceLovedTracks, m_source, ViewManager::instance()->widget() ); {
CustomPlaylistView* view = new CustomPlaylistView( m_source.isNull() ? CustomPlaylistView::TopLovedTracks : CustomPlaylistView::SourceLovedTracks, m_source, ViewManager::instance()->widget() );
view->setItemDelegate( new PlaylistLargeItemDelegate( view, view->proxyModel() ) );
m_lovedTracksPage = view;
}
ViewManager::instance()->show( m_lovedTracksPage ); ViewManager::instance()->show( m_lovedTracksPage );
return m_lovedTracksPage; return m_lovedTracksPage;
@@ -523,8 +526,13 @@ SourceItem::latestAdditionsClicked()
if ( !m_latestAdditionsPage ) if ( !m_latestAdditionsPage )
{ {
CollectionView* cv = new CollectionView( ViewManager::instance()->widget() ); CollectionView* cv = new CollectionView( ViewManager::instance()->widget() );
RecentlyAddedModel* raModel = new RecentlyAddedModel( m_source, cv ); cv->setFrameShape( QFrame::NoFrame );
cv->setAttribute( Qt::WA_MacShowFocusRect, 0 );
RecentlyAddedModel* raModel = new RecentlyAddedModel( m_source, cv );
raModel->setStyle( TrackModel::Large );
cv->setItemDelegate( new PlaylistLargeItemDelegate( cv, cv->proxyModel() ) );
cv->setTrackModel( raModel ); cv->setTrackModel( raModel );
cv->sortByColumn( TrackModel::Age, Qt::DescendingOrder ); cv->sortByColumn( TrackModel::Age, Qt::DescendingOrder );
@@ -549,8 +557,13 @@ SourceItem::recentPlaysClicked()
if ( !m_recentPlaysPage ) if ( !m_recentPlaysPage )
{ {
PlaylistView* pv = new PlaylistView( ViewManager::instance()->widget() ); PlaylistView* pv = new PlaylistView( ViewManager::instance()->widget() );
RecentlyPlayedModel* raModel = new RecentlyPlayedModel( m_source, pv ); pv->setFrameShape( QFrame::NoFrame );
pv->setAttribute( Qt::WA_MacShowFocusRect, 0 );
RecentlyPlayedModel* raModel = new RecentlyPlayedModel( m_source, pv );
raModel->setStyle( TrackModel::Large );
pv->setItemDelegate( new PlaylistLargeItemDelegate( pv, pv->proxyModel() ) );
pv->setPlaylistModel( raModel ); pv->setPlaylistModel( raModel );
m_recentPlaysPage = pv; m_recentPlaysPage = pv;