mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-10 16:14:40 +02:00
Make sure we use the current font metrics when eliding text in TrackView.
This commit is contained in:
@@ -58,8 +58,6 @@ using namespace Tomahawk;
|
|||||||
|
|
||||||
PlaylistItemDelegate::PlaylistItemDelegate( TrackView* parent, PlayableProxyModel* proxy )
|
PlaylistItemDelegate::PlaylistItemDelegate( TrackView* parent, PlayableProxyModel* proxy )
|
||||||
: QStyledItemDelegate( (QObject*)parent )
|
: QStyledItemDelegate( (QObject*)parent )
|
||||||
, m_demiBoldFontMetrics( QFontMetrics( parent->font() ) )
|
|
||||||
, m_normalFontMetrics( QFontMetrics( parent->font() ) )
|
|
||||||
, m_view( parent )
|
, m_view( parent )
|
||||||
, m_model( proxy )
|
, m_model( proxy )
|
||||||
{
|
{
|
||||||
@@ -80,9 +78,6 @@ PlaylistItemDelegate::PlaylistItemDelegate( TrackView* parent, PlayableProxyMode
|
|||||||
m_normalFont = parent->font();
|
m_normalFont = parent->font();
|
||||||
m_normalFont.setPointSize( TomahawkUtils::defaultFontSize() + 1 );
|
m_normalFont.setPointSize( TomahawkUtils::defaultFontSize() + 1 );
|
||||||
|
|
||||||
m_normalFontMetrics = QFontMetrics( m_normalFont );
|
|
||||||
m_demiBoldFontMetrics = QFontMetrics( m_demiBoldFont );
|
|
||||||
|
|
||||||
connect( this, SIGNAL( updateIndex( QModelIndex ) ), parent, SLOT( update( QModelIndex ) ) );
|
connect( this, SIGNAL( updateIndex( QModelIndex ) ), parent, SLOT( update( QModelIndex ) ) );
|
||||||
connect( proxy, SIGNAL( modelReset() ), SLOT( modelChanged() ) );
|
connect( proxy, SIGNAL( modelReset() ), SLOT( modelChanged() ) );
|
||||||
connect( parent, SIGNAL( modelChanged() ), SLOT( modelChanged() ) );
|
connect( parent, SIGNAL( modelChanged() ), SLOT( modelChanged() ) );
|
||||||
@@ -624,14 +619,13 @@ PlaylistItemDelegate::drawTrack( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
painter->drawRect( rect.adjusted( 0, 4, -rightMargin, -4 ) );
|
painter->drawRect( rect.adjusted( 0, 4, -rightMargin, -4 ) );
|
||||||
}
|
}
|
||||||
painter->setPen( TomahawkStyle::SELECTION_FOREGROUND );
|
painter->setPen( TomahawkStyle::SELECTION_FOREGROUND );
|
||||||
|
painter->setFont( m_demiBoldFont );
|
||||||
|
|
||||||
QRect r = rect.adjusted( 32, 6, -32 -rightMargin, -6 );
|
QRect r = rect.adjusted( 32, 6, -32 -rightMargin, -6 );
|
||||||
const int margin = 8;
|
const int margin = 8;
|
||||||
|
|
||||||
painter->setFont( m_demiBoldFont );
|
const int numberWidth = painter->fontMetrics().width( "00" ) + 32;
|
||||||
|
const int durationWidth = painter->fontMetrics().width( "00:00" ) + 32;
|
||||||
const int numberWidth = m_demiBoldFontMetrics.width( "00" ) + 32;
|
|
||||||
const int durationWidth = m_demiBoldFontMetrics.width( "00:00" ) + 32;
|
|
||||||
int stateWidth = 0;
|
int stateWidth = 0;
|
||||||
|
|
||||||
QRect numberRect = QRect( r.x(), r.y(), numberWidth, r.height() );
|
QRect numberRect = QRect( r.x(), r.y(), numberWidth, r.height() );
|
||||||
@@ -667,13 +661,13 @@ PlaylistItemDelegate::drawTrack( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
opacityCo = 0.5;
|
opacityCo = 0.5;
|
||||||
|
|
||||||
painter->setOpacity( 1.0 * opacityCo );
|
painter->setOpacity( 1.0 * opacityCo );
|
||||||
QString text = m_demiBoldFontMetrics.elidedText( track->track(), Qt::ElideRight, titleRect.width() - margin );
|
QString text = painter->fontMetrics().elidedText( track->track(), Qt::ElideRight, titleRect.width() - margin );
|
||||||
painter->drawText( titleRect, text, m_centerOption );
|
painter->drawText( titleRect, text, m_centerOption );
|
||||||
|
|
||||||
// draw artist
|
// draw artist
|
||||||
painter->setOpacity( 0.8 * opacityCo );
|
painter->setOpacity( 0.8 * opacityCo );
|
||||||
painter->setFont( m_normalFont );
|
painter->setFont( m_normalFont );
|
||||||
text = m_normalFontMetrics.elidedText( track->artist(), Qt::ElideRight, artistRect.width() - margin );
|
text = painter->fontMetrics().elidedText( track->artist(), Qt::ElideRight, artistRect.width() - margin );
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
if ( m_hoveringOverArtist == index )
|
if ( m_hoveringOverArtist == index )
|
||||||
@@ -683,7 +677,7 @@ PlaylistItemDelegate::drawTrack( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
painter->setFont( f );
|
painter->setFont( f );
|
||||||
}
|
}
|
||||||
painter->drawText( artistRect, text, m_centerOption );
|
painter->drawText( artistRect, text, m_centerOption );
|
||||||
m_artistNameRects[ index ] = m_normalFontMetrics.boundingRect( artistRect, Qt::AlignLeft | Qt::AlignVCenter, text );
|
m_artistNameRects[ index ] = painter->fontMetrics().boundingRect( artistRect, Qt::AlignLeft | Qt::AlignVCenter, text );
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
// draw number or source icon
|
// draw number or source icon
|
||||||
|
@@ -107,9 +107,6 @@ protected:
|
|||||||
QFont m_demiBoldFont;
|
QFont m_demiBoldFont;
|
||||||
QFont m_normalFont;
|
QFont m_normalFont;
|
||||||
|
|
||||||
QFontMetrics m_demiBoldFontMetrics;
|
|
||||||
QFontMetrics m_normalFontMetrics;
|
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
virtual void modelChanged();
|
virtual void modelChanged();
|
||||||
virtual void onAudioEngineTick( qint64 ms );
|
virtual void onAudioEngineTick( qint64 ms );
|
||||||
|
Reference in New Issue
Block a user