]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/util/input_slider.cpp
Qt: hide the tip when the playback ends (blind fix for #6120)
[vlc] / modules / gui / qt4 / util / input_slider.cpp
index 34e03d9643898ee8cbe8718aa5ca57dc06d67b6c..0e70263303c666a2f8cac8fbf3e4067521dc555d 100644 (file)
@@ -1,11 +1,12 @@
 /*****************************************************************************
- * input_manager.cpp : Manage an input and interact with its GUI elements
+ * input_slider.cpp : VolumeSlider and SeekSlider
  ****************************************************************************
- * Copyright (C) 2006 the VideoLAN team
+ * Copyright (C) 2006-2011 the VideoLAN team
  * $Id$
  *
  * Authors: Clément Stenac <zorglub@videolan.org>
  *          Jean-Baptiste Kempf <jb@videolan.org>
+ *          Ludovic Fauvet <etix@videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 # include "config.h"
 #endif
 
+#include "qt4.hpp"
+
 #include "util/input_slider.hpp"
+#include "adapters/seekpoints.hpp"
+#include <vlc_aout_intf.h>
 
 #include <QPaintEvent>
 #include <QPainter>
 #include <QBitmap>
-#include <QPainter>
 #include <QStyleOptionSlider>
 #include <QLinearGradient>
-
+#include <QTimer>
+#include <QRadialGradient>
+#include <QLinearGradient>
+#include <QSize>
+#include <QPalette>
+#include <QColor>
+#include <QPoint>
+#include <QPropertyAnimation>
+#include <QApplication>
 
 #define MINIMUM 0
 #define MAXIMUM 1000
+#define CHAPTERSSPOTSIZE 3
+#define FADEDURATION 300
+#define FADEOUTDELAY 2000
 
-InputSlider::InputSlider( QWidget *_parent ) : QSlider( _parent )
-{
-    InputSlider( Qt::Horizontal, _parent );
-}
-
-InputSlider::InputSlider( Qt::Orientation q, QWidget *_parent )
-            : QSlider( q, _parent )
+SeekSlider::SeekSlider( Qt::Orientation q, QWidget *_parent, bool _static )
+          : QSlider( q, _parent ), b_classic( _static )
 {
-    b_isSliding = false;
+    isSliding = false;
+    f_buffering = 1.0;
+    mHandleOpacity = 1.0;
+    chapters = NULL;
+    mHandleLength = -1;
+
+    // prepare some static colors
+    QPalette p = palette();
+    QColor background = p.color( QPalette::Active, QPalette::Background );
+    tickpointForeground = p.color( QPalette::Active, QPalette::WindowText );
+    tickpointForeground.setHsv( tickpointForeground.hue(),
+            ( background.saturation() + tickpointForeground.saturation() ) / 2,
+            ( background.value() + tickpointForeground.value() ) / 2 );
+
+    // set the background color and gradient
+    QColor backgroundBase( p.window().color() );
+    backgroundGradient.setColorAt( 0.0, backgroundBase.darker( 140 ) );
+    backgroundGradient.setColorAt( 1.0, backgroundBase );
+
+    // set the foreground color and gradient
+    QColor foregroundBase( 50, 156, 255 );
+    foregroundGradient.setColorAt( 0.0,  foregroundBase );
+    foregroundGradient.setColorAt( 1.0,  foregroundBase.darker( 140 ) );
+
+    // prepare the handle's gradient
+    handleGradient.setColorAt( 0.0, p.window().color().lighter( 120 ) );
+    handleGradient.setColorAt( 0.9, p.window().color().darker( 120 ) );
+
+    // prepare the handle's shadow gradient
+    QColor shadowBase = p.shadow().color();
+    if( shadowBase.lightness() > 100 )
+        shadowBase = QColor( 60, 60, 60 ); // Palette's shadow is too bright
+    shadowDark = shadowBase.darker( 150 );
+    shadowLight = shadowBase.lighter( 180 );
+    shadowLight.setAlpha( 50 );
 
     /* Timer used to fire intermediate updatePos() when sliding */
-    seekLimitTimer = new QTimer(this);
-    seekLimitTimer->setSingleShot(true);
+    seekLimitTimer = new QTimer( this );
+    seekLimitTimer->setSingleShot( true );
+
+    /* Tooltip bubble */
+    mTimeTooltip = new TimeTooltip( this );
+    mTimeTooltip->setMouseTracking( true );
 
     /* Properties */
     setRange( MINIMUM, MAXIMUM );
     setSingleStep( 2 );
     setPageStep( 10 );
-    setMouseTracking(true);
+    setMouseTracking( true );
     setTracking( true );
     setFocusPolicy( Qt::NoFocus );
 
+    /* Use the new/classic style */
+    if( !b_classic )
+        setStyle( new SeekStyle );
+
     /* Init to 0 */
     setPosition( -1.0, 0, 0 );
     secstotimestr( psz_length, 0 );
 
-    CONNECT( this, sliderMoved(int), this, startSeekTimer( int ) );
+    animHandle = new QPropertyAnimation( this, "handleOpacity", this );
+    animHandle->setDuration( FADEDURATION );
+    animHandle->setStartValue( 0.0 );
+    animHandle->setEndValue( 1.0 );
+
+    hideHandleTimer = new QTimer( this );
+    hideHandleTimer->setSingleShot( true );
+    hideHandleTimer->setInterval( FADEOUTDELAY );
+
+    CONNECT( this, sliderMoved( int ), this, startSeekTimer() );
     CONNECT( seekLimitTimer, timeout(), this, updatePos() );
+    CONNECT( hideHandleTimer, timeout(), this, hideHandle() );
+    mTimeTooltip->installEventFilter( this );
+}
+
+SeekSlider::~SeekSlider()
+{
+    delete chapters;
 }
 
 /***
- * \brief Public interface, like setValue,  but disabling the slider too
+ * \brief Sets the chapters seekpoints adapter
+ *
+ * \params SeekPoints initilized with current intf thread
+***/
+void SeekSlider::setChapters( SeekPoints *chapters_ )
+{
+    delete chapters;
+    chapters = chapters_;
+    chapters->setParent( this );
+}
+
+/***
+ * \brief Main public method, superseeding setValue. Disabling the slider when neeeded
+ *
+ * \param pos Position, between 0 and 1. -1 disables the slider
+ * \param time Elapsed time. Unused
+ * \param legnth Duration time.
  ***/
