mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-13 20:39:57 +01:00
Added tooltips to avatars in delegate boxes
This commit is contained in:
parent
d0d285fcbd
commit
a471c5c6e6
@ -25,6 +25,7 @@
|
||||
#include <QDateTime>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QToolTip>
|
||||
|
||||
#include <boost/concept_check.hpp>
|
||||
|
||||
@ -357,7 +358,7 @@ PlaylistItemDelegate::drawLoveBox( QPainter* painter, const QRect& rect, Playabl
|
||||
|
||||
QRect avatarsRect = innerRect.adjusted( 4, 4, -4, -4 );
|
||||
|
||||
drawAvatarsForBox( painter, avatarsRect, avatarSize, avatarMargin, count, sources );
|
||||
drawAvatarsForBox( painter, avatarsRect, avatarSize, avatarMargin, count, sources, index );
|
||||
|
||||
TomahawkUtils::ImageType type = item->query()->queryTrack()->loved() ? TomahawkUtils::Loved : TomahawkUtils::NotLoved;
|
||||
QRect r = innerRect.adjusted( innerRect.width() - rect.height() + 4, 4, -4, -4 );
|
||||
@ -369,9 +370,11 @@ PlaylistItemDelegate::drawLoveBox( QPainter* painter, const QRect& rect, Playabl
|
||||
|
||||
|
||||
QRect
|
||||
PlaylistItemDelegate::drawGenericBox( QPainter* painter, const QStyleOptionViewItem& option,
|
||||
PlaylistItemDelegate::drawGenericBox( QPainter* painter,
|
||||
const QStyleOptionViewItem& option,
|
||||
const QRect& rect, const QString& text,
|
||||
const QList< Tomahawk::source_ptr >& sources ) const
|
||||
const QList< Tomahawk::source_ptr >& sources,
|
||||
const QModelIndex& index ) const
|
||||
{
|
||||
const int avatarSize = rect.height() - 4 * 2;
|
||||
const int avatarMargin = 2;
|
||||
@ -397,7 +400,7 @@ PlaylistItemDelegate::drawGenericBox( QPainter* painter, const QStyleOptionViewI
|
||||
drawRectForBox( painter, innerRect );
|
||||
|
||||
QRect avatarsRect = innerRect.adjusted( textDoc.idealWidth() + 3*4, 4, -4, -4 );
|
||||
drawAvatarsForBox( painter, avatarsRect, avatarSize, avatarMargin, count, sources );
|
||||
drawAvatarsForBox( painter, avatarsRect, avatarSize, avatarMargin, count, sources, index );
|
||||
|
||||
return rect;
|
||||
}
|
||||
@ -421,20 +424,20 @@ PlaylistItemDelegate::drawRectForBox( QPainter* painter, const QRect& rect ) con
|
||||
|
||||
|
||||
void
|
||||
PlaylistItemDelegate::drawAvatarsForBox( QPainter* painter, const QRect& avatarsRect,
|
||||
int avatarSize, int avatarMargin, int count,
|
||||
const QList< Tomahawk::source_ptr >& sources ) const
|
||||
PlaylistItemDelegate::drawAvatarsForBox( QPainter* painter,
|
||||
const QRect& avatarsRect,
|
||||
int avatarSize,
|
||||
int avatarMargin,
|
||||
int count,
|
||||
const QList< Tomahawk::source_ptr >& sources,
|
||||
const QModelIndex& index ) const
|
||||
{
|
||||
QList< QPixmap > pixmaps;
|
||||
foreach ( const Tomahawk::source_ptr& s, sources )
|
||||
{
|
||||
pixmaps << s->avatar( TomahawkUtils::Original, QSize( avatarSize, avatarSize ) );
|
||||
}
|
||||
|
||||
painter->save();
|
||||
|
||||
QHash< Tomahawk::source_ptr, QRect > rectsToSave;
|
||||
|
||||
unsigned int i = 0;
|
||||
foreach ( QPixmap pixmap, pixmaps )
|
||||
foreach ( const Tomahawk::source_ptr& s, sources )
|
||||
{
|
||||
if ( i >= count )
|
||||
break;
|
||||
@ -442,13 +445,20 @@ PlaylistItemDelegate::drawAvatarsForBox( QPainter* painter, const QRect& avatars
|
||||
QRect r = avatarsRect.adjusted( ( avatarSize + avatarMargin ) * i, 0, 0, 0 );
|
||||
r.setWidth( avatarSize + avatarMargin );
|
||||
|
||||
QPixmap pixmap = s->avatar( TomahawkUtils::Original, QSize( avatarSize, avatarSize ) );
|
||||
|
||||
if ( pixmap.isNull() )
|
||||
pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultSourceAvatar, TomahawkUtils::Original, QSize( r.height(), r.height() ) );
|
||||
painter->drawPixmap( r.adjusted( avatarMargin/2, 0, -(avatarMargin/2), 0 ), pixmap );
|
||||
|
||||
rectsToSave.insert( s, r );
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if ( !rectsToSave.isEmpty() )
|
||||
m_avatarBoxRects.insert( index, rectsToSave );
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
@ -511,6 +521,8 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con
|
||||
|
||||
bool hoveringInfo = false;
|
||||
bool hoveringLove = false;
|
||||
Tomahawk::source_ptr hoveredAvatar;
|
||||
QRect hoveredAvatarRect;
|
||||
if ( m_infoButtonRects.contains( index ) )
|
||||
{
|
||||
const QRect infoRect = m_infoButtonRects[ index ];
|
||||
@ -523,6 +535,20 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con
|
||||
const QMouseEvent* ev = static_cast< QMouseEvent* >( event );
|
||||
hoveringLove = loveRect.contains( ev->pos() );
|
||||
}
|
||||
if ( m_avatarBoxRects.contains( index ) )
|
||||
{
|
||||
const QMouseEvent* ev = static_cast< QMouseEvent* >( event );
|
||||
for ( QHash< Tomahawk::source_ptr, QRect >::const_iterator it = m_avatarBoxRects[ index ].constBegin();
|
||||
it != m_avatarBoxRects[ index ].constEnd(); ++it )
|
||||
{
|
||||
if ( it.value().contains( ev->pos() ) )
|
||||
{
|
||||
hoveredAvatar = it.key();
|
||||
hoveredAvatarRect = it.value();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( event->type() == QEvent::MouseMove )
|
||||
{
|
||||
@ -531,6 +557,15 @@ PlaylistItemDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, con
|
||||
else
|
||||
m_view->setCursor( Qt::ArrowCursor );
|
||||
|
||||
if ( !hoveredAvatar.isNull() )
|
||||
{
|
||||
const QMouseEvent* ev = static_cast< QMouseEvent* >( event );
|
||||
QToolTip::showText( m_view->mapToGlobal( hoveredAvatarRect.bottomLeft() ),
|
||||
hoveredAvatar->friendlyName(),
|
||||
m_view,
|
||||
hoveredAvatarRect );
|
||||
}
|
||||
|
||||
if ( m_hoveringOver != index )
|
||||
{
|
||||
QPersistentModelIndex ti = m_hoveringOver;
|
||||
|
@ -67,12 +67,24 @@ protected:
|
||||
QRect drawInfoButton( QPainter* painter, const QRect& rect, const QModelIndex& index, float height ) const;
|
||||
QRect drawSourceIcon( QPainter* painter, const QRect& rect, PlayableItem* item, float height ) const;
|
||||
QRect drawCover( QPainter* painter, const QRect& rect, PlayableItem* item, const QModelIndex& index ) const;
|
||||
QRect drawLoveBox( QPainter* painter, const QRect& rect, PlayableItem* item, const QModelIndex& index ) const;
|
||||
QRect drawGenericBox( QPainter* painter, const QStyleOptionViewItem& option, const QRect& rect,
|
||||
const QString& text, const QList< Tomahawk::source_ptr >& sources ) const;
|
||||
QRect drawLoveBox( QPainter* painter,
|
||||
const QRect& rect,
|
||||
PlayableItem* item,
|
||||
const QModelIndex& index ) const;
|
||||
QRect drawGenericBox( QPainter* painter,
|
||||
const QStyleOptionViewItem& option,
|
||||
const QRect& rect,
|
||||
const QString& text,
|
||||
const QList< Tomahawk::source_ptr >& sources,
|
||||
const QModelIndex& index ) const;
|
||||
void drawRectForBox( QPainter* painter, const QRect& rect ) const;
|
||||
void drawAvatarsForBox( QPainter* painter, const QRect& avatarsRect, int avatarSize, int avatarMargin,
|
||||
int count, const QList< Tomahawk::source_ptr >& sources ) const;
|
||||
void drawAvatarsForBox( QPainter* painter,
|
||||
const QRect& avatarsRect,
|
||||
int avatarSize,
|
||||
int avatarMargin,
|
||||
int count,
|
||||
const QList< Tomahawk::source_ptr >& sources,
|
||||
const QModelIndex& index ) const;
|
||||
void drawRichText( QPainter* painter, const QStyleOptionViewItem& option, const QRect& rect, int flags, QTextDocument& text ) const;
|
||||
|
||||
void paintDetailed( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||
@ -98,6 +110,7 @@ private:
|
||||
mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps;
|
||||
mutable QHash< QPersistentModelIndex, QRect > m_infoButtonRects;
|
||||
mutable QHash< QPersistentModelIndex, QRect > m_loveButtonRects;
|
||||
mutable QHash< QPersistentModelIndex, QHash< Tomahawk::source_ptr, QRect > > m_avatarBoxRects;
|
||||
QPersistentModelIndex m_hoveringOver;
|
||||
|
||||
TrackView* m_view;
|
||||
|
@ -222,7 +222,7 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
||||
|
||||
QString timeString = TomahawkUtils::ageToString( earliestTimestamp, true );
|
||||
|
||||
drawGenericBox( painter, opt, leftRect, timeString, sources );
|
||||
drawGenericBox( painter, opt, leftRect, timeString, sources, index );
|
||||
}
|
||||
else if ( m_mode == RecentlyPlayed )
|
||||
{
|
||||
@ -233,7 +233,7 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
||||
|
||||
QString playtime = TomahawkUtils::ageToString( QDateTime::fromTime_t( item->playbackLog().timestamp ), true );
|
||||
|
||||
drawGenericBox( painter, opt, leftRect, playtime, sources );
|
||||
drawGenericBox( painter, opt, leftRect, playtime, sources, index );
|
||||
}
|
||||
}
|
||||
else if ( m_mode == LatestAdditions )
|
||||
@ -244,7 +244,7 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
||||
|
||||
QString modtime = TomahawkUtils::ageToString( QDateTime::fromTime_t( item->query()->results().first()->modificationTime() ), true );
|
||||
|
||||
drawGenericBox( painter, opt, leftRect, modtime, sources );
|
||||
drawGenericBox( painter, opt, leftRect, modtime, sources, index );
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user