]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/interface_widgets.cpp
Qt: PLModel: move zoom value out of model
[vlc] / modules / gui / qt4 / components / interface_widgets.cpp
index ce17b9d7f1abe0f4f6531eb09f0b78059eaa7326..85ce5325a8db7b28de59ab54c08ca3dcee5f9d44 100644 (file)
 # include "config.h"
 #endif
 
+#include "qt4.hpp"
 #include "components/interface_widgets.hpp"
+#include "dialogs_provider.hpp"
+#include "util/customwidgets.hpp"               // qtEventToVLCKey, QVLCStackedWidget
 
 #include "menus.hpp"             /* Popup menu on bgWidget */
 
@@ -37,6 +40,7 @@
 #include <QLabel>
 #include <QToolButton>
 #include <QPalette>
+#include <QEvent>
 #include <QResizeEvent>
 #include <QDate>
 #include <QMenu>
 #include <QBitmap>
 
 #ifdef Q_WS_X11
-# include <X11/Xlib.h>
-# include <qx11info_x11.h>
-static void videoSync( void )
-{
-    /* Make sure the X server has processed all requests.
-     * This protects other threads using distinct connections from getting
-     * the video widget window in an inconsistent states. */
-    XSync( QX11Info::display(), False );
-}
-#else
-# define videoSync() (void)0
+#   include <X11/Xlib.h>
+#   include <qx11info_x11.h>
 #endif
 
 #include <math.h>
 #include <assert.h>
 
-class ReparentableWidget : public QWidget
-{
-private:
-    VideoWidget *owner;
-public:
-    ReparentableWidget( VideoWidget *owner ) : owner( owner )
-    {
-    }
-
-protected:
-    void keyPressEvent( QKeyEvent *e )
-    {
-        emit owner->keyPressed( e );
-    }
-};
-
 /**********************************************************************
  * Video Widget. A simple frame on which video is drawn
  * This class handles resize issues
  **********************************************************************/
 
 VideoWidget::VideoWidget( intf_thread_t *_p_i )
-    : QFrame( NULL )
-      , p_intf( _p_i )
-      , reparentable( NULL )
+            : QFrame( NULL ) , p_intf( _p_i )
 {
     /* Set the policy to expand in both directions */
     // setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
 
     layout = new QHBoxLayout( this );
     layout->setContentsMargins( 0, 0, 0, 0 );
-    setLayout( layout );
+    stable = NULL;
+    show();
 }
 
 VideoWidget::~VideoWidget()
 {
     /* Ensure we are not leaking the video output. This would crash. */
-    assert( reparentable == NULL );
+    assert( !stable );
+}
+
+void VideoWidget::sync( void )
+{
+#ifdef Q_WS_X11
+    /* Make sure the X server has processed all requests.
+     * This protects other threads using distinct connections from getting
+     * the video widget window in an inconsistent states. */
+    XSync( QX11Info::display(), False );
+#endif
 }
 
 /**
@@ -113,10 +101,10 @@ WId VideoWidget::request( int *pi_x, int *pi_y,
 {
     msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
 
-    if( reparentable != NULL )
+    if( stable )
     {
         msg_Dbg( p_intf, "embedded video already in use" );
-        return NULL;
+        return 0;
     }
     if( b_keep_size )
     {
@@ -124,31 +112,26 @@ WId VideoWidget::request( int *pi_x, int *pi_y,
         *pi_height = size().height();
     }
 
-    /* The Qt4 UI needs a fixed a widget ("this"), so that the parent layout is
-     * not messed up when we the video is reparented. Hence, we create an extra
-     * reparentable widget, that will be within the VideoWidget in windowed
-     * mode, and within the root window (NULL parent) in full-screen mode.
-     */
-    reparentable = new ReparentableWidget( this );
-    QLayout *innerLayout = new QHBoxLayout( reparentable );
-    innerLayout->setContentsMargins( 0, 0, 0, 0 );
-
     /* The owner of the video window needs a stable handle (WinId). Reparenting
      * in Qt4-X11 changes the WinId of the widget, so we need to create another
      * dummy widget that stays within the reparentable widget. */
-    QWidget *stable = new QWidget();
+    stable = new QWidget();
     QPalette plt = palette();
     plt.setColor( QPalette::Window, Qt::black );
     stable->setPalette( plt );
     stable->setAutoFillBackground(true);
