mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 06:07:37 +02:00
* Improvements to item-delegates.
This commit is contained in:
@@ -240,20 +240,7 @@ PlayableModel::queryData( const query_ptr& query, int column, int role ) const
|
|||||||
case Score:
|
case Score:
|
||||||
{
|
{
|
||||||
float score = query->results().first()->score();
|
float score = query->results().first()->score();
|
||||||
if ( score == 1.0 )
|
return scoreText( score );
|
||||||
return tr( "Perfect match" );
|
|
||||||
if ( score > 0.9 )
|
|
||||||
return tr( "Very good match" );
|
|
||||||
if ( score > 0.7 )
|
|
||||||
return tr( "Good match" );
|
|
||||||
if ( score > 0.5 )
|
|
||||||
return tr( "Vague match" );
|
|
||||||
if ( score > 0.3 )
|
|
||||||
return tr( "Bad match" );
|
|
||||||
if ( score > 0.0 )
|
|
||||||
return tr( "Very bad match" );
|
|
||||||
|
|
||||||
return tr( "Not available" );
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,9 +254,9 @@ PlayableModel::queryData( const query_ptr& query, int column, int role ) const
|
|||||||
{
|
{
|
||||||
case Score:
|
case Score:
|
||||||
if ( query->resolvingFinished() )
|
if ( query->resolvingFinished() )
|
||||||
return tr( "Not available" );
|
return scoreText( 0.0 );
|
||||||
else
|
else
|
||||||
return tr( "Searching..." );
|
return scoreText( -1.0 );
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -751,6 +738,41 @@ PlayableModel::columnAlignment( int column ) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString
|
||||||
|
PlayableModel::scoreText( float score ) const
|
||||||
|
{
|
||||||
|
static QMap<float, QString> texts;
|
||||||
|
if ( texts.isEmpty() )
|
||||||
|
{
|
||||||
|
texts[ 1.0 ] = tr( "Perfect match" );
|
||||||
|
texts[ 0.9 ] = tr( "Very good match" );
|
||||||
|
texts[ 0.7 ] = tr( "Good match" );
|
||||||
|
texts[ 0.5 ] = tr( "Vague match" );
|
||||||
|
texts[ 0.3 ] = tr( "Bad match" );
|
||||||
|
texts[ 0.1 ] = tr( "Very bad match" );
|
||||||
|
texts[ 0.0 ] = tr( "Not available" );
|
||||||
|
texts[ -1.0 ] = tr( "Searching..." );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( score == 1.0 )
|
||||||
|
return texts[ 1.0 ];
|
||||||
|
if ( score > 0.9 )
|
||||||
|
return texts[ 0.9 ];
|
||||||
|
if ( score > 0.7 )
|
||||||
|
return texts[ 0.7 ];
|
||||||
|
if ( score > 0.5 )
|
||||||
|
return texts[ 0.5 ];
|
||||||
|
if ( score > 0.3 )
|
||||||
|
return texts[ 0.3 ];
|
||||||
|
if ( score > 0.0 )
|
||||||
|
return texts[ 0.1 ];
|
||||||
|
if ( score == 0.0 )
|
||||||
|
return texts[ 0.0 ];
|
||||||
|
|
||||||
|
return texts[ -1.0 ];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlayableModel::onDataChanged()
|
PlayableModel::onDataChanged()
|
||||||
{
|
{
|
||||||
|
@@ -171,6 +171,7 @@ private:
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
void insertInternal( const QList< T >& items, int row, const QList< Tomahawk::PlaybackLog >& logs = QList< Tomahawk::PlaybackLog >() );
|
void insertInternal( const QList< T >& items, int row, const QList< Tomahawk::PlaybackLog >& logs = QList< Tomahawk::PlaybackLog >() );
|
||||||
|
|
||||||
|
QString scoreText( float score ) const;
|
||||||
Qt::Alignment columnAlignment( int column ) const;
|
Qt::Alignment columnAlignment( int column ) const;
|
||||||
|
|
||||||
PlayableItem* m_rootItem;
|
PlayableItem* m_rootItem;
|
||||||
|
@@ -99,7 +99,7 @@ PlaylistItemDelegate::prepareStyleOption( QStyleOptionViewItemV4* option, const
|
|||||||
void
|
void
|
||||||
PlaylistItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
PlaylistItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||||
{
|
{
|
||||||
int style = index.data( PlayableProxyModel::StyleRole ).toInt();
|
const int style = index.data( PlayableProxyModel::StyleRole ).toInt();
|
||||||
switch ( style )
|
switch ( style )
|
||||||
{
|
{
|
||||||
case PlayableProxyModel::Detailed:
|
case PlayableProxyModel::Detailed:
|
||||||
@@ -160,7 +160,7 @@ PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
{
|
{
|
||||||
const int pixMargin = 2;
|
const int pixMargin = 2;
|
||||||
const int pixHeight = r.height() - pixMargin * 2;
|
const int pixHeight = r.height() - pixMargin * 2;
|
||||||
QRect npr = r.adjusted( pixMargin, pixMargin + 1, pixHeight - r.width() + pixMargin, -pixMargin + 1 );
|
const QRect npr = r.adjusted( pixMargin, pixMargin + 1, pixHeight - r.width() + pixMargin, -pixMargin + 1 );
|
||||||
painter->drawPixmap( npr, TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeaker, TomahawkUtils::Original, npr.size() ) );
|
painter->drawPixmap( npr, TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeaker, TomahawkUtils::Original, npr.size() ) );
|
||||||
r.adjust( pixHeight + 8, 0, 0, 0 );
|
r.adjust( pixHeight + 8, 0, 0, 0 );
|
||||||
}
|
}
|
||||||
@@ -225,10 +225,8 @@ PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewIt
|
|||||||
( index.column() == PlayableModel::Artist || index.column() == PlayableModel::Album || index.column() == PlayableModel::Track ) )
|
( index.column() == PlayableModel::Artist || index.column() == PlayableModel::Album || index.column() == PlayableModel::Track ) )
|
||||||
{
|
{
|
||||||
opt.rect.setWidth( opt.rect.width() - opt.rect.height() - 2 );
|
opt.rect.setWidth( opt.rect.width() - opt.rect.height() - 2 );
|
||||||
QRect arrowRect( opt.rect.x() + opt.rect.width(), opt.rect.y() + 1, opt.rect.height() - 2, opt.rect.height() - 2 );
|
const QRect arrowRect( opt.rect.x() + opt.rect.width(), opt.rect.y() + 1, opt.rect.height() - 2, opt.rect.height() - 2 );
|
||||||
|
painter->drawPixmap( arrowRect, TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, arrowRect.size() ) );
|
||||||
QPixmap infoIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, arrowRect.size() );
|
|
||||||
painter->drawPixmap( arrowRect, infoIcon );
|
|
||||||
|
|
||||||
m_infoButtonRects[ index ] = arrowRect;
|
m_infoButtonRects[ index ] = arrowRect;
|
||||||
}
|
}
|
||||||
@@ -257,7 +255,8 @@ PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewIt
|
|||||||
|
|
||||||
painter->drawRect( fillR );
|
painter->drawRect( fillR );
|
||||||
}
|
}
|
||||||
else */ if ( item->isPlaying() )
|
else */
|
||||||
|
if ( item->isPlaying() )
|
||||||
{
|
{
|
||||||
QRect r = opt.rect.adjusted( 3, 0, 0, 0 );
|
QRect r = opt.rect.adjusted( 3, 0, 0, 0 );
|
||||||
|
|
||||||
@@ -266,19 +265,19 @@ PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewIt
|
|||||||
{
|
{
|
||||||
const int pixMargin = 1;
|
const int pixMargin = 1;
|
||||||
const int pixHeight = r.height() - pixMargin * 2;
|
const int pixHeight = r.height() - pixMargin * 2;
|
||||||
QRect npr = r.adjusted( pixMargin, pixMargin, pixHeight - r.width() + pixMargin, -pixMargin );
|
const QRect npr = r.adjusted( pixMargin, pixMargin, pixHeight - r.width() + pixMargin, -pixMargin );
|
||||||
painter->drawPixmap( npr, TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeaker, TomahawkUtils::Original, npr.size() ) );
|
painter->drawPixmap( npr, TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeaker, TomahawkUtils::Original, npr.size() ) );
|
||||||
r.adjust( pixHeight + 6, 0, 0, 0 );
|
r.adjust( pixHeight + 6, 0, 0, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->setPen( opt.palette.text().color() );
|
painter->setPen( opt.palette.text().color() );
|
||||||
QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, r.width() - 3 );
|
const QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, r.width() - 3 );
|
||||||
painter->drawText( r.adjusted( 0, 1, 0, 0 ), text, textOption );
|
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 );
|
const QString text = painter->fontMetrics().elidedText( index.data().toString(), Qt::ElideRight, opt.rect.width() - 6 );
|
||||||
painter->drawText( opt.rect.adjusted( 3, 1, -3, 0 ), text, textOption );
|
painter->drawText( opt.rect.adjusted( 3, 1, -3, 0 ), text, textOption );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user