Commit f36e3361 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Qt4 - volumeSlider: correct the sliders functions and calculus...

parent 7297ab36
...@@ -760,38 +760,24 @@ SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) : ...@@ -760,38 +760,24 @@ SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
speedSlider->setMaximumSize( QSize( 80, 200 ) ); speedSlider->setMaximumSize( QSize( 80, 200 ) );
speedSlider->setOrientation( Qt::Vertical ); speedSlider->setOrientation( Qt::Vertical );
speedSlider->setTickPosition( QSlider::TicksRight ); speedSlider->setTickPosition( QSlider::TicksRight );
speedSlider->setFocusPolicy( Qt::NoFocus );
speedSlider->setMinimum( -100 ); speedSlider->setRange( -100, 100 );
speedSlider->setMaximum( 100 );
speedSlider->setSingleStep( 10 ); speedSlider->setSingleStep( 10 );
speedSlider->setPageStep( 20 ); speedSlider->setPageStep( 20 );
speedSlider->setTickInterval( 20 ); speedSlider->setTickInterval( 20 );
CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) ); CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
//QWidgetAction *wa = new QWidgetAction( this );
//wa->setDefaultWidget( playSpeedSlider );
//menu.addAction( wa );
normalSpeedButton = new QPushButton( "N" ); normalSpeedButton = new QPushButton( "N" );
//BUTTON_SET_ACT( revertToNormalButton, "N", qtr( "Normal" ), slower() );
//controlLayout->addWidget( revertToNormalButton, 0, 0 );
normalSpeedButton->setMaximumSize( QSize( 26, 20 ) ); normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
normalSpeedButton->setFlat(true); normalSpeedButton->setFlat( true );
normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
CONNECT( normalSpeedButton, clicked(), this, resetRate() ); CONNECT( normalSpeedButton, clicked(), this, resetRate() );
QLabel *volMuteLabel = new QLabel("N");
//volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
volMuteLabel->setToolTip( qtr( "Revert to normal play speed" ) );
//volMuteLabel->installEventFilter( h );
QVBoxLayout *speedControlLayout = new QVBoxLayout; QVBoxLayout *speedControlLayout = new QVBoxLayout;
speedControlLayout->addWidget(speedSlider); speedControlLayout->addWidget(speedSlider);
speedControlLayout->addWidget(normalSpeedButton); speedControlLayout->addWidget(normalSpeedButton);
//speedControlLayout->addWidget(volMuteLabel);
setLayout(speedControlLayout); setLayout(speedControlLayout);
} }
...@@ -799,12 +785,9 @@ SpeedControlWidget::~SpeedControlWidget() ...@@ -799,12 +785,9 @@ SpeedControlWidget::~SpeedControlWidget()
{ {
} }
#define RATE_SLIDER_CONSTANT 3.0 #define RATE_SLIDER_MAXIMUM 3.0
#define RATE_SLIDER_MINIMUM 0.3
#define SLIDER_MIN_SPEED 1.0 / RATE_SLIDER_CONSTANT #define RATE_SLIDER_LENGTH 100.0
#define SLIDER_SLOW_RANGE 1.0 - SLIDER_MIN_SPEED
#define SLIDER_MAX_SPEED RATE_SLIDER_CONSTANT
#define SLIDER_FAST_RANGE 1.0 - SLIDER_MAX_SPEED
void SpeedControlWidget::updateControls( int rate ) void SpeedControlWidget::updateControls( int rate )
{ {
...@@ -819,49 +802,48 @@ void SpeedControlWidget::updateControls( int rate ) ...@@ -819,49 +802,48 @@ void SpeedControlWidget::updateControls( int rate )
if( rate >= INPUT_RATE_DEFAULT ) if( rate >= INPUT_RATE_DEFAULT )
{ {
if( speed < SLIDER_MIN_SPEED ) if( speed < RATE_SLIDER_MINIMUM )
{ {
sliderValue = speedSlider->minimum(); sliderValue = speedSlider->minimum();
} }
else else
{ {
double currPos = speed / (double)(SLIDER_SLOW_RANGE); sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
sliderValue = (int)( currPos * speedSlider->minimum() ); / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
} }
} }
else else
{ {
if( speed > SLIDER_MAX_SPEED ) if( speed > RATE_SLIDER_MAXIMUM )
{ {
sliderValue = speedSlider->maximum(); sliderValue = speedSlider->maximum();
} }
else else
{ {
double currPos = ( 1.0 - speed ) / (double)(SLIDER_FAST_RANGE); sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
sliderValue = (int)( currPos * speedSlider->maximum() ); / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
} }
} }
//Block signals to avoid feedback loop //Block signals to avoid feedback loop
speedSlider->blockSignals(true); speedSlider->blockSignals( true );
speedSlider->setValue(sliderValue); speedSlider->setValue( sliderValue );
speedSlider->blockSignals(false); speedSlider->blockSignals( false );
} }
void SpeedControlWidget::updateRate( int sliderValue ) void SpeedControlWidget::updateRate( int sliderValue )
{ {
int rate; int rate;
double var;
if( sliderValue < 0.0 ) if( sliderValue < 0.0 )
{ {
var = 1.0 + ((-sliderValue/100.0) * RATE_SLIDER_CONSTANT-1.0); rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
rate = INPUT_RATE_DEFAULT * var; ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ) ;
} }
else else
{ {
var = 1.0 + ((sliderValue/100.0) * RATE_SLIDER_CONSTANT-1.0); rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
rate = INPUT_RATE_DEFAULT / var; ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
} }
THEMIM->getIM()->setRate(rate); THEMIM->getIM()->setRate(rate);
......
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