+    /* Force the widget to be native so that it gets a winId() */
+    stable->setAttribute( Qt::WA_NativeWindow, true );
     /* Indicates that the widget wants to draw directly onto the screen.
        Widgets with this attribute set do not participate in composition
        management */
+    /* This is currently disabled on X11 as it does not seem to improve
+     * performance, but causes the video widget to be transparent... */
+#if !defined (Q_WS_X11) && !defined (Q_WS_QPA)
     stable->setAttribute( Qt::WA_PaintOnScreen, true );
+#endif
 
-    innerLayout->addWidget( stable );
-
-    layout->addWidget( reparentable );
+    layout->addWidget( stable );
 
 #ifdef Q_WS_X11
     /* HACK: Only one X11 client can subscribe to mouse button press events.
@@ -162,11 +145,7 @@ WId VideoWidget::request( int *pi_x, int *pi_y,
     attr.your_event_mask &= ~(ButtonPressMask|ButtonReleaseMask);
     XSelectInput( dpy, w, attr.your_event_mask );
 #endif
-    videoSync();
-#ifndef NDEBUG
-    msg_Dbg( p_intf, "embedded video ready (handle %p)",
-             (void *)stable->winId() );
-#endif
+    sync();
     return stable->winId();
 }
 
@@ -175,98 +154,30 @@ WId VideoWidget::request( int *pi_x, int *pi_y,
    Parent has to care about resizing itself */
 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
 {
-    if (reparentable->windowState() & Qt::WindowFullScreen )
-        return;
-    if( !isVisible() ) show();
     resize( w, h );
     emit sizeChanged( w, h );
-    videoSync();
-}
-
-void VideoWidget::SetFullScreen( bool b_fs )
-{
-    const Qt::WindowStates curstate = reparentable->windowState();
-    Qt::WindowStates newstate = curstate;
-    Qt::WindowFlags  newflags = reparentable->windowFlags();
-
-
-    if( b_fs )
-    {
-        newstate |= Qt::WindowFullScreen;
-        newflags |= Qt::WindowStaysOnTopHint;
-    }
-    else
-    {
-        newstate &= ~Qt::WindowFullScreen;
-        newflags &= ~Qt::WindowStaysOnTopHint;
-    }
-    if( newstate == curstate )
-        return; /* no changes needed */
-
-    if( b_fs )
-    {   /* Go full-screen */
-        int numscreen = var_InheritInteger( p_intf, "qt-fullscreen-screennumber" );
-        /* if user hasn't defined screennumber, or screennumber that is bigger
-         * than current number of screens, take screennumber where current interface
-         * is
-         */
-        if( numscreen == -1 || numscreen > QApplication::desktop()->numScreens() )
-            numscreen = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
-
-        QRect screenres = QApplication::desktop()->screenGeometry( numscreen );
-
-        reparentable->setParent( NULL, newflags );
-        reparentable->setWindowState( newstate );
-        /* To be sure window is on proper-screen in xinerama */
-        if( !screenres.contains( reparentable->pos() ) )
-        {
-            msg_Dbg( p_intf, "Moving video to correct screen");
-            reparentable->move( QPoint( screenres.x(), screenres.y() ) );
-        }
-        reparentable->show();
-    }
-    else
-    {   /* Go windowed */
-        reparentable->setWindowFlags( newflags );
-        reparentable->setWindowState( newstate );
-        layout->addWidget( reparentable );
-    }
-    videoSync();
+    /* Work-around a bug?misconception? that would happen when vout core resize
+       twice to the same size and would make the vout not centered.
+       This cause a small flicker.
+       See #3621
+     */
+    if( (unsigned)size().width() == w && (unsigned)size().height() == h )
+        updateGeometry();
+    sync();
 }
 
 void VideoWidget::release( void )
 {
     msg_Dbg( p_intf, "Video is not needed anymore" );
-    //layout->removeWidget( reparentable );
-
-#ifdef WIN32
-    /* Come back to default thumbnail for Windows 7 taskbar */
-    LPTASKBARLIST3 p_taskbl;
 
-    CoInitialize( 0 );
-
-    if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
-                NULL, CLSCTX_INPROC_SERVER,
-                &IID_ITaskbarList3,
-                (void **)&p_taskbl) )
+    if( stable )
     {
-        p_taskbl->vt->HrInit(p_taskbl);
-
-        HWND hroot = GetAncestor(reparentable->winId(),GA_ROOT);
-
-        if (S_OK != p_taskbl->vt->SetThumbnailClip(p_taskbl, hroot, NULL))
-            msg_Err(p_intf, "SetThumbNailClip failed");
-        msg_Err(p_intf, "Releasing taskbar | root handle = %08x", hroot);
-        p_taskbl->vt->Release(p_taskbl);
+        layout->removeWidget( stable );
+        stable->deleteLater();
+        stable = NULL;
     }
