[vlc-devel] commit: Qt4: position slider: send seek events at regular intervals ( Jakob Leben )

git version control git at videolan.org
Wed Nov 25 15:39:51 CET 2009


vlc | branch: master | Jakob Leben <jleben at videolan.org> | Wed Nov 25 15:25:18 2009 +0100| [15288858575b3ab35f3e2824e6464f6bc5c4e186] | committer: Jakob Leben 

Qt4: position slider: send seek events at regular intervals

Improves seeking experience by sending less seek requests and actually allowing output to update between them.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=15288858575b3ab35f3e2824e6464f6bc5c4e186
---

 modules/gui/qt4/util/input_slider.cpp |   18 +++++++++++++++---
 modules/gui/qt4/util/input_slider.hpp |    4 ++++
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/modules/gui/qt4/util/input_slider.cpp b/modules/gui/qt4/util/input_slider.cpp
index d71cadd..c2d861c 100644
--- a/modules/gui/qt4/util/input_slider.cpp
+++ b/modules/gui/qt4/util/input_slider.cpp
@@ -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)
diff --git a/modules/gui/qt4/util/input_slider.hpp b/modules/gui/qt4/util/input_slider.hpp
index 1e6ec6a..4925d19 100644
--- a/modules/gui/qt4/util/input_slider.hpp
+++ b/modules/gui/qt4/util/input_slider.hpp
@@ -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 );




More information about the vlc-devel mailing list