-void InputSlider::setPosition( float pos, int64_t a, int b )
+void SeekSlider::setPosition( float pos, int64_t time, int length )
 {
+    VLC_UNUSED(time);
     if( pos == -1.0 )
     {
         setEnabled( false );
-        b_isSliding = false;
+        mTimeTooltip->hide();
+        isSliding = false;
     }
     else
         setEnabled( true );
 
-    if( !b_isSliding )
-        setValue( (int)(pos * 1000.0 ) );
+    if( !isSliding )
+        setValue( (int)( pos * 1000.0 ) );
 
-    inputLength = b;
+    inputLength = length;
 }
 
-void InputSlider::startSeekTimer( int new_value )
+void SeekSlider::startSeekTimer()
 {
     /* Only fire one update, when sliding, every 150ms */
-    if( b_isSliding && !seekLimitTimer->isActive() )
+    if( isSliding && !seekLimitTimer->isActive() )
         seekLimitTimer->start( 150 );
 }
 
-void InputSlider::updatePos()
+void SeekSlider::updatePos()
 {
-    float f_pos = (float)(value())/1000.0;
+    float f_pos = (float)( value() ) / 1000.0;
     emit sliderDragged( f_pos ); /* Send new position to VLC's core */
 }
 
-void InputSlider::mouseReleaseEvent( QMouseEvent *event )
+void SeekSlider::updateBuffering( float f_buffering_ )
+{
+    f_buffering = f_buffering_;
+    repaint();
+}
+
+void SeekSlider::mouseReleaseEvent( QMouseEvent *event )
 {
     event->accept();
-    b_isSliding = false;
+    isSliding = false;
+    bool b_seekPending = seekLimitTimer->isActive();
     seekLimitTimer->stop(); /* We're not sliding anymore: only last seek on release */
+    if ( isJumping )
+    {
+        isJumping = false;
+        return;
+    }
     QSlider::mouseReleaseEvent( event );
-    updatePos();
+    if( b_seekPending )
+        updatePos();
 }
 