-    CoUninitialize();
-
-#endif
 
-    delete reparentable;
-    reparentable = NULL;
     updateGeometry();
-    hide();
 }
 
 /**********************************************************************
@@ -275,7 +186,7 @@ void VideoWidget::release( void )
  **********************************************************************/
 
 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
-                 :QWidget( NULL ), p_intf( _p_i ), b_expandPixmap( false )
+    :QWidget( NULL ), p_intf( _p_i ), b_expandPixmap( false ), b_withart( true )
 {
     /* A dark background */
     setAutoFillBackground( true );
@@ -299,8 +210,8 @@ void BackgroundWidget::updateArt( const QString& url )
     }
     else
     {   /* Xmas joke */
-        if( QDate::currentDate().dayOfYear() >= 354 )
-            pixmapUrl = QString( ":/logo/vlc128-christmas.png" );
+        if( QDate::currentDate().dayOfYear() >= QT_XMAS_JOKE_DAY && var_InheritBool( p_intf, "qt-icon-change" ) )
+            pixmapUrl = QString( ":/logo/vlc128-xmas.png" );
         else
             pixmapUrl = QString( ":/logo/vlc128.png" );
     }
@@ -309,14 +220,21 @@ void BackgroundWidget::updateArt( const QString& url )
 
 void BackgroundWidget::paintEvent( QPaintEvent *e )
 {
+    if ( !b_withart )
+    {
+        /* we just want background autofill */
+        QWidget::paintEvent( e );
+        return;
+    }
+
     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;
+    i_maxwidth  = __MIN( maximumWidth(), width() ) - MARGIN * 2;
+    i_maxheight = __MIN( maximumHeight(), height() ) - MARGIN * 2;
 
     if ( height() > MARGIN * 2 )
     {
@@ -356,7 +274,7 @@ void BackgroundWidget::paintEvent( QPaintEvent *e )
 
 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
 {
-    QVLCMenu::PopupMenu( p_intf, true );
+    VLCMenuBar::PopupMenu( p_intf, true );
     event->accept();
 }
 
@@ -427,12 +345,16 @@ SpeedLabel::SpeedLabel( intf_thread_t *_p_intf, QWidget *parent )
     widgetAction->setDefaultWidget( speedControl );
     speedControlMenu->addAction( widgetAction );
 
-    /* Change the SpeedRate in the Status Bar */
+    /* Change the SpeedRate in the Label */
     CONNECT( THEMIM->getIM(), rateChanged( float ), this, setRate( float ) );
 
     DCONNECT( THEMIM, inputChanged( input_thread_t * ),
               speedControl, activateOnState() );
-    setRate( var_InheritFloat( p_intf, "rate" ) );
+
+    setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
+    setLineWidth( 1 );
+
+    setRate( var_InheritFloat( THEPL, "rate" ) );
 }
 
 SpeedLabel::~SpeedLabel()
@@ -448,7 +370,7 @@ SpeedLabel::~SpeedLabel()
 void SpeedLabel::showSpeedMenu( QPoint pos )
 {
     speedControlMenu->exec( QCursor::pos() - pos
-                          + QPoint( 0, height() ) );
+                            + QPoint( -70 + width()/2, height() ) );
 }
 
 void SpeedLabel::setRate( float rate )
@@ -467,15 +389,15 @@ void SpeedLabel::setRate( float rate )
 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i, QWidget *_parent )
                     : QFrame( _parent ), p_intf( _p_i )
 {
-    QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
+    QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Maximum );
     sizePolicy.setHorizontalStretch( 0 );
     sizePolicy.setVerticalStretch( 0 );
 
     speedSlider = new QSlider( this );
     speedSlider->setSizePolicy( sizePolicy );
