[vlc-devel] [PATCH 3/3] qt: make seek tooltip + actual seek less surprising

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


Previously seeking could be somewhat of a surprise if one relied on the
text present in the tooltip above the SeekSlider when hovering it with
your mouse.

Since the position of where we are going to end up was calculated
differently in different parts of the code, you could aim for "00:10:42"
but end up quite far from there (how far depends on the length of the
media you are playing).

This patch fixes the above by introducing two helper functions,
effectively making all calculations that are based on the X-coordinate
relative to the SeekSlider the same, and as such less surprising.
---
 modules/gui/qt/util/input_slider.cpp | 21 ++++++++++++++++++---
 modules/gui/qt/util/input_slider.hpp |  3 +++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/modules/gui/qt/util/input_slider.cpp b/modules/gui/qt/util/input_slider.cpp
index 335a916..cf28b35 100644
--- a/modules/gui/qt/util/input_slider.cpp
+++ b/modules/gui/qt/util/input_slider.cpp
@@ -336,7 +336,7 @@ void SeekSlider::mousePressEvent( QMouseEvent* event )
 
     isSliding = true ;
 
-    setValue( QStyle::sliderValueFromPosition( minimum(), maximum(), event->x() - handleLength() / 2, width() - handleLength(), false ) );
+    setValue( getValueFromXPos( event->x() ) );
     emit sliderMoved( value() );
     event->accept();
 }
@@ -353,7 +353,7 @@ void SeekSlider::mouseMoveEvent( QMouseEvent *event )
 
     if( isSliding )
     {
-        setValue( QStyle::sliderValueFromPosition( minimum(), maximum(), event->x() - handleLength() / 2, width() - handleLength(), false) );
+        setValue( getValueFromXPos( event->x() ) );
         emit sliderMoved( value() );
     }
 
@@ -384,7 +384,7 @@ void SeekSlider::mouseMoveEvent( QMouseEvent *event )
         QPoint target( event->globalX() - ( event->x() - posX ),
                 QWidget::mapToGlobal( QPoint( 0, 0 ) ).y() );
         if( likely( size().width() > handleLength() ) ) {
-            secstotimestr( psz_length, ( ( posX - margin ) * inputLength ) / ( size().width() - handleLength() ) );
+            secstotimestr( psz_length, getValuePercentageFromXPos( event->x() ) * inputLength );
             mTimeTooltip->setTip( target, psz_length, chapterLabel );
         }
     }
@@ -531,6 +531,21 @@ inline int SeekSlider::handleLength()
     return mHandleLength;
 }
 
+inline int SeekSlider::getValueFromXPos( int posX )
+{
+    return QStyle::sliderValueFromPosition(
+        minimum(), maximum(),
+        posX    - handleLength() / 2,
+        width() - handleLength(),
+        false
+    );
+}
+
+inline float SeekSlider::getValuePercentageFromXPos( int posX )
+{
+    return getValueFromXPos( posX ) / static_cast<float>( maximum() );
+}
+
 void SeekSlider::hideHandle()
 {
     /* If pause is called while not running Qt will complain */
diff --git a/modules/gui/qt/util/input_slider.hpp b/modules/gui/qt/util/input_slider.hpp
index ad006cd..ca57b3b 100644
--- a/modules/gui/qt/util/input_slider.hpp
+++ b/modules/gui/qt/util/input_slider.hpp
@@ -80,6 +80,9 @@ protected:
     void setLoading( qreal loading );
     int handleLength();
 
+    float getValuePercentageFromXPos( int );
+    int   getValueFromXPos( int );
+
 private:
     bool isSliding;        /* Whether we are currently sliding by user action */
     bool isJumping;              /* if we requested a jump to another chapter */
-- 
2.7.4



More information about the vlc-devel mailing list