1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-02 04:10:20 +02:00

Polish up the playlist widget a whole bunch. TWK-348

This commit is contained in:
Leo Franchi
2011-08-11 18:05:58 -04:00
parent eda5893012
commit c99fff2b16
17 changed files with 87 additions and 8 deletions

View File

@@ -219,4 +219,6 @@ private:
}; // namespace }; // namespace
Q_DECLARE_METATYPE( QSharedPointer< Tomahawk::DynamicPlaylist > )
#endif #endif

View File

@@ -427,6 +427,17 @@ DynamicWidget::paintRoundedFilledRect( QPainter& p, QPalette& pal, QRect& r, qre
p.drawRoundedRect( r, 10, 10 ); p.drawRoundedRect( r, 10, 10 );
} }
QPixmap
DynamicWidget::pixmap() const
{
if ( m_playlist->mode() == OnDemand )
return QPixmap( RESPATH "images/station.png" );
else if ( m_playlist->mode() == Static )
return QPixmap( RESPATH "images/automatic-playlist.png" );
else
return QPixmap();
}
bool bool
DynamicWidget::jumpToCurrentTrack() DynamicWidget::jumpToCurrentTrack()

View File

@@ -77,7 +77,7 @@ public:
virtual QString title() const { return m_model->title(); } virtual QString title() const { return m_model->title(); }
virtual QString description() const { return m_model->description(); } virtual QString description() const { return m_model->description(); }
virtual QPixmap pixmap() const { return QPixmap( RESPATH "images/playlist-icon.png" ); } virtual QPixmap pixmap() const;
virtual bool jumpToCurrentTrack(); virtual bool jumpToCurrentTrack();

View File

@@ -110,8 +110,32 @@ WelcomePlaylistModel::data( const QModelIndex& index, int role ) const
return m_artists[pl]; return m_artists[pl];
} }
case PlaylistTypeRole:
{
if ( !pl.dynamicCast< Tomahawk::DynamicPlaylist >().isNull() )
{
dynplaylist_ptr dynp = pl.dynamicCast< Tomahawk::DynamicPlaylist >();
if ( dynp->mode() == Static )
return AutoPlaylist;
else if ( dynp->mode() == OnDemand )
return Station;
} else
{
return StaticPlaylist;
}
}
case DynamicPlaylistRole:
{
dynplaylist_ptr dynp = pl.dynamicCast< Tomahawk::DynamicPlaylist >();
return QVariant::fromValue< Tomahawk::dynplaylist_ptr >( dynp );
}
case TrackCountRole: case TrackCountRole:
return pl->entries().count(); {
if ( !pl.dynamicCast< Tomahawk::DynamicPlaylist >().isNull() )
return QString( QChar( 0x221E ) );
else
return pl->entries().count();
}
default: default:
return QVariant(); return QVariant();
} }

View File

@@ -30,7 +30,9 @@ class WelcomePlaylistModel : public QAbstractListModel
Q_OBJECT Q_OBJECT
public: public:
enum ItemRoles enum ItemRoles
{ ArtistRole = Qt::UserRole, TrackCountRole, PlaylistRole }; { ArtistRole = Qt::UserRole, TrackCountRole, PlaylistRole, PlaylistTypeRole, DynamicPlaylistRole };
enum PlaylistTypes
{ StaticPlaylist, AutoPlaylist, Station };
explicit WelcomePlaylistModel( QObject* parent = 0 ); explicit WelcomePlaylistModel( QObject* parent = 0 );

View File

@@ -32,6 +32,7 @@
#include "widgets/overlaywidget.h" #include "widgets/overlaywidget.h"
#include "utils/tomahawkutils.h" #include "utils/tomahawkutils.h"
#include "utils/logger.h" #include "utils/logger.h"
#include <dynamic/GeneratorInterface.h>
#define HISTORY_TRACK_ITEMS 25 #define HISTORY_TRACK_ITEMS 25
#define HISTORY_PLAYLIST_ITEMS 5 #define HISTORY_PLAYLIST_ITEMS 5
@@ -222,9 +223,29 @@ PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
QFont italicFont = opt.font; QFont italicFont = opt.font;
italicFont.setItalic( true ); italicFont.setItalic( true );
painter->drawPixmap( option.rect.adjusted( 10, 13, -option.rect.width() + 48, -13 ), m_playlistIcon ); QPixmap icon;
WelcomePlaylistModel::PlaylistTypes type = (WelcomePlaylistModel::PlaylistTypes)index.data( WelcomePlaylistModel::PlaylistTypeRole ).toInt();
if( type == WelcomePlaylistModel::StaticPlaylist )
icon = m_playlistIcon;
else if( type == WelcomePlaylistModel::AutoPlaylist )
icon = m_autoIcon;
else if( type == WelcomePlaylistModel::Station )
icon = m_stationIcon;
painter->drawText( option.rect.adjusted( 56, 26, -100, -8 ), index.data( WelcomePlaylistModel::ArtistRole ).toString() ); QRect pixmapRect = option.rect.adjusted( 10, 13, -option.rect.width() + 48, -13 );
icon = icon.scaled( pixmapRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation );
painter->drawPixmap( pixmapRect, icon );
QString descText;
if ( type == WelcomePlaylistModel::Station )
{
descText = index.data( WelcomePlaylistModel::DynamicPlaylistRole ).value< Tomahawk::dynplaylist_ptr >()->generator()->sentenceSummary();
} else
{
descText = index.data( WelcomePlaylistModel::ArtistRole ).toString();
}
painter->drawText( option.rect.adjusted( 56, 26, -100, -8 ), descText );
QString trackCount = tr( "%1 tracks" ).arg( index.data( WelcomePlaylistModel::TrackCountRole ).toString() ); QString trackCount = tr( "%1 tracks" ).arg( index.data( WelcomePlaylistModel::TrackCountRole ).toString() );
painter->drawText( option.rect.adjusted( option.rect.width() - 96, 12, 0, -2 - opt.rect.height() / 2 ), trackCount, to ); painter->drawText( option.rect.adjusted( option.rect.width() - 96, 12, 0, -2 - opt.rect.height() / 2 ), trackCount, to );

View File

@@ -50,6 +50,8 @@ public:
PlaylistDelegate() PlaylistDelegate()
{ {
m_playlistIcon = QPixmap( RESPATH "images/playlist-icon.png" ); m_playlistIcon = QPixmap( RESPATH "images/playlist-icon.png" );
m_autoIcon = QPixmap( RESPATH "images/automatic-playlist.png" );
m_stationIcon = QPixmap( RESPATH "images/station.png" );
} }
protected: protected:
@@ -57,7 +59,7 @@ protected:
QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
private: private:
QPixmap m_playlistIcon; QPixmap m_playlistIcon, m_autoIcon, m_stationIcon;
}; };
class DLLEXPORT PlaylistWidget : public QListView class DLLEXPORT PlaylistWidget : public QListView

View File

@@ -1,4 +1,6 @@
/* /*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,4 +1,6 @@
/* /*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,4 +1,6 @@
/* /*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,4 +1,6 @@
/* /*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,4 +1,7 @@
/* /*
*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,4 +1,6 @@
/* /*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,4 +1,6 @@
/* /*
Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,4 +1,6 @@
/* /*
Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or

View File

@@ -1,6 +1,6 @@
/* === 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, Leo Franchi <lfranchi@kde.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by

View File

@@ -1,6 +1,6 @@
/* === 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, Leo Franchi <lfranchi@kde.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by