-void InputSlider::mousePressEvent(QMouseEvent* event)
+void SeekSlider::mousePressEvent( QMouseEvent* event )
 {
     /* Right-click */
     if( event->button() != Qt::LeftButton &&
@@ -120,166 +219,206 @@ void InputSlider::mousePressEvent(QMouseEvent* event)
         return;
     }
 
-    b_isSliding = true ;
-    setValue( QStyle::sliderValueFromPosition( MINIMUM, MAXIMUM, event->x(), width(), false) );
+    isJumping = false;
+    /* handle chapter clicks */
+    int i_width = size().width();
+    if ( chapters && inputLength && i_width)
+    {
+        if ( orientation() == Qt::Horizontal ) /* TODO: vertical */
+        {
+             /* only on chapters zone */
+            if ( event->y() < CHAPTERSSPOTSIZE ||
+                 event->y() > ( size().height() - CHAPTERSSPOTSIZE ) )
+            {
+                QList<SeekPoint> points = chapters->getPoints();
+                int i_selected = -1;
+                bool b_startsnonzero = false; /* as we always starts at 1 */
+                if ( points.count() > 0 ) /* do we need an extra offset ? */
+                    b_startsnonzero = ( points.at(0).time > 0 );
+                int i_min_diff = i_width + 1;
+                for( int i = 0 ; i < points.count() ; i++ )
+                {
+                    int x = points.at(i).time / 1000000.0 / inputLength * i_width;
+                    int diff_x = abs( x - event->x() );
+                    if ( diff_x < i_min_diff )
+                    {
+                        i_min_diff = diff_x;
+                        i_selected = i + ( ( b_startsnonzero )? 1 : 0 );
+                    } else break;
+                }
+                if ( i_selected && i_min_diff < 4 ) // max 4px around mark
+                {
+                    chapters->jumpTo( i_selected );
+                    event->accept();
+                    isJumping = true;
+                    return;
+                }
+            }
+        }
+    }
+
+    isSliding = true ;
+
+    setValue( QStyle::sliderValueFromPosition( MINIMUM, MAXIMUM, event->x() - handleLength() / 2, width() - handleLength(), false ) );
+    emit sliderMoved( value() );
     event->accept();
 }
 
-void InputSlider::mouseMoveEvent(QMouseEvent *event)
+void SeekSlider::mouseMoveEvent( QMouseEvent *event )
 {
-    if( b_isSliding )
+    if( isSliding )
     {
-        setValue( QStyle::sliderValueFromPosition( MINIMUM, MAXIMUM, event->x(), width(), false) );
+        setValue( QStyle::sliderValueFromPosition( MINIMUM, MAXIMUM, event->x() - handleLength() / 2, width() - handleLength(), false) );
+        emit sliderMoved( value() );
     }
 
     /* Tooltip */
-    secstotimestr( psz_length, ( event->x() * inputLength) / size().width() );
-    setToolTip( psz_length );
+    if ( inputLength > 0 )
+    {
+        int margin = handleLength() / 2;
+        int posX = qMax( rect().left() + margin, qMin( rect().right() - margin, event->x() ) );
+
+        QString chapterLabel;
+
+        if ( orientation() == Qt::Horizontal ) /* TODO: vertical */
+        {
+                QList<SeekPoint> points = chapters->getPoints();
+                int i_selected = -1;
+                bool b_startsnonzero = false;
+                if ( points.count() > 0 )
+                    b_startsnonzero = ( points.at(0).time > 0 );
+                for( int i = 0 ; i < points.count() ; i++ )
+                {
+                    int x = points.at(i).time / 1000000.0 / inputLength * size().width();
+                    if ( event->x() >= x )
+                        i_selected = i + ( ( b_startsnonzero )? 1 : 0 );
+                }
+                if ( i_selected >= 0 && i_selected < points.size() )
+                    chapterLabel = points.at( i_selected ).name;
+        }
+
+        QPoint target( event->globalX() - ( event->x() - posX ),
+                  QWidget::mapToGlobal( pos() ).y() );
+        secstotimestr( psz_length, ( ( posX - margin ) * inputLength ) / ( size().width() - handleLength() ) );
+        mTimeTooltip->setTip( target, psz_length, chapterLabel );
+    }
     event->accept();
 }
 