-    speedSlider->setMaximumSize( QSize( 80, 200 ) );
-    speedSlider->setOrientation( Qt::Vertical );
-    speedSlider->setTickPosition( QSlider::TicksRight );
+    speedSlider->setMinimumSize( QSize( 140, 20 ) );
+    speedSlider->setOrientation( Qt::Horizontal );
+    speedSlider->setTickPosition( QSlider::TicksBelow );
 
     speedSlider->setRange( -34, 34 );
     speedSlider->setSingleStep( 1 );
@@ -485,18 +407,44 @@ SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i, QWidget *_parent )
     CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
 
     QToolButton *normalSpeedButton = new QToolButton( this );
-    normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
+    normalSpeedButton->setMaximumSize( QSize( 26, 16 ) );
     normalSpeedButton->setAutoRaise( true );
     normalSpeedButton->setText( "1x" );
     normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
 
     CONNECT( normalSpeedButton, clicked(), this, resetRate() );
 
-    QVBoxLayout *speedControlLayout = new QVBoxLayout( this );
-    speedControlLayout->setContentsMargins( 4, 4, 4, 4 );
-    speedControlLayout->setSpacing( 4 );
-    speedControlLayout->addWidget( speedSlider );
-    speedControlLayout->addWidget( normalSpeedButton );
+    QToolButton *slowerButton = new QToolButton( this );
+    slowerButton->setMaximumSize( QSize( 26, 16 ) );
+    slowerButton->setAutoRaise( true );
+    slowerButton->setToolTip( tooltipL[SLOWER_BUTTON] );
+    slowerButton->setIcon( QIcon( iconL[SLOWER_BUTTON] ) );
+    CONNECT( slowerButton, clicked(), THEMIM->getIM(), slower() );
+
+    QToolButton *fasterButton = new QToolButton( this );
+    fasterButton->setMaximumSize( QSize( 26, 16 ) );
+    fasterButton->setAutoRaise( true );
+    fasterButton->setToolTip( tooltipL[FASTER_BUTTON] );
+    fasterButton->setIcon( QIcon( iconL[FASTER_BUTTON] ) );
+    CONNECT( fasterButton, clicked(), THEMIM->getIM(), faster() );
+
+/*    spinBox = new QDoubleSpinBox();
+    spinBox->setDecimals( 2 );
+    spinBox->setMaximum( 32 );
+    spinBox->setMinimum( 0.03F );
+    spinBox->setSingleStep( 0.10F );
+    spinBox->setAlignment( Qt::AlignRight );
+
+    CONNECT( spinBox, valueChanged( double ), this, updateSpinBoxRate( double ) ); */
+
+    QGridLayout* speedControlLayout = new QGridLayout( this );
+    speedControlLayout->addWidget( speedSlider, 0, 0, 1, 3 );
+    speedControlLayout->addWidget( slowerButton, 1, 0 );
+    speedControlLayout->addWidget( normalSpeedButton, 1, 1, 1, 1, Qt::AlignRight );
+    speedControlLayout->addWidget( fasterButton, 1, 2, 1, 1, Qt::AlignRight );
+    //speedControlLayout->addWidget( spinBox );
+    speedControlLayout->setContentsMargins( 0, 0, 0, 0 );
+    speedControlLayout->setSpacing( 0 );
 
     lastValue = 0;
 
@@ -506,6 +454,7 @@ SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i, QWidget *_parent )
 void SpeedControlWidget::activateOnState()
 {
     speedSlider->setEnabled( THEMIM->getIM()->hasInput() );
+    //spinBox->setEnabled( THEMIM->getIM()->hasInput() );
 }
 
 void SpeedControlWidget::updateControls( float rate )
@@ -516,7 +465,7 @@ void SpeedControlWidget::updateControls( float rate )
         return;
     }
 
-    double value = 17 * log( rate ) / log( 2 );
+    double value = 17 * log( rate ) / log( 2. );
     int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
 
     if( sliderValue < speedSlider->minimum() )
@@ -530,6 +479,7 @@ void SpeedControlWidget::updateControls( float rate )
     lastValue = sliderValue;
 
     speedSlider->setValue( sliderValue );
+    //spinBox->setValue( rate );
 }
 
 void SpeedControlWidget::updateRate( int sliderValue )
@@ -541,6 +491,12 @@ void SpeedControlWidget::updateRate( int sliderValue )
     int rate = INPUT_RATE_DEFAULT / speed;
 
     THEMIM->getIM()->setRate(rate);
