]> git.sesse.net Git - vlc/commitdiff
Qt4: position slider: send seek events at regular intervals
authorJakob Leben <jleben@videolan.org>
Wed, 25 Nov 2009 14:25:18 +0000 (15:25 +0100)
committerJakob Leben <jleben@videolan.org>
Wed, 25 Nov 2009 14:30:58 +0000 (15:30 +0100)
Improves seeking experience by sending less seek requests and actually allowing output to update between them.

modules/gui/qt4/util/input_slider.cpp
modules/gui/qt4/util/input_slider.hpp

index d71caddf182d2703a154d163d66da665c8c0b2cf..c2d861c6cd8786e68ae45df612c023709d4ac209 100644 (file)
@@ -41,6 +41,9 @@ InputSlider::InputSlider( Qt::Orientation q, QWidget *_parent ) :
                                  QSlider( q, _parent )
 {
     b_isSliding = false;
+    lastSeeked = 0;
+    timer = new QTimer(this);
+    timer->setSingleShot(true);
     setMinimum( 0 );
     setMouseTracking(true);
     setMaximum( 1000 );
@@ -51,6 +54,7 @@ InputSlider::InputSlider( Qt::Orientation q, QWidget *_parent ) :
     secstotimestr( psz_length, 0 );
     setFocusPolicy( Qt::NoFocus );
     CONNECT( this, valueChanged(int), this, userDrag( int ) );
+    CONNECT( timer, timeout(), this, seekTick() );
 }
 
 void InputSlider::setPosition( float pos, int a, int b )
@@ -68,9 +72,15 @@ void InputSlider::setPosition( float pos, int a, int b )
 
 void InputSlider::userDrag( int new_value )
 {
-    if( b_isSliding )
-    {
-        float f_pos = (float)(new_value)/1000.0;
+    if( b_isSliding && !timer->isActive() )
+            timer->start( 150 );
+}
+
+void InputSlider::seekTick()
+{
+    if( value() != lastSeeked ) {
+        lastSeeked = value();
+        float f_pos = (float)(lastSeeked)/1000.0;
         emit sliderDragged( f_pos );
     }
 }
@@ -97,6 +107,8 @@ void InputSlider::mousePressEvent(QMouseEvent* event)
         Qt::MouseButtons( event->buttons() ^ Qt::LeftButton ^ Qt::MidButton ),
         event->modifiers() );
     QSlider::mousePressEvent( &newEvent );
+
+    seekTick();
 }
 
 void InputSlider::mouseMoveEvent(QMouseEvent *event)
index 1e6ec6ae9ef0d3acc09554dd0f31157b76856257..4925d19c01decc17af3311464dcf0d4d78182c68 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <QMouseEvent>
 #include <QWheelEvent>
+#include <QTimer>
 
 /* Input Slider derived from QSlider */
 class InputSlider : public QSlider
@@ -49,11 +50,14 @@ private:
     bool b_isSliding; /* Whether we are currently sliding by user action */
     int inputLength;  /* InputLength that can change */
     char psz_length[MSTRTIME_MAX_SIZE]; /* Used for the ToolTip */
+    int lastSeeked;
+    QTimer *timer;
 
 public slots:
     void setPosition( float, int, int );
 private slots:
     void userDrag( int );
+    void seekTick();
 
 signals:
     void sliderDragged( float );