-void InputSlider::wheelEvent( QWheelEvent *event)
+void SeekSlider::wheelEvent( QWheelEvent *event )
 {
     /* Don't do anything if we are for somehow reason sliding */
-    if( !b_isSliding )
+    if( !isSliding )
     {
-        setValue( value() + event->delta()/12 ); /* 12 = 8 * 15 / 10
+        setValue( value() + event->delta() / 12 ); /* 12 = 8 * 15 / 10
          Since delta is in 1/8 of ° and mouse have steps of 15 °
          and that our slider is in 0.1% and we want one step to be a 1%
          increment of position */
-        emit sliderDragged( value()/1000.0 );
+        emit sliderDragged( value() / 1000.0 );
     }
-    /* We do accept because for we don't want the parent to change the sound
-       vol */
     event->accept();
 }
 
-QSize InputSlider::sizeHint() const
+void SeekSlider::enterEvent( QEvent * )
 {
-    return ( orientation() == Qt::Horizontal ) ? QSize( 100, 18 )
-                                               : QSize( 18, 100 );
+    /* Cancel the fade-out timer */
+    hideHandleTimer->stop();
+    /* Only start the fade-in if needed */
+    if( animHandle->direction() != QAbstractAnimation::Forward )
+    {
+        /* If pause is called while not running Qt will complain */
+        if( animHandle->state() == QAbstractAnimation::Running )
+            animHandle->pause();
+        animHandle->setDirection( QAbstractAnimation::Forward );
+        animHandle->start();
+    }
+    /* Don't show the tooltip if the slider is disabled or a menu is open */
+    if( isEnabled() && inputLength > 0 && !qApp->activePopupWidget() )
+        mTimeTooltip->show();
 }
 
-QSize InputSlider::handleSize() const
+void SeekSlider::leaveEvent( QEvent * )
 {
-    const int size = ( orientation() == Qt::Horizontal ? height() : width() );
-    return QSize( size, size );
+    hideHandleTimer->start();
+    /* Hide the tooltip
+       - if the mouse leave the slider rect (Note: it can still be
+         over the tooltip!)
+       - if another window is on the way of the cursor */
+    if( !rect().contains( mapFromGlobal( QCursor::pos() ) ) ||
+      ( !isActiveWindow() && !mTimeTooltip->isActiveWindow() ) )
+    {
+        mTimeTooltip->hide();
+    }
 }
 
-void InputSlider::paintEvent( QPaintEvent *event )
+void SeekSlider::hideEvent( QHideEvent * )
 {
-    Q_UNUSED( event );
-
-    QStyleOptionSlider option;
-    initStyleOption( &option );
+    mTimeTooltip->hide();
+}
 
