1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-09 07:36:48 +02:00

TWK-815: Lets not copy and paste the same code in 3 places and only fix it in one :)

This commit is contained in:
Leo Franchi
2012-04-01 13:43:06 -04:00
parent 57e36d5d01
commit 83a35fe3aa
5 changed files with 49 additions and 73 deletions

View File

@@ -75,7 +75,7 @@ PlaylistChartItemDelegate::sizeHint( const QStyleOptionViewItem& option, const Q
case 2: case 2:
stretch = 4; stretch = 4;
break; break;
default: default:
if ( index.row() < 10 ) if ( index.row() < 10 )
stretch = 3; stretch = 3;
@@ -108,27 +108,7 @@ PlaylistChartItemDelegate::prepareStyleOption( QStyleOptionViewItemV4* option, c
{ {
initStyleOption( option, index ); initStyleOption( option, index );
if ( item->isPlaying() ) TomahawkUtils::prepareStyleOption( option, index, item );
{
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 );
}
} }
@@ -230,7 +210,7 @@ PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultTrackImage, TomahawkUtils::ScaledCover, pixmapRect.size() ); pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultTrackImage, TomahawkUtils::ScaledCover, pixmapRect.size() );
} }
painter->drawPixmap( pixmapRect, pixmap ); painter->drawPixmap( pixmapRect, pixmap );
r.adjust( pixmapRect.width() + figureRect.width() + 18, 1, -28, 0 ); r.adjust( pixmapRect.width() + figureRect.width() + 18, 1, -28, 0 );
QRect leftRect = r.adjusted( 0, 0, -48, 0 ); QRect leftRect = r.adjusted( 0, 0, -48, 0 );
QRect rightRect = r.adjusted( r.width() - 40, 0, 0, 0 ); QRect rightRect = r.adjusted( r.width() - 40, 0, 0, 0 );

View File

@@ -87,27 +87,7 @@ PlaylistLargeItemDelegate::prepareStyleOption( QStyleOptionViewItemV4* option, c
{ {
initStyleOption( option, index ); initStyleOption( option, index );
if ( item->isPlaying() ) TomahawkUtils::prepareStyleOption( option, index, item );
{
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 );
}
} }
@@ -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 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 ); QRect avatarRect = r.adjusted( option.rect.width() - r.left() - 12 - avatarSize.width(), ( option.rect.height() - avatarSize.height() ) / 2 - 5, 0, 0 );
avatarRect.setSize( avatarSize ); avatarRect.setSize( avatarSize );
pixmap = item->query()->cover( pixmapRect.size(), false ); pixmap = item->query()->cover( pixmapRect.size(), false );
if ( !pixmap ) if ( !pixmap )
{ {
@@ -215,7 +195,7 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
} }
painter->drawPixmap( pixmapRect, pixmap ); painter->drawPixmap( pixmapRect, pixmap );
if ( !avatar.isNull() ) if ( !avatar.isNull() )
painter->drawPixmap( avatarRect, avatar ); painter->drawPixmap( avatarRect, avatar );
@@ -250,7 +230,7 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
textDoc.setDocumentMargin( 0 ); textDoc.setDocumentMargin( 0 );
textDoc.setDefaultFont( painter->font() ); textDoc.setDefaultFont( painter->font() );
textDoc.setDefaultTextOption( m_bottomOption ); textDoc.setDefaultTextOption( m_bottomOption );
if ( textDoc.idealWidth() > leftRect.width() ) if ( textDoc.idealWidth() > leftRect.width() )
textDoc.setHtml( item->query()->socialActionDescription( "Love", Query::Short ) ); textDoc.setHtml( item->query()->socialActionDescription( "Love", Query::Short ) );

View File

@@ -94,30 +94,7 @@ PlaylistItemDelegate::prepareStyleOption( QStyleOptionViewItemV4* option, const
{ {
initStyleOption( option, index ); initStyleOption( option, index );
if ( item->isPlaying() ) TomahawkUtils::prepareStyleOption( option, index, item );
{
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 );
}
} }

View File

@@ -17,16 +17,21 @@
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "config.h"
#include "tomahawkutilsgui.h" #include "tomahawkutilsgui.h"
#include "config.h"
#include "query.h"
#include "result.h"
#include "logger.h" #include "logger.h"
#include "trackmodelitem.h"
#include <QtGui/QLayout> #include <QtGui/QLayout>
#include <QtGui/QPainter> #include <QtGui/QPainter>
#include <QtGui/QPixmap> #include <QtGui/QPixmap>
#include <QtGui/QPalette> #include <QtGui/QPalette>
#include <QtGui/QApplication> #include <QtGui/QApplication>
#include <QtGui/QWidget> #include <QtGui/QWidget>
#include <QStyleOption>
#ifdef Q_WS_X11 #ifdef Q_WS_X11
#include <QtGui/QX11Info> #include <QtGui/QX11Info>
@@ -344,7 +349,7 @@ defaultPixmap( ImageType type, ImageMode mode, const QSize& size )
case DefaultTrackImage: case DefaultTrackImage:
pixmap = QPixmap( RESPATH "images/track-placeholder.png" ); pixmap = QPixmap( RESPATH "images/track-placeholder.png" );
break; break;
case DefaultSourceAvatar: case DefaultSourceAvatar:
if ( mode == AvatarInFrame ) if ( mode == AvatarInFrame )
pixmap = TomahawkUtils::createAvatarFrame( QPixmap( RESPATH "images/user-avatar.png" ) ); 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 } // ns

View File

@@ -21,10 +21,13 @@
#define TOMAHAWKUTILSGUI_H #define TOMAHAWKUTILSGUI_H
#include <QSize> #include <QSize>
#include <QModelIndex>
#include "tomahawkutils.h" #include "tomahawkutils.h"
#include "dllmacro.h" #include "dllmacro.h"
class TrackModelItem;
class QStyleOptionViewItemV4;
class QPainter; class QPainter;
class QColor; class QColor;
class QPixmap; class QPixmap;
@@ -52,6 +55,8 @@ namespace TomahawkUtils
DLLEXPORT QPixmap defaultPixmap( ImageType type, ImageMode mode = TomahawkUtils::Original, const QSize& size = QSize( 0, 0 ) ); 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 #endif // TOMAHAWKUTILSGUI_H