1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-11 16:44:05 +02:00

* Support setting Artist / Album on a QueryLabel directly. We need a proper 'CleverLabel' so badly.

This commit is contained in:
Christian Muehlhaeuser
2012-06-29 04:28:08 +02:00
parent 5ed6bb52b5
commit d890ea3b14
2 changed files with 59 additions and 48 deletions

View File

@@ -103,7 +103,7 @@ QueryLabel::text() const
{
QString text;
if ( m_result.isNull() && m_query.isNull() )
if ( m_result.isNull() && m_query.isNull() && m_artist.isNull() && m_album.isNull() )
return m_text;
if ( !m_result.isNull() )
@@ -121,7 +121,7 @@ QueryLabel::text() const
smartAppend( text, m_result->track() );
}
}
else
else if ( !m_query.isNull() )
{
if ( m_type & Artist )
{
@@ -136,37 +136,19 @@ QueryLabel::text() const
smartAppend( text, m_query->track() );
}
}
else if ( !m_artist.isNull() )
{
text += m_artist->name();
}
else if ( !m_album.isNull() )
{
text += m_album->name();
}
return text;
}
QString
QueryLabel::artist() const
{
if ( m_result.isNull() && m_query.isNull() )
return QString();
if ( !m_result.isNull() )
return m_result->artist()->name();
else
return m_query->artist();
}
QString
QueryLabel::album() const
{
if ( m_result.isNull() && m_query.isNull() )
return QString();
if ( !m_result.isNull() )
return m_result->album()->name();
else
return m_query->album();
}
QString
QueryLabel::track() const
{
@@ -187,6 +169,8 @@ QueryLabel::setText( const QString& text )
m_result.clear();
m_query.clear();
m_artist.clear();
m_album.clear();
m_text = text;
updateLabel();
@@ -211,6 +195,8 @@ QueryLabel::setResult( const Tomahawk::result_ptr& result )
{
m_result = result;
m_query = m_result->toQuery();
m_artist = result->artist();
m_album = result->album();
updateLabel();
@@ -231,7 +217,10 @@ QueryLabel::setQuery( const Tomahawk::query_ptr& query )
if ( m_query.isNull() || m_query.data() != query.data() )
{
m_query = query;
m_artist = Artist::get( query->artist() );
m_album = Album::get( m_artist, query->album() );
m_result.clear();
updateLabel();
emit textChanged( text() );
@@ -240,6 +229,26 @@ QueryLabel::setQuery( const Tomahawk::query_ptr& query )
}
void
QueryLabel::setArtist( const artist_ptr& artist )
{
m_artist = artist;
updateLabel();
emit textChanged( text() );
}
void
QueryLabel::setAlbum( const album_ptr& album )
{
m_album = album;
updateLabel();
emit textChanged( text() );
}
void
QueryLabel::setJumpLinkVisible( bool visible )
{
@@ -395,7 +404,7 @@ QueryLabel::paintEvent( QPaintEvent* event )
TomahawkUtils::drawQueryBackground( &p, palette(), m_hoverArea );
}
if ( elidedText != s || ( m_result.isNull() && m_query.isNull() ) )
if ( elidedText != s || ( m_result.isNull() && m_query.isNull() && m_artist.isNull() && m_album.isNull() ) )
{
if ( m_hoverArea.width() )
{
@@ -412,8 +421,8 @@ QueryLabel::paintEvent( QPaintEvent* event )
else
{
int dashX = fm.width( DASH );
int artistX = m_type & Artist ? fm.width( artist() ) : 0;
int albumX = m_type & Album ? fm.width( album() ) : 0;
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_useCustomPen )
@@ -431,7 +440,7 @@ QueryLabel::paintEvent( QPaintEvent* event )
p.setBrush( palette().highlight() );
}
p.drawText( r, m_align, artist() );
p.drawText( r, m_align, artist()->name() );
r.adjust( artistX, 0, 0, 0 );
}
if ( m_type & Album )
@@ -451,7 +460,7 @@ QueryLabel::paintEvent( QPaintEvent* event )
p.setBrush( palette().highlight() );
}
p.drawText( r, m_align, album() );
p.drawText( r, m_align, album()->name() );
r.adjust( albumX, 0, 0, 0 );
}
if ( m_type & Track )
@@ -513,15 +522,12 @@ QueryLabel::contextMenuEvent( QContextMenuEvent* event )
{
case Artist:
{
artist_ptr artist = Artist::get( m_query->artist() );
m_contextMenu->setArtist( artist );
m_contextMenu->setArtist( artist() );
break;
}
case Album:
{
artist_ptr artist = Artist::get( m_query->artist() );
album_ptr album = Album::get( artist, m_query->album() );
m_contextMenu->setAlbum( album );
m_contextMenu->setAlbum( album() );
break;
}
@@ -587,7 +593,7 @@ QueryLabel::mouseMoveEvent( QMouseEvent* event )
return;
}
if ( m_query.isNull() && m_result.isNull() )
if ( m_query.isNull() && m_result.isNull() && m_artist.isNull() && m_album.isNull() )
{
m_hoverArea = QRect();
m_hoverType = None;
@@ -599,8 +605,8 @@ QueryLabel::mouseMoveEvent( QMouseEvent* event )
fm = QFontMetrics( m_font );
int dashX = fm.width( DASH );
int artistX = m_type & Artist ? fm.width( artist() ) : 0;
int albumX = m_type & Album ? fm.width( album() ) : 0;
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 )
@@ -694,7 +700,7 @@ QueryLabel::leaveEvent( QEvent* event )
void
QueryLabel::startDrag()
{
if ( m_query.isNull() )
if ( m_query.isNull() && m_album.isNull() && m_artist.isNull() )
return;
QDrag *drag = new QDrag( this );
@@ -707,15 +713,15 @@ QueryLabel::startDrag()
{
case Artist:
{
dataStream << m_query->artist();
dataStream << artist()->name();
mimeData->setData( "application/tomahawk.metadata.artist", data );
drag->setPixmap( TomahawkUtils::createDragPixmap( TomahawkUtils::MediaTypeArtist ) );
break;
}
case Album:
{
dataStream << m_query->artist();
dataStream << m_query->album();
dataStream << artist()->name();
dataStream << album()->name();
mimeData->setData( "application/tomahawk.metadata.album", data );
drag->setPixmap( TomahawkUtils::createDragPixmap( TomahawkUtils::MediaTypeAlbum ) );
break;

View File

@@ -58,12 +58,12 @@ public:
virtual ~QueryLabel();
QString text() const;
QString artist() const;
QString album() const;
QString track() const;
Tomahawk::result_ptr result() const { return m_result; }
Tomahawk::query_ptr query() const { return m_query; }
Tomahawk::artist_ptr artist() const { return m_artist; }
Tomahawk::album_ptr album() const { return m_album; }
DisplayType type() const { return m_type; }
void setType( DisplayType type ) { m_type = type; }
@@ -93,6 +93,8 @@ public slots:
void setText( const QString& text );
void setResult( const Tomahawk::result_ptr& result );
void setQuery( const Tomahawk::query_ptr& query );
void setArtist( const Tomahawk::artist_ptr& artist );
void setAlbum( const Tomahawk::album_ptr& album );
signals:
void clicked();
@@ -123,8 +125,11 @@ private:
DisplayType m_type;
QString m_text;
Tomahawk::result_ptr m_result;
Tomahawk::query_ptr m_query;
Tomahawk::artist_ptr m_artist;
Tomahawk::album_ptr m_album;
Tomahawk::ContextMenu* m_contextMenu;
@@ -139,7 +144,7 @@ private:
QRect m_hoverArea;
QPoint m_dragPos;
QMargins m_textMargins;
bool m_jumpLinkVisible;
QPixmap m_jumpPixmap;
};