-    /* */
-    QPainter painter( this );
-    painter.setRenderHints( QPainter::Antialiasing );
-
-    // draw bar
-    const int barCorner = 3;
-    qreal sliderPos     = -1;
-    int range           = MAXIMUM;
-    QRect barRect = rect();
-
-    if ( option.sliderPosition != 0 ) {
-        switch ( orientation() ) {
-            case Qt::Horizontal:
-                sliderPos = ( ( (qreal)width() ) /(qreal)range ) *(qreal)option.sliderPosition;
-                break;
-            case Qt::Vertical:
-                sliderPos = ( ( (qreal)height() ) /(qreal)range ) *(qreal)option.sliderPosition;
-                break;
+bool SeekSlider::eventFilter( QObject *obj, QEvent *event )
+{
+    if( obj == mTimeTooltip )
+    {
+        if( event->type() == QEvent::Leave ||
+            event->type() == QEvent::MouseMove )
+        {
+            QMouseEvent *e = static_cast<QMouseEvent*>( event );
+            if( !rect().contains( mapFromGlobal( e->globalPos() ) ) )
+                mTimeTooltip->hide();
         }
+        return false;
     }
+    else
+        return QSlider::eventFilter( obj, event );
+}
 
-    switch ( orientation() ) {
-        case Qt::Horizontal:
-            barRect.setHeight( handleSize().height() /2 );
-            break;
-        case Qt::Vertical:
-            barRect.setWidth( handleSize().width() /2 );
-            break;
-    }
-
-    barRect.moveCenter( rect().center() );
-
-    QLinearGradient backgroundGradient( 0, 0, 0, height() );
-    backgroundGradient.setColorAt( 0.0, QColor( 126, 126, 126 ) );
-    backgroundGradient.setColorAt( 0.30, QColor( 110, 110, 110 ) );
-    backgroundGradient.setColorAt( 0.31, QColor( 101, 101, 101 ) );
-    backgroundGradient.setColorAt( 1.0, QColor( 86, 86, 86 ) );
-
-    QLinearGradient foregroundGradient( 0, 0, 0, height() );
-    foregroundGradient.setColorAt( 0.0,  QColor( 26, 49, 128 ) );
-    foregroundGradient.setColorAt( 0.30, QColor( 28, 77, 175) );
-    foregroundGradient.setColorAt( 0.32, QColor( 32, 85, 177) );
-    foregroundGradient.setColorAt( 1.0,  QColor( 81, 50, 210 ) );
-
-    //foregroundGradient.setColorAt( 0.0, palette().color( QPalette::Inactive, QPalette::Mid ) );
-    //foregroundGradient.setColorAt( 0.30, palette().color( QPalette::Inactive, QPalette::Light ) );
-    //foregroundGradient.setColorAt( 1.0, palette().color( QPalette::Inactive, QPalette::Midlight ) );
+QSize SeekSlider::sizeHint() const
+{
+    if ( b_classic )
+        return QSlider::sizeHint();
+    return ( orientation() == Qt::Horizontal ) ? QSize( 100, 18 )
+                                               : QSize( 18, 100 );
+}
 
-    //foregroundGradient.setColorAt( 0.0, QColor( 35, 213, 7 ) );
-    //foregroundGradient.setColorAt( 0.30, QColor( 37, 133, 21 ) );
-    //foregroundGradient.setColorAt( 1.0, QColor( 81, 215, 55 ) );
+qreal SeekSlider::handleOpacity() const
+{
+    return mHandleOpacity;
+}
 
-    painter.setPen( Qt::NoPen );
-    painter.setBrush( backgroundGradient );
-    painter.drawRoundedRect( barRect.adjusted( 0, 0, 0, 0 ), barCorner, barCorner );
-
-    switch ( orientation() ) {
-        case Qt::Horizontal:
-            barRect.setWidth( qMin( width(), int( sliderPos ) ) );
-            break;
-        case Qt::Vertical:
-            barRect.setHeight( qMin( height(), int( sliderPos ) ) );
-            barRect.moveBottom( rect().bottom() );
-            break;
-    }
+void SeekSlider::setHandleOpacity(qreal opacity)
+{
+    mHandleOpacity = opacity;
+    /* Request a new paintevent */
+    update();
+}
 
-    if ( option.sliderPosition > minimum() && option.sliderPosition <= maximum() ) {
-        painter.setPen( Qt::black );
-    //    painter.setBrush( foregroundGradient );
+inline int SeekSlider::handleLength()
+{
+    if ( mHandleLength > 0 )
+        return mHandleLength;
 
-        QBrush brush;
-        brush.setTexture( QPixmap( ":/progress" ) );
-        painter.setBrush( brush );
-        painter.drawRoundedRect( barRect.adjusted( 1, 1, -1, -1 ), barCorner, barCorner );
-    }
+    /* Ask for the length of the handle to the underlying style */
+    QStyleOptionSlider option;
+    initStyleOption( &option );
+    mHandleLength = style()->pixelMetric( QStyle::PM_SliderLength, &option );
+    return mHandleLength;
+}
 
-    // draw handle
-    if ( option.state & QStyle::State_MouseOver ) {
-        QLinearGradient buttonGradient( 0, 0, 0, height() );
-        buttonGradient.setColorAt( 0.0, QColor( 1, 92, 195 ) );
-        buttonGradient.setColorAt( 0.40, QColor( 41, 80, 124 ) );
-        buttonGradient.setColorAt( 1.0, QColor( 1, 92, 195 ) );
-
-        painter.setPen( QPen( Qt::blue ) );
-        painter.setBrush( buttonGradient );
-
-        if ( sliderPos != -1 ) {
-            const int margin = 5;
-            QSize hs = handleSize() -QSize( 2, 2 );
-            QPoint pos;
-
-            switch ( orientation() ) {
-                case Qt::Horizontal:
-                    pos = QPoint( sliderPos -( handleSize().width() /2 ), 1 );
-                    pos.rx() = qMax( margin, pos.x() );
-                    pos.rx() = qMin( width() -hs.width() -margin, pos.x() );
-                    break;
-                case Qt::Vertical:
-                    pos = QPoint( 1, height() -( sliderPos +( handleSize().height() /2 ) ) );
-                    pos.ry() = qMax( margin, pos.y() );
-                    pos.ry() = qMin( height() -hs.height() -margin, pos.y() );
-                    break;
-            }
+void SeekSlider::hideHandle()
+{
+    /* If pause is called while not running Qt will complain */
+    if( animHandle->state() == QAbstractAnimation::Running )
+        animHandle->pause();
+    /* Play the animation backward */
+    animHandle->setDirection( QAbstractAnimation::Backward );
+    animHandle->start();
+}
 
-            painter.drawEllipse( pos.x(), pos.y(), hs.width(), hs.height() );
-        }
-    }
+bool SeekSlider::isAnimationRunning() const
+{
+    return animHandle->state() == QAbstractAnimation::Running
+            || hideHandleTimer->isActive();
 }
 
 
@@ -299,7 +438,7 @@ SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard,
     f_step = ( _i_step * 100 ) / AOUT_VOLUME_MAX ;
     setRange( SOUNDMIN, b_hard ? (2 * SOUNDMAX) : SOUNDMAX  );
     setMouseTracking( true );
-    b_isSliding = false;
+    isSliding = false;
     b_mouseOutside = true;
     b_isMuted = false;
 
@@ -321,10 +460,19 @@ SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard,
     free( psz_colors );
 
     /* Fill with 255 if the list is too short */
-    if( colorList.size() < 12 )
-        for( int i = colorList.size(); i < 12; i++)
+    if( colorList.count() < 12 )
+        for( int i = colorList.count(); i < 12; i++)
             colorList.append( "255" );
 
+    background = palette().color( QPalette::Active, QPalette::Background );
+    foreground = palette().color( QPalette::Active, QPalette::WindowText );
+    foreground.setHsv( foreground.hue(),
+                    ( background.saturation() + foreground.saturation() ) / 2,
+                    ( background.value() + foreground.value() ) / 2 );
+
+    textfont.setPixelSize( 9 );
+    textrect.setRect( 0, 0, 34, 15 );
+
     /* Regular colors */
 #define c(i) colorList.at(i).toInt()
 #define add_color(gradient, range, c1, c2, c3) \
@@ -342,13 +490,14 @@ SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard,
     add_color( gradient1, range, c1, c2, c3 ); \
     add_desaturated_color( gradient2, range, c1, c2, c3 );
 
+    float f_mid_point = ( 100.0 / maximum() );
     QColor * foo;
     add_colors( gradient, gradient2, 0.0, 0, 1, 2 );
-    add_colors( gradient, gradient2, 0.22, 3, 4, 5 );
-    add_colors( gradient, gradient2, 0.5, 6, 7, 8 );
+    add_colors( gradient, gradient2, f_mid_point - 0.05, 3, 4, 5 );
+    add_colors( gradient, gradient2, f_mid_point + 0.05, 6, 7, 8 );
     add_colors( gradient, gradient2, 1.0, 9, 10, 11 );
 
-    QPainter painter( &pixGradient );
+    painter.begin( &pixGradient );
     painter.setPen( Qt::NoPen );
     painter.setBrush( gradient );
     painter.drawRect( pixGradient.rect() );
@@ -378,7 +527,7 @@ void SoundSlider::mousePressEvent( QMouseEvent *event )
     if( event->button() != Qt::RightButton )
     {
         /* We enter the sliding mode */
-        b_isSliding = true;
+        isSliding = true;
         i_oldvalue = value();
         emit sliderPressed();
         changeValue( event->x() - paddingL );
@@ -396,14 +545,14 @@ void SoundSlider::mouseReleaseEvent( QMouseEvent *event )
             setValue( value() );
             emit sliderMoved( value() );
         }
-        b_isSliding = false;
+        isSliding = false;
         b_mouseOutside = false;
     }
 }
 
 void SoundSlider::mouseMoveEvent( QMouseEvent *event )
 {
-    if( b_isSliding )
+    if( isSliding )
     {
         QRect rect( paddingL - 15,    -1,
                     WLENGTH + 15 * 2 , WHEIGHT + 5 );
@@ -424,7 +573,7 @@ void SoundSlider::mouseMoveEvent( QMouseEvent *event )
     {
         int i = ( ( event->x() - paddingL ) * maximum() + 40 ) / WLENGTH;
         i = __MIN( __MAX( 0, i ), maximum() );
-        setToolTip( QString("%1  \%" ).arg( i ) );
+        setToolTip( QString("%1  %" ).arg( i ) );
     }
 }
 
@@ -441,29 +590,27 @@ void SoundSlider::setMuted( bool m )
 
 void SoundSlider::paintEvent( QPaintEvent *e )
 {
-    QPainter painter( this );
-    QPixmap *pixGradient;
+    QPixmap *paintGradient;
     if (b_isMuted)
-        pixGradient = &this->pixGradient2;
+        paintGradient = &this->pixGradient2;
     else
-        pixGradient = &this->pixGradient;
+        paintGradient = &this->pixGradient;
+
+    painter.begin( this );
 
     const int offset = int( ( WLENGTH * value() + 100 ) / maximum() ) + paddingL;
 
-    const QRectF boundsG( 0, 0, offset , pixGradient->height() );
-    painter.drawPixmap( boundsG, *pixGradient, boundsG );
+    const QRectF boundsG( 0, 0, offset , paintGradient->height() );
+    painter.drawPixmap( boundsG, *paintGradient, boundsG );
 
     const QRectF boundsO( 0, 0, pixOutside.width(), pixOutside.height() );
     painter.drawPixmap( boundsO, pixOutside, boundsO );
 
-    painter.setPen( palette().color( QPalette::Active, QPalette::Mid ) );
-    QFont font; font.setPixelSize( 9 );
-    painter.setFont( font );
-    const QRect rect( 0, 0, 34, 15 );
-    painter.drawText( rect, Qt::AlignRight | Qt::AlignVCenter,
+    painter.setPen( foreground );
+    painter.setFont( textfont );
+    painter.drawText( textrect, Qt::AlignRight | Qt::AlignVCenter,
                       QString::number( value() ) + '%' );
 
     painter.end();
     e->accept();
 }
-