1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 03:10:12 +02:00

* Nicer AlbumView.

This commit is contained in:
Christian Muehlhaeuser
2012-05-12 13:21:54 -07:00
parent 92b5d3cb84
commit 69987877a1
9 changed files with 72 additions and 28 deletions

View File

@@ -9,6 +9,8 @@
<file>data/images/not-loved.png</file> <file>data/images/not-loved.png</file>
<file>data/images/no-album-art-placeholder.png</file> <file>data/images/no-album-art-placeholder.png</file>
<file>data/images/no-artist-image-placeholder.png</file> <file>data/images/no-artist-image-placeholder.png</file>
<file>data/images/artist-placeholder-grid.png</file>
<file>data/images/album-placeholder-grid.png</file>
<file>data/images/track-placeholder.png</file> <file>data/images/track-placeholder.png</file>
<file>data/images/now-playing-panel.png</file> <file>data/images/now-playing-panel.png</file>
<file>data/images/now-playing-speaker.png</file> <file>data/images/now-playing-speaker.png</file>

View File

@@ -71,7 +71,7 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
painter->save(); painter->save();
painter->setRenderHint( QPainter::Antialiasing ); painter->setRenderHint( QPainter::Antialiasing );
if ( !( option.state & QStyle::State_Selected ) ) /* if ( !( option.state & QStyle::State_Selected ) )
{ {
QRect shadowRect = option.rect.adjusted( 5, 4, -5, -40 ); QRect shadowRect = option.rect.adjusted( 5, 4, -5, -40 );
painter->setPen( QColor( 90, 90, 90 ) ); painter->setPen( QColor( 90, 90, 90 ) );
@@ -92,9 +92,10 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
painter->drawLine( shadowRect.topLeft() + QPoint( -2, 3 ), shadowRect.bottomLeft() + QPoint( -2, 1 ) ); painter->drawLine( shadowRect.topLeft() + QPoint( -2, 3 ), shadowRect.bottomLeft() + QPoint( -2, 1 ) );
painter->drawLine( shadowRect.topRight() + QPoint( 3, 3 ), shadowRect.bottomRight() + QPoint( 3, 1 ) ); painter->drawLine( shadowRect.topRight() + QPoint( 3, 3 ), shadowRect.bottomRight() + QPoint( 3, 1 ) );
painter->drawLine( shadowRect.bottomLeft() + QPoint( 0, 4 ), shadowRect.bottomRight() + QPoint( 0, 4 ) ); painter->drawLine( shadowRect.bottomLeft() + QPoint( 0, 4 ), shadowRect.bottomRight() + QPoint( 0, 4 ) );
} }*/
QRect r = option.rect.adjusted( 6, 5, -6, -41 ); // QRect r = option.rect.adjusted( 6, 5, -6, -41 );
QRect r = option.rect;
QString top, bottom; QString top, bottom;
if ( !item->album().isNull() ) if ( !item->album().isNull() )
@@ -118,15 +119,15 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
{ {
if ( !item->album().isNull() ) if ( !item->album().isNull() )
{ {
m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->album(), r.size(), TomahawkUtils::CoverInCase ) ) ); m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->album(), r.size(), TomahawkUtils::Grid ) ) );
} }
else if ( !item->artist().isNull() ) else if ( !item->artist().isNull() )
{ {
m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->artist(), r.size(), TomahawkUtils::CoverInCase ) ) ); m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->artist(), r.size(), TomahawkUtils::Grid ) ) );
} }
else else
{ {
m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->query(), r.size(), TomahawkUtils::CoverInCase ) ) ); m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->query(), r.size(), TomahawkUtils::Grid ) ) );
} }
_detail::Closure* closure = NewClosure( m_covers[ index ], SIGNAL( repaintRequest() ), const_cast<AlbumItemDelegate*>(this), SLOT( doUpdateIndex( QPersistentModelIndex ) ), QPersistentModelIndex( index ) ); _detail::Closure* closure = NewClosure( m_covers[ index ], SIGNAL( repaintRequest() ), const_cast<AlbumItemDelegate*>(this), SLOT( doUpdateIndex( QPersistentModelIndex ) ), QPersistentModelIndex( index ) );
@@ -135,11 +136,10 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
const QPixmap cover = m_covers[ index ]->currentPixmap(); const QPixmap cover = m_covers[ index ]->currentPixmap();
if ( option.state & QStyle::State_Selected ) if ( false && option.state & QStyle::State_Selected )
{ {
#if defined(Q_WS_MAC) || defined(Q_WS_WIN) #if defined(Q_WS_MAC) || defined(Q_WS_WIN)
painter->save(); painter->save();
painter->setRenderHint( QPainter::Antialiasing );
QPainterPath border; QPainterPath border;
border.addRoundedRect( r.adjusted( -2, -2, 2, 2 ), 3, 3 ); border.addRoundedRect( r.adjusted( -2, -2, 2, 2 ), 3, 3 );
@@ -154,19 +154,41 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
#endif #endif
} }
painter->drawPixmap( r, cover ); painter->drawPixmap( r, cover.scaled( r.size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
painter->setPen( opt.palette.color( QPalette::Text ) ); if ( m_hoverIndex == index )
{
painter->save();
painter->setPen( QColor( 33, 33, 33 ) );
painter->setBrush( QColor( 33, 33, 33 ) );
painter->setOpacity( 0.5 );
painter->drawRect( r );
painter->restore();
}
painter->save();
painter->setPen( QColor( 33, 33, 33 ) );
painter->setBrush( QColor( 33, 33, 33 ) );
painter->setOpacity( 0.5 );
painter->drawRoundedRect( r.adjusted( 4, +r.height() - 36, -4, -4 ), 3, 3 );
painter->restore();
painter->setPen( opt.palette.color( QPalette::HighlightedText ) );
QTextOption to; QTextOption to;
to.setWrapMode( QTextOption::NoWrap ); to.setWrapMode( QTextOption::NoWrap );
QString text; QString text;
QFont font = opt.font; QFont font = opt.font;
font.setPixelSize( 11 ); font.setPixelSize( 10 );
QFont boldFont = font; QFont boldFont = font;
boldFont.setBold( true ); boldFont.setBold( true );
boldFont.setPixelSize( 14 );
QRect textRect = option.rect.adjusted( 0, option.rect.height() - 32, 0, -2 ); QRect textRect = option.rect.adjusted( 6, option.rect.height() - 36, -4, -6 );
painter->setFont( boldFont ); painter->setFont( boldFont );
bool oneLiner = false; bool oneLiner = false;
@@ -188,6 +210,7 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
text = painter->fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - 3 ); text = painter->fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - 3 );
painter->drawText( textRect, text, to ); painter->drawText( textRect, text, to );
painter->setFont( font );
// If the user is hovering over an artist rect, draw a background so she knows it's clickable // If the user is hovering over an artist rect, draw a background so she knows it's clickable
QRect r = textRect; QRect r = textRect;
r.setTop( r.bottom() - painter->fontMetrics().height() ); r.setTop( r.bottom() - painter->fontMetrics().height() );
@@ -199,12 +222,12 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
} }
else else
{ {
if ( !( option.state & QStyle::State_Selected ) ) /* if ( !( option.state & QStyle::State_Selected ) )
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
painter->setPen( opt.palette.color( QPalette::Dark ).darker( 200 ) ); painter->setPen( opt.palette.color( QPalette::Dark ).darker( 200 ) );
#else #else
painter->setPen( opt.palette.color( QPalette::Dark ) ); painter->setPen( opt.palette.color( QPalette::Dark ) );
#endif #endif*/
} }
to.setAlignment( Qt::AlignHCenter | Qt::AlignBottom ); to.setAlignment( Qt::AlignHCenter | Qt::AlignBottom );
@@ -231,6 +254,9 @@ AlbumItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const
event->type() != QEvent::Leave ) event->type() != QEvent::Leave )
return false; return false;
if ( event->type() == QEvent::MouseMove )
m_hoverIndex = index;
if ( m_artistNameRects.contains( index ) ) if ( m_artistNameRects.contains( index ) )
{ {
QMouseEvent* ev = static_cast< QMouseEvent* >( event ); QMouseEvent* ev = static_cast< QMouseEvent* >( event );

View File

@@ -61,6 +61,7 @@ private:
mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_covers; mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_covers;
QPersistentModelIndex m_hoveringOver; QPersistentModelIndex m_hoveringOver;
QPersistentModelIndex m_hoverIndex;
QPixmap m_shadowPixmap; QPixmap m_shadowPixmap;
}; };

