1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 19:30:21 +02: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 "ContextMenu.h"
#include "utils/TomahawkUtilsGui.h" #include "utils/TomahawkUtilsGui.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "ViewManager.h"
#include "Source.h" #include "Source.h"
#define BOXMARGIN 2 #define BOXMARGIN 2
@@ -91,6 +92,9 @@ QueryLabel::init()
m_useCustomFont = false; m_useCustomFont = false;
m_align = Qt::AlignLeft | Qt::AlignVCenter; m_align = Qt::AlignLeft | Qt::AlignVCenter;
m_mode = Qt::ElideMiddle; 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 Qt::Alignment
QueryLabel::alignment() const QueryLabel::alignment() const
{ {
@@ -466,6 +478,13 @@ QueryLabel::paintEvent( QPaintEvent* event )
p.drawText( r, m_align, track() ); p.drawText( r, m_align, track() );
r.adjust( trackX, 0, 0, 0 ); 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(); p.restore();
@@ -527,6 +546,10 @@ QueryLabel::mouseReleaseEvent( QMouseEvent* event )
case Track: case Track:
emit clickedTrack(); emit clickedTrack();
break; break;
case Complete:
ViewManager::instance()->showCurrentTrack();
break;
default: default:
emit clicked(); emit clicked();
@@ -583,6 +606,7 @@ QueryLabel::mouseMoveEvent( QMouseEvent* event )
QRect hoverArea; QRect hoverArea;
m_hoverType = None; m_hoverType = None;
if ( m_type & Artist && x < artistX ) if ( m_type & Artist && x < artistX )
{ {
m_hoverType = Artist; m_hoverType = Artist;
@@ -603,12 +627,22 @@ QueryLabel::mouseMoveEvent( QMouseEvent* event )
hoverArea.setLeft( albumX + spacing ); hoverArea.setLeft( albumX + spacing );
hoverArea.setRight( trackX + contentsMargins().left() - 1 ); 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() ) if ( hoverArea.width() )
{ {
hoverArea.setY( 1 ); hoverArea.setY( 1 );
hoverArea.setHeight( height() - 2 ); hoverArea.setHeight( height() - 2 );
} }
if ( m_hoverType != None )
setCursor( Qt::PointingHandCursor );
else
setCursor( Qt::ArrowCursor );
if ( hoverArea != m_hoverArea ) if ( hoverArea != m_hoverArea )
{ {
m_hoverArea = hoverArea; m_hoverArea = hoverArea;

View File

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