mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-12 09:04:33 +02:00
* Support setting Artist / Album on a QueryLabel directly. We need a proper 'CleverLabel' so badly.
This commit is contained in:
@@ -103,7 +103,7 @@ QueryLabel::text() const
|
|||||||
{
|
{
|
||||||
QString text;
|
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;
|
return m_text;
|
||||||
|
|
||||||
if ( !m_result.isNull() )
|
if ( !m_result.isNull() )
|
||||||
@@ -121,7 +121,7 @@ QueryLabel::text() const
|
|||||||
smartAppend( text, m_result->track() );
|
smartAppend( text, m_result->track() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if ( !m_query.isNull() )
|
||||||
{
|
{
|
||||||
if ( m_type & Artist )
|
if ( m_type & Artist )
|
||||||
{
|
{
|
||||||
@@ -136,37 +136,19 @@ QueryLabel::text() const
|
|||||||
smartAppend( text, m_query->track() );
|
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;
|
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
|
QString
|
||||||
QueryLabel::track() const
|
QueryLabel::track() const
|
||||||
{
|
{
|
||||||
@@ -187,6 +169,8 @@ QueryLabel::setText( const QString& text )
|
|||||||
|
|
||||||
m_result.clear();
|
m_result.clear();
|
||||||
m_query.clear();
|
m_query.clear();
|
||||||
|
m_artist.clear();
|
||||||
|
m_album.clear();
|
||||||
m_text = text;
|
m_text = text;
|
||||||
|
|
||||||
updateLabel();
|
updateLabel();
|
||||||
@@ -211,6 +195,8 @@ QueryLabel::setResult( const Tomahawk::result_ptr& result )
|
|||||||
{
|
{
|
||||||
m_result = result;
|
m_result = result;
|
||||||
m_query = m_result->toQuery();
|
m_query = m_result->toQuery();
|
||||||
|
m_artist = result->artist();
|
||||||
|
m_album = result->album();
|
||||||
|
|
||||||
updateLabel();
|
updateLabel();
|
||||||
|
|
||||||
@@ -231,7 +217,10 @@ QueryLabel::setQuery( const Tomahawk::query_ptr& query )
|
|||||||
if ( m_query.isNull() || m_query.data() != query.data() )
|
if ( m_query.isNull() || m_query.data() != query.data() )
|
||||||
{
|
{
|
||||||
m_query = query;
|
m_query = query;
|
||||||
|
m_artist = Artist::get( query->artist() );
|
||||||
|
m_album = Album::get( m_artist, query->album() );
|
||||||
m_result.clear();
|
m_result.clear();
|
||||||
|
|
||||||
updateLabel();
|
updateLabel();
|
||||||
|
|
||||||
emit textChanged( text() );
|
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
|
void
|
||||||
QueryLabel::setJumpLinkVisible( bool visible )
|
QueryLabel::setJumpLinkVisible( bool visible )
|
||||||
{
|
{
|
||||||
@@ -395,7 +404,7 @@ QueryLabel::paintEvent( QPaintEvent* event )
|
|||||||
TomahawkUtils::drawQueryBackground( &p, palette(), m_hoverArea );
|
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() )
|
if ( m_hoverArea.width() )
|
||||||
{
|
{
|
||||||
@@ -412,8 +421,8 @@ QueryLabel::paintEvent( QPaintEvent* event )
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
int dashX = fm.width( DASH );
|
int dashX = fm.width( DASH );
|
||||||
int artistX = m_type & Artist ? fm.width( artist() ) : 0;
|
int artistX = m_type & Artist ? fm.width( artist()->name() ) : 0;
|
||||||
int albumX = m_type & Album ? fm.width( album() ) : 0;
|
int albumX = m_type & Album ? fm.width( album()->name() ) : 0;
|
||||||
int trackX = m_type & Track ? fm.width( track() ) : 0;
|
int trackX = m_type & Track ? fm.width( track() ) : 0;
|
||||||
|
|
||||||
if ( m_useCustomPen )
|
if ( m_useCustomPen )
|
||||||
@@ -431,7 +440,7 @@ QueryLabel::paintEvent( QPaintEvent* event )
|
|||||||
p.setBrush( palette().highlight() );
|
p.setBrush( palette().highlight() );
|
||||||
}
|
}
|
||||||
|
|
||||||
p.drawText( r, m_align, artist() );
|
p.drawText( r, m_align, artist()->name() );
|
||||||
r.adjust( artistX, 0, 0, 0 );
|
r.adjust( artistX, 0, 0, 0 );
|
||||||
}
|
}
|
||||||
if ( m_type & Album )
|
if ( m_type & Album )
|
||||||
@@ -451,7 +460,7 @@ QueryLabel::paintEvent( QPaintEvent* event )
|
|||||||
p.setBrush( palette().highlight() );
|
p.setBrush( palette().highlight() );
|
||||||
}
|
}
|
||||||
|
|
||||||
p.drawText( r, m_align, album() );
|
p.drawText( r, m_align, album()->name() );
|
||||||
r.adjust( albumX, 0, 0, 0 );
|
r.adjust( albumX, 0, 0, 0 );
|
||||||
}
|
}
|
||||||
if ( m_type & Track )
|
if ( m_type & Track )
|
||||||
@@ -513,15 +522,12 @@ QueryLabel::contextMenuEvent( QContextMenuEvent* event )
|
|||||||
{
|
{
|
||||||
case Artist:
|
case Artist:
|
||||||
{
|
{
|
||||||
artist_ptr artist = Artist::get( m_query->artist() );
|
m_contextMenu->setArtist( artist() );
|
||||||
m_contextMenu->setArtist( artist );
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Album:
|
case Album:
|
||||||
{
|
{
|
||||||
artist_ptr artist = Artist::get( m_query->artist() );
|
m_contextMenu->setAlbum( album() );
|
||||||
album_ptr album = Album::get( artist, m_query->album() );
|
|
||||||
m_contextMenu->setAlbum( album );
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -587,7 +593,7 @@ QueryLabel::mouseMoveEvent( QMouseEvent* event )
|
|||||||
return;
|
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_hoverArea = QRect();
|
||||||
m_hoverType = None;
|
m_hoverType = None;
|
||||||
@@ -599,8 +605,8 @@ QueryLabel::mouseMoveEvent( QMouseEvent* event )
|
|||||||
fm = QFontMetrics( m_font );
|
fm = QFontMetrics( m_font );
|
||||||
|
|
||||||
int dashX = fm.width( DASH );
|
int dashX = fm.width( DASH );
|
||||||
int artistX = m_type & Artist ? fm.width( artist() ) : 0;
|
int artistX = m_type & Artist ? fm.width( artist()->name() ) : 0;
|
||||||
int albumX = m_type & Album ? fm.width( album() ) : 0;
|
int albumX = m_type & Album ? fm.width( album()->name() ) : 0;
|
||||||
int trackX = m_type & Track ? fm.width( track() ) : 0;
|
int trackX = m_type & Track ? fm.width( track() ) : 0;
|
||||||
|
|
||||||
if ( m_type & Track )
|
if ( m_type & Track )
|
||||||
@@ -694,7 +700,7 @@ QueryLabel::leaveEvent( QEvent* event )
|
|||||||
void
|
void
|
||||||
QueryLabel::startDrag()
|
QueryLabel::startDrag()
|
||||||
{
|
{
|
||||||
if ( m_query.isNull() )
|
if ( m_query.isNull() && m_album.isNull() && m_artist.isNull() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QDrag *drag = new QDrag( this );
|
QDrag *drag = new QDrag( this );
|
||||||
@@ -707,15 +713,15 @@ QueryLabel::startDrag()
|
|||||||
{
|
{
|
||||||
case Artist:
|
case Artist:
|
||||||
{
|
{
|
||||||
dataStream << m_query->artist();
|
dataStream << artist()->name();
|
||||||
mimeData->setData( "application/tomahawk.metadata.artist", data );
|
mimeData->setData( "application/tomahawk.metadata.artist", data );
|
||||||
drag->setPixmap( TomahawkUtils::createDragPixmap( TomahawkUtils::MediaTypeArtist ) );
|
drag->setPixmap( TomahawkUtils::createDragPixmap( TomahawkUtils::MediaTypeArtist ) );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Album:
|
case Album:
|
||||||
{
|
{
|
||||||
dataStream << m_query->artist();
|
dataStream << artist()->name();
|
||||||
dataStream << m_query->album();
|
dataStream << album()->name();
|
||||||
mimeData->setData( "application/tomahawk.metadata.album", data );
|
mimeData->setData( "application/tomahawk.metadata.album", data );
|
||||||
drag->setPixmap( TomahawkUtils::createDragPixmap( TomahawkUtils::MediaTypeAlbum ) );
|
drag->setPixmap( TomahawkUtils::createDragPixmap( TomahawkUtils::MediaTypeAlbum ) );
|
||||||
break;
|
break;
|
||||||
|
@@ -58,12 +58,12 @@ public:
|
|||||||
virtual ~QueryLabel();
|
virtual ~QueryLabel();
|
||||||
|
|
||||||
QString text() const;
|
QString text() const;
|
||||||
QString artist() const;
|
|
||||||
QString album() const;
|
|
||||||
QString track() 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; }
|
||||||
|
Tomahawk::artist_ptr artist() const { return m_artist; }
|
||||||
|
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 ) { m_type = type; }
|
||||||
@@ -93,6 +93,8 @@ public slots:
|
|||||||
void setText( const QString& text );
|
void setText( const QString& text );
|
||||||
void setResult( const Tomahawk::result_ptr& result );
|
void setResult( const Tomahawk::result_ptr& result );
|
||||||
void setQuery( const Tomahawk::query_ptr& query );
|
void setQuery( const Tomahawk::query_ptr& query );
|
||||||
|
void setArtist( const Tomahawk::artist_ptr& artist );
|
||||||
|
void setAlbum( const Tomahawk::album_ptr& album );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void clicked();
|
void clicked();
|
||||||
@@ -123,8 +125,11 @@ private:
|
|||||||
|
|
||||||
DisplayType m_type;
|
DisplayType m_type;
|
||||||
QString m_text;
|
QString m_text;
|
||||||
|
|
||||||
Tomahawk::result_ptr m_result;
|
Tomahawk::result_ptr m_result;
|
||||||
Tomahawk::query_ptr m_query;
|
Tomahawk::query_ptr m_query;
|
||||||
|
Tomahawk::artist_ptr m_artist;
|
||||||
|
Tomahawk::album_ptr m_album;
|
||||||
|
|
||||||
Tomahawk::ContextMenu* m_contextMenu;
|
Tomahawk::ContextMenu* m_contextMenu;
|
||||||
|
|
||||||
@@ -139,7 +144,7 @@ private:
|
|||||||
QRect m_hoverArea;
|
QRect m_hoverArea;
|
||||||
QPoint m_dragPos;
|
QPoint m_dragPos;
|
||||||
QMargins m_textMargins;
|
QMargins m_textMargins;
|
||||||
|
|
||||||
bool m_jumpLinkVisible;
|
bool m_jumpLinkVisible;
|
||||||
QPixmap m_jumpPixmap;
|
QPixmap m_jumpPixmap;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user