mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
* Let's make alignment a data-role as it's intended to be.
This commit is contained in:
@@ -56,12 +56,6 @@ PlaylistItemDelegate::PlaylistItemDelegate( TrackView* parent, TrackProxyModel*
|
|||||||
m_bottomOption = QTextOption( Qt::AlignBottom );
|
m_bottomOption = QTextOption( Qt::AlignBottom );
|
||||||
m_bottomOption.setWrapMode( QTextOption::NoWrap );
|
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" ) );
|
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 ) );
|
TrackModelItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) );
|
||||||
Q_ASSERT( item );
|
Q_ASSERT( item );
|
||||||
|
|
||||||
|
QTextOption textOption( Qt::AlignVCenter | (Qt::Alignment)index.data( Qt::TextAlignmentRole ).toUInt() );
|
||||||
|
textOption.setWrapMode( QTextOption::NoWrap );
|
||||||
|
|
||||||
QStyleOptionViewItemV4 opt = option;
|
QStyleOptionViewItemV4 opt = option;
|
||||||
prepareStyleOption( &opt, index, item );
|
prepareStyleOption( &opt, index, item );
|
||||||
opt.text.clear();
|
opt.text.clear();
|
||||||
@@ -297,48 +294,26 @@ PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewIt
|
|||||||
}
|
}
|
||||||
else if ( item->isPlaying() )
|
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 );
|
r.adjust( 0, 0, 0, -3 );
|
||||||
|
painter->drawPixmap( r.adjusted( 3, 1, 18 - r.width(), 1 ), m_nowPlayingIcon );
|
||||||
// Paint Now Playing Speaker Icon
|
r.adjust( 25, 0, 0, 3 );
|
||||||
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() ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
else
|
||||||
{
|
{
|
||||||
painter->setPen( opt.palette.text().color() );
|
painter->setPen( opt.palette.text().color() );
|
||||||
QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, opt.rect.width() - 6 );
|
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();
|
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 paintDetailed( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
void paintShort( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, bool useAvatars = false ) 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;
|
unsigned int m_removalProgress;
|
||||||
|
|
||||||
mutable QHash< qint64, QPixmap > m_cache;
|
mutable QHash< qint64, QPixmap > m_cache;
|
||||||
@@ -61,9 +59,7 @@ private:
|
|||||||
mutable QPixmap m_arrowIcon;
|
mutable QPixmap m_arrowIcon;
|
||||||
|
|
||||||
QTextOption m_topOption;
|
QTextOption m_topOption;
|
||||||
QTextOption m_centerOption;
|
|
||||||
QTextOption m_bottomOption;
|
QTextOption m_bottomOption;
|
||||||
QTextOption m_verticalCenterOption;
|
|
||||||
|
|
||||||
TrackView* m_view;
|
TrackView* m_view;
|
||||||
TrackProxyModel* m_model;
|
TrackProxyModel* m_model;
|
||||||
|
@@ -136,6 +136,24 @@ TrackModel::data( const QModelIndex& index, int role ) const
|
|||||||
return QSize( 0, 18 );
|
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 )
|
if ( role == StyleRole )
|
||||||
{
|
{
|
||||||
return m_style;
|
return m_style;
|
||||||
|
Reference in New Issue
Block a user