mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-12 09:04:33 +02:00
* Make artist name in PlayableCover clickable.
This commit is contained in:
@@ -18,7 +18,9 @@
|
|||||||
|
|
||||||
#include "PlayableCover.h"
|
#include "PlayableCover.h"
|
||||||
|
|
||||||
|
#include "Artist.h"
|
||||||
#include "Album.h"
|
#include "Album.h"
|
||||||
|
#include "ViewManager.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"
|
||||||
@@ -77,6 +79,56 @@ PlayableCover::resizeEvent( QResizeEvent* event )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayableCover::mouseMoveEvent( QMouseEvent* event )
|
||||||
|
{
|
||||||
|
QLabel::mouseMoveEvent( event );
|
||||||
|
|
||||||
|
foreach ( const QRect& rect, m_itemRects )
|
||||||
|
{
|
||||||
|
if ( rect.contains( event->pos() ) )
|
||||||
|
{
|
||||||
|
if ( m_hoveredRect != rect )
|
||||||
|
{
|
||||||
|
setCursor( Qt::PointingHandCursor );
|
||||||
|
m_hoveredRect = rect;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !m_hoveredRect.isNull() )
|
||||||
|
{
|
||||||
|
setCursor( Qt::ArrowCursor );
|
||||||
|
m_hoveredRect = QRect();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
PlayableCover::mouseReleaseEvent( QMouseEvent* event )
|
||||||
|
{
|
||||||
|
QLabel::mouseReleaseEvent( event );
|
||||||
|
|
||||||
|
foreach ( const QRect& rect, m_itemRects )
|
||||||
|
{
|
||||||
|
if ( rect.contains( event->pos() ) )
|
||||||
|
{
|
||||||
|
if ( m_artist )
|
||||||
|
ViewManager::instance()->show( m_artist );
|
||||||
|
else if ( m_album )
|
||||||
|
ViewManager::instance()->show( m_album->artist() );
|
||||||
|
else if ( m_query )
|
||||||
|
ViewManager::instance()->show( Tomahawk::Artist::get( m_query->artist() ) );
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlayableCover::setPixmap( const QPixmap& pixmap )
|
PlayableCover::setPixmap( const QPixmap& pixmap )
|
||||||
{
|
{
|
||||||
@@ -87,6 +139,8 @@ PlayableCover::setPixmap( const QPixmap& pixmap )
|
|||||||
void
|
void
|
||||||
PlayableCover::paintEvent( QPaintEvent* event )
|
PlayableCover::paintEvent( QPaintEvent* event )
|
||||||
{
|
{
|
||||||
|
Q_UNUSED( event );
|
||||||
|
|
||||||
QPainter painter( this );
|
QPainter painter( this );
|
||||||
painter.setRenderHint( QPainter::Antialiasing );
|
painter.setRenderHint( QPainter::Antialiasing );
|
||||||
painter.drawPixmap( 0, 0, pixmap() );
|
painter.drawPixmap( 0, 0, pixmap() );
|
||||||
@@ -98,6 +152,7 @@ PlayableCover::paintEvent( QPaintEvent* event )
|
|||||||
QPixmap buffer( r.size() );
|
QPixmap buffer( r.size() );
|
||||||
buffer.fill( Qt::transparent );
|
buffer.fill( Qt::transparent );
|
||||||
QPainter bufpainter( &buffer );
|
QPainter bufpainter( &buffer );
|
||||||
|
bufpainter.setRenderHint( QPainter::Antialiasing );
|
||||||
|
|
||||||
QTextOption to;
|
QTextOption to;
|
||||||
to.setWrapMode( QTextOption::NoWrap );
|
to.setWrapMode( QTextOption::NoWrap );
|
||||||
@@ -181,18 +236,25 @@ PlayableCover::paintEvent( QPaintEvent* event )
|
|||||||
bufpainter.drawText( textRect, text, to );
|
bufpainter.drawText( textRect, text, to );
|
||||||
|
|
||||||
bufpainter.setFont( font );
|
bufpainter.setFont( font );
|
||||||
// If the user is hovering over an artist rect, draw a background so she knows it's clickable
|
|
||||||
QRect r = textRect;
|
QRect r = textRect;
|
||||||
r.setTop( r.bottom() - bufpainter.fontMetrics().height() );
|
r.setTop( r.bottom() - bufpainter.fontMetrics().height() );
|
||||||
r.adjust( 4, 0, -4, -1 );
|
r.adjust( 4, 0, -4, -1 );
|
||||||
/* if ( m_hoveringOver == index )
|
|
||||||
|
text = bufpainter.fontMetrics().elidedText( bottom, Qt::ElideRight, textRect.width() - 16 );
|
||||||
|
int textWidth = bufpainter.fontMetrics().width( text );
|
||||||
|
r.adjust( ( r.width() - textWidth ) / 2 - 6, 0, - ( ( r.width() - textWidth ) / 2 - 6 ), 0 );
|
||||||
|
|
||||||
|
m_itemRects.clear();
|
||||||
|
m_itemRects << r;
|
||||||
|
|
||||||
|
if ( m_hoveredRect == r )
|
||||||
{
|
{
|
||||||
TomahawkUtils::drawQueryBackground( bufpainter, opt.palette, r, 1.1 );
|
TomahawkUtils::drawQueryBackground( &bufpainter, palette(), r, 1.1 );
|
||||||
bufpainter.setPen( opt.palette.color( QPalette::HighlightedText ) );
|
bufpainter.setPen( Qt::white );
|
||||||
}*/
|
}
|
||||||
|
|
||||||
to.setAlignment( Qt::AlignHCenter | Qt::AlignBottom );
|
to.setAlignment( Qt::AlignHCenter | Qt::AlignBottom );
|
||||||
text = bufpainter.fontMetrics().elidedText( bottom, Qt::ElideRight, textRect.width() - 16 );
|
|
||||||
bufpainter.drawText( textRect.adjusted( 5, -1, -5, -1 ), text, to );
|
bufpainter.drawText( textRect.adjusted( 5, -1, -5, -1 ), text, to );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -56,6 +56,9 @@ protected:
|
|||||||
virtual void resizeEvent( QResizeEvent* event );
|
virtual void resizeEvent( QResizeEvent* event );
|
||||||
virtual void paintEvent( QPaintEvent* event );
|
virtual void paintEvent( QPaintEvent* event );
|
||||||
|
|
||||||
|
virtual void mouseMoveEvent( QMouseEvent* event );
|
||||||
|
virtual void mouseReleaseEvent( QMouseEvent* event );
|
||||||
|
|
||||||
void leaveEvent( QEvent* event );
|
void leaveEvent( QEvent* event );
|
||||||
void enterEvent( QEvent* event );
|
void enterEvent( QEvent* event );
|
||||||
|
|
||||||
@@ -70,6 +73,9 @@ private:
|
|||||||
Tomahawk::album_ptr m_album;
|
Tomahawk::album_ptr m_album;
|
||||||
Tomahawk::query_ptr m_query;
|
Tomahawk::query_ptr m_query;
|
||||||
|
|
||||||
|
QList< QRect > m_itemRects;
|
||||||
|
QRect m_hoveredRect;
|
||||||
|
|
||||||
bool m_showText;
|
bool m_showText;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user