View File

@@ -110,7 +110,7 @@ AlbumModel::data( const QModelIndex& index, int role ) const
{ {
if ( role == Qt::SizeHintRole ) if ( role == Qt::SizeHintRole )
{ {
return QSize( 116, 150 ); return m_itemSize;
} }
AlbumItem* entry = itemFromIndex( index ); AlbumItem* entry = itemFromIndex( index );

View File

@@ -72,6 +72,9 @@ public:
virtual void setTitle( const QString& title ) { m_title = title; } virtual void setTitle( const QString& title ) { m_title = title; }
virtual void setDescription( const QString& description ) { m_description = description; } virtual void setDescription( const QString& description ) { m_description = description; }
QSize itemSize() const { return m_itemSize; }
void setItemSize( const QSize& size ) { m_itemSize = size; }
AlbumItem* findItem( const Tomahawk::artist_ptr& artist ) const; AlbumItem* findItem( const Tomahawk::artist_ptr& artist ) const;
AlbumItem* findItem( const Tomahawk::album_ptr& album ) const; AlbumItem* findItem( const Tomahawk::album_ptr& album ) const;
@@ -116,6 +119,8 @@ private:
QString m_description; QString m_description;
bool m_overwriteOnAdd; bool m_overwriteOnAdd;
QSize m_itemSize;
Tomahawk::collection_ptr m_collection; Tomahawk::collection_ptr m_collection;
}; };

View File

@@ -54,9 +54,10 @@ AlbumView::AlbumView( QWidget* parent )
setDropIndicatorShown( false ); setDropIndicatorShown( false );
setDragDropOverwriteMode( false ); setDragDropOverwriteMode( false );
setUniformItemSizes( true ); setUniformItemSizes( true );
setSpacing( 16 ); setSpacing( 0 );
setContentsMargins( 0, 0, 0, 0 ); setContentsMargins( 0, 0, 0, 0 );
setMouseTracking( true ); setMouseTracking( true );
setStyleSheet( "QListView { background-color: #323435; }" );
setResizeMode( Adjust ); setResizeMode( Adjust );
setViewMode( IconMode ); setViewMode( IconMode );
@@ -181,21 +182,22 @@ AlbumView::resizeEvent( QResizeEvent* event )
if ( autoFitItems() ) if ( autoFitItems() )
{ {
#ifdef Q_WS_X11 #ifdef Q_WS_X11
int scrollbar = verticalScrollBar()->isVisible() ? verticalScrollBar()->width() : 0; int scrollbar = verticalScrollBar()->isVisible() ? verticalScrollBar()->width() + 16 : 0;
#else #else
int scrollbar = verticalScrollBar()->rect().width(); int scrollbar = verticalScrollBar()->rect().width();
#endif #endif
int rectWidth = contentsRect().width() - scrollbar - 16 - 3; int rectWidth = contentsRect().width() - scrollbar - 3;
int itemWidth = 160;
QSize itemSize = m_proxyModel->data( QModelIndex(), Qt::SizeHintRole ).toSize(); QSize itemSize = m_proxyModel->data( QModelIndex(), Qt::SizeHintRole ).toSize();
int itemsPerRow = qFloor( rectWidth / ( itemSize.width() + 16 ) ); int itemsPerRow = qFloor( rectWidth / itemWidth );
int rightSpacing = rectWidth - ( itemsPerRow * ( itemSize.width() + 16 ) ); // int rightSpacing = rectWidth - ( itemsPerRow * ( itemSize.width() + 16 ) );
int newSpacing = 16 + floor( rightSpacing / ( itemsPerRow + 1 ) ); // int newSpacing = 16 + floor( rightSpacing / ( itemsPerRow + 1 ) );
if ( itemsPerRow < 1 ) int remSpace = rectWidth - ( itemsPerRow * itemWidth );
setSpacing( 16 ); int extraSpace = remSpace / itemsPerRow;
else int newItemWidth = itemWidth + extraSpace;
setSpacing( newSpacing ); m_model->setItemSize( QSize( newItemWidth, newItemWidth ) );
if ( !m_inited ) if ( !m_inited )
{ {

View File

@@ -59,6 +59,7 @@ PixmapDelegateFader::PixmapDelegateFader( const artist_ptr& artist, const QSize&
init(); init();
} }
PixmapDelegateFader::PixmapDelegateFader( const album_ptr& album, const QSize& size, TomahawkUtils::ImageMode mode, bool forceLoad ) PixmapDelegateFader::PixmapDelegateFader( const album_ptr& album, const QSize& size, TomahawkUtils::ImageMode mode, bool forceLoad )
: m_album( album ) : m_album( album )
, m_size( size ) , m_size( size )
@@ -99,7 +100,6 @@ PixmapDelegateFader::PixmapDelegateFader( const query_ptr& track, const QSize& s
PixmapDelegateFader::~PixmapDelegateFader() PixmapDelegateFader::~PixmapDelegateFader()
{ {
} }
@@ -117,7 +117,7 @@ PixmapDelegateFader::init()
else if ( !m_artist.isNull() ) else if ( !m_artist.isNull() )
m_current = m_currentReference = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultArtistImage, m_mode, m_size ); m_current = m_currentReference = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultArtistImage, m_mode, m_size );
else if ( !m_track.isNull() ) else if ( !m_track.isNull() )
m_current = m_currentReference = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultTrackImage, m_mode, m_size ); m_current = m_currentReference = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultArtistImage, m_mode, m_size );
return; return;
} }
@@ -139,6 +139,7 @@ PixmapDelegateFader::albumChanged()
QMetaObject::invokeMethod( this, "setPixmap", Qt::QueuedConnection, Q_ARG( QPixmap, m_album->cover( m_size ) ) ); QMetaObject::invokeMethod( this, "setPixmap", Qt::QueuedConnection, Q_ARG( QPixmap, m_album->cover( m_size ) ) );
} }
void void
PixmapDelegateFader::artistChanged() PixmapDelegateFader::artistChanged()
{ {

View File

@@ -53,12 +53,14 @@ namespace TomahawkUtils
NowPlayingSpeaker, NowPlayingSpeaker,
InfoIcon InfoIcon
}; };
enum ImageMode enum ImageMode
{ {
Original, Original,
CoverInCase, CoverInCase,
AvatarInFrame, AvatarInFrame,
ScaledCover ScaledCover,
Grid
}; };

View File

@@ -338,11 +338,16 @@ defaultPixmap( ImageType type, ImageMode mode, const QSize& size )
case DefaultAlbumCover: case DefaultAlbumCover:
if ( mode == CoverInCase ) if ( mode == CoverInCase )
pixmap = QPixmap( RESPATH "images/no-album-art-placeholder.png" ); pixmap = QPixmap( RESPATH "images/no-album-art-placeholder.png" );
else if ( mode == Grid )
pixmap = QPixmap( RESPATH "images/album-placeholder-grid.png" );
else else
pixmap = QPixmap( RESPATH "images/no-album-no-case.png" ); pixmap = QPixmap( RESPATH "images/no-album-no-case.png" );
break; break;
case DefaultArtistImage: case DefaultArtistImage:
if ( mode == Grid )
pixmap = QPixmap( RESPATH "images/artist-placeholder-grid.png" );
else
pixmap = QPixmap( RESPATH "images/no-artist-image-placeholder.png" ); pixmap = QPixmap( RESPATH "images/no-artist-image-placeholder.png" );
break; break;