mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 16:29:43 +01:00
misc avatar and welcome widget work
This commit is contained in:
parent
70b0203acd
commit
b9f7bf2656
@ -57,6 +57,8 @@ PlaylistItemDelegate::PlaylistItemDelegate( TrackView* parent, TrackProxyModel*
|
||||
|
||||
m_centerOption = QTextOption( Qt::AlignVCenter );
|
||||
m_centerOption.setWrapMode( QTextOption::NoWrap );
|
||||
|
||||
m_defaultAvatar = TomahawkUtils::createAvatarFrame( QPixmap( RESPATH "images/user-avatar.png" ) );
|
||||
}
|
||||
|
||||
|
||||
@ -75,7 +77,7 @@ PlaylistItemDelegate::sizeHint( const QStyleOptionViewItem& option, const QModel
|
||||
if ( index.isValid() )
|
||||
{
|
||||
int style = index.data( TrackModel::StyleRole ).toInt();
|
||||
if ( style == TrackModel::Short )
|
||||
if ( style == TrackModel::Short || style == TrackModel::ShortWithAvatars )
|
||||
size.setHeight( 44 );
|
||||
}
|
||||
|
||||
@ -135,12 +137,14 @@ PlaylistItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& opti
|
||||
case TrackModel::Short:
|
||||
paintShort( painter, option, index );
|
||||
break;
|
||||
case TrackModel::ShortWithAvatars:
|
||||
paintShort( painter, option, index, true );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||
PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, bool useAvatars ) const
|
||||
{
|
||||
TrackModelItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) );
|
||||
Q_ASSERT( item );
|
||||
@ -184,11 +188,14 @@ PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem&
|
||||
else
|
||||
lowerText = QString( "played %1 ago by %2" ).arg( playtime ).arg( source->friendlyName() );
|
||||
|
||||
pixmap = source->avatar();
|
||||
if ( useAvatars )
|
||||
pixmap = source->avatar( Source::FancyStyle );
|
||||
}
|
||||
|
||||
if ( pixmap.isNull() )
|
||||
if ( pixmap.isNull() && !useAvatars )
|
||||
pixmap = QPixmap( RESPATH "images/track-placeholder.png" );
|
||||
else if ( pixmap.isNull() && useAvatars )
|
||||
pixmap = m_defaultAvatar;
|
||||
|
||||
painter->save();
|
||||
{
|
||||
@ -227,7 +234,8 @@ PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem&
|
||||
QString text = painter->fontMetrics().elidedText( upperText, Qt::ElideRight, r.width() );
|
||||
painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, m_topOption );
|
||||
|
||||
painter->setFont( opt.font );
|
||||
|
||||
painter->setFont( opt.font);
|
||||
text = painter->fontMetrics().elidedText( lowerText, Qt::ElideRight, r.width() );
|
||||
painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, m_bottomOption );
|
||||
}
|
||||
|
@ -50,12 +50,12 @@ private:
|
||||
void prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, TrackModelItem* item ) const;
|
||||
|
||||
void paintDetailed( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||
void paintShort( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||
void paintShort( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, bool useAvatars = false ) const;
|
||||
|
||||
unsigned int m_removalProgress;
|
||||
|
||||
mutable QHash< qint64, QPixmap > m_cache;
|
||||
QPixmap m_nowPlayingIcon;
|
||||
QPixmap m_nowPlayingIcon, m_defaultAvatar;
|
||||
mutable QPixmap m_arrowIcon;
|
||||
|
||||
QTextOption m_topOption;
|
||||
|
@ -34,7 +34,7 @@ Q_OBJECT
|
||||
|
||||
public:
|
||||
enum TrackItemStyle
|
||||
{ Detailed = 0, Short = 1 };
|
||||
{ Detailed = 0, Short = 1, ShortWithAvatars = 2 };
|
||||
|
||||
enum TrackModelRole
|
||||
{ StyleRole = Qt::UserRole + 1 };
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <QCoreApplication>
|
||||
|
||||
#include "utils/logger.h"
|
||||
#include "utils/tomahawkutils.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
@ -126,10 +127,17 @@ Source::setAvatar( const QPixmap& avatar )
|
||||
|
||||
|
||||
QPixmap
|
||||
Source::avatar() const
|
||||
Source::avatar( AvatarStyle style ) const
|
||||
{
|
||||
if( !m_avatar.isNull() )
|
||||
if ( style == FancyStyle &&
|
||||
!m_avatar.isNull() &&
|
||||
m_fancyAvatar.isNull() )
|
||||
m_fancyAvatar = TomahawkUtils::createAvatarFrame( m_avatar );
|
||||
|
||||
if ( style == Original && !m_avatar.isNull() )
|
||||
return m_avatar;
|
||||
else if ( style == FancyStyle && !m_fancyAvatar.isNull() )
|
||||
return m_fancyAvatar;
|
||||
else
|
||||
return QPixmap();
|
||||
}
|
||||
|
@ -45,6 +45,8 @@ friend class ::DBSyncConnection;
|
||||
friend class ::DatabaseCommand_SocialAction;
|
||||
|
||||
public:
|
||||
enum AvatarStyle { Original, FancyStyle };
|
||||
|
||||
explicit Source( int id, const QString& username = QString() );
|
||||
virtual ~Source();
|
||||
|
||||
@ -58,7 +60,7 @@ public:
|
||||
void setFriendlyName( const QString& fname );
|
||||
|
||||
void setAvatar( const QPixmap& avatar );
|
||||
QPixmap avatar() const;
|
||||
QPixmap avatar( AvatarStyle style = Original ) const;
|
||||
|
||||
collection_ptr collection() const;
|
||||
void addCollection( const Tomahawk::collection_ptr& c );
|
||||
@ -132,6 +134,7 @@ private:
|
||||
ControlConnection* m_cc;
|
||||
|
||||
QPixmap m_avatar;
|
||||
mutable QPixmap m_fancyAvatar;
|
||||
|
||||
Tomahawk::playlistinterface_ptr m_playlistInterface;
|
||||
};
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include <dynamic/GeneratorInterface.h>
|
||||
|
||||
#define HISTORY_TRACK_ITEMS 25
|
||||
#define HISTORY_PLAYLIST_ITEMS 5
|
||||
#define HISTORY_PLAYLIST_ITEMS 10
|
||||
#define HISTORY_RESOLVING_TIMEOUT 2500
|
||||
|
||||
using namespace Tomahawk;
|
||||
@ -78,7 +78,7 @@ WelcomeWidget::WelcomeWidget( QWidget* parent )
|
||||
connect( model, SIGNAL( emptinessChanged( bool) ), this, SLOT( updatePlaylists() ) );
|
||||
|
||||
m_tracksModel = new PlaylistModel( ui->tracksView );
|
||||
m_tracksModel->setStyle( TrackModel::Short );
|
||||
m_tracksModel->setStyle( TrackModel::ShortWithAvatars );
|
||||
ui->tracksView->overlay()->setEnabled( false );
|
||||
ui->tracksView->setPlaylistModel( m_tracksModel );
|
||||
|
||||
@ -262,6 +262,8 @@ PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
||||
QRect rectText = option.rect.adjusted( 66, 20, -100, -8 );
|
||||
#ifdef Q_OS_MAC
|
||||
rectText.adjust( 0, 1, 0, 0 );
|
||||
#elif Q_OS_WIN
|
||||
rectText.adjust( 0, 2, 0, 0 );
|
||||
#endif
|
||||
|
||||
painter->drawText( rectText, descText );
|
||||
@ -276,12 +278,12 @@ PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
||||
// int bottomEdge = pixmapRect
|
||||
// right edge 10px past right edge of pixmapRect
|
||||
// bottom edge flush with bottom of pixmap
|
||||
QRect rect( pixmapRect.right() - width, 0, width - 8, 0 );
|
||||
rect.adjust( 0, 0, -1, 0 );
|
||||
QRect rect( pixmapRect.right() - width , 0, width - 8, 0 );
|
||||
rect.adjust( -1, 0, 0, 0 );
|
||||
rect.setTop( pixmapRect.bottom() - painter->fontMetrics().height() - 1 );
|
||||
rect.setBottom( pixmapRect.bottom() + 1 );
|
||||
|
||||
QColor figColor( 191, 191, 191 );
|
||||
QColor figColor( 153, 153, 153 );
|
||||
painter->setPen( figColor );
|
||||
painter->setBrush( figColor );
|
||||
painter->setFont( boldFont );
|
||||
@ -291,10 +293,9 @@ PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
||||
}
|
||||
|
||||
|
||||
QPixmap avatar = index.data( WelcomePlaylistModel::PlaylistRole ).value< Tomahawk::playlist_ptr >()->author()->avatar();
|
||||
QPixmap avatar = index.data( WelcomePlaylistModel::PlaylistRole ).value< Tomahawk::playlist_ptr >()->author()->avatar( Source::FancyStyle );
|
||||
if ( avatar.isNull() )
|
||||
avatar = m_defaultAvatar;
|
||||
avatar = TomahawkUtils::createAvatarFrame( avatar );
|
||||
QRect r( option.rect.width() - avatar.width() - 10, option.rect.top() + option.rect.height()/2 - avatar.height()/2, avatar.width(), avatar.height() );
|
||||
painter->drawPixmap( r, avatar );
|
||||
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
m_playlistIcon = QPixmap( RESPATH "images/playlist-icon.png" );
|
||||
m_autoIcon = QPixmap( RESPATH "images/automatic-playlist.png" );
|
||||
m_stationIcon = QPixmap( RESPATH "images/station.png" );
|
||||
m_defaultAvatar = QPixmap( RESPATH "images/user-avatar.png" );
|
||||
m_defaultAvatar = TomahawkUtils::createAvatarFrame( QPixmap( RESPATH "images/user-avatar.png" ) );
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -71,6 +71,7 @@ CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, cons
|
||||
// );
|
||||
// m_coolPlaylistsItem->setSortValue( 200 );
|
||||
|
||||
m_superCol = TomahawkUtils::createAvatarFrame( QPixmap( RESPATH "images/supercollection.png" ) );
|
||||
|
||||
return;
|
||||
}
|
||||
@ -101,6 +102,8 @@ CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, cons
|
||||
if( ViewManager::instance()->pageForCollection( source->collection() ) )
|
||||
model()->linkSourceItemToPage( this, ViewManager::instance()->pageForCollection( source->collection() ) );
|
||||
|
||||
m_defaultAvatar = TomahawkUtils::createAvatarFrame( QPixmap( RESPATH "images/user-avatar.png" ) );
|
||||
|
||||
// load auto playlists and stations!
|
||||
|
||||
connect( source.data(), SIGNAL( stats( QVariantMap ) ), this, SIGNAL( updated() ) );
|
||||
@ -164,17 +167,15 @@ CollectionItem::activate()
|
||||
QIcon
|
||||
CollectionItem::icon() const
|
||||
{
|
||||
QPixmap pixmap;
|
||||
if( m_source.isNull() )
|
||||
pixmap = QPixmap( RESPATH "images/supercollection.png" );
|
||||
return m_superCol;
|
||||
else
|
||||
{
|
||||
if( m_source->avatar().isNull() )
|
||||
pixmap = QPixmap( RESPATH "images/user-avatar.png" );
|
||||
return m_defaultAvatar;
|
||||
else
|
||||
pixmap = m_source->avatar();
|
||||
return m_source->avatar( Source::FancyStyle );
|
||||
}
|
||||
return QIcon( TomahawkUtils::createAvatarFrame( pixmap ) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -74,6 +74,7 @@ private:
|
||||
void playlistDeletedInternal( SourceTreeItem* parent, const T& playlists );
|
||||
|
||||
Tomahawk::source_ptr m_source;
|
||||
QPixmap m_superCol, m_defaultAvatar;
|
||||
CategoryItem* m_playlists;
|
||||
CategoryItem* m_stations;
|
||||
|
||||
|
@ -673,9 +673,12 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
|
||||
{
|
||||
painter->setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
QRect figRect = o.rect.adjusted( o.rect.width() - figWidth - 6, 0, -15, -o.rect.height() + 16 );
|
||||
QRect figRect = o.rect.adjusted( o.rect.width() - figWidth - 8, 0, -13, -o.rect.height() + 16 );
|
||||
int hd = ( option.rect.height() - figRect.height() ) / 2;
|
||||
figRect.adjust( 0, hd, 0, hd );
|
||||
#ifdef Q_OS_WIN
|
||||
figRect.adjust( -3, 0, 3, 0 );
|
||||
#endif
|
||||
painter->setFont( bold );
|
||||
|
||||
QColor figColor( 167, 183, 211 );
|
||||
|
Loading…
x
Reference in New Issue
Block a user