]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/interface_widgets.cpp
Qt: Fix SpeedLabel's tooltip
[vlc] / modules / gui / qt4 / components / interface_widgets.cpp
index dc405d625966be37335f88e11c3aaf366d257a08..2409bf163dc99cd2aae26a65d096a11a7b5d010f 100644 (file)
@@ -45,6 +45,7 @@
 #include <QPainter>
 #include <QTimer>
 #include <QSlider>
+#include <QBitmap>
 
 #ifdef Q_WS_X11
 # include <X11/Xlib.h>
@@ -176,11 +177,9 @@ void VideoWidget::SetSizing( unsigned int w, unsigned int h )
 {
     if (reparentable->windowState() & Qt::WindowFullScreen )
         return;
-    msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
-    videoSize.setWidth( w );
-    videoSize.setHeight( h );
     if( !isVisible() ) show();
-    updateGeometry(); // Needed for deinterlace
+    resize( w, h );
+    emit sizeChanged( w, h );
     videoSync();
 }
 
@@ -266,32 +265,18 @@ void VideoWidget::release( void )
 
     delete reparentable;
     reparentable = NULL;
-    videoSize = QSize();
     updateGeometry();
     hide();
 }
 
-
-QSize VideoWidget::sizeHint() const
-{
-    return videoSize;
-}
-
 /**********************************************************************
  * Background Widget. Show a simple image background. Currently,
  * it's album art if present or cone.
  **********************************************************************/
-#define ICON_SIZE 128
-#define MAX_BG_SIZE 400
-#define MIN_BG_SIZE 128
-#define MARGIN 5
 
 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
-                 :QWidget( NULL ), p_intf( _p_i )
+                 :QWidget( NULL ), p_intf( _p_i ), b_expandPixmap( false )
 {
-    /* We should use that one to take the more size it can */
-    //setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding);
-
     /* A dark background */
     setAutoFillBackground( true );
     QPalette plt = palette();
@@ -299,58 +284,74 @@ BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
     plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
     setPalette( plt );
 
-    /* A cone in the middle */
-    label = new QLabel;
-    label->setMargin( MARGIN );
-    label->setAlignment( Qt::AlignCenter );
-
     /* Init the cone art */
     updateArt( "" );
 
-    /* Grid, because of the visual selector */
-    QGridLayout *backgroundLayout = new QGridLayout( this );
-    backgroundLayout->setMargin( 0 );
-    backgroundLayout->addWidget( label, 0, 1 );
-    backgroundLayout->setColumnStretch( 0, 1 );
-    backgroundLayout->setColumnStretch( 2, 1 );
-
     CONNECT( THEMIM->getIM(), artChanged( QString ),
              this, updateArt( const QString& ) );
-
-    /* Start Hidden */
-    label->hide();
-}
-
-void BackgroundWidget::resizeEvent( QResizeEvent * event )
-{
-    if( event->size().height() <= MIN_BG_SIZE + MARGIN * 2 + 2 )
-        label->hide();
-    else
-        label->show();
 }
 
 void BackgroundWidget::updateArt( const QString& url )
 {
-    ifurl.isEmpty() )
+    if ( !url.isEmpty() )
     {
-        /* Xmas joke */
+        pixmapUrl = url;
+    }
+    else
+    {   /* Xmas joke */
         if( QDate::currentDate().dayOfYear() >= 354 )
-            label->setPixmap( QPixmap( ":/logo/vlc128-christmas.png" ) );
+            pixmapUrl = QString( ":/logo/vlc128-christmas.png" );
         else
-            label->setPixmap( QPixmap( ":/logo/vlc128.png" ) );
+            pixmapUrl = QString( ":/logo/vlc128.png" );
     }