+    //spinBox->setValue( var_InheritFloat( THEPL, "rate" ) );
+}
+
+void SpeedControlWidget::updateSpinBoxRate( double r )
+{
+    var_SetFloat( THEPL, "rate", r );
 }
 
 void SpeedControlWidget::resetRate()
@@ -549,19 +505,17 @@ void SpeedControlWidget::resetRate()
 }
 
 CoverArtLabel::CoverArtLabel( QWidget *parent, intf_thread_t *_p_i )
-              : QLabel( parent ), p_intf( _p_i )
+    : QLabel( parent ), p_intf( _p_i ), p_item( NULL )
 {
     setContextMenuPolicy( Qt::ActionsContextMenu );
-    CONNECT( this, updateRequested(), this, askForUpdate() );
+    CONNECT( THEMIM->getIM(), artChanged( input_item_t * ),
+             this, showArtUpdate( input_item_t * ) );
 
     setMinimumHeight( 128 );
     setMinimumWidth( 128 );
-    setMaximumHeight( 128 );
-    setMaximumWidth( 128 );
     setScaledContents( false );
     setAlignment( Qt::AlignCenter );
 
-    QList< QAction* > artActions = actions();
     QAction *action = new QAction( qtr( "Download cover art" ), this );
     CONNECT( action, triggered(), this, askForUpdate() );
     addAction( action );
@@ -574,6 +528,14 @@ CoverArtLabel::~CoverArtLabel()
     QList< QAction* > artActions = actions();
     foreach( QAction *act, artActions )
         removeAction( act );
+    if ( p_item ) vlc_gc_decref( p_item );
+}
+
+void CoverArtLabel::setItem( input_item_t *_p_item )
+{
+    if ( p_item ) vlc_gc_decref( p_item );
+    p_item = _p_item;
+    if ( p_item ) vlc_gc_incref( p_item );
 }
 
 void CoverArtLabel::showArtUpdate( const QString& url )
@@ -581,8 +543,9 @@ void CoverArtLabel::showArtUpdate( const QString& url )
     QPixmap pix;
     if( !url.isEmpty() && pix.load( url ) )
     {
-        pix = pix.scaled( maximumWidth(), maximumHeight(),
-                          Qt::KeepAspectRatioByExpanding );
+        pix = pix.scaled( minimumWidth(), minimumHeight(),
+                          Qt::KeepAspectRatioByExpanding,
+                          Qt::SmoothTransformation );
     }
     else
     {
@@ -591,22 +554,51 @@ void CoverArtLabel::showArtUpdate( const QString& url )
     setPixmap( pix );
 }
 
+void CoverArtLabel::showArtUpdate( input_item_t *_p_item )
+{
+    /* not for me */
+    if ( _p_item != p_item )
+        return;
+
+    QString url;
+    if ( _p_item ) url = THEMIM->getIM()->decodeArtURL( _p_item );
+    showArtUpdate( url );
+}
+
 void CoverArtLabel::askForUpdate()
 {
-    THEMIM->getIM()->requestArtUpdate();
+    THEMIM->getIM()->requestArtUpdate( p_item );
 }
 
