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

* Make artist names in GridView clickable.

This commit is contained in:
Christian Muehlhaeuser
2014-08-20 07:08:20 +02:00
parent 8d94bbe8e3
commit 2251401cef

View File

@@ -117,7 +117,7 @@ GridItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
} }
painter->save(); painter->save();
painter->setRenderHint( QPainter::Antialiasing ); // painter->setRenderHint( QPainter::Antialiasing );
if ( !m_covers.contains( index ) ) if ( !m_covers.contains( index ) )
{ {
@@ -200,9 +200,20 @@ GridItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
painter->setPen( Qt::black ); painter->setPen( Qt::black );
if ( oneLiner ) if ( oneLiner )
{ {
// If the user is hovering over an artist rect, draw a background so they knows it's clickable
if ( m_hoveringOver == index )
{
QFont f = painter->font();
f.setUnderline( true );
painter->setFont( f );
}
to.setAlignment( Qt::AlignLeft | Qt::AlignTop ); to.setAlignment( Qt::AlignLeft | Qt::AlignTop );
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 );
// Calculate rect of artist on-hover button click area
m_artistNameRects[ index ] = painter->fontMetrics().boundingRect( textRect, Qt::AlignLeft | Qt::AlignVCenter, text );
} }
else else
{ {
@@ -212,22 +223,22 @@ GridItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
painter->setOpacity( 0.5 ); painter->setOpacity( 0.5 );
painter->setFont( smallFont ); painter->setFont( smallFont );
// If the user is hovering over an artist rect, draw a background so they knows it's clickable // If the user is hovering over an artist rect, draw a background so they knows it's clickable
/* QRect r = textRect;
r.setTop( r.bottom() - painter->fontMetrics().height() );
r.adjust( 4, 0, -4, -1 );
if ( m_hoveringOver == index ) if ( m_hoveringOver == index )
{ {
TomahawkUtils::drawQueryBackground( painter, r ); QFont f = painter->font();
painter->setPen( TomahawkStyle::SELECTION_FOREGROUND ); f.setUnderline( true );
}*/ painter->setFont( f );
}
textRect.adjust( 0, 2, 0, 2 );
to.setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); to.setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
text = painter->fontMetrics().elidedText( bottom, Qt::ElideRight, textRect.width() - 10 ); text = painter->fontMetrics().elidedText( bottom, Qt::ElideRight, textRect.width() - 3 );
painter->drawText( textRect.adjusted( 0, 2, 0, 2 ), text, to ); painter->drawText( textRect, text, to );
// Calculate rect of artist on-hover button click area // Calculate rect of artist on-hover button click area
// m_artistNameRects[ index ] = r; m_artistNameRects[ index ] = painter->fontMetrics().boundingRect( textRect, Qt::AlignLeft | Qt::AlignVCenter, text );
} }
painter->restore(); painter->restore();
@@ -402,6 +413,8 @@ GridItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const Q
ViewManager::instance()->show( item->query()->track()->artistPtr() ); ViewManager::instance()->show( item->query()->track()->artistPtr() );
else if ( item->album() && item->album()->artist() ) else if ( item->album() && item->album()->artist() )
ViewManager::instance()->show( item->album()->artist() ); ViewManager::instance()->show( item->album()->artist() );
else if ( item->artist() )
ViewManager::instance()->show( item->artist() );
event->accept(); event->accept();
return true; return true;