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

Show a querylabel in the infobar if there's artist we can link it to

This commit is contained in:
Leo Franchi 2011-10-29 18:27:08 -04:00
parent ec66cf29f3
commit c1ee97fc40
12 changed files with 230 additions and 60 deletions

View File

@ -27,6 +27,7 @@
#include "utils/tomahawkutils.h"
#include "utils/logger.h"
#include <QCheckBox>
#include <widgets/querylabel.h>
#define ANIMATION_TIME 400
#define IMAGE_HEIGHT 64
@ -37,10 +38,12 @@ using namespace Tomahawk;
InfoBar::InfoBar( QWidget* parent )
: QWidget( parent )
, ui( new Ui::InfoBar )
, m_queryLabel( 0 )
{
ui->setupUi( this );
TomahawkUtils::unmarginLayout( layout() );
layout()->setContentsMargins( 8, 4, 8, 4 );
ui->verticalLayout->setContentsMargins( 0, 0, 0, 15 );
QFont boldFont = ui->captionLabel->font();
boldFont.setPixelSize( 18 );
@ -71,6 +74,14 @@ InfoBar::InfoBar( QWidget* parent )
ui->longDescriptionLabel->setText( QString() );
ui->imageLabel->setText( QString() );
m_queryLabel = new QueryLabel( this );
m_queryLabel->setType( QueryLabel::Artist );
m_queryLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
m_queryLabel->setTextPen( palette().brightText().color() );
m_queryLabel->setFont( boldFont );
m_queryLabel->hide();
connect( m_queryLabel, SIGNAL( clickedArtist() ), this, SLOT( artistClicked() ) );
m_autoUpdate = new QCheckBox( this );
m_autoUpdate->setText( tr( "Automatically update" ) );
m_autoUpdate->setLayoutDirection( Qt::RightToLeft );
@ -116,9 +127,47 @@ InfoBar::setCaption( const QString& s )
void
InfoBar::setDescription( const QString& s )
{
if ( m_queryLabel->isVisible() )
{
ui->verticalLayout->removeWidget( m_queryLabel );
m_queryLabel->hide();
ui->verticalLayout->addWidget( ui->descriptionLabel );
ui->descriptionLabel->show();
}
ui->descriptionLabel->setText( s );
}
void
InfoBar::setDescription( const artist_ptr& artist )
{
m_queryLabel->setQuery( Query::get( artist->name(), QString(), QString() ) );
m_queryLabel->setExtraContentsMargins( 4, 0, 0, 0 );
if ( !m_queryLabel->isVisible() )
{
ui->verticalLayout->removeWidget( ui->descriptionLabel );
ui->descriptionLabel->hide();
m_queryLabel->show();
ui->verticalLayout->addWidget( m_queryLabel );
}
}
void
InfoBar::setDescription( const album_ptr& album_ptr )
{
// TODO
}
void
InfoBar::artistClicked()
{
if ( m_queryLabel && !m_queryLabel->query().isNull() )
ViewManager::instance()->show( Artist::get( m_queryLabel->artist() ) );
}
void
InfoBar::setLongDescription( const QString& s )

View File

@ -22,7 +22,9 @@
#include <QWidget>
#include "dllmacro.h"
#include "artist.h"
class QueryLabel;
class QCheckBox;
class QTimeLine;
class QSearchField;
@ -43,7 +45,12 @@ public:
public slots:
void setCaption( const QString& s );
void setDescription( const QString& s );
// If you want a querylabel instead of an ElidedLabel
void setDescription( const Tomahawk::artist_ptr& artist );
void setDescription( const Tomahawk::album_ptr& album_ptr );
void setLongDescription( const QString& s );
void setPixmap( const QPixmap& p );
@ -60,12 +67,14 @@ protected:
private slots:
void onFilterEdited();
void artistClicked();
private:
Ui::InfoBar* ui;
QSearchField* m_searchWidget;
QCheckBox* m_autoUpdate;
QueryLabel* m_queryLabel;
};
#endif // INFOBAR_H

View File

@ -65,10 +65,13 @@
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="ElidedLabel" name="captionLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>