-TimeLabel::TimeLabel( intf_thread_t *_p_intf  )
-    : QLabel(), p_intf( _p_intf ), bufTimer( new QTimer(this) ),
-      buffering( false ), showBuffering(false), bufVal( -1 )
+TimeLabel::TimeLabel( intf_thread_t *_p_intf, TimeLabel::Display _displayType  )
+    : ClickableQLabel(), p_intf( _p_intf ), bufTimer( new QTimer(this) ),
+      buffering( false ), showBuffering(false), bufVal( -1 ), displayType( _displayType )
 {
     b_remainingTime = false;
-    setText( " --:--/--:-- " );
+    if( _displayType != TimeLabel::Elapsed )
+        b_remainingTime = getSettings()->value( "MainWindow/ShowRemainingTime", false ).toBool();
+    switch( _displayType ) {
+        case TimeLabel::Elapsed:
+            setText( " --:-- " );
+            setToolTip( qtr("Elapsed time") );
+            break;
+        case TimeLabel::Remaining:
+            setText( " --:-- " );
+            setToolTip( qtr("Total/Remaining time")
+                        + QString("\n-")
+                        + qtr("Click to toggle between total and remaining time")
+                      );
+            break;
+        case TimeLabel::Both:
+            setText( " --:--/--:-- " );
+            setToolTip( QString( "- " )
+                + qtr( "Click to toggle between elapsed and remaining time" )
+                + QString( "\n- " )
+                + qtr( "Double click to jump to a chosen time position" ) );
+            break;
+    }
     setAlignment( Qt::AlignRight | Qt::AlignVCenter );
-    setToolTip( QString( "- " )
-        + qtr( "Click to toggle between elapsed and remaining time" )
-        + QString( "\n- " )
-        + qtr( "Double click to jump to a chosen time position" ) );
+
     bufTimer->setSingleShot( true );
 
     CONNECT( THEMIM->getIM(), positionUpdated( float, int64_t, int ),
@@ -614,6 +606,8 @@ TimeLabel::TimeLabel( intf_thread_t *_p_intf  )
     CONNECT( THEMIM->getIM(), cachingChanged( float ),
               this, updateBuffering( float ) );
     CONNECT( bufTimer, timeout(), this, updateBuffering() );
+
+    setStyleSheet( "padding-left: 4px; padding-right: 4px;" );
 }
 
 void TimeLabel::setDisplayPosition( float pos, int64_t t, int length )
@@ -623,7 +617,11 @@ void TimeLabel::setDisplayPosition( float pos, int64_t t, int length )
 
     if( pos == -1.f )
     {
-        setText( " --:--/--:-- " );
+        setMinimumSize( QSize( 0, 0 ) );
+        if( displayType == TimeLabel::Both )
+            setText( "--:--/--:--" );
+        else
+            setText( "--:--" );
         return;
     }
 
@@ -633,13 +631,50 @@ void TimeLabel::setDisplayPosition( float pos, int64_t t, int length )
     secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
                                                            : time );
 
-    QString timestr = QString( " %1%2/%3 " )
+    // compute the minimum size that will be required for the psz_length
+    // and use it to enforce a minimal size to avoid "dancing" widgets
+    QSize minsize( 0, 0 );
+    if ( length > 0 )
+    {
+        QMargins margins = contentsMargins();
+        minsize += QSize(
+                  fontMetrics().size( 0, QString( psz_length ), 0, 0 ).width(),
+                  sizeHint().height()
+                );
+        minsize += QSize( margins.left() + margins.right() + 8, 0 ); /* +padding */
+
+        if ( b_remainingTime )
+            minsize += QSize( fontMetrics().size( 0, "-", 0, 0 ).width(), 0 );
+    }
+
+    switch( displayType )
+    {
+        case TimeLabel::Elapsed:
+            setMinimumSize( minsize );
+            setText( QString( psz_time ) );
+            break;
+        case TimeLabel::Remaining:
+            if( b_remainingTime )
+            {
+                setMinimumSize( minsize );
+                setText( QString("-") + QString( psz_time ) );
+            }
+            else
+            {
+                setMinimumSize( QSize( 0, 0 ) );
+                setText( QString( psz_length ) );
+            }
+            break;
+        case TimeLabel::Both:
+        default:
+            QString timestr = QString( "%1%2/%3" )
             .arg( QString( (b_remainingTime && length) ? "-" : "" ) )
             .arg( QString( psz_time ) )
             .arg( QString( ( !length && time ) ? "--:--" : psz_length ) );
 
-    setText( timestr );
-
+            setText( timestr );
+            break;
+    }
     cachedLength = length;
 }
 
@@ -655,7 +690,7 @@ void TimeLabel::setDisplayPosition( float pos )
     secstotimestr( psz_time,
                    ( b_remainingTime && cachedLength ?
                    cachedLength - time : time ) );
-    QString timestr = QString( " %1%2/%3 " )
+    QString timestr = QString( "%1%2/%3" )
         .arg( QString( (b_remainingTime && cachedLength) ? "-" : "" ) )
         .arg( QString( psz_time ) )
         .arg( QString( ( !cachedLength && time ) ? "--:--" : psz_length ) );
@@ -667,6 +702,7 @@ void TimeLabel::setDisplayPosition( float pos )
 void TimeLabel::toggleTimeDisplay()
 {
     b_remainingTime = !b_remainingTime;
+    getSettings()->setValue( "MainWindow/ShowRemainingTime", b_remainingTime );
 }