mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-19 12: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;
|
||||
|
||||
float opacity = 0.0;
|
||||
painter->save();
|
||||
if ( item->query()->results().count() )
|
||||
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 );
|
||||
int r = textcol.red(), g = textcol.green(), b = textcol.blue();
|
||||
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 );
|
||||
QColor textColor = TomahawkUtils::alphaBlend( option.palette.color( QPalette::Foreground ), option.palette.color( QPalette::Background ), opacity );
|
||||
|
||||
if ( item->isPlaying() )
|
||||
{
|
||||
// painter->setRenderHint( QPainter::Antialiasing );
|
||||
painter->save();
|
||||
|
||||
{
|
||||
QRect r = option.rect.adjusted( 3, 0, 0, 0 );
|
||||
@@ -120,18 +112,18 @@ PlaylistItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& opti
|
||||
painter->setPen( pen );
|
||||
painter->drawRoundedRect( r, 3.0, 3.0 );
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( const QStyleOptionViewItem *vioption = qstyleoption_cast<const QStyleOptionViewItem *>(&option))
|
||||
{
|
||||
QStyleOptionViewItemV4 o( *vioption );
|
||||
o.palette.setColor( QPalette::Text, textcol );
|
||||
o.palette.setColor( QPalette::Text, textColor );
|
||||
QStyledItemDelegate::paint( painter, o, index );
|
||||
}
|
||||
else
|
||||
QStyledItemDelegate::paint( painter, option, index );
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
@@ -66,7 +66,19 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
||||
}
|
||||
else if ( !item->result().isNull() )
|
||||
{
|
||||
return QStyledItemDelegate::paint( painter, option, index );
|
||||
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 );
|
||||
}
|
||||
|
||||
QStyleOptionViewItemV4 opt = option;
|
||||
@@ -99,7 +111,7 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
||||
text = painter->fontMetrics().elidedText( text, Qt::ElideRight, r.width() );
|
||||
painter->drawText( r, text, to );
|
||||
|
||||
painter->setFont( boldFont );
|
||||
// painter->setFont( boldFont );
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "tomahawkutils.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QColor>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#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
|
||||
createDragPixmap( int itemCount )
|
||||
{
|
||||
@@ -366,7 +380,7 @@ dnsResolver()
|
||||
{
|
||||
if( !s_dnsResolver )
|
||||
s_dnsResolver = new DNSResolver();
|
||||
|
||||
|
||||
return s_dnsResolver;
|
||||
}
|
||||
|
||||
@@ -387,7 +401,7 @@ DNSResolver::resolve( QString &host, QString type )
|
||||
{
|
||||
// For the moment, assume we are looking for XMPP...
|
||||
QString fullHost( "_xmpp-client._tcp." + host );
|
||||
|
||||
|
||||
qDebug() << "Looking up SRV record for " << fullHost.toUtf8();
|
||||
|
||||
m_dnsSharedRequest->query( fullHost.toUtf8(), QJDns::Srv );
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#define RESPATH ":/data/"
|
||||
|
||||
class QColor;
|
||||
class QDir;
|
||||
class QDateTime;
|
||||
class QString;
|
||||
@@ -70,11 +71,11 @@ namespace TomahawkUtils
|
||||
{
|
||||
QThread::sleep( secs );
|
||||
}
|
||||
static void msleep( unsigned long msecs )
|
||||
static void msleep( unsigned long msecs )
|
||||
{
|
||||
QThread::msleep( msecs );
|
||||
}
|
||||
static void usleep( unsigned long usecs )
|
||||
static void usleep( unsigned long usecs )
|
||||
{
|
||||
QThread::usleep( usecs );
|
||||
}
|
||||
@@ -89,6 +90,7 @@ namespace TomahawkUtils
|
||||
DLLEXPORT QString filesizeToString( unsigned int size );
|
||||
DLLEXPORT QString extensionToMimetype( const QString& extension );
|
||||
|
||||
DLLEXPORT QColor alphaBlend( const QColor& colorFrom, const QColor& colorTo, float opacity );
|
||||
DLLEXPORT QPixmap createDragPixmap( int itemCount = 1 );
|
||||
|
||||
DLLEXPORT QNetworkAccessManager* nam();
|
||||
|
Reference in New Issue
Block a user