diff --git a/data/images/supercollection.png b/data/images/supercollection.png index e965f88e4..6c6f192d9 100644 Binary files a/data/images/supercollection.png and b/data/images/supercollection.png differ diff --git a/data/images/user-avatar.png b/data/images/user-avatar.png index ae26a18a4..0c761043b 100644 Binary files a/data/images/user-avatar.png and b/data/images/user-avatar.png differ diff --git a/src/libtomahawk/utils/tomahawkutils.cpp b/src/libtomahawk/utils/tomahawkutils.cpp index 9b37b9c8d..fdef729be 100644 --- a/src/libtomahawk/utils/tomahawkutils.cpp +++ b/src/libtomahawk/utils/tomahawkutils.cpp @@ -349,6 +349,42 @@ createDragPixmap( int itemCount ) return dragPixmap; } +void +drawBackgroundAndNumbers( QPainter* painter, const QString& text, const QRect& figRectIn ) +{ + QRect figRect = figRectIn; + if ( text.length() == 1 ) + figRect.adjust( -painter->fontMetrics().averageCharWidth(), 0, 0, 0 ); + + QPen origpen = painter->pen(); + QPen pen = origpen; + pen.setWidth( 1.0 ); + painter->setPen( pen ); + painter->drawRect( figRect ); + + // circles look bad. make it an oval. (thanks, apple) + const int bulgeWidth = 8; + const int offset = 0; // number of pixels to begin, counting inwards from figRect.x() and figRect.width(). 0 means start at each end, negative means start inside the rect. + + QPainterPath ppath; + ppath.moveTo( QPoint( figRect.x() + offset, figRect.y() + figRect.height() / 2 ) ); + QRect leftArcRect( figRect.x() + offset - bulgeWidth, figRect.y(), 2*bulgeWidth, figRect.height() ); + ppath.arcTo( leftArcRect, 90, 180 ); + painter->drawPath( ppath ); + + ppath = QPainterPath(); + ppath.moveTo( figRect.x() + figRect.width() - offset, figRect.y() + figRect.height() / 2 ); + leftArcRect = QRect( figRect.x() + figRect.width() - offset - bulgeWidth, figRect.y(), 2*bulgeWidth, figRect.height() ); + ppath.arcTo( leftArcRect, 270, 180 ); + painter->drawPath( ppath ); + + painter->setPen( origpen ); + + QTextOption to( Qt::AlignCenter ); + painter->setPen( Qt::white ); + painter->drawText( figRect.adjusted( -5, 0, 6, 0 ), text, to ); +} + void unmarginLayout( QLayout* layout ) diff --git a/src/libtomahawk/utils/tomahawkutils.h b/src/libtomahawk/utils/tomahawkutils.h index d72fcd015..238e63143 100644 --- a/src/libtomahawk/utils/tomahawkutils.h +++ b/src/libtomahawk/utils/tomahawkutils.h @@ -25,9 +25,11 @@ #include #include #include +#include #define RESPATH ":/data/" +class QPainter; class QColor; class QDir; class QDateTime; @@ -74,6 +76,8 @@ namespace TomahawkUtils DLLEXPORT QColor alphaBlend( const QColor& colorFrom, const QColor& colorTo, float opacity ); DLLEXPORT QPixmap createDragPixmap( int itemCount = 1 ); + DLLEXPORT void drawBackgroundAndNumbers( QPainter* p, const QString& text, const QRect& rect ); + DLLEXPORT void unmarginLayout( QLayout* layout ); DLLEXPORT NetworkProxyFactory* proxyFactory(); diff --git a/src/libtomahawk/widgets/welcomeplaylistmodel.cpp b/src/libtomahawk/widgets/welcomeplaylistmodel.cpp index fbb8fcacf..618354562 100644 --- a/src/libtomahawk/widgets/welcomeplaylistmodel.cpp +++ b/src/libtomahawk/widgets/welcomeplaylistmodel.cpp @@ -167,10 +167,27 @@ WelcomePlaylistModel::playlistRevisionLoaded() void WelcomePlaylistModel::onSourceAdded( const Tomahawk::source_ptr& source ) { + connect( source.data(), SIGNAL( online() ), this, SLOT( sourceOnline() ) ); connect( source->collection().data(), SIGNAL( playlistsAdded( QList ) ), SLOT( loadFromSettings() ) ); connect( source->collection().data(), SIGNAL( playlistsDeleted( QList ) ), SLOT( onPlaylistsRemoved( QList ) ) ); } +void +WelcomePlaylistModel::sourceOnline() +{ + Source* s = qobject_cast< Source* >( sender() ); + Q_ASSERT( s ); + + for ( int i = 0; i < m_recplaylists.size(); i++ ) + { + if ( m_recplaylists[ i ]->author().data() == s ) + { + QModelIndex idx = index( i, 0, QModelIndex() ); + emit dataChanged( idx, idx ); + } + } +} + void WelcomePlaylistModel::onPlaylistsRemoved( QList< playlist_ptr > playlists ) diff --git a/src/libtomahawk/widgets/welcomeplaylistmodel.h b/src/libtomahawk/widgets/welcomeplaylistmodel.h index 08d8ffcc6..c30d83ea0 100644 --- a/src/libtomahawk/widgets/welcomeplaylistmodel.h +++ b/src/libtomahawk/widgets/welcomeplaylistmodel.h @@ -60,6 +60,8 @@ private: unsigned int m_maxPlaylists; bool m_waitingForSome; + public slots: + void sourceOnline(); }; #endif // WELCOMEPLAYLISTMODEL_H diff --git a/src/libtomahawk/widgets/welcomewidget.cpp b/src/libtomahawk/widgets/welcomewidget.cpp index c408e7fed..8c423d6ad 100644 --- a/src/libtomahawk/widgets/welcomewidget.cpp +++ b/src/libtomahawk/widgets/welcomewidget.cpp @@ -221,8 +221,6 @@ PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, QFont font = opt.font; QFont boldFont = opt.font; boldFont.setBold( true ); - QFont italicFont = opt.font; - italicFont.setItalic( true ); QPixmap icon; WelcomePlaylistModel::PlaylistTypes type = (WelcomePlaylistModel::PlaylistTypes)index.data( WelcomePlaylistModel::PlaylistTypeRole ).toInt(); @@ -246,16 +244,40 @@ PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, { descText = index.data( WelcomePlaylistModel::ArtistRole ).toString(); } - painter->drawText( option.rect.adjusted( 56, 26, -100, -8 ), descText ); + QColor c = painter->pen().color(); + painter->setPen( QColor( Qt::gray ).darker() ); + painter->drawText( option.rect.adjusted( 66, 19, -100, -8 ), descText ); + painter->setPen( c ); - 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 ); + if ( type != WelcomePlaylistModel::Station ) + { + painter->save(); + QString tracks = index.data( WelcomePlaylistModel::TrackCountRole ).toString(); + int width = painter->fontMetrics().width( tracks ); +// 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 ); + rect.setTop( pixmapRect.bottom() - painter->fontMetrics().height() - 1 ); + rect.setBottom( pixmapRect.bottom() + 1 ); - QString author = index.data( WelcomePlaylistModel::PlaylistRole ).value< Tomahawk::playlist_ptr >()->author()->friendlyName(); - QRect r = option.rect.adjusted( option.rect.width() - 96, 2 + opt.rect.height() / 2, 0, -12); - painter->setFont( italicFont ); - author = painter->fontMetrics().elidedText( author, Qt::ElideRight, r.width() ); - painter->drawText( r, author, to ); + QColor figColor( 191, 191, 191 ); + painter->setPen( figColor ); + painter->setBrush( figColor ); + painter->setFont( boldFont ); + + TomahawkUtils::drawBackgroundAndNumbers( painter, tracks, rect ); + painter->restore(); + } + + + QPixmap avatar = index.data( WelcomePlaylistModel::PlaylistRole ).value< Tomahawk::playlist_ptr >()->author()->avatar(); + 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 ); painter->setFont( boldFont ); painter->drawText( option.rect.adjusted( 56, 6, -100, -option.rect.height() + 20 ), index.data().toString() ); diff --git a/src/libtomahawk/widgets/welcomewidget.h b/src/libtomahawk/widgets/welcomewidget.h index 0f4de5c69..dcbd7837a 100644 --- a/src/libtomahawk/widgets/welcomewidget.h +++ b/src/libtomahawk/widgets/welcomewidget.h @@ -52,6 +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" ); } protected: @@ -59,7 +60,7 @@ protected: QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; private: - QPixmap m_playlistIcon, m_autoIcon, m_stationIcon; + QPixmap m_playlistIcon, m_autoIcon, m_stationIcon, m_defaultAvatar; }; class DLLEXPORT PlaylistWidget : public QListView diff --git a/src/sourcetree/sourcetreeview.cpp b/src/sourcetree/sourcetreeview.cpp index 4acbf7f56..3f169dc36 100644 --- a/src/sourcetree/sourcetreeview.cpp +++ b/src/sourcetree/sourcetreeview.cpp @@ -673,34 +673,16 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co { painter->setRenderHint( QPainter::Antialiasing ); - QRect figRect = o.rect.adjusted( o.rect.width() - figWidth - 18, 0, -10, -o.rect.height() + 16 ); + QRect figRect = o.rect.adjusted( o.rect.width() - figWidth - 6, 0, -15, -o.rect.height() + 16 ); int hd = ( option.rect.height() - figRect.height() ) / 2; figRect.adjust( 0, hd, 0, hd ); + painter->setFont( bold ); QColor figColor( 167, 183, 211 ); painter->setPen( figColor ); painter->setBrush( figColor ); - QPen origpen = painter->pen(); - QPen pen = origpen; - pen.setWidth( 1.0 ); - painter->setPen( pen ); - painter->drawRect( figRect ); - - QPainterPath ppath; - ppath.moveTo( QPoint( figRect.x(), figRect.y() ) ); - ppath.quadTo( QPoint( figRect.x() - 8, figRect.y() + figRect.height() / 2 ), QPoint( figRect.x(), figRect.y() + figRect.height() ) ); - painter->drawPath( ppath ); - ppath.moveTo( QPoint( figRect.x() + figRect.width(), figRect.y() ) ); - ppath.quadTo( QPoint( figRect.x() + figRect.width() + 8, figRect.y() + figRect.height() / 2 ), QPoint( figRect.x() + figRect.width(), figRect.y() + figRect.height() ) ); - painter->drawPath( ppath ); - - painter->setPen( origpen ); - - QTextOption to( Qt::AlignCenter ); - painter->setFont( bold ); - painter->setPen( Qt::white ); - painter->drawText( figRect, tracks, to ); + TomahawkUtils::drawBackgroundAndNumbers( painter, tracks, figRect ); } painter->restore();