From 30f60c2450957bc64ae3377d31352c85221dae3d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Kempf Date: Sun, 9 Sep 2007 17:42:50 +0000 Subject: [PATCH] =?UTF-8?q?Qt4=20-=20Have=20a=20slider=20to=20control=20pr?= =?UTF-8?q?ecisely=20the=20rate,=20usefull=20since=20we=20can=20here=20aud?= =?UTF-8?q?io=20at=20all=20speeds=20now.=20:D=20Patch=20by=20StFS=20-=20St?= =?UTF-8?q?ef=C3=A1n=20Freyr=20Stef=C3=A1nsson?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gui/qt4/components/interface_widgets.cpp | 131 +++++++++++++++++- .../gui/qt4/components/interface_widgets.hpp | 19 +++ modules/gui/qt4/main_interface.cpp | 13 +- modules/gui/qt4/main_interface.hpp | 3 + 4 files changed, 160 insertions(+), 6 deletions(-) diff --git a/modules/gui/qt4/components/interface_widgets.cpp b/modules/gui/qt4/components/interface_widgets.cpp index ae7941639c..469249bcbb 100644 --- a/modules/gui/qt4/components/interface_widgets.cpp +++ b/modules/gui/qt4/components/interface_widgets.cpp @@ -494,7 +494,6 @@ ControlsWidget::ControlsWidget( intf_thread_t *_p_i, bool b_advControls ) : /* Volume control connection */ CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) ); - } ControlsWidget::~ControlsWidget() { @@ -673,8 +672,8 @@ void ControlsWidget::toggleAdvanced() #include "components/playlist/panels.hpp" #include "components/playlist/selector.hpp" -PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) : - p_intf ( _p_intf ) +PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) : + p_intf ( _p_i ) { /* Left Part and design */ QWidget *leftW = new QWidget( this ); @@ -746,3 +745,129 @@ QSize PlaylistWidget::sizeHint() const 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); +} diff --git a/modules/gui/qt4/components/interface_widgets.hpp b/modules/gui/qt4/components/interface_widgets.hpp index 2ac1b59a31..a42a63a023 100644 --- a/modules/gui/qt4/components/interface_widgets.hpp +++ b/modules/gui/qt4/components/interface_widgets.hpp @@ -233,4 +233,23 @@ signals: 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 diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp index bfba720fb6..f2ea88f5b4 100644 --- a/modules/gui/qt4/main_interface.cpp +++ b/modules/gui/qt4/main_interface.cpp @@ -42,6 +42,8 @@ #include #include #include +#include +#include #include #include @@ -302,6 +304,12 @@ void MainInterface::handleMainUi( QSettings *settings ) /* Add the controls Widget to the main Widget */ 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 */ resize( PREF_W, PREF_H ); @@ -397,9 +405,7 @@ void MainInterface::resizeEvent( QResizeEvent *e ) ****************************************************************************/ void MainInterface::showSpeedMenu( QPoint pos ) { - QMenu menu( this ); - menu.addAction( "Not Implemented Yet" ); - menu.exec( QCursor::pos() ); + speedControlMenu->exec( QCursor::pos() ); } void MainInterface::showTimeMenu( QPoint pos ) @@ -694,6 +700,7 @@ void MainInterface::setRate( int rate ) str.setNum( ( 1000/(double)rate), 'f', 2 ); str.append( "x" ); speedLabel->setText( str ); + speedControl->updateControls( rate ); } void MainInterface::updateOnTimer() diff --git a/modules/gui/qt4/main_interface.hpp b/modules/gui/qt4/main_interface.hpp index f7878963f6..ea5c908842 100644 --- a/modules/gui/qt4/main_interface.hpp +++ b/modules/gui/qt4/main_interface.hpp @@ -44,6 +44,7 @@ class PlaylistWidget; class VisualSelector; class AdvControlsWidget; class ControlsWidget; +class SpeedControlWidget; class QMenu; class QSize; @@ -82,6 +83,8 @@ private: QString input_name; QVBoxLayout *mainLayout; ControlsWidget *controls; + QMenu *speedControlMenu; + SpeedControlWidget *speedControl; bool need_components_update; -- GitLab