diff --git a/src/libtomahawk/playlist/PlaylistChartItemDelegate.cpp b/src/libtomahawk/playlist/PlaylistChartItemDelegate.cpp index 9c13106f4..760795143 100644 --- a/src/libtomahawk/playlist/PlaylistChartItemDelegate.cpp +++ b/src/libtomahawk/playlist/PlaylistChartItemDelegate.cpp @@ -75,7 +75,7 @@ PlaylistChartItemDelegate::sizeHint( const QStyleOptionViewItem& option, const Q case 2: stretch = 4; break; - + default: if ( index.row() < 10 ) stretch = 3; @@ -108,27 +108,7 @@ PlaylistChartItemDelegate::prepareStyleOption( QStyleOptionViewItemV4* option, c { initStyleOption( option, index ); - if ( item->isPlaying() ) - { - option->palette.setColor( QPalette::Highlight, option->palette.color( QPalette::Mid ) ); - option->state |= QStyle::State_Selected; - } - - if ( option->state & QStyle::State_Selected ) - { - option->palette.setColor( QPalette::Text, option->palette.color( QPalette::HighlightedText ) ); - } - else - { - float opacity = 0.0; - if ( item->query()->results().count() ) - opacity = item->query()->results().first()->score(); - - opacity = qMax( (float)0.3, opacity ); - QColor textColor = TomahawkUtils::alphaBlend( option->palette.color( QPalette::Text ), option->palette.color( QPalette::BrightText ), opacity ); - - option->palette.setColor( QPalette::Text, textColor ); - } + TomahawkUtils::prepareStyleOption( option, index, item ); } @@ -230,7 +210,7 @@ PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultTrackImage, TomahawkUtils::ScaledCover, pixmapRect.size() ); } painter->drawPixmap( pixmapRect, pixmap ); - + r.adjust( pixmapRect.width() + figureRect.width() + 18, 1, -28, 0 ); QRect leftRect = r.adjusted( 0, 0, -48, 0 ); QRect rightRect = r.adjusted( r.width() - 40, 0, 0, 0 ); diff --git a/src/libtomahawk/playlist/PlaylistLargeItemDelegate.cpp b/src/libtomahawk/playlist/PlaylistLargeItemDelegate.cpp index 95ff66915..561e69366 100644 --- a/src/libtomahawk/playlist/PlaylistLargeItemDelegate.cpp +++ b/src/libtomahawk/playlist/PlaylistLargeItemDelegate.cpp @@ -87,27 +87,7 @@ PlaylistLargeItemDelegate::prepareStyleOption( QStyleOptionViewItemV4* option, c { initStyleOption( option, index ); - if ( item->isPlaying() ) - { - option->palette.setColor( QPalette::Highlight, option->palette.color( QPalette::Mid ) ); - option->state |= QStyle::State_Selected; - } - - if ( option->state & QStyle::State_Selected ) - { - option->palette.setColor( QPalette::Text, option->palette.color( QPalette::HighlightedText ) ); - } - else - { - float opacity = 0.0; - if ( item->query()->results().count() ) - opacity = item->query()->results().first()->score(); - - opacity = qMax( (float)0.3, opacity ); - QColor textColor = TomahawkUtils::alphaBlend( option->palette.color( QPalette::Text ), option->palette.color( QPalette::BrightText ), opacity ); - - option->palette.setColor( QPalette::Text, textColor ); - } + TomahawkUtils::prepareStyleOption( option, index, item ); } @@ -207,7 +187,7 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& QRect pixmapRect = r.adjusted( 6, 0, -option.rect.width() + option.rect.height() - 6 + r.left(), 0 ); QRect avatarRect = r.adjusted( option.rect.width() - r.left() - 12 - avatarSize.width(), ( option.rect.height() - avatarSize.height() ) / 2 - 5, 0, 0 ); avatarRect.setSize( avatarSize ); - + pixmap = item->query()->cover( pixmapRect.size(), false ); if ( !pixmap ) { @@ -215,7 +195,7 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& } painter->drawPixmap( pixmapRect, pixmap ); - + if ( !avatar.isNull() ) painter->drawPixmap( avatarRect, avatar ); @@ -250,7 +230,7 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& textDoc.setDocumentMargin( 0 ); textDoc.setDefaultFont( painter->font() ); textDoc.setDefaultTextOption( m_bottomOption ); - + if ( textDoc.idealWidth() > leftRect.width() ) textDoc.setHtml( item->query()->socialActionDescription( "Love", Query::Short ) ); diff --git a/src/libtomahawk/playlist/playlistitemdelegate.cpp b/src/libtomahawk/playlist/playlistitemdelegate.cpp index 696ad2ad2..5bd8b6c06 100644 --- a/src/libtomahawk/playlist/playlistitemdelegate.cpp +++ b/src/libtomahawk/playlist/playlistitemdelegate.cpp @@ -94,30 +94,7 @@ PlaylistItemDelegate::prepareStyleOption( QStyleOptionViewItemV4* option, const { initStyleOption( option, index ); - if ( item->isPlaying() ) - { - option->palette.setColor( QPalette::Highlight, option->palette.color( QPalette::Mid ) ); - - option->backgroundBrush = option->palette.color( QPalette::Mid ); - option->palette.setColor( QPalette::Text, option->palette.color( QPalette::Text ) ); - - } - - if ( option->state & QStyle::State_Selected && !item->isPlaying() ) - { - option->palette.setColor( QPalette::Text, option->palette.color( QPalette::HighlightedText ) ); - } - else - { - float opacity = 0.0; - if ( item->query()->results().count() ) - opacity = item->query()->results().first()->score(); - - opacity = qMax( (float)0.3, opacity ); - QColor textColor = TomahawkUtils::alphaBlend( option->palette.color( QPalette::Text ), option->palette.color( QPalette::BrightText ), opacity ); - - option->palette.setColor( QPalette::Text, textColor ); - } + TomahawkUtils::prepareStyleOption( option, index, item ); } diff --git a/src/libtomahawk/utils/tomahawkutilsgui.cpp b/src/libtomahawk/utils/tomahawkutilsgui.cpp index 583b7de6c..05f68ad75 100644 --- a/src/libtomahawk/utils/tomahawkutilsgui.cpp +++ b/src/libtomahawk/utils/tomahawkutilsgui.cpp @@ -17,16 +17,21 @@ * along with Tomahawk. If not, see . */ -#include "config.h" #include "tomahawkutilsgui.h" +#include "config.h" +#include "query.h" +#include "result.h" #include "logger.h" +#include "trackmodelitem.h" + #include #include #include #include #include #include +#include #ifdef Q_WS_X11 #include @@ -344,7 +349,7 @@ defaultPixmap( ImageType type, ImageMode mode, const QSize& size ) case DefaultTrackImage: pixmap = QPixmap( RESPATH "images/track-placeholder.png" ); break; - + case DefaultSourceAvatar: if ( mode == AvatarInFrame ) pixmap = TomahawkUtils::createAvatarFrame( QPixmap( RESPATH "images/user-avatar.png" ) ); @@ -380,4 +385,33 @@ defaultPixmap( ImageType type, ImageMode mode, const QSize& size ) } +void +prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, TrackModelItem* item ) +{ + if ( item->isPlaying() ) + { + option->palette.setColor( QPalette::Highlight, option->palette.color( QPalette::Mid ) ); + + option->backgroundBrush = option->palette.color( QPalette::Mid ); + option->palette.setColor( QPalette::Text, option->palette.color( QPalette::Text ) ); + + } + + if ( option->state & QStyle::State_Selected && !item->isPlaying() ) + { + option->palette.setColor( QPalette::Text, option->palette.color( QPalette::HighlightedText ) ); + } + else + { + float opacity = 0.0; + if ( item->query()->results().count() ) + opacity = item->query()->results().first()->score(); + + opacity = qMax( (float)0.3, opacity ); + QColor textColor = alphaBlend( option->palette.color( QPalette::Text ), option->palette.color( QPalette::BrightText ), opacity ); + + option->palette.setColor( QPalette::Text, textColor ); + } +} + } // ns diff --git a/src/libtomahawk/utils/tomahawkutilsgui.h b/src/libtomahawk/utils/tomahawkutilsgui.h index 86e842014..d6e47f584 100644 --- a/src/libtomahawk/utils/tomahawkutilsgui.h +++ b/src/libtomahawk/utils/tomahawkutilsgui.h @@ -21,10 +21,13 @@ #define TOMAHAWKUTILSGUI_H #include +#include #include "tomahawkutils.h" #include "dllmacro.h" +class TrackModelItem; +class QStyleOptionViewItemV4; class QPainter; class QColor; class QPixmap; @@ -52,6 +55,8 @@ namespace TomahawkUtils DLLEXPORT QPixmap defaultPixmap( ImageType type, ImageMode mode = TomahawkUtils::Original, const QSize& size = QSize( 0, 0 ) ); + DLLEXPORT void prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, TrackModelItem* item ); + } #endif // TOMAHAWKUTILSGUI_H