Commit 79980287 authored by Erwan Tulou's avatar Erwan Tulou

qt4: CoverArtLabel and BackgroundWidget improvments

    - preserve apect ratio
    - alignment set to Center
    - signal-slot connection moved to a better place
    - Art updated in info Panel when artUrl is file://
parent 5eb13a62
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "components/interface_widgets.hpp" #include "components/interface_widgets.hpp"
#include <assert.h> #include <assert.h>
#include <vlc_url.h>
#include <QTreeWidget> #include <QTreeWidget>
#include <QHeaderView> #include <QHeaderView>
...@@ -226,6 +227,21 @@ void MetaPanel::update( input_item_t *p_item ) ...@@ -226,6 +227,21 @@ void MetaPanel::update( input_item_t *p_item )
#undef UPDATE_META_INT #undef UPDATE_META_INT
#undef UPDATE_META #undef UPDATE_META
// If a artURL is available as a local file, directly display it !
QString file;
char *psz_art = input_item_GetArtURL( p_item );
if( psz_art && !strncmp( psz_art, "file://", 7 ) &&
decode_URI( psz_art + 7 ) )
#ifdef WIN32
file = qfu( psz_art + 8 ); // Remove extra / on Win32 URI.
#else
file = qfu( psz_art + 7 );
#endif
free( psz_art );
art_cover->showArtUpdate( file );
} }
/** /**
......
...@@ -245,6 +245,7 @@ BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) ...@@ -245,6 +245,7 @@ BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
label->setMaximumWidth( MAX_BG_SIZE ); label->setMaximumWidth( MAX_BG_SIZE );
label->setMinimumHeight( MIN_BG_SIZE ); label->setMinimumHeight( MIN_BG_SIZE );
label->setMinimumWidth( MIN_BG_SIZE ); label->setMinimumWidth( MIN_BG_SIZE );
label->setAlignment( Qt::AlignCenter );
if( QDate::currentDate().dayOfYear() >= 354 ) if( QDate::currentDate().dayOfYear() >= 354 )
label->setPixmap( QPixmap( ":/logo/vlc128-christmas.png" ) ); label->setPixmap( QPixmap( ":/logo/vlc128-christmas.png" ) );
else else
...@@ -281,7 +282,15 @@ void BackgroundWidget::updateArt( const QString& url ) ...@@ -281,7 +282,15 @@ void BackgroundWidget::updateArt( const QString& url )
} }
else else
{ {
label->setPixmap( QPixmap( url ) ); QPixmap pixmap( url );
if( pixmap.width() > label->maximumWidth() ||
pixmap.height() > label->maximumHeight() )
{
pixmap = pixmap.scaled( label->maximumWidth(),
label->maximumHeight(), Qt::KeepAspectRatio );
}
label->setPixmap( pixmap );
} }
} }
...@@ -479,14 +488,13 @@ CoverArtLabel::CoverArtLabel( QWidget *parent, intf_thread_t *_p_i ) ...@@ -479,14 +488,13 @@ CoverArtLabel::CoverArtLabel( QWidget *parent, intf_thread_t *_p_i )
{ {
setContextMenuPolicy( Qt::ActionsContextMenu ); setContextMenuPolicy( Qt::ActionsContextMenu );
CONNECT( this, updateRequested(), this, askForUpdate() ); CONNECT( this, updateRequested(), this, askForUpdate() );
CONNECT( THEMIM->getIM(), artChanged( QString ),
this, showArtUpdate( const QString& ) );
setMinimumHeight( 128 ); setMinimumHeight( 128 );
setMinimumWidth( 128 ); setMinimumWidth( 128 );
setMaximumHeight( 128 ); setMaximumHeight( 128 );
setMaximumWidth( 128 ); setMaximumWidth( 128 );
setScaledContents( true ); setScaledContents( false );
setAlignment( Qt::AlignCenter );
QList< QAction* > artActions = actions(); QList< QAction* > artActions = actions();
QAction *action = new QAction( qtr( "Download cover art" ), this ); QAction *action = new QAction( qtr( "Download cover art" ), this );
...@@ -508,12 +516,14 @@ void CoverArtLabel::showArtUpdate( const QString& url ) ...@@ -508,12 +516,14 @@ void CoverArtLabel::showArtUpdate( const QString& url )
QPixmap pix; QPixmap pix;
if( !url.isEmpty() && pix.load( url ) ) if( !url.isEmpty() && pix.load( url ) )
{ {
setPixmap( pix ); pix = pix.scaled( maximumWidth(), maximumHeight(),
Qt::KeepAspectRatioByExpanding );
} }
else else
{ {
setPixmap( QPixmap( ":/noart.png" ) ); pix = QPixmap( ":/noart.png" );
} }
setPixmap( pix );
} }
void CoverArtLabel::askForUpdate() void CoverArtLabel::askForUpdate()
......
...@@ -204,10 +204,10 @@ public slots: ...@@ -204,10 +204,10 @@ public slots:
{ {
requestUpdate(); requestUpdate();
} }
void showArtUpdate( const QString& );
private slots: private slots:
void askForUpdate(); void askForUpdate();
void showArtUpdate( const QString& );
signals: signals:
void updateRequested(); void updateRequested();
......
...@@ -60,6 +60,9 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) : p_intf ( _p_i ) ...@@ -60,6 +60,9 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) : p_intf ( _p_i )
art = new ArtLabel( artContainer, p_intf ); art = new ArtLabel( artContainer, p_intf );
art->setToolTip( qtr( "Double click to get media information" ) ); art->setToolTip( qtr( "Double click to get media information" ) );
CONNECT( THEMIM->getIM(), artChanged( QString ),
art, showArtUpdate( const QString& ) );
artContLay->addWidget( art, 1 ); artContLay->addWidget( art, 1 );
leftW->addWidget( artContainer ); leftW->addWidget( artContainer );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment