Commit 30f60c24 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Qt4 - Have a slider to control precisely the rate, usefull since we can here...

Qt4 - Have a slider to control precisely the rate, usefull since we can here audio at all speeds now. :D
Patch by StFS - Stefán Freyr Stefánsson

parent af3f3a10
...@@ -494,7 +494,6 @@ ControlsWidget::ControlsWidget( intf_thread_t *_p_i, bool b_advControls ) : ...@@ -494,7 +494,6 @@ ControlsWidget::ControlsWidget( intf_thread_t *_p_i, bool b_advControls ) :
/* Volume control connection */ /* Volume control connection */
CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) ); CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
} }
ControlsWidget::~ControlsWidget() ControlsWidget::~ControlsWidget()
{ {
...@@ -673,8 +672,8 @@ void ControlsWidget::toggleAdvanced() ...@@ -673,8 +672,8 @@ void ControlsWidget::toggleAdvanced()
#include "components/playlist/panels.hpp" #include "components/playlist/panels.hpp"
#include "components/playlist/selector.hpp" #include "components/playlist/selector.hpp"
PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) : PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) :
p_intf ( _p_intf ) p_intf ( _p_i )
{ {
/* Left Part and design */ /* Left Part and design */
QWidget *leftW = new QWidget( this ); QWidget *leftW = new QWidget( this );
...@@ -746,3 +745,129 @@ QSize PlaylistWidget::sizeHint() const ...@@ -746,3 +745,129 @@ QSize PlaylistWidget::sizeHint() const
return widgetSize; return widgetSize;
} }
/**********************************************************************
* Speed control widget
**********************************************************************/
SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
QFrame( NULL ), p_intf( _p_i )
{
QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
sizePolicy.setHorizontalStretch( 0 );
sizePolicy.setVerticalStretch( 0 );
speedSlider = new QSlider;
speedSlider->setSizePolicy( sizePolicy );
speedSlider->setMaximumSize( QSize( 80, 200 ) );
speedSlider->setOrientation( Qt::Vertical );
speedSlider->setTickPosition( QSlider::TicksRight );
speedSlider->setFocusPolicy( Qt::NoFocus );
speedSlider->setMinimum( -100 );
speedSlider->setMaximum( 100 );
speedSlider->setSingleStep( 10 );
speedSlider->setPageStep( 20 );
speedSlider->setTickInterval( 20 );
CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
//QWidgetAction *wa = new QWidgetAction( this );
//wa->setDefaultWidget( playSpeedSlider );
//menu.addAction( wa );
normalSpeedButton = new QPushButton( "N" );
//BUTTON_SET_ACT( revertToNormalButton, "N", qtr( "Normal" ), slower() );
//controlLayout->addWidget( revertToNormalButton, 0, 0 );
normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
normalSpeedButton->setFlat(true);
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;
speedControlLayout->addWidget(speedSlider);
speedControlLayout->addWidget(normalSpeedButton);
//speedControlLayout->addWidget(volMuteLabel);
setLayout(speedControlLayout);
}
SpeedControlWidget::~SpeedControlWidget()
{
}
#define RATE_SLIDER_CONSTANT 3.0
#define SLIDER_MIN_SPEED 1.0 / RATE_SLIDER_CONSTANT
#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 )
{
if( speedSlider->isSliderDown() )
{
//We don't want to change anything if the user is using the slider
return;
}
int sliderValue;
double speed = INPUT_RATE_DEFAULT / (double)rate;
if( rate >= INPUT_RATE_DEFAULT )
{
if( speed < SLIDER_MIN_SPEED )
{
sliderValue = speedSlider->minimum();
}
else
{
double currPos = speed / (double)(SLIDER_SLOW_RANGE);
sliderValue = (int)( currPos * speedSlider->minimum() );
}
}
else
{
if( speed > SLIDER_MAX_SPEED )
{
sliderValue = speedSlider->maximum();
}
else
{
double currPos = ( 1.0 - speed ) / (double)(SLIDER_FAST_RANGE);
sliderValue = (int)( currPos * speedSlider->maximum() );
}
}
//Block signals to avoid feedback loop
speedSlider->blockSignals(true);
speedSlider->setValue(sliderValue);
speedSlider->blockSignals(false);
}
void SpeedControlWidget::updateRate( int sliderValue )
{
int rate;
double var;
if( sliderValue < 0.0 )
{
var = 1.0 + ((-sliderValue/100.0) * RATE_SLIDER_CONSTANT-1.0);
rate = INPUT_RATE_DEFAULT * var;
}
else
{
var = 1.0 + ((sliderValue/100.0) * RATE_SLIDER_CONSTANT-1.0);
rate = INPUT_RATE_DEFAULT / var;
}
THEMIM->getIM()->setRate(rate);
}
void SpeedControlWidget::resetRate()
{
THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
}
...@@ -233,4 +233,23 @@ signals: ...@@ -233,4 +233,23 @@ signals:
void artSet( QString ); void artSet( QString );
}; };
/******************** Speed Control Widgets ****************/
class SpeedControlWidget : public QFrame
{
Q_OBJECT
public:
SpeedControlWidget( intf_thread_t *);
virtual ~SpeedControlWidget();
void updateControls( int );
private:
intf_thread_t *p_intf;
QSlider *speedSlider;
QPushButton *normalSpeedButton;
private slots:
void updateRate( int );
void resetRate();
};
#endif #endif
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
#include <QSize> #include <QSize>
#include <QMenu> #include <QMenu>
#include <QLabel> #include <QLabel>
#include <QSlider>
#include <QWidgetAction>
#include <assert.h> #include <assert.h>
#include <vlc_keys.h> #include <vlc_keys.h>
...@@ -302,6 +304,12 @@ void MainInterface::handleMainUi( QSettings *settings ) ...@@ -302,6 +304,12 @@ void MainInterface::handleMainUi( QSettings *settings )
/* Add the controls Widget to the main Widget */ /* Add the controls Widget to the main Widget */
mainLayout->addWidget( controls ); mainLayout->addWidget( controls );
/* Create the Speed Control Widget */
speedControl = new SpeedControlWidget( p_intf );
speedControlMenu = new QMenu( this );
QWidgetAction *widgetAction = new QWidgetAction( this );
widgetAction->setDefaultWidget( speedControl );
speedControlMenu->addAction( widgetAction );
/* Set initial size */ /* Set initial size */
resize( PREF_W, PREF_H ); resize( PREF_W, PREF_H );
...@@ -397,9 +405,7 @@ void MainInterface::resizeEvent( QResizeEvent *e ) ...@@ -397,9 +405,7 @@ void MainInterface::resizeEvent( QResizeEvent *e )
****************************************************************************/ ****************************************************************************/
void MainInterface::showSpeedMenu( QPoint pos ) void MainInterface::showSpeedMenu( QPoint pos )
{ {
QMenu menu( this ); speedControlMenu->exec( QCursor::pos() );
menu.addAction( "Not Implemented Yet" );
menu.exec( QCursor::pos() );
} }
void MainInterface::showTimeMenu( QPoint pos ) void MainInterface::showTimeMenu( QPoint pos )
...@@ -694,6 +700,7 @@ void MainInterface::setRate( int rate ) ...@@ -694,6 +700,7 @@ void MainInterface::setRate( int rate )
str.setNum( ( 1000/(double)rate), 'f', 2 ); str.setNum( ( 1000/(double)rate), 'f', 2 );
str.append( "x" ); str.append( "x" );
speedLabel->setText( str ); speedLabel->setText( str );
speedControl->updateControls( rate );
} }
void MainInterface::updateOnTimer() void MainInterface::updateOnTimer()
......
...@@ -44,6 +44,7 @@ class PlaylistWidget; ...@@ -44,6 +44,7 @@ class PlaylistWidget;
class VisualSelector; class VisualSelector;
class AdvControlsWidget; class AdvControlsWidget;
class ControlsWidget; class ControlsWidget;
class SpeedControlWidget;
class QMenu; class QMenu;
class QSize; class QSize;
...@@ -82,6 +83,8 @@ private: ...@@ -82,6 +83,8 @@ private:
QString input_name; QString input_name;
QVBoxLayout *mainLayout; QVBoxLayout *mainLayout;
ControlsWidget *controls; ControlsWidget *controls;
QMenu *speedControlMenu;
SpeedControlWidget *speedControl;
bool need_components_update; bool need_components_update;
......
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