1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-23 01:09:42 +01:00

* Show play button on item-views.

This commit is contained in:
Christian Muehlhaeuser 2012-05-18 12:13:54 +02:00
parent ee7986180f
commit b76b96ef3e
2 changed files with 31 additions and 4 deletions

View File

@ -165,6 +165,12 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
painter->setOpacity( 0.5 );
painter->drawRect( r );
painter->setOpacity( 1.0 );
QPixmap playButton = QPixmap( RESPATH "images/play-rest.png" );
int delta = ( r.width() - playButton.width() ) / 2;
m_playButtonRect = r.adjusted( delta, delta, -delta, -delta );
painter->drawPixmap( m_playButtonRect, playButton );
painter->restore();
}
@ -189,14 +195,16 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
boldFont.setPixelSize( 14 );
QRect textRect = option.rect.adjusted( 6, option.rect.height() - 36, -4, -6 );
painter->setFont( font );
int bottomHeight = painter->fontMetrics().boundingRect( bottom ).height();
painter->setFont( boldFont );
int topHeight = painter->fontMetrics().boundingRect( top ).height();
bool oneLiner = false;
if ( bottom.isEmpty() )
oneLiner = true;
else
oneLiner = ( textRect.height() / 2 < painter->fontMetrics().boundingRect( top ).height() ||
textRect.height() / 2 < painter->fontMetrics().boundingRect( bottom ).height() );
oneLiner = ( textRect.height() < topHeight + bottomHeight );
if ( oneLiner )
{
@ -257,9 +265,27 @@ AlbumItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const
if ( event->type() == QEvent::MouseMove )
m_hoverIndex = index;
QMouseEvent* ev = static_cast< QMouseEvent* >( event );
if ( event->type() == QEvent::MouseButtonRelease )
{
if ( m_playButtonRect.contains( ev->pos() ) )
{
AlbumItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) );
if ( !item->query().isNull() )
AudioEngine::instance()->playItem( Tomahawk::playlistinterface_ptr(), item->query() );
else if ( !item->album().isNull() )
AudioEngine::instance()->playItem( item->album() );
else if ( !item->artist().isNull() )
AudioEngine::instance()->playItem( item->artist() );
event->accept();
return true;
}
}
if ( m_artistNameRects.contains( index ) )
{
QMouseEvent* ev = static_cast< QMouseEvent* >( event );
QRect artistNameRect = m_artistNameRects[ index ];
if ( artistNameRect.contains( ev->pos() ) )
{

View File

@ -62,6 +62,7 @@ private:
QPersistentModelIndex m_hoveringOver;
QPersistentModelIndex m_hoverIndex;
mutable QRect m_playButtonRect;
QPixmap m_shadowPixmap;
};