mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-21 13:21:52 +02:00
* Added alphaBlend method to TomahawkUtils. DRY.
This commit is contained in:
@@ -76,24 +76,16 @@ PlaylistItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& opti
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
float opacity = 0.0;
|
float opacity = 0.0;
|
||||||
painter->save();
|
|
||||||
if ( item->query()->results().count() )
|
if ( item->query()->results().count() )
|
||||||
opacity = item->query()->results().first()->score();
|
opacity = item->query()->results().first()->score();
|
||||||
|
|
||||||
QColor textcol, bgcol;
|
|
||||||
textcol = option.palette.color( QPalette::Foreground );
|
|
||||||
bgcol = option.palette.color( QPalette::Background );
|
|
||||||
|
|
||||||
opacity = qMax( (float)0.3, opacity );
|
opacity = qMax( (float)0.3, opacity );
|
||||||
int r = textcol.red(), g = textcol.green(), b = textcol.blue();
|
QColor textColor = TomahawkUtils::alphaBlend( option.palette.color( QPalette::Foreground ), option.palette.color( QPalette::Background ), opacity );
|
||||||
r = opacity * r + ( 1 - opacity ) * bgcol.red();
|
|
||||||
g = opacity * g + ( 1 - opacity ) * bgcol.green();
|
|
||||||
b = opacity * b + ( 1 - opacity ) * bgcol.blue();
|
|
||||||
textcol = QColor( r, g, b );
|
|
||||||
|
|
||||||
if ( item->isPlaying() )
|
if ( item->isPlaying() )
|
||||||
{
|
{
|
||||||
// painter->setRenderHint( QPainter::Antialiasing );
|
// painter->setRenderHint( QPainter::Antialiasing );
|
||||||
|
painter->save();
|
||||||
|
|
||||||
{
|
{
|
||||||
QRect r = option.rect.adjusted( 3, 0, 0, 0 );
|
QRect r = option.rect.adjusted( 3, 0, 0, 0 );
|
||||||
@@ -120,18 +112,18 @@ PlaylistItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& opti
|
|||||||
painter->setPen( pen );
|
painter->setPen( pen );
|
||||||
painter->drawRoundedRect( r, 3.0, 3.0 );
|
painter->drawRoundedRect( r, 3.0, 3.0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
painter->restore();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( const QStyleOptionViewItem *vioption = qstyleoption_cast<const QStyleOptionViewItem *>(&option))
|
if ( const QStyleOptionViewItem *vioption = qstyleoption_cast<const QStyleOptionViewItem *>(&option))
|
||||||
{
|
{
|
||||||
QStyleOptionViewItemV4 o( *vioption );
|
QStyleOptionViewItemV4 o( *vioption );
|
||||||
o.palette.setColor( QPalette::Text, textcol );
|
o.palette.setColor( QPalette::Text, textColor );
|
||||||
QStyledItemDelegate::paint( painter, o, index );
|
QStyledItemDelegate::paint( painter, o, index );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
QStyledItemDelegate::paint( painter, option, index );
|
QStyledItemDelegate::paint( painter, option, index );
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->restore();
|
|
||||||
}
|
}
|
||||||
|
@@ -66,6 +66,18 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
|||||||
}
|
}
|
||||||
else if ( !item->result().isNull() )
|
else if ( !item->result().isNull() )
|
||||||
{
|
{
|
||||||
|
float opacity = item->result()->score();
|
||||||
|
|
||||||
|
opacity = qMax( (float)0.3, opacity );
|
||||||
|
QColor textColor = TomahawkUtils::alphaBlend( option.palette.color( QPalette::Foreground ), option.palette.color( QPalette::Background ), opacity );
|
||||||
|
|
||||||
|
if ( const QStyleOptionViewItem *vioption = qstyleoption_cast<const QStyleOptionViewItem *>(&option))
|
||||||
|
{
|
||||||
|
QStyleOptionViewItemV4 o( *vioption );
|
||||||
|
o.palette.setColor( QPalette::Text, textColor );
|
||||||
|
return QStyledItemDelegate::paint( painter, o, index );
|
||||||
|
}
|
||||||
|
else
|
||||||
return QStyledItemDelegate::paint( painter, option, index );
|
return QStyledItemDelegate::paint( painter, option, index );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +111,7 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
|||||||
text = painter->fontMetrics().elidedText( text, Qt::ElideRight, r.width() );
|
text = painter->fontMetrics().elidedText( text, Qt::ElideRight, r.width() );
|
||||||
painter->drawText( r, text, to );
|
painter->drawText( r, text, to );
|
||||||
|
|
||||||
painter->setFont( boldFont );
|
// painter->setFont( boldFont );
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
#include "tomahawkutils.h"
|
#include "tomahawkutils.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QColor>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
@@ -265,6 +266,19 @@ extensionToMimetype( const QString& extension )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QColor
|
||||||
|
alphaBlend( const QColor& colorFrom, const QColor& colorTo, float opacity )
|
||||||
|
{
|
||||||
|
opacity = qMax( (float)0.3, opacity );
|
||||||
|
int r = colorFrom.red(), g = colorFrom.green(), b = colorFrom.blue();
|
||||||
|
r = opacity * r + ( 1 - opacity ) * colorTo.red();
|
||||||
|
g = opacity * g + ( 1 - opacity ) * colorTo.green();
|
||||||
|
b = opacity * b + ( 1 - opacity ) * colorTo.blue();
|
||||||
|
|
||||||
|
return QColor( r, g, b );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QPixmap
|
QPixmap
|
||||||
createDragPixmap( int itemCount )
|
createDragPixmap( int itemCount )
|
||||||
{
|
{
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#define RESPATH ":/data/"
|
#define RESPATH ":/data/"
|
||||||
|
|
||||||
|
class QColor;
|
||||||
class QDir;
|
class QDir;
|
||||||
class QDateTime;
|
class QDateTime;
|
||||||
class QString;
|
class QString;
|
||||||
@@ -89,6 +90,7 @@ namespace TomahawkUtils
|
|||||||
DLLEXPORT QString filesizeToString( unsigned int size );
|
DLLEXPORT QString filesizeToString( unsigned int size );
|
||||||
DLLEXPORT QString extensionToMimetype( const QString& extension );
|
DLLEXPORT QString extensionToMimetype( const QString& extension );
|
||||||
|
|
||||||
|
DLLEXPORT QColor alphaBlend( const QColor& colorFrom, const QColor& colorTo, float opacity );
|
||||||
DLLEXPORT QPixmap createDragPixmap( int itemCount = 1 );
|
DLLEXPORT QPixmap createDragPixmap( int itemCount = 1 );
|
||||||
|
|
||||||
DLLEXPORT QNetworkAccessManager* nam();
|
DLLEXPORT QNetworkAccessManager* nam();
|
||||||
|
Reference in New Issue
Block a user