From b76b96ef3ea8a8b16a7368166dff8bdc561efb89 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Fri, 18 May 2012 12:13:54 +0200 Subject: [PATCH] * Show play button on item-views. --- .../playlist/AlbumItemDelegate.cpp | 34 ++++++++++++++++--- src/libtomahawk/playlist/AlbumItemDelegate.h | 1 + 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/libtomahawk/playlist/AlbumItemDelegate.cpp b/src/libtomahawk/playlist/AlbumItemDelegate.cpp index b8a3b2a78..3caa38c26 100644 --- a/src/libtomahawk/playlist/AlbumItemDelegate.cpp +++ b/src/libtomahawk/playlist/AlbumItemDelegate.cpp @@ -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() ) ) { diff --git a/src/libtomahawk/playlist/AlbumItemDelegate.h b/src/libtomahawk/playlist/AlbumItemDelegate.h index 45b8853f3..e2a78468d 100644 --- a/src/libtomahawk/playlist/AlbumItemDelegate.h +++ b/src/libtomahawk/playlist/AlbumItemDelegate.h @@ -62,6 +62,7 @@ private: QPersistentModelIndex m_hoveringOver; QPersistentModelIndex m_hoverIndex; + mutable QRect m_playButtonRect; QPixmap m_shadowPixmap; };