mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-08 07:07:05 +02:00
* Show text on PlayableCover.
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "PlayableCover.h"
|
#include "PlayableCover.h"
|
||||||
|
|
||||||
|
#include "Album.h"
|
||||||
#include "audio/AudioEngine.h"
|
#include "audio/AudioEngine.h"
|
||||||
#include "widgets/ImageButton.h"
|
#include "widgets/ImageButton.h"
|
||||||
#include "utils/TomahawkUtilsGui.h"
|
#include "utils/TomahawkUtilsGui.h"
|
||||||
@@ -75,6 +76,131 @@ PlayableCover::resizeEvent( QResizeEvent* event )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayableCover::paintEvent( QPaintEvent* event )
|
||||||
|
{
|
||||||
|
QLabel::paintEvent( event );
|
||||||
|
|
||||||
|
QRect r = contentsRect().adjusted( margin(), margin(), -margin(), -margin() );
|
||||||
|
QPixmap buffer( r.size() );
|
||||||
|
buffer.fill( Qt::transparent );
|
||||||
|
|
||||||
|
QPainter painter( &buffer );
|
||||||
|
|
||||||
|
QTextOption to;
|
||||||
|
to.setWrapMode( QTextOption::NoWrap );
|
||||||
|
|
||||||
|
QColor c1;
|
||||||
|
c1.setRgb( 0, 0, 0 );
|
||||||
|
c1.setAlphaF( 0.00 );
|
||||||
|
QColor c2;
|
||||||
|
c2.setRgb( 0, 0, 0 );
|
||||||
|
c2.setAlphaF( 0.88 );
|
||||||
|
|
||||||
|
QString text;
|
||||||
|
QFont font = QLabel::font();
|
||||||
|
font.setPointSize( TomahawkUtils::defaultFontSize() );
|
||||||
|
QFont boldFont = font;
|
||||||
|
boldFont.setBold( true );
|
||||||
|
boldFont.setPointSize( TomahawkUtils::defaultFontSize() + 5 );
|
||||||
|
|
||||||
|
QString top, bottom;
|
||||||
|
if ( m_artist )
|
||||||
|
{
|
||||||
|
top = m_artist->name();
|
||||||
|
}
|
||||||
|
else if ( m_album )
|
||||||
|
{
|
||||||
|
top = m_album->name();
|
||||||
|
bottom = m_album->artist()->name();
|
||||||
|
}
|
||||||
|
else if ( m_query )
|
||||||
|
{
|
||||||
|
top = m_query->track();
|
||||||
|
bottom = m_query->artist();
|
||||||
|
}
|
||||||
|
|
||||||
|
int bottomHeight = QFontMetrics( font ).boundingRect( bottom ).height();
|
||||||
|
int topHeight = QFontMetrics( boldFont ).boundingRect( top ).height();
|
||||||
|
int frameHeight = bottomHeight + topHeight + 4;
|
||||||
|
|
||||||
|
QRect gradientRect = r.adjusted( 0, r.height() - frameHeight * 3, 0, 0 );
|
||||||
|
QLinearGradient gradient( QPointF( 0, 0 ), QPointF( 0, 1 ) );
|
||||||
|
gradient.setCoordinateMode( QGradient::ObjectBoundingMode );
|
||||||
|
gradient.setColorAt( 0.0, c1 );
|
||||||
|
gradient.setColorAt( 0.6, c2 );
|
||||||
|
gradient.setColorAt( 1.0, c2 );
|
||||||
|
|
||||||
|
painter.save();
|
||||||
|
painter.setPen( Qt::transparent );
|
||||||
|
painter.setBrush( gradient );
|
||||||
|
painter.drawRect( gradientRect );
|
||||||
|
painter.restore();
|
||||||
|
|
||||||
|
painter.setPen( Qt::white );
|
||||||
|
|
||||||
|
QRect textRect = r.adjusted( 8, r.height() - frameHeight - 16, -8, -16 );
|
||||||
|
bool oneLiner = false;
|
||||||
|
if ( bottom.isEmpty() )
|
||||||
|
oneLiner = true;
|
||||||
|
|
||||||
|
painter.setFont( boldFont );
|
||||||
|
if ( oneLiner )
|
||||||
|
{
|
||||||
|
painter.save();
|
||||||
|
QFont f = painter.font();
|
||||||
|
|
||||||
|
while ( f.pointSizeF() > 9 && painter.fontMetrics().width( top ) > textRect.width() )
|
||||||
|
{
|
||||||
|
f.setPointSizeF( f.pointSizeF() - 0.2 );
|
||||||
|
painter.setFont( f );
|
||||||
|
}
|
||||||
|
|
||||||
|
to.setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
|
||||||
|
text = painter.fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - 3 );
|
||||||
|
painter.drawText( textRect, text, to );
|
||||||
|
|
||||||
|
painter.restore();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
to.setAlignment( Qt::AlignHCenter | Qt::AlignTop );
|
||||||
|
text = painter.fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - 3 );
|
||||||
|
painter.drawText( textRect, text, to );
|
||||||
|
|
||||||
|
painter.setFont( font );
|
||||||
|
// If the user is hovering over an artist rect, draw a background so she knows it's clickable
|
||||||
|
QRect r = textRect;
|
||||||
|
r.setTop( r.bottom() - painter.fontMetrics().height() );
|
||||||
|
r.adjust( 4, 0, -4, -1 );
|
||||||
|
/* if ( m_hoveringOver == index )
|
||||||
|
{
|
||||||
|
TomahawkUtils::drawQueryBackground( painter, opt.palette, r, 1.1 );
|
||||||
|
painter.setPen( opt.palette.color( QPalette::HighlightedText ) );
|
||||||
|
}*/
|
||||||
|
|
||||||
|
to.setAlignment( Qt::AlignHCenter | Qt::AlignBottom );
|
||||||
|
text = painter.fontMetrics().elidedText( bottom, Qt::ElideRight, textRect.width() - 16 );
|
||||||
|
painter.drawText( textRect.adjusted( 5, -1, -5, -1 ), text, to );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QPainter painter( this );
|
||||||
|
painter.setRenderHint( QPainter::Antialiasing );
|
||||||
|
|
||||||
|
QBrush brush( buffer );
|
||||||
|
QPen pen;
|
||||||
|
pen.setColor( Qt::transparent );
|
||||||
|
pen.setJoinStyle( Qt::RoundJoin );
|
||||||
|
|
||||||
|
float frameWidthPct = 0.20;
|
||||||
|
painter.setBrush( brush );
|
||||||
|
painter.setPen( pen );
|
||||||
|
painter.drawRoundedRect( r, frameWidthPct * 100.0, frameWidthPct * 100.0, Qt::RelativeSize );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlayableCover::onClicked()
|
PlayableCover::onClicked()
|
||||||
{
|
{
|
||||||
|
@@ -47,6 +47,7 @@ public slots:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void resizeEvent( QResizeEvent* event );
|
virtual void resizeEvent( QResizeEvent* event );
|
||||||
|
virtual void paintEvent( QPaintEvent* event );
|
||||||
|
|
||||||
void leaveEvent( QEvent* event );
|
void leaveEvent( QEvent* event );
|
||||||
void enterEvent( QEvent* event );
|
void enterEvent( QEvent* event );
|
||||||
|
Reference in New Issue
Block a user