diff --git a/src/libtomahawk/playlist/PlayableModel.cpp b/src/libtomahawk/playlist/PlayableModel.cpp index 4ccb20b7a..499a3707b 100644 --- a/src/libtomahawk/playlist/PlayableModel.cpp +++ b/src/libtomahawk/playlist/PlayableModel.cpp @@ -240,20 +240,7 @@ PlayableModel::queryData( const query_ptr& query, int column, int role ) const case Score: { float score = query->results().first()->score(); - if ( score == 1.0 ) - 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" ); + return scoreText( score ); break; } @@ -267,9 +254,9 @@ PlayableModel::queryData( const query_ptr& query, int column, int role ) const { case Score: if ( query->resolvingFinished() ) - return tr( "Not available" ); + return scoreText( 0.0 ); else - return tr( "Searching..." ); + return scoreText( -1.0 ); default: break; @@ -751,6 +738,41 @@ PlayableModel::columnAlignment( int column ) const } +QString +PlayableModel::scoreText( float score ) const +{ + static QMap 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 PlayableModel::onDataChanged() { diff --git a/src/libtomahawk/playlist/PlayableModel.h b/src/libtomahawk/playlist/PlayableModel.h index 0f228c916..4f0d91dfd 100644 --- a/src/libtomahawk/playlist/PlayableModel.h +++ b/src/libtomahawk/playlist/PlayableModel.h @@ -171,6 +171,7 @@ private: template 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; PlayableItem* m_rootItem; diff --git a/src/libtomahawk/playlist/PlaylistItemDelegate.cpp b/src/libtomahawk/playlist/PlaylistItemDelegate.cpp index ea3682224..a6c5c6952 100644 --- a/src/libtomahawk/playlist/PlaylistItemDelegate.cpp +++ b/src/libtomahawk/playlist/PlaylistItemDelegate.cpp @@ -99,7 +99,7 @@ PlaylistItemDelegate::prepareStyleOption( QStyleOptionViewItemV4* option, const void 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 ) { case PlayableProxyModel::Detailed: @@ -160,7 +160,7 @@ PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem& { const int 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() ) ); 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 ) ) { 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 ); - - QPixmap infoIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::InfoIcon, TomahawkUtils::Original, arrowRect.size() ); - painter->drawPixmap( arrowRect, infoIcon ); + 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() ) ); m_infoButtonRects[ index ] = arrowRect; } @@ -257,7 +255,8 @@ PlaylistItemDelegate::paintDetailed( QPainter* painter, const QStyleOptionViewIt painter->drawRect( fillR ); } - else */ if ( item->isPlaying() ) + else */ + if ( item->isPlaying() ) { 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 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() ) ); r.adjust( pixHeight + 6, 0, 0, 0 ); } 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 ); } else { 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 ); }