1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 19:30:21 +02:00

* You can now hover / click artist names in playlists.

This commit is contained in:
Christian Muehlhaeuser
2014-08-19 07:41:54 +02:00
parent 87e2ae99b6
commit 306feab812
2 changed files with 45 additions and 2 deletions

View File

@@ -627,7 +627,17 @@ PlaylistItemDelegate::drawTrack( QPainter* painter, const QStyleOptionViewItem&
painter->setOpacity( 0.8 );
painter->setFont( f );
text = fm.elidedText( track->artist(), Qt::ElideRight, artistRect.width() - margin );
painter->save();
if ( m_hoveringOverArtist == index )
{
QFont f = painter->font();
f.setUnderline( true );
painter->setFont( f );
}
painter->drawText( artistRect, text, m_centerOption );
m_artistNameRects[ index ] = painter->fontMetrics().boundingRect( artistRect, Qt::AlignLeft | Qt::AlignVCenter, text );
painter->restore();
// draw number
painter->setOpacity( 0.6 );
@@ -681,6 +691,7 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con
return false;
}
bool hoveringArtist = false;
bool hoveringInfo = false;
bool hoveringLove = false;
Tomahawk::source_ptr hoveredAvatar;
@@ -691,6 +702,12 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con
const QMouseEvent* ev = static_cast< QMouseEvent* >( event );
hoveringInfo = infoRect.contains( ev->pos() );
}
if ( m_artistNameRects.contains( index ) )
{
const QRect nameRect = m_artistNameRects[ index ];
const QMouseEvent* ev = static_cast< QMouseEvent* >( event );
hoveringArtist = nameRect.contains( ev->pos() );
}
if ( m_loveButtonRects.contains( index ) )
{
const QRect loveRect = m_loveButtonRects[ index ];
@@ -714,7 +731,7 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con
if ( event->type() == QEvent::MouseMove )
{
if ( hoveringInfo || hoveringLove )
if ( hoveringInfo || hoveringLove || hoveringArtist )
m_view->setCursor( Qt::PointingHandCursor );
else
m_view->setCursor( Qt::ArrowCursor );
@@ -727,6 +744,24 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con
hoveredAvatarRect );
}
if ( hoveringArtist && m_hoveringOverArtist != index )
{
QPersistentModelIndex ti = m_hoveringOverArtist;
m_hoveringOverArtist = index;
PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( ti ) );
item->requestRepaint();
emit updateIndex( m_hoveringOverArtist );
}
if ( !hoveringArtist && m_hoveringOverArtist.isValid() )
{
QPersistentModelIndex ti = m_hoveringOverArtist;
m_hoveringOverArtist = QModelIndex();
PlayableItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( ti ) );
item->requestRepaint();
}
if ( m_hoveringOver != index )
{
QPersistentModelIndex ti = m_hoveringOver;
@@ -750,7 +785,11 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con
if ( !item )
return false;
if ( hoveringLove )
if ( hoveringArtist )
{
ViewManager::instance()->show( item->query()->track()->artistPtr() );
}
else if ( hoveringLove )
{
item->query()->queryTrack()->setLoved( !item->query()->queryTrack()->loved() );
}
@@ -806,8 +845,10 @@ PlaylistItemDelegate::resetHoverIndex()
QPersistentModelIndex idx = m_hoveringOver;
m_hoveringOver = QModelIndex();
m_hoveringOverArtist = QModelIndex();
m_infoButtonRects.clear();
m_loveButtonRects.clear();
m_artistNameRects.clear();
QModelIndex itemIdx = m_model->mapToSource( idx );
if ( itemIdx.isValid() )

View File

@@ -113,8 +113,10 @@ private:
mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps;
mutable QHash< QPersistentModelIndex, QRect > m_infoButtonRects;
mutable QHash< QPersistentModelIndex, QRect > m_loveButtonRects;
mutable QHash< QPersistentModelIndex, QRect > m_artistNameRects;
mutable QHash< QPersistentModelIndex, QHash< Tomahawk::source_ptr, QRect > > m_avatarBoxRects;
QPersistentModelIndex m_hoveringOver;
QPersistentModelIndex m_hoveringOverArtist;
TrackView* m_view;
PlayableProxyModel* m_model;