1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-20 07:52:30 +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/no-album-art-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/now-playing-panel.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->setRenderHint( QPainter::Antialiasing );
if ( !( option.state & QStyle::State_Selected ) )
/* if ( !( option.state & QStyle::State_Selected ) )
{
QRect shadowRect = option.rect.adjusted( 5, 4, -5, -40 );
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.topRight() + QPoint( 3, 3 ), shadowRect.bottomRight() + QPoint( 3, 1 ) );
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;
if ( !item->album().isNull() )
@ -118,15 +119,15 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
{
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() )
{
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
{
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 ) );
@ -135,11 +136,10 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
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)
painter->save();
painter->setRenderHint( QPainter::Antialiasing );
QPainterPath border;
border.addRoundedRect( r.adjusted( -2, -2, 2, 2 ), 3, 3 );
@ -154,19 +154,41 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
#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;
to.setWrapMode( QTextOption::NoWrap );
QString text;
QFont font = opt.font;
font.setPixelSize( 11 );
font.setPixelSize( 10 );
QFont boldFont = font;
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 );
bool oneLiner = false;
@ -188,6 +210,7 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
text = painter->fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - 3 );
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
QRect r = textRect;
r.setTop( r.bottom() - painter->fontMetrics().height() );
@ -199,12 +222,12 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
}
else
{
if ( !( option.state & QStyle::State_Selected ) )
/* if ( !( option.state & QStyle::State_Selected ) )
#ifdef Q_WS_MAC
painter->setPen( opt.palette.color( QPalette::Dark ).darker( 200 ) );
#else
painter->setPen( opt.palette.color( QPalette::Dark ) );
#endif
#endif*/
}
to.setAlignment( Qt::AlignHCenter | Qt::AlignBottom );
@ -231,6 +254,9 @@ AlbumItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const
event->type() != QEvent::Leave )
return false;
if ( event->type() == QEvent::MouseMove )
m_hoverIndex = index;
if ( m_artistNameRects.contains( index ) )
{
QMouseEvent* ev = static_cast< QMouseEvent* >( event );

View File

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

View File

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

View File

@ -72,6 +72,9 @@ public:
virtual void setTitle( const QString& title ) { m_title = title; }
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::album_ptr& album ) const;
@ -116,6 +119,8 @@ private:
QString m_description;
bool m_overwriteOnAdd;
QSize m_itemSize;
Tomahawk::collection_ptr m_collection;
};

View File

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

View File

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

View File

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

View File

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