1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 15:59:42 +01:00

* QueryLabel now draws a fancier text in the AudioControls.

This commit is contained in:
Christian Muehlhaeuser 2012-12-07 18:07:26 +01:00
parent 035b815cfb
commit 452c5b7cce
2 changed files with 40 additions and 6 deletions

View File

@ -365,6 +365,36 @@ QueryLabel::minimumSizeHint() const
}
void
QueryLabel::drawFancyText( QPainter* painter, const QRect& rect, const QString& text )
{
if ( m_align & Qt::AlignLeft )
{
painter->save();
QFont fnt = painter->font();
fnt.setStyleStrategy( QFont::ForceOutline );
QFontMetrics fm( fnt );
QPainterPath textPath;
textPath.addText( rect.topLeft() + QPoint( 0, fm.ascent() ), fnt, text );
QLinearGradient gradient( 0, 0, 0, 1 );
gradient.setCoordinateMode( QGradient::ObjectBoundingMode );
gradient.setColorAt( 0, painter->pen().color() );
gradient.setColorAt( 1, painter->pen().color().lighter() );
painter->setPen( QPen( gradient, 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
painter->setBrush( gradient );
painter->drawPath( textPath );
painter->restore();
}
else
painter->drawText( rect, m_align, text );
}
void
QueryLabel::paintEvent( QPaintEvent* event )
{
@ -377,6 +407,7 @@ QueryLabel::paintEvent( QPaintEvent* event )
p.save();
p.setRenderHint( QPainter::Antialiasing );
p.setRenderHint( QPainter::TextAntialiasing );
if ( m_hoverArea.width() )
{
@ -402,7 +433,8 @@ QueryLabel::paintEvent( QPaintEvent* event )
p.setBrush( palette().window() );
p.setPen( palette().color( foregroundRole() ) );
}
p.drawText( r, m_align, elidedText );
drawFancyText( &p, r, elidedText );
}
else
{
@ -426,7 +458,7 @@ QueryLabel::paintEvent( QPaintEvent* event )
p.setBrush( palette().highlight() );
}
p.drawText( r, m_align, artist()->name() );
drawFancyText( &p, r, artist()->name() );
r.adjust( artistX, 0, 0, 0 );
}
if ( m_type & Album )
@ -437,7 +469,7 @@ QueryLabel::paintEvent( QPaintEvent* event )
if ( m_type & Artist )
{
p.drawText( r, m_align, DASH );
drawFancyText( &p, r, DASH );
r.adjust( dashX, 0, 0, 0 );
}
if ( m_hoverType == Album )
@ -446,7 +478,7 @@ QueryLabel::paintEvent( QPaintEvent* event )
p.setBrush( palette().highlight() );
}
p.drawText( r, m_align, album()->name() );
drawFancyText( &p, r, album()->name() );
r.adjust( albumX, 0, 0, 0 );
}
if ( m_type & Track )
@ -457,7 +489,7 @@ QueryLabel::paintEvent( QPaintEvent* event )
if ( m_type & Artist || m_type & Album )
{
p.drawText( r, m_align, DASH );
drawFancyText( &p, r, DASH );
r.adjust( dashX, 0, 0, 0 );
}
if ( m_hoverType == Track )
@ -466,7 +498,7 @@ QueryLabel::paintEvent( QPaintEvent* event )
p.setBrush( palette().highlight() );
}
p.drawText( r, m_align, track() );
drawFancyText( &p, r, track() );
r.adjust( trackX, 0, 0, 0 );
}

View File

@ -104,6 +104,8 @@ signals:
void queryChanged( const Tomahawk::query_ptr& query );
protected:
void drawFancyText( QPainter* painter, const QRect& rect, const QString& text );
virtual void contextMenuEvent( QContextMenuEvent* event );
virtual void mousePressEvent( QMouseEvent* event );