mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 21:57:41 +02:00
* Simplified QueryLabel.
This commit is contained in:
@@ -36,22 +36,19 @@
|
|||||||
#include <QDrag>
|
#include <QDrag>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
|
|
||||||
#define BOXMARGIN 2
|
|
||||||
#define DASH " - "
|
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
|
||||||
QueryLabel::QueryLabel( QWidget* parent, Qt::WindowFlags flags )
|
QueryLabel::QueryLabel( QWidget* parent, Qt::WindowFlags flags )
|
||||||
: QFrame( parent, flags )
|
: QLabel( parent, flags )
|
||||||
, m_type( Complete )
|
, m_type( None )
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QueryLabel::QueryLabel( DisplayType type, QWidget* parent, Qt::WindowFlags flags )
|
QueryLabel::QueryLabel( DisplayType type, QWidget* parent, Qt::WindowFlags flags )
|
||||||
: QFrame( parent, flags )
|
: QLabel( parent, flags )
|
||||||
, m_type( type )
|
, m_type( type )
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
@@ -59,7 +56,7 @@ QueryLabel::QueryLabel( DisplayType type, QWidget* parent, Qt::WindowFlags flags
|
|||||||
|
|
||||||
|
|
||||||
QueryLabel::QueryLabel( const Tomahawk::result_ptr& result, DisplayType type, QWidget* parent, Qt::WindowFlags flags )
|
QueryLabel::QueryLabel( const Tomahawk::result_ptr& result, DisplayType type, QWidget* parent, Qt::WindowFlags flags )
|
||||||
: QFrame( parent, flags )
|
: QLabel( parent, flags )
|
||||||
, m_type( type )
|
, m_type( type )
|
||||||
, m_result( result )
|
, m_result( result )
|
||||||
{
|
{
|
||||||
@@ -68,7 +65,7 @@ QueryLabel::QueryLabel( const Tomahawk::result_ptr& result, DisplayType type, QW
|
|||||||
|
|
||||||
|
|
||||||
QueryLabel::QueryLabel( const Tomahawk::query_ptr& query, DisplayType type, QWidget* parent, Qt::WindowFlags flags )
|
QueryLabel::QueryLabel( const Tomahawk::query_ptr& query, DisplayType type, QWidget* parent, Qt::WindowFlags flags )
|
||||||
: QFrame( parent, flags )
|
: QLabel( parent, flags )
|
||||||
, m_type( type )
|
, m_type( type )
|
||||||
, m_query( query )
|
, m_query( query )
|
||||||
{
|
{
|
||||||
@@ -87,22 +84,17 @@ QueryLabel::init()
|
|||||||
m_contextMenu = new ContextMenu( this );
|
m_contextMenu = new ContextMenu( this );
|
||||||
m_contextMenu->setSupportedActions( ContextMenu::ActionQueue | ContextMenu::ActionCopyLink | ContextMenu::ActionStopAfter | ContextMenu::ActionLove | ContextMenu::ActionPage );
|
m_contextMenu->setSupportedActions( ContextMenu::ActionQueue | ContextMenu::ActionCopyLink | ContextMenu::ActionStopAfter | ContextMenu::ActionLove | ContextMenu::ActionPage );
|
||||||
|
|
||||||
m_hoverType = None;
|
|
||||||
setContentsMargins( 0, 0, 0, 0 );
|
|
||||||
setMouseTracking( true );
|
setMouseTracking( true );
|
||||||
|
|
||||||
m_align = Qt::AlignLeft | Qt::AlignVCenter;
|
setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
|
||||||
m_mode = Qt::ElideMiddle;
|
m_mode = Qt::ElideMiddle;
|
||||||
|
m_hovering = false;
|
||||||
m_jumpLinkVisible = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
QueryLabel::text() const
|
QueryLabel::text() const
|
||||||
{
|
{
|
||||||
QString text;
|
|
||||||
|
|
||||||
if ( m_result.isNull() && m_query.isNull() && m_artist.isNull() && m_album.isNull() )
|
if ( m_result.isNull() && m_query.isNull() && m_artist.isNull() && m_album.isNull() )
|
||||||
return m_text;
|
return m_text;
|
||||||
|
|
||||||
@@ -110,70 +102,58 @@ QueryLabel::text() const
|
|||||||
{
|
{
|
||||||
if ( m_type & Artist )
|
if ( m_type & Artist )
|
||||||
{
|
{
|
||||||
text += m_result->track()->artist();
|
return m_result->track()->artist();
|
||||||
}
|
}
|
||||||
if ( m_type & Album && !m_result->track()->album().isEmpty() )
|
if ( m_type & Album && !m_result->track()->album().isEmpty() )
|
||||||
{
|
{
|
||||||
smartAppend( text, m_result->track()->album() );
|
return m_result->track()->album();
|
||||||
}
|
}
|
||||||
if ( m_type & Track )
|
if ( m_type & Track )
|
||||||
{
|
{
|
||||||
smartAppend( text, m_result->track()->track() );
|
return m_result->track()->track();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( !m_query.isNull() )
|
else if ( !m_query.isNull() )
|
||||||
{
|
{
|
||||||
if ( m_type & Artist )
|
if ( m_type & Artist )
|
||||||
{
|
{
|
||||||
text += m_query->track()->artist();
|
return m_query->track()->artist();
|
||||||
}
|
}
|
||||||
if ( m_type & Album && !m_query->track()->album().isEmpty() )
|
if ( m_type & Album && !m_query->track()->album().isEmpty() )
|
||||||
{
|
{
|
||||||
smartAppend( text, m_query->track()->album() );
|
return m_query->track()->album();
|
||||||
}
|
}
|
||||||
if ( m_type & Track )
|
if ( m_type & Track )
|
||||||
{
|
{
|
||||||
smartAppend( text, m_query->track()->track() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( !m_artist.isNull() )
|
|
||||||
{
|
|
||||||
text += m_artist->name();
|
|
||||||
}
|
|
||||||
else if ( !m_album.isNull() )
|
|
||||||
{
|
|
||||||
text += m_album->name();
|
|
||||||
}
|
|
||||||
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString
|
|
||||||
QueryLabel::track() const
|
|
||||||
{
|
|
||||||
if ( m_result.isNull() && m_query.isNull() )
|
|
||||||
return QString();
|
|
||||||
|
|
||||||
if ( !m_result.isNull() )
|
|
||||||
return m_result->track()->track();
|
|
||||||
else
|
|
||||||
return m_query->track()->track();
|
return m_query->track()->track();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ( m_type & Artist && !m_artist.isNull() )
|
||||||
|
{
|
||||||
|
return m_artist->name();
|
||||||
|
}
|
||||||
|
else if ( m_type & Album && !m_album.isNull() )
|
||||||
|
{
|
||||||
|
return m_album->name();
|
||||||
|
}
|
||||||
|
|
||||||
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
QueryLabel::setText( const QString& text )
|
QueryLabel::setText( const QString& text )
|
||||||
{
|
{
|
||||||
setContentsMargins( m_textMargins );
|
|
||||||
|
|
||||||
m_result.clear();
|
m_result.clear();
|
||||||
m_query.clear();
|
m_query.clear();
|
||||||
m_artist.clear();
|
m_artist.clear();
|
||||||
m_album.clear();
|
m_album.clear();
|
||||||
|
|
||||||
|
QLabel::setText( m_text );
|
||||||
m_text = text;
|
m_text = text;
|
||||||
|
|
||||||
updateLabel();
|
updateGeometry();
|
||||||
|
update();
|
||||||
|
|
||||||
emit textChanged( m_text );
|
emit textChanged( m_text );
|
||||||
emit resultChanged( m_result );
|
emit resultChanged( m_result );
|
||||||
@@ -187,7 +167,8 @@ QueryLabel::onResultChanged()
|
|||||||
m_artist = m_result->track()->artistPtr();
|
m_artist = m_result->track()->artistPtr();
|
||||||
m_album = m_result->track()->albumPtr();
|
m_album = m_result->track()->albumPtr();
|
||||||
|
|
||||||
updateLabel();
|
updateGeometry();
|
||||||
|
update();
|
||||||
|
|
||||||
emit textChanged( text() );
|
emit textChanged( text() );
|
||||||
}
|
}
|
||||||
@@ -199,11 +180,6 @@ QueryLabel::setResult( const Tomahawk::result_ptr& result )
|
|||||||
if ( result.isNull() )
|
if ( result.isNull() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( !m_text.isEmpty() && contentsMargins().left() != 0 ) // FIXME: hacky
|
|
||||||
m_textMargins = contentsMargins();
|
|
||||||
|
|
||||||
setContentsMargins( BOXMARGIN * 2, BOXMARGIN / 2, BOXMARGIN * 2, BOXMARGIN / 2);
|
|
||||||
|
|
||||||
if ( m_result.isNull() || m_result.data() != result.data() )
|
if ( m_result.isNull() || m_result.data() != result.data() )
|
||||||
{
|
{
|
||||||
m_result = result;
|
m_result = result;
|
||||||
@@ -221,8 +197,6 @@ QueryLabel::setQuery( const Tomahawk::query_ptr& query )
|
|||||||
if ( query.isNull() )
|
if ( query.isNull() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
setContentsMargins( BOXMARGIN * 2, BOXMARGIN / 2, BOXMARGIN * 2, BOXMARGIN / 2 );
|
|
||||||
|
|
||||||
if ( m_query.isNull() || m_query.data() != query.data() )
|
if ( m_query.isNull() || m_query.data() != query.data() )
|
||||||
{
|
{
|
||||||
m_query = query;
|
m_query = query;
|
||||||
@@ -230,7 +204,8 @@ QueryLabel::setQuery( const Tomahawk::query_ptr& query )
|
|||||||
m_album = Album::get( m_artist, query->track()->album() );
|
m_album = Album::get( m_artist, query->track()->album() );
|
||||||
m_result.clear();
|
m_result.clear();
|
||||||
|
|
||||||
updateLabel();
|
updateGeometry();
|
||||||
|
update();
|
||||||
|
|
||||||
emit textChanged( text() );
|
emit textChanged( text() );
|
||||||
emit queryChanged( m_query );
|
emit queryChanged( m_query );
|
||||||
@@ -243,7 +218,8 @@ QueryLabel::setArtist( const artist_ptr& artist )
|
|||||||
{
|
{
|
||||||
m_artist = artist;
|
m_artist = artist;
|
||||||
|
|
||||||
updateLabel();
|
updateGeometry();
|
||||||
|
update();
|
||||||
emit textChanged( text() );
|
emit textChanged( text() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,36 +229,12 @@ QueryLabel::setAlbum( const album_ptr& album )
|
|||||||
{
|
{
|
||||||
m_album = album;
|
m_album = album;
|
||||||
|
|
||||||
updateLabel();
|
updateGeometry();
|
||||||
|
update();
|
||||||
emit textChanged( text() );
|
emit textChanged( text() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
QueryLabel::setJumpLinkVisible( bool visible )
|
|
||||||
{
|
|
||||||
m_jumpLinkVisible = visible;
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Qt::Alignment
|
|
||||||
QueryLabel::alignment() const
|
|
||||||
{
|
|
||||||
return m_align;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
QueryLabel::setAlignment( Qt::Alignment alignment )
|
|
||||||
{
|
|
||||||
if ( m_align != alignment )
|
|
||||||
{
|
|
||||||
m_align = alignment;
|
|
||||||
update(); // no geometry change, repaint is sufficient
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Qt::TextElideMode
|
Qt::TextElideMode
|
||||||
QueryLabel::elideMode() const
|
QueryLabel::elideMode() const
|
||||||
@@ -297,31 +249,9 @@ QueryLabel::setElideMode( Qt::TextElideMode mode )
|
|||||||
if ( m_mode != mode )
|
if ( m_mode != mode )
|
||||||
{
|
{
|
||||||
m_mode = mode;
|
m_mode = mode;
|
||||||
updateLabel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
QueryLabel::updateLabel()
|
|
||||||
{
|
|
||||||
m_hoverArea = QRect();
|
|
||||||
m_hoverType = None;
|
|
||||||
|
|
||||||
updateGeometry();
|
updateGeometry();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
QueryLabel::setExtraContentsMargins( int left, int top, int right, int bottom )
|
|
||||||
{
|
|
||||||
QMargins margins = contentsMargins();
|
|
||||||
margins.setLeft( margins.left() + left );
|
|
||||||
margins.setTop( margins.top() + top );
|
|
||||||
margins.setRight( margins.right() + right );
|
|
||||||
margins.setBottom( margins.bottom() + bottom );
|
|
||||||
setContentsMargins( margins );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -353,125 +283,33 @@ QueryLabel::minimumSizeHint() const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
QueryLabel::paintEvent( QPaintEvent* event )
|
QueryLabel::paintEvent( QPaintEvent* /* event */ )
|
||||||
{
|
{
|
||||||
QFrame::paintEvent( event );
|
|
||||||
QPainter p( this );
|
QPainter p( this );
|
||||||
QRect r = contentsRect();
|
QRect r = contentsRect();
|
||||||
QString s = text();
|
|
||||||
const QFontMetrics& fm = fontMetrics();
|
|
||||||
const QString elidedText = fm.elidedText( s, m_mode, r.width() );
|
|
||||||
|
|
||||||
p.save();
|
if ( m_hovering )
|
||||||
p.setRenderHint( QPainter::Antialiasing );
|
|
||||||
|
|
||||||
if ( m_hoverArea.width() )
|
|
||||||
{
|
{
|
||||||
if ( elidedText != s )
|
QFont f = p.font();
|
||||||
{
|
f.setUnderline( true );
|
||||||
m_hoverArea.setLeft( 0 );
|
p.setFont( f );
|
||||||
m_hoverArea.setRight( fm.width( elidedText ) + contentsMargins().left() * 2 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TomahawkUtils::drawQueryBackground( &p, m_hoverArea );
|
const QFontMetrics fm( p.font() );
|
||||||
}
|
p.drawText( r, alignment(), fm.elidedText( text(), m_mode, r.width() ) );
|
||||||
|
|
||||||
if ( elidedText != s || ( m_result.isNull() && m_query.isNull() && m_artist.isNull() && m_album.isNull() ) )
|
|
||||||
{
|
|
||||||
if ( m_hoverArea.width() )
|
|
||||||
{
|
|
||||||
p.setBrush( TomahawkStyle::SELECTION_BACKGROUND );
|
|
||||||
p.setPen( TomahawkStyle::SELECTION_FOREGROUND );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
p.setBrush( palette().window() );
|
|
||||||
p.setPen( palette().color( foregroundRole() ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
p.drawText( r, m_align, elidedText );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int dashX = fm.width( DASH );
|
|
||||||
int artistX = m_type & Artist ? fm.width( artist()->name() ) : 0;
|
|
||||||
int albumX = m_type & Album ? fm.width( album()->name() ) : 0;
|
|
||||||
int trackX = m_type & Track ? fm.width( track() ) : 0;
|
|
||||||
|
|
||||||
if ( m_type & Artist )
|
|
||||||
{
|
|
||||||
p.setBrush( palette().window() );
|
|
||||||
p.setPen( palette().color( foregroundRole() ) );
|
|
||||||
|
|
||||||
if ( m_hoverType == Artist )
|
|
||||||
{
|
|
||||||
p.setBrush( TomahawkStyle::SELECTION_BACKGROUND );
|
|
||||||
p.setPen( TomahawkStyle::SELECTION_FOREGROUND );
|
|
||||||
}
|
|
||||||
|
|
||||||
p.drawText( r, m_align, artist()->name() );
|
|
||||||
r.adjust( artistX, 0, 0, 0 );
|
|
||||||
}
|
|
||||||
if ( m_type & Album && !album()->name().isEmpty() )
|
|
||||||
{
|
|
||||||
p.setBrush( palette().window() );
|
|
||||||
p.setPen( palette().color( foregroundRole() ) );
|
|
||||||
|
|
||||||
if ( m_type & Artist )
|
|
||||||
{
|
|
||||||
p.drawText( r, m_align, DASH );
|
|
||||||
r.adjust( dashX, 0, 0, 0 );
|
|
||||||
}
|
|
||||||
if ( m_hoverType == Album )
|
|
||||||
{
|
|
||||||
p.setBrush( TomahawkStyle::SELECTION_BACKGROUND );
|
|
||||||
p.setPen( TomahawkStyle::SELECTION_FOREGROUND );
|
|
||||||
}
|
|
||||||
|
|
||||||
p.drawText( r, m_align, album()->name() );
|
|
||||||
r.adjust( albumX, 0, 0, 0 );
|
|
||||||
}
|
|
||||||
if ( m_type & Track )
|
|
||||||
{
|
|
||||||
p.setBrush( palette().window() );
|
|
||||||
p.setPen( palette().color( foregroundRole() ) );
|
|
||||||
|
|
||||||
if ( m_type & Artist || ( m_type & Album && !album()->name().isEmpty() ) )
|
|
||||||
{
|
|
||||||
p.drawText( r, m_align, DASH );
|
|
||||||
r.adjust( dashX, 0, 0, 0 );
|
|
||||||
}
|
|
||||||
if ( m_hoverType == Track )
|
|
||||||
{
|
|
||||||
p.setBrush( TomahawkStyle::SELECTION_BACKGROUND );
|
|
||||||
p.setPen( TomahawkStyle::SELECTION_FOREGROUND );
|
|
||||||
}
|
|
||||||
|
|
||||||
p.drawText( r, m_align, track() );
|
|
||||||
r.adjust( trackX, 0, 0, 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( m_jumpLinkVisible )
|
|
||||||
{
|
|
||||||
r.adjust( 6, 0, 0, 0 );
|
|
||||||
r.setWidth( r.height() );
|
|
||||||
p.drawPixmap( r, TomahawkUtils::defaultPixmap( TomahawkUtils::JumpLink, TomahawkUtils::Original, r.size() ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
p.restore();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
QueryLabel::changeEvent( QEvent* event )
|
QueryLabel::changeEvent( QEvent* event )
|
||||||
{
|
{
|
||||||
QFrame::changeEvent( event );
|
QLabel::changeEvent( event );
|
||||||
switch ( event->type() )
|
switch ( event->type() )
|
||||||
{
|
{
|
||||||
case QEvent::FontChange:
|
case QEvent::FontChange:
|
||||||
case QEvent::ApplicationFontChange:
|
case QEvent::ApplicationFontChange:
|
||||||
updateLabel();
|
updateGeometry();
|
||||||
|
update();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -485,7 +323,7 @@ QueryLabel::contextMenuEvent( QContextMenuEvent* event )
|
|||||||
{
|
{
|
||||||
m_contextMenu->clear();
|
m_contextMenu->clear();
|
||||||
|
|
||||||
switch( m_hoverType )
|
switch( m_type )
|
||||||
{
|
{
|
||||||
case Artist:
|
case Artist:
|
||||||
{
|
{
|
||||||
@@ -509,7 +347,7 @@ QueryLabel::contextMenuEvent( QContextMenuEvent* event )
|
|||||||
void
|
void
|
||||||
QueryLabel::mousePressEvent( QMouseEvent* event )
|
QueryLabel::mousePressEvent( QMouseEvent* event )
|
||||||
{
|
{
|
||||||
QFrame::mousePressEvent( event );
|
QLabel::mousePressEvent( event );
|
||||||
m_time.restart();
|
m_time.restart();
|
||||||
m_dragPos = event->pos();
|
m_dragPos = event->pos();
|
||||||
}
|
}
|
||||||
@@ -518,30 +356,28 @@ QueryLabel::mousePressEvent( QMouseEvent* event )
|
|||||||
void
|
void
|
||||||
QueryLabel::mouseReleaseEvent( QMouseEvent* event )
|
QueryLabel::mouseReleaseEvent( QMouseEvent* event )
|
||||||
{
|
{
|
||||||
QFrame::mouseReleaseEvent( event );
|
QLabel::mouseReleaseEvent( event );
|
||||||
|
|
||||||
m_dragPos = QPoint();
|
m_dragPos = QPoint();
|
||||||
if ( m_time.elapsed() < qApp->doubleClickInterval() )
|
if ( m_time.elapsed() < qApp->doubleClickInterval() )
|
||||||
{
|
{
|
||||||
switch( m_hoverType )
|
switch ( m_type )
|
||||||
{
|
{
|
||||||
case Artist:
|
case Artist:
|
||||||
emit clickedArtist();
|
{
|
||||||
|
ViewManager::instance()->show( artist() );
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case Album:
|
case Album:
|
||||||
emit clickedAlbum();
|
{
|
||||||
break;
|
ViewManager::instance()->show( album() );
|
||||||
case Track:
|
|
||||||
emit clickedTrack();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Complete:
|
|
||||||
ViewManager::instance()->showCurrentTrack();
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
emit clicked();
|
ViewManager::instance()->show( m_query );
|
||||||
}
|
}
|
||||||
|
emit clicked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -549,8 +385,7 @@ QueryLabel::mouseReleaseEvent( QMouseEvent* event )
|
|||||||
void
|
void
|
||||||
QueryLabel::mouseMoveEvent( QMouseEvent* event )
|
QueryLabel::mouseMoveEvent( QMouseEvent* event )
|
||||||
{
|
{
|
||||||
QFrame::mouseMoveEvent( event );
|
QLabel::mouseMoveEvent( event );
|
||||||
int x = event->x();
|
|
||||||
|
|
||||||
if ( event->buttons() & Qt::LeftButton &&
|
if ( event->buttons() & Qt::LeftButton &&
|
||||||
( m_dragPos - event->pos() ).manhattanLength() >= QApplication::startDragDistance() )
|
( m_dragPos - event->pos() ).manhattanLength() >= QApplication::startDragDistance() )
|
||||||
@@ -560,93 +395,10 @@ QueryLabel::mouseMoveEvent( QMouseEvent* event )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_query.isNull() && m_result.isNull() && m_artist.isNull() && m_album.isNull() )
|
if ( !m_hovering )
|
||||||
{
|
{
|
||||||
m_hoverArea = QRect();
|
m_hovering = true;
|
||||||
m_hoverType = None;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFontMetrics fm = fontMetrics();
|
|
||||||
|
|
||||||
int dashX = fm.width( DASH );
|
|
||||||
int artistX = m_type & Artist ? fm.width( artist()->name() ) : 0;
|
|
||||||
int albumX = m_type & Album ? fm.width( album()->name() ) : 0;
|
|
||||||
int trackX = m_type & Track ? fm.width( track() ) : 0;
|
|
||||||
|
|
||||||
if ( m_type & Track )
|
|
||||||
{
|
|
||||||
trackX += contentsMargins().left();
|
|
||||||
}
|
|
||||||
if ( m_type & Album && !album()->name().isEmpty() )
|
|
||||||
{
|
|
||||||
trackX += albumX + dashX;
|
|
||||||
albumX += contentsMargins().left();
|
|
||||||
}
|
|
||||||
if ( m_type & Artist )
|
|
||||||
{
|
|
||||||
albumX += artistX + dashX;
|
|
||||||
trackX += artistX + dashX;
|
|
||||||
artistX += contentsMargins().left();
|
|
||||||
}
|
|
||||||
|
|
||||||
QRect hoverArea;
|
|
||||||
m_hoverType = None;
|
|
||||||
|
|
||||||
if ( m_align & Qt::AlignLeft )
|
|
||||||
{
|
|
||||||
if ( m_type & Artist && x < artistX )
|
|
||||||
{
|
|
||||||
m_hoverType = Artist;
|
|
||||||
hoverArea.setLeft( 0 );
|
|
||||||
hoverArea.setRight( artistX + contentsMargins().left() - 1 );
|
|
||||||
}
|
|
||||||
else if ( m_type & Album && !album()->name().isEmpty() && x < albumX && x > artistX )
|
|
||||||
{
|
|
||||||
m_hoverType = Album;
|
|
||||||
int spacing = ( m_type & Artist ) ? dashX : 0;
|
|
||||||
hoverArea.setLeft( artistX + spacing - contentsMargins().left() );
|
|
||||||
hoverArea.setRight( albumX + contentsMargins().left() - 1 );
|
|
||||||
}
|
|
||||||
else if ( m_type & Track && x < trackX && x > albumX )
|
|
||||||
{
|
|
||||||
m_hoverType = Track;
|
|
||||||
int spacing = ( m_type & Album && !album()->name().isEmpty() ) ? dashX : 0;
|
|
||||||
hoverArea.setLeft( albumX + spacing );
|
|
||||||
hoverArea.setRight( trackX + contentsMargins().left() - 1 );
|
|
||||||
}
|
|
||||||
else if ( m_jumpLinkVisible && x < trackX + 6 + fm.height() && x > trackX + 6 )
|
|
||||||
{
|
|
||||||
m_hoverType = Complete;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hoverArea.setLeft( 0 );
|
|
||||||
hoverArea.setRight( width() - 1 );
|
|
||||||
|
|
||||||
if ( m_type & Artist )
|
|
||||||
m_hoverType = Artist;
|
|
||||||
else if ( m_type & Album )
|
|
||||||
m_hoverType = Album;
|
|
||||||
else if ( m_type & Track )
|
|
||||||
m_hoverType = Track;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( hoverArea.width() )
|
|
||||||
{
|
|
||||||
hoverArea.setY( 1 );
|
|
||||||
hoverArea.setHeight( height() - 2 );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( m_hoverType != None )
|
|
||||||
setCursor( Qt::PointingHandCursor );
|
setCursor( Qt::PointingHandCursor );
|
||||||
else
|
|
||||||
setCursor( Qt::ArrowCursor );
|
|
||||||
|
|
||||||
if ( hoverArea != m_hoverArea )
|
|
||||||
{
|
|
||||||
m_hoverArea = hoverArea;
|
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -655,9 +407,9 @@ QueryLabel::mouseMoveEvent( QMouseEvent* event )
|
|||||||
void
|
void
|
||||||
QueryLabel::leaveEvent( QEvent* event )
|
QueryLabel::leaveEvent( QEvent* event )
|
||||||
{
|
{
|
||||||
Q_UNUSED( event );
|
QLabel::leaveEvent( event );
|
||||||
m_hoverArea = QRect();
|
|
||||||
m_hoverType = None;
|
m_hovering = false;
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -674,7 +426,7 @@ QueryLabel::startDrag()
|
|||||||
QMimeData* mimeData = new QMimeData();
|
QMimeData* mimeData = new QMimeData();
|
||||||
mimeData->setText( text() );
|
mimeData->setText( text() );
|
||||||
|
|
||||||
switch( m_hoverType )
|
switch( m_type )
|
||||||
{
|
{
|
||||||
case Artist:
|
case Artist:
|
||||||
{
|
{
|
||||||
@@ -710,13 +462,10 @@ QueryLabel::startDrag()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
void
|
||||||
QueryLabel::smartAppend( QString& text, const QString& appendage ) const
|
QueryLabel::setType( DisplayType type )
|
||||||
{
|
{
|
||||||
QString s;
|
m_type = type;
|
||||||
if ( !text.isEmpty() )
|
updateGeometry();
|
||||||
s = DASH;
|
update();
|
||||||
|
|
||||||
text += s + appendage;
|
|
||||||
return text;
|
|
||||||
}
|
}
|
||||||
|
@@ -19,10 +19,8 @@
|
|||||||
#ifndef QUERYLABEL_H
|
#ifndef QUERYLABEL_H
|
||||||
#define QUERYLABEL_H
|
#define QUERYLABEL_H
|
||||||
|
|
||||||
#include <QFrame>
|
#include <QLabel>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QPen>
|
|
||||||
#include <QPixmap>
|
|
||||||
|
|
||||||
#include "Result.h"
|
#include "Result.h"
|
||||||
#include "Query.h"
|
#include "Query.h"
|
||||||
@@ -34,7 +32,7 @@ namespace Tomahawk
|
|||||||
class ContextMenu;
|
class ContextMenu;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DLLEXPORT QueryLabel : public QFrame
|
class DLLEXPORT QueryLabel : public QLabel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -45,20 +43,15 @@ public:
|
|||||||
Artist = 1,
|
Artist = 1,
|
||||||
Album = 2,
|
Album = 2,
|
||||||
Track = 4,
|
Track = 4,
|
||||||
ArtistAndAlbum = 3,
|
|
||||||
ArtistAndTrack = 5,
|
|
||||||
AlbumAndTrack = 6,
|
|
||||||
Complete = 7
|
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit QueryLabel( QWidget* parent = 0, Qt::WindowFlags flags = 0 );
|
explicit QueryLabel( QWidget* parent = 0, Qt::WindowFlags flags = 0 );
|
||||||
explicit QueryLabel( DisplayType type = Complete, QWidget* parent = 0, Qt::WindowFlags flags = 0 );
|
explicit QueryLabel( DisplayType type, QWidget* parent = 0, Qt::WindowFlags flags = 0 );
|
||||||
explicit QueryLabel( const Tomahawk::result_ptr& result, DisplayType type = Complete, QWidget* parent = 0, Qt::WindowFlags flags = 0 );
|
explicit QueryLabel( const Tomahawk::result_ptr& result, DisplayType type = None, QWidget* parent = 0, Qt::WindowFlags flags = 0 );
|
||||||
explicit QueryLabel( const Tomahawk::query_ptr& query, DisplayType type = Complete, QWidget* parent = 0, Qt::WindowFlags flags = 0 );
|
explicit QueryLabel( const Tomahawk::query_ptr& query, DisplayType type = None, QWidget* parent = 0, Qt::WindowFlags flags = 0 );
|
||||||
virtual ~QueryLabel();
|
virtual ~QueryLabel();
|
||||||
|
|
||||||
QString text() const;
|
QString text() const;
|
||||||
QString track() const;
|
|
||||||
|
|
||||||
Tomahawk::result_ptr result() const { return m_result; }
|
Tomahawk::result_ptr result() const { return m_result; }
|
||||||
Tomahawk::query_ptr query() const { return m_query; }
|
Tomahawk::query_ptr query() const { return m_query; }
|
||||||
@@ -66,22 +59,15 @@ public:
|
|||||||
Tomahawk::album_ptr album() const { return m_album; }
|
Tomahawk::album_ptr album() const { return m_album; }
|
||||||
|
|
||||||
DisplayType type() const { return m_type; }
|
DisplayType type() const { return m_type; }
|
||||||
void setType( DisplayType type ) { m_type = type; }
|
void setType( DisplayType type );
|
||||||
|
|
||||||
Qt::Alignment alignment() const;
|
|
||||||
void setAlignment( Qt::Alignment alignment );
|
|
||||||
|
|
||||||
Qt::TextElideMode elideMode() const;
|
Qt::TextElideMode elideMode() const;
|
||||||
void setElideMode( Qt::TextElideMode mode );
|
void setElideMode( Qt::TextElideMode mode );
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void updateLabel();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setText( const QString& text );
|
void setText( const QString& text );
|
||||||
@@ -92,9 +78,6 @@ public slots:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void clicked();
|
void clicked();
|
||||||
void clickedArtist();
|
|
||||||
void clickedAlbum();
|
|
||||||
void clickedTrack();
|
|
||||||
|
|
||||||
void textChanged( const QString& text );
|
void textChanged( const QString& text );
|
||||||
void resultChanged( const Tomahawk::result_ptr& result );
|
void resultChanged( const Tomahawk::result_ptr& result );
|
||||||
@@ -117,7 +100,6 @@ private slots:
|
|||||||
void onResultChanged();
|
void onResultChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString smartAppend( QString& text, const QString& appendage ) const;
|
|
||||||
QTime m_time;
|
QTime m_time;
|
||||||
|
|
||||||
DisplayType m_type;
|
DisplayType m_type;
|
||||||
@@ -130,15 +112,10 @@ private:
|
|||||||
|
|
||||||
Tomahawk::ContextMenu* m_contextMenu;
|
Tomahawk::ContextMenu* m_contextMenu;
|
||||||
|
|
||||||
Qt::Alignment m_align;
|
|
||||||
Qt::TextElideMode m_mode;
|
Qt::TextElideMode m_mode;
|
||||||
|
|
||||||
DisplayType m_hoverType;
|
|
||||||
QRect m_hoverArea;
|
|
||||||
QPoint m_dragPos;
|
QPoint m_dragPos;
|
||||||
QMargins m_textMargins;
|
|
||||||
|
|
||||||
bool m_jumpLinkVisible;
|
bool m_hovering;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QUERYLABEL_H
|
#endif // QUERYLABEL_H
|
||||||
|
Reference in New Issue
Block a user