-    else
+    update();
+}
+
+void BackgroundWidget::paintEvent( QPaintEvent *e )
+{
+    int i_maxwidth, i_maxheight;
+    QPixmap pixmap = QPixmap( pixmapUrl );
+    QPainter painter(this);
+    QBitmap pMask;
+    float f_alpha = 1.0;
+
+    i_maxwidth = std::min( maximumWidth(), width() ) - MARGIN * 2;
+    i_maxheight = std::min( maximumHeight(), height() ) - MARGIN * 2;
+
+    if ( height() > MARGIN * 2 )
     {
-        QPixmap pixmap( url );
-        if( pixmap.width() > label->maximumWidth() ||
-            pixmap.height() > label->maximumHeight() )
+        /* Scale down the pixmap if the widget is too small */
+        if( pixmap.width() > i_maxwidth || pixmap.height() > i_maxheight )
         {
-            pixmap = pixmap.scaled( label->maximumWidth(),
-                          label->maximumHeight(), Qt::KeepAspectRatio );
+            pixmap = pixmap.scaled( i_maxwidth, i_maxheight,
+                            Qt::KeepAspectRatio, Qt::SmoothTransformation );
+        }
+        else
+        if ( b_expandPixmap &&
+             pixmap.width() < width() && pixmap.height() < height() )
+        {
+            /* Scale up the pixmap to fill widget's size */
+            f_alpha = ( (float) pixmap.height() / (float) height() );
+            pixmap = pixmap.scaled(
+                    width() - MARGIN * 2,
+                    height() - MARGIN * 2,
+                    Qt::KeepAspectRatio,
+                    ( f_alpha < .2 )? /* Don't waste cpu when not visible */
+                        Qt::SmoothTransformation:
+                        Qt::FastTransformation
+                    );
+            /* Non agressive alpha compositing when sizing up */
+            pMask = QBitmap( pixmap.width(), pixmap.height() );
+            pMask.fill( QColor::fromRgbF( 1.0, 1.0, 1.0, f_alpha ) );
+            pixmap.setMask( pMask );
         }
 
-        label->setPixmap( pixmap );
+        painter.drawPixmap(
+                MARGIN + ( i_maxwidth - pixmap.width() ) /2,
+                MARGIN + ( i_maxheight - pixmap.height() ) /2,
+                pixmap);
     }
+    QWidget::paintEvent( e );
 }
 
 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
@@ -416,7 +417,7 @@ void VisualSelector::next()
 SpeedLabel::SpeedLabel( intf_thread_t *_p_intf, QWidget *parent )
            : QLabel( parent ), p_intf( _p_intf )
 {
-    setToolTip( qtr( "Current playback speed.\nClick to adjust" ) );
+    tooltipStringPattern = qtr( "Current playback speed: %1\nClick to adjust" );
 
     /* Create the Speed Control Widget */
     speedControl = new SpeedControlWidget( p_intf, this );
@@ -456,7 +457,7 @@ void SpeedLabel::setRate( float rate )
     str.setNum( rate, 'f', 2 );
     str.append( "x" );
     setText( str );
-    setToolTip( str );
+    setToolTip( tooltipStringPattern.arg( str ) );
     speedControl->updateControls( rate );
 }
 
@@ -497,6 +498,8 @@ SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i, QWidget *_parent )
     speedControlLayout->addWidget( speedSlider );
     speedControlLayout->addWidget( normalSpeedButton );
 
+    lastValue = 0;
+
     activateOnState();
 }
 
@@ -524,12 +527,16 @@ void SpeedControlWidget::updateControls( float rate )
     {
         sliderValue = speedSlider->maximum();
     }
+    lastValue = sliderValue;
 
     speedSlider->setValue( sliderValue );
 }
 
 void SpeedControlWidget::updateRate( int sliderValue )
 {
+    if( sliderValue == lastValue )
+        return;
+
     double speed = pow( 2, (double)sliderValue / 17 );
     int rate = INPUT_RATE_DEFAULT / speed;
 
@@ -623,9 +630,10 @@ void TimeLabel::setDisplayPosition( float pos, int64_t t, int length )
     secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
                                                            : time );
 
-    QString timestr;
-    timestr.sprintf( " %s%s/%s ", (b_remainingTime && length) ? "-" : "",
-                     psz_time, ( !length && time ) ? "--:--" : psz_length );
+    QString timestr = QString( " %1%2/%3 " )
+            .arg( QString( (b_remainingTime && length) ? "-" : "" ) )
+            .arg( QString( psz_time ) )
+            .arg( QString( ( !length && time ) ? "--:--" : psz_length ) );
 
     setText( timestr );
 
@@ -644,9 +652,10 @@ void TimeLabel::setDisplayPosition( float pos )
     secstotimestr( psz_time,
                    ( b_remainingTime && cachedLength ?
                    cachedLength - time : time ) );
-    QString timestr;
-    timestr.sprintf( " %s%s/%s ", (b_remainingTime && cachedLength) ? "-" : "",
-                     psz_time, ( !cachedLength && time ) ? "--:--" : psz_length );
+    QString timestr = QString( " %1%2/%3 " )
+        .arg( QString( (b_remainingTime && cachedLength) ? "-" : "" ) )
+        .arg( QString( psz_time ) )
+        .arg( QString( ( !cachedLength && time ) ? "--:--" : psz_length ) );
 
     setText( timestr );
 }