1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-10 16:14:40 +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

@@ -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 );
}

View File

@@ -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 );
}

View File

@@ -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 );
}

View File

@@ -17,16 +17,21 @@
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "tomahawkutilsgui.h"
#include "config.h"
#include "query.h"
#include "result.h"
#include "logger.h"
#include "trackmodelitem.h"
#include <QtGui/QLayout>
#include <QtGui/QPainter>
#include <QtGui/QPixmap>
#include <QtGui/QPalette>
#include <QtGui/QApplication>
#include <QtGui/QWidget>
#include <QStyleOption>
#ifdef Q_WS_X11
#include <QtGui/QX11Info>
@@ -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

View File

@@ -21,10 +21,13 @@
#define TOMAHAWKUTILSGUI_H
#include <QSize>
#include <QModelIndex>
#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