[vlc-devel] [PATCH 2/3] qt: replaced magic constants with QtAbstractSlider::{maximum, minimum}

Filip Roséen filip at videolabs.io
Tue Mar 22 19:26:05 CET 2016


Replaced the use of constants with calls to QAbstractSlider::maximum and
QAbstractSlider::minimum, making it easier to maintain the class in the
future.
---
 modules/gui/qt/util/input_slider.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/modules/gui/qt/util/input_slider.cpp b/modules/gui/qt/util/input_slider.cpp
index 6f23de6..335a916 100644
--- a/modules/gui/qt/util/input_slider.cpp
+++ b/modules/gui/qt/util/input_slider.cpp
@@ -209,7 +209,7 @@ void SeekSlider::setPosition( float pos, int64_t time, int length )
 
     if( !isSliding )
     {
-        setValue( (int)( pos * 1000.0 ) );
+        setValue( pos * static_cast<float>( maximum() ) );
         if ( animLoading != NULL && pos >= 0.0f && animLoading->state() != QAbstractAnimation::Stopped )
         {
             animLoading->stop();
@@ -230,7 +230,7 @@ void SeekSlider::startSeekTimer()
 
 void SeekSlider::updatePos()
 {
-    float f_pos = (float)( value() ) / 1000.0;
+    float f_pos = value() / static_cast<float>( maximum() );
     emit sliderDragged( f_pos ); /* Send new position to VLC's core */
 }
 
@@ -336,7 +336,7 @@ void SeekSlider::mousePressEvent( QMouseEvent* event )
 
     isSliding = true ;
 
-    setValue( QStyle::sliderValueFromPosition( MIN_SLIDER_VALUE, MAX_SLIDER_VALUE, event->x() - handleLength() / 2, width() - handleLength(), false ) );
+    setValue( QStyle::sliderValueFromPosition( minimum(), maximum(), event->x() - handleLength() / 2, width() - handleLength(), false ) );
     emit sliderMoved( value() );
     event->accept();
 }
@@ -353,7 +353,7 @@ void SeekSlider::mouseMoveEvent( QMouseEvent *event )
 
     if( isSliding )
     {
-        setValue( QStyle::sliderValueFromPosition( MIN_SLIDER_VALUE, MAX_SLIDER_VALUE, event->x() - handleLength() / 2, width() - handleLength(), false) );
+        setValue( QStyle::sliderValueFromPosition( minimum(), maximum(), event->x() - handleLength() / 2, width() - handleLength(), false) );
         emit sliderMoved( value() );
     }
 
@@ -400,7 +400,7 @@ void SeekSlider::wheelEvent( QWheelEvent *event )
          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() / static_cast<float>( maximum() ) );
     }
     event->accept();
 }
-- 
2.7.4



More information about the vlc-devel mailing list