View File

@ -555,6 +555,12 @@ ViewManager::setPage( ViewPage* page, bool trackHistory )
if( obj->metaObject()->indexOfSignal( "descriptionChanged(QString)" ) > -1 )
connect( obj, SIGNAL( descriptionChanged( QString ) ), m_infobar, SLOT( setDescription( QString ) ), Qt::UniqueConnection );
if( obj->metaObject()->indexOfSignal( "descriptionChanged(Tomahawk::artist_ptr)" ) > -1 )
connect( obj, SIGNAL( descriptionChanged( Tomahawk::artist_ptr ) ), m_infobar, SLOT( setDescription( Tomahawk::artist_ptr ) ), Qt::UniqueConnection );
if( obj->metaObject()->indexOfSignal( "descriptionChanged(Tomahawk::album_ptr)" ) > -1 )
connect( obj, SIGNAL( descriptionChanged( Tomahawk::album_ptr ) ), m_infobar, SLOT( setDescription( Tomahawk::album_ptr ) ), Qt::UniqueConnection );
if( obj->metaObject()->indexOfSignal( "longDescriptionChanged(QString)" ) > -1 )
connect( obj, SIGNAL( longDescriptionChanged( QString ) ), m_infobar, SLOT( setLongDescription( QString ) ), Qt::UniqueConnection );
@ -672,7 +678,19 @@ ViewManager::updateView()
m_infobar->setVisible( currentPage()->showInfoBar() );
m_infobar->setCaption( currentPage()->title() );
m_infobar->setDescription( currentPage()->description() );
switch( currentPage()->descriptionType() )
{
case ViewPage::TextType:
m_infobar->setDescription( currentPage()->description() );
break;
case ViewPage::ArtistType:
m_infobar->setDescription( currentPage()->descriptionArtist() );
break;
case ViewPage::AlbumType:
m_infobar->setDescription( currentPage()->descriptionAlbum() );
break;
}
m_infobar->setLongDescription( currentPage()->longDescription() );
m_infobar->setPixmap( currentPage()->pixmap() );

View File

@ -23,6 +23,8 @@
#include "typedefs.h"
#include "playlistinterface.h"
#include "artist.h"
#include "album.h"
#include "utils/tomahawkutils.h"
#include "dllmacro.h"
@ -33,6 +35,12 @@ namespace Tomahawk
class DLLEXPORT ViewPage
{
public:
enum DescriptionType {
TextType = 0,
ArtistType = 1,
AlbumType = 2
};
ViewPage() {}
virtual ~ViewPage() {}
@ -40,7 +48,12 @@ public:
virtual Tomahawk::PlaylistInterface* playlistInterface() const = 0;
virtual QString title() const = 0;
virtual DescriptionType descriptionType() { return TextType; }
virtual QString description() const = 0;
virtual Tomahawk::artist_ptr descriptionArtist() const { return Tomahawk::artist_ptr(); }
virtual Tomahawk::album_ptr descriptionAlbum() const { return Tomahawk::album_ptr(); }
virtual QString longDescription() const { return QString(); }
virtual QPixmap pixmap() const { return QPixmap( RESPATH "icons/tomahawk-icon-128x128.png" ); }
@ -62,6 +75,8 @@ public:
/** subclasses implementing ViewPage can emit the following signals:
* nameChanged( const QString& )
* descriptionChanged( const QString& )
* descriptionChanged( const Tomahawk::artist_ptr& artist )
* descriptionChanged( const Tomahawk::album_ptr& album )
* longDescriptionChanged( const QString& )
* pixmapChanged( const QPixmap& )
* destroyed( QWidget* widget );

View File

@ -121,10 +121,10 @@ Breadcrumb::updateButtons( const QModelIndex& updateFrom )
// Animate all buttons except the first
if ( m_buttons.count() > 0 )
{
QPropertyAnimation* animation = new QPropertyAnimation( btn, "pos" );
QPropertyAnimation* animation = new QPropertyAnimation( btn, "x" );
animation->setDuration( 300 );
animation->setStartValue( m_buttons.last()->pos() );
animation->setEndValue( btn->pos() );
animation->setStartValue( m_buttons.last()->pos().x() );
animation->setEndValue( btn->pos().x() );
animation->start( QAbstractAnimation::DeleteWhenStopped );
}
@ -150,19 +150,7 @@ Breadcrumb::updateButtons( const QModelIndex& updateFrom )
while ( m_buttons.size() > cur )
{
BreadcrumbButton* b = m_buttons.takeLast();
m_buttonlayout->removeWidget( b );
b->show();
if ( m_buttons.size() )
{
QPropertyAnimation* animation = new QPropertyAnimation( b, "pos" );
animation->setDuration( 300 );
animation->setStartValue( b->pos() );
animation->setEndValue( m_buttons.last()->pos() );
animation->start( QAbstractAnimation::DeleteWhenStopped );
}
b->deleteLater();
}

View File

@ -59,6 +59,7 @@ BreadcrumbButton::paintEvent( QPaintEvent* )
StyleHelper::horizontalHeader( &p, r ); // draw the background
qDebug() << "BREADCRUMBBUTTON PAINTING IN:" << r << mapToParent( r.topLeft() ) << m_curIndex.data();
if( !hasChildren() )
return;

View File

@ -136,6 +136,23 @@ AlbumInfoWidget::isBeingPlayed() const
return false;
}
artist_ptr AlbumInfoWidget::descriptionArtist() const
{
if ( !m_album.isNull() && !m_album->artist().isNull() )
return m_album->artist();
return artist_ptr();
}
ViewPage::DescriptionType
AlbumInfoWidget::descriptionType()
{
if ( !m_album.isNull() && !m_album->artist().isNull() )
return ViewPage::ArtistType;
return ViewPage::TextType;
}
void
AlbumInfoWidget::load( const album_ptr& album )
@ -143,6 +160,7 @@ AlbumInfoWidget::load( const album_ptr& album )
m_album = album;
m_title = album->name();
m_description = album->artist()->name();
ui->albumsLabel->setText( tr( "Other Albums by %1" ).arg( album->artist()->name() ) );
m_tracksModel->addTracks( album, QModelIndex() );

View File

@ -53,6 +53,24 @@ public:
AlbumInfoWidget( const Tomahawk::album_ptr& album, QWidget* parent = 0 );
~AlbumInfoWidget();
virtual QWidget* widget() { return this; }
virtual Tomahawk::PlaylistInterface* playlistInterface() const;
virtual QString title() const { return m_title; }
virtual DescriptionType descriptionType();
virtual QString description() const { return m_description; }
virtual Tomahawk::artist_ptr descriptionArtist() const;
virtual QString longDescription() const { return m_longDescription; }
virtual QPixmap pixmap() const { if ( m_pixmap.isNull() ) return Tomahawk::ViewPage::pixmap(); else return m_pixmap; }
virtual bool isTemporaryPage() const { return true; }
virtual bool showStatsBar() const { return false; }
virtual bool jumpToCurrentTrack() { return false; }
virtual bool isBeingPlayed() const;
public slots:
/** \brief Loads information for a given album.
* \param album The album that you want to load information for.
*
@ -63,23 +81,9 @@ public:
*/
void load( const Tomahawk::album_ptr& album );
virtual QWidget* widget() { return this; }
virtual Tomahawk::PlaylistInterface* playlistInterface() const;
virtual QString title() const { return m_title; }
virtual QString description() const { return m_description; }
virtual QString longDescription() const { return m_longDescription; }
virtual QPixmap pixmap() const { if ( m_pixmap.isNull() ) return Tomahawk::ViewPage::pixmap(); else return m_pixmap; }
virtual bool isTemporaryPage() const { return true; }
virtual bool showStatsBar() const { return false; }
virtual bool jumpToCurrentTrack() { return false; }
virtual bool isBeingPlayed() const;
signals:
void longDescriptionChanged( const QString& description );
void descriptionChanged( const QString& description );
void descriptionChanged( const Tomahawk::artist_ptr& artist );
void pixmapChanged( const QPixmap& pixmap );
protected:

View File

@ -80,8 +80,10 @@ QueryLabel::init()
setContentsMargins( 0, 0, 0, 0 );
setMouseTracking( true );
align = Qt::AlignLeft;
mode = Qt::ElideMiddle;
m_useCustomPen = false;
m_useCustomFont = false;
m_align = Qt::AlignLeft;
m_mode = Qt::ElideMiddle;
}
@ -234,38 +236,63 @@ QueryLabel::setQuery( const Tomahawk::query_ptr& query )
Qt::Alignment
QueryLabel::alignment() const
{
return align;
return m_align;
}
void
QueryLabel::setAlignment( Qt::Alignment alignment )
{
if ( this->align != alignment )
if ( m_align != alignment )
{
this->align = alignment;
m_align = alignment;
update(); // no geometry change, repaint is sufficient
}
}
void
QueryLabel::setTextPen( const QPen & pen )
{
m_useCustomPen = true;
m_textPen = pen;
}
QPen
QueryLabel::textPen() const
{
return m_textPen;
}
Qt::TextElideMode
QueryLabel::elideMode() const
{
return mode;
return m_mode;
}
void
QueryLabel::setElideMode( Qt::TextElideMode mode )
{
if ( this->mode != mode )
if ( m_mode != mode )
{
this->mode = mode;
m_mode = mode;
updateLabel();
}
}
QFont
QueryLabel::font() const
{
return m_font;
}
void
QueryLabel::setFont( const QFont& font )
{
m_useCustomFont = true;
m_font = font;
}
void
QueryLabel::updateLabel()
@ -277,6 +304,17 @@ QueryLabel::updateLabel()
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 );
}
QSize
QueryLabel::sizeHint() const
@ -290,7 +328,7 @@ QueryLabel::sizeHint() const
QSize
QueryLabel::minimumSizeHint() const
{
switch ( mode )
switch ( m_mode )
{
case Qt::ElideNone:
return sizeHint();
@ -312,11 +350,14 @@ QueryLabel::paintEvent( QPaintEvent* event )
QPainter p( this );
QRect r = contentsRect();
QString s = text();
const QString elidedText = fontMetrics().elidedText( s, mode, r.width() );
const QString elidedText = fontMetrics().elidedText( s, m_mode, r.width() );
p.save();
p.setRenderHint( QPainter::Antialiasing );
if ( m_useCustomFont )
p.setFont( m_font );
if ( m_hoverArea.width() )
{
if ( elidedText != s )
@ -343,7 +384,7 @@ QueryLabel::paintEvent( QPaintEvent* event )
p.setBrush( palette().window() );
p.setPen( palette().color( foregroundRole() ) );
}
p.drawText( r, align, elidedText );
p.drawText( r, m_align, elidedText );
}
else
{
@ -353,10 +394,14 @@ QueryLabel::paintEvent( QPaintEvent* event )
int albumX = m_type & Album ? fm.width( album() ) : 0;
int trackX = m_type & Track ? fm.width( track() ) : 0;
if ( m_useCustomPen )
p.setPen( m_textPen );
if ( m_type & Artist )
{
p.setBrush( palette().window() );
p.setPen( palette().color( foregroundRole() ) );
if ( !m_useCustomPen )
p.setPen( palette().color( foregroundRole() ) );
if ( m_hoverType == Artist )
{
@ -364,17 +409,18 @@ QueryLabel::paintEvent( QPaintEvent* event )
p.setBrush( palette().highlight() );
}
p.drawText( r, align, artist() );
p.drawText( r, m_align, artist() );
r.adjust( artistX, 0, 0, 0 );
}
if ( m_type & Album )
{
p.setBrush( palette().window() );
p.setPen( palette().color( foregroundRole() ) );
if ( !m_useCustomPen )
p.setPen( palette().color( foregroundRole() ) );
if ( m_type & Artist )
{
p.drawText( r, align, DASH );
p.drawText( r, m_align, DASH );
r.adjust( dashX, 0, 0, 0 );
}
if ( m_hoverType == Album )
@ -383,17 +429,18 @@ QueryLabel::paintEvent( QPaintEvent* event )
p.setBrush( palette().highlight() );
}
p.drawText( r, align, album() );
p.drawText( r, m_align, album() );
r.adjust( albumX, 0, 0, 0 );
}
if ( m_type & Track )
{
p.setBrush( palette().window() );
p.setPen( palette().color( foregroundRole() ) );
if ( !m_useCustomPen )
p.setPen( palette().color( foregroundRole() ) );
if ( m_type & Artist || m_type & Album )
{
p.drawText( r, align, DASH );
p.drawText( r, m_align, DASH );
r.adjust( dashX, 0, 0, 0 );
}
if ( m_hoverType == Track )
@ -402,7 +449,7 @@ QueryLabel::paintEvent( QPaintEvent* event )
p.setBrush( palette().highlight() );
}
p.drawText( r, align, track() );
p.drawText( r, m_align, track() );
r.adjust( trackX, 0, 0, 0 );
}
}
@ -432,7 +479,8 @@ void
QueryLabel::mousePressEvent( QMouseEvent* event )
{
QFrame::mousePressEvent( event );
time.start();
m_time.restart();
m_dragPos = event->pos();
}
@ -442,7 +490,8 @@ QueryLabel::mouseReleaseEvent( QMouseEvent* event )
QFrame::mouseReleaseEvent( event );
m_dragPos = QPoint();
if ( time.elapsed() < qApp->doubleClickInterval() )
qDebug() << "ELAPSED TIME" << m_time.elapsed() << "limit:" << qApp->doubleClickInterval();
if ( m_time.elapsed() < qApp->doubleClickInterval() )
{
switch( m_hoverType )
{
@ -484,7 +533,10 @@ QueryLabel::mouseMoveEvent( QMouseEvent* event )
return;
}
const QFontMetrics& fm = fontMetrics();
QFontMetrics fm = fontMetrics();
if ( m_useCustomFont )
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;

View File

@ -1,5 +1,5 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
@ -21,6 +21,7 @@
#include <QFrame>
#include <QTime>
#include <QPen>
#include "result.h"
#include "query.h"
@ -67,6 +68,14 @@ public:
Qt::TextElideMode elideMode() const;
void setElideMode( Qt::TextElideMode mode );
void setTextPen( const QPen& );
QPen textPen() const;
void setFont( const QFont& );
QFont font() const;
void setExtraContentsMargins( int left, int top, int right, int bottom );
virtual QSize sizeHint() const;
virtual QSize minimumSizeHint() const;
@ -98,18 +107,22 @@ protected:
virtual void paintEvent( QPaintEvent* event );
virtual void startDrag();
private:
QString smartAppend( QString& text, const QString& appendage ) const;
QTime time;
QTime m_time;
DisplayType m_type;
QString m_text;
Tomahawk::result_ptr m_result;
Tomahawk::query_ptr m_query;
Qt::Alignment align;
Qt::TextElideMode mode;
Qt::Alignment m_align;
Qt::TextElideMode m_mode;
bool m_useCustomPen, m_useCustomFont;
QPen m_textPen;
QFont m_font;
DisplayType m_hoverType;
QRect m_hoverArea;

View File

@ -710,7 +710,7 @@ TomahawkWindow::showAboutTomahawk()
{
QMessageBox::about( this, tr( "About Tomahawk" ),
tr( "<h2><b>Tomahawk %1<br/>(%2)</h2>Copyright 2010, 2011<br/>Christian Muehlhaeuser &lt;muesli@tomahawk-player.org&gt;<br/><br/>"
"Thanks to: Leo Franchi, Jeff Mitchell, Dominik Schmidt, Jason Herskowitz, Alejandro Wainzinger, Michael Zanetti, Harald Sitter and Steve Robertson" )
"Thanks to: Leo Franchi, Jeff Mitchell, Dominik Schmidt, Jason Herskowitz, Alejandro Wainzinger, Hugo Lindström, Michael Zanetti, Harald Sitter and Steve Robertson" )
.arg( TomahawkUtils::appFriendlyVersion() )
.arg( qApp->applicationVersion() ) );
}