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

* QueryLabel now supports displaying a jump-label and handles cursor states itself.

This commit is contained in:
Christian Muehlhaeuser 2012-06-12 07:45:14 +02:00
parent aeeaaadcd2
commit fa4ef44e4a
2 changed files with 39 additions and 0 deletions

View File

@ -30,6 +30,7 @@
#include "ContextMenu.h"
#include "utils/TomahawkUtilsGui.h"
#include "utils/Logger.h"
#include "ViewManager.h"
#include "Source.h"
#define BOXMARGIN 2
@ -91,6 +92,9 @@ QueryLabel::init()
m_useCustomFont = false;
m_align = Qt::AlignLeft | Qt::AlignVCenter;
m_mode = Qt::ElideMiddle;
m_jumpLinkVisible = false;
m_jumpPixmap = QPixmap( RESPATH "images/jump-link.png" ).scaled( QSize( fontMetrics().height(), fontMetrics().height() ), Qt::KeepAspectRatio, Qt::SmoothTransformation );
}
@ -240,6 +244,14 @@ QueryLabel::setQuery( const Tomahawk::query_ptr& query )
}
void
QueryLabel::setJumpLinkVisible( bool visible )
{
m_jumpLinkVisible = visible;
repaint();
}
Qt::Alignment
QueryLabel::alignment() const
{
@ -466,6 +478,13 @@ QueryLabel::paintEvent( QPaintEvent* event )
p.drawText( r, m_align, track() );
r.adjust( trackX, 0, 0, 0 );
}
if ( m_jumpLinkVisible )
{
r.adjust( 6, 0, 0, 0 );
r.setSize( m_jumpPixmap.size() );
p.drawPixmap( r, m_jumpPixmap );
}
}
p.restore();
@ -527,6 +546,10 @@ QueryLabel::mouseReleaseEvent( QMouseEvent* event )
case Track:
emit clickedTrack();
break;
case Complete:
ViewManager::instance()->showCurrentTrack();
break;
default:
emit clicked();
@ -583,6 +606,7 @@ QueryLabel::mouseMoveEvent( QMouseEvent* event )
QRect hoverArea;
m_hoverType = None;
if ( m_type & Artist && x < artistX )
{
m_hoverType = Artist;
@ -603,12 +627,22 @@ QueryLabel::mouseMoveEvent( QMouseEvent* event )
hoverArea.setLeft( albumX + spacing );
hoverArea.setRight( trackX + contentsMargins().left() - 1 );
}
else if ( m_jumpLinkVisible && x < trackX + 6 + m_jumpPixmap.width() && x > trackX + 6 )
{
m_hoverType = Complete;
}
if ( hoverArea.width() )
{
hoverArea.setY( 1 );
hoverArea.setHeight( height() - 2 );
}
if ( m_hoverType != None )
setCursor( Qt::PointingHandCursor );
else
setCursor( Qt::ArrowCursor );
if ( hoverArea != m_hoverArea )
{
m_hoverArea = hoverArea;

View File

@ -22,6 +22,7 @@
#include <QFrame>
#include <QTime>
#include <QPen>
#include <QPixmap>
#include "Result.h"
#include "Query.h"
@ -80,6 +81,7 @@ public:
QFont font() const;
void setExtraContentsMargins( int left, int top, int right, int bottom );
void setJumpLinkVisible( bool visible );
virtual QSize sizeHint() const;
virtual QSize minimumSizeHint() const;
@ -137,6 +139,9 @@ private:
QRect m_hoverArea;
QPoint m_dragPos;
QMargins m_textMargins;
bool m_jumpLinkVisible;
QPixmap m_jumpPixmap;
};
#endif // QUERYLABEL_H