mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-18 23:09:42 +01:00
* Let's make alignment a data-role as it's intended to be.
This commit is contained in:
parent
1e022bf627
commit
9f99108701
@ -56,12 +56,6 @@ PlaylistItemDelegate::PlaylistItemDelegate( TrackView* parent, TrackProxyModel*
|
||||
m_bottomOption = QTextOption( Qt::AlignBottom );
|
||||
m_bottomOption.setWrapMode( QTextOption::NoWrap );
|
||||
|
||||
m_verticalCenterOption = QTextOption( Qt::AlignVCenter );
|
||||
m_verticalCenterOption.setWrapMode( QTextOption::NoWrap );
|
||||
|
||||
m_centerOption = QTextOption( Qt::AlignCenter );
|
||||
m_centerOption.setWrapMode( QTextOption::NoWrap );
|
||||
|
||||
m_defaultAvatar = TomahawkUtils::createAvatarFrame( QPixmap( RESPATH "images/user-avatar.png" ) );
|
||||
}
|
||||
|
||||
@ -255,6 +249,9 @@ PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewIt
|
||||
TrackModelItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) );
|
||||
Q_ASSERT( item );
|
||||
|
||||
QTextOption textOption( Qt::AlignVCenter | (Qt::Alignment)index.data( Qt::TextAlignmentRole ).toUInt() );
|
||||
textOption.setWrapMode( QTextOption::NoWrap );
|
||||
|
||||
QStyleOptionViewItemV4 opt = option;
|
||||
prepareStyleOption( &opt, index, item );
|
||||
opt.text.clear();
|
||||
@ -297,48 +294,26 @@ PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewIt
|
||||
}
|
||||
else if ( item->isPlaying() )
|
||||
{
|
||||
QRect r = opt.rect.adjusted( 3, 0, 0, 0 );
|
||||
|
||||
// Paint Now Playing Speaker Icon
|
||||
if ( m_view->header()->visualIndex( index.column() ) == 0 )
|
||||
{
|
||||
QRect r = opt.rect.adjusted( 3, 0, 0, 0 );
|
||||
|
||||
// Paint Now Playing Speaker Icon
|
||||
if ( m_view->header()->visualIndex( index.column() ) == 0 )
|
||||
{
|
||||
r.adjust( 0, 0, 0, -3 );
|
||||
painter->drawPixmap( r.adjusted( 3, 1, 18 - r.width(), 1 ), m_nowPlayingIcon );
|
||||
r.adjust( 25, 0, 0, 3 );
|
||||
}
|
||||
|
||||
painter->setPen( opt.palette.text().color() );
|
||||
QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, r.width() - 3 );
|
||||
painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, textOptionForColumn( index.column() ) );
|
||||
r.adjust( 0, 0, 0, -3 );
|
||||
painter->drawPixmap( r.adjusted( 3, 1, 18 - r.width(), 1 ), m_nowPlayingIcon );
|
||||
r.adjust( 25, 0, 0, 3 );
|
||||
}
|
||||
|
||||
painter->setPen( opt.palette.text().color() );
|
||||
QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, r.width() - 3 );
|
||||
painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, textOption );
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->setPen( opt.palette.text().color() );
|
||||
QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, opt.rect.width() - 6 );
|
||||
painter->drawText( opt.rect.adjusted( 3, 1, -3, 0 ), text, textOptionForColumn( index.column() ) );
|
||||
painter->drawText( opt.rect.adjusted( 3, 1, -3, 0 ), text, textOption );
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
const QTextOption
|
||||
PlaylistItemDelegate::textOptionForColumn( int column ) const
|
||||
{
|
||||
switch( column )
|
||||
{
|
||||
case TrackModel::Age:
|
||||
case TrackModel::AlbumPos:
|
||||
case TrackModel::Bitrate:
|
||||
case TrackModel::Duration:
|
||||
case TrackModel::Filesize:
|
||||
case TrackModel::Year:
|
||||
return m_centerOption;
|
||||
break;
|
||||
|
||||
default:
|
||||
return m_verticalCenterOption;
|
||||
}
|
||||
}
|
||||
|
@ -52,8 +52,6 @@ private:
|
||||
void paintDetailed( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||
void paintShort( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, bool useAvatars = false ) const;
|
||||
|
||||
const QTextOption textOptionForColumn( int column ) const;
|
||||
|
||||
unsigned int m_removalProgress;
|
||||
|
||||
mutable QHash< qint64, QPixmap > m_cache;
|
||||
@ -61,9 +59,7 @@ private:
|
||||
mutable QPixmap m_arrowIcon;
|
||||
|
||||
QTextOption m_topOption;
|
||||
QTextOption m_centerOption;
|
||||
QTextOption m_bottomOption;
|
||||
QTextOption m_verticalCenterOption;
|
||||
|
||||
TrackView* m_view;
|
||||
TrackProxyModel* m_model;
|
||||
|
@ -136,6 +136,24 @@ TrackModel::data( const QModelIndex& index, int role ) const
|
||||
return QSize( 0, 18 );
|
||||
}
|
||||
|
||||
if ( role == Qt::TextAlignmentRole )
|
||||
{
|
||||
switch( index.column() )
|
||||
{
|
||||
case Age:
|
||||
case AlbumPos:
|
||||
case Bitrate:
|
||||
case Duration:
|
||||
case Filesize:
|
||||
case Year:
|
||||
return Qt::AlignHCenter;
|
||||
break;
|
||||
|
||||
default:
|
||||
return Qt::AlignLeft;
|
||||
}
|
||||
}
|
||||
|
||||
if ( role == StyleRole )
|
||||
{
|
||||
return m_style;
|
||||
|
Loading…
x
Reference in New Issue
Block a user