]> git.sesse.net Git - vlc/commitdiff
Qt4 - Stop the stupidity of the input Slider:
authorJean-Baptiste Kempf <jb@videolan.org>
Wed, 23 Jan 2008 02:31:38 +0000 (02:31 +0000)
committerJean-Baptiste Kempf <jb@videolan.org>
Wed, 23 Jan 2008 02:31:38 +0000 (02:31 +0000)
- Click on a point on the timeline goes to that point directly
- Draging the timeline makes the position follow your draging
- Hovering a point on the timeline gives you the time of the position under your cursor.

This make break your neck, and kill your favourite ant, but I think this is not that wrong.

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

index 01921af8aa758b0065661145364edf9e393b5e68..cdb6f6ce3114778e75aa9486cc36f99ee881a759 100644 (file)
@@ -21,7 +21,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-#include "qt4.hpp"
 #include "util/input_slider.hpp"
 
 #include <QPaintEvent>
@@ -37,13 +36,14 @@ InputSlider::InputSlider( QWidget *_parent ) : QSlider( _parent )
 InputSlider::InputSlider( Qt::Orientation q,QWidget *_parent ) :
                                  QSlider( q, _parent )
 {
-    mymove = false;
+    b_sliding = false;
     setMinimum( 0 );
     setMouseTracking(true);
     setMaximum( 1000 );
     setSingleStep( 2 );
     setPageStep( 10 );
     setTracking( true );
+    secstotimestr( psz_length, 0 );
     CONNECT( this, valueChanged(int), this, userDrag( int ) );
 }
 
@@ -53,39 +53,50 @@ void InputSlider::setPosition( float pos, int a, int b )
         setEnabled( false );
     else
         setEnabled( true );
-    mymove = true;
-    setValue( (int)(pos * 1000.0 ) );
-    mymove = false;
+
+    if( !b_sliding )
+        setValue( (int)(pos * 1000.0 ) );
     inputLength = b;
 }
 
 void InputSlider::userDrag( int new_value )
 {
-    float f_pos = (float)(new_value)/1000.0;
-    if( !mymove )
+    if( b_sliding )
     {
+        float f_pos = (float)(new_value)/1000.0;
         emit sliderDragged( f_pos );
     }
 }
 
+void InputSlider::mouseReleaseEvent( QMouseEvent *event )
+{
+    b_sliding = false;
+}
+
 void InputSlider::mousePressEvent(QMouseEvent* event)
 {
-    if( event->button() != Qt::LeftButton && event->button() != Qt::MidButton )
+    b_sliding = true ;
+    if( event->button() != Qt::LeftButton &&
+        event->button() != Qt::MidButton )
     {
         QSlider::mousePressEvent( event );
         return;
     }
 
     QMouseEvent newEvent( event->type(), event->pos(), event->globalPos(),
-            Qt::MouseButton( event->button() ^ Qt::LeftButton ^ Qt::MidButton ),
-            Qt::MouseButtons( event->buttons() ^ Qt::LeftButton ^ Qt::MidButton ),
-            event->modifiers() );
+        Qt::MouseButton( event->button() ^ Qt::LeftButton ^ Qt::MidButton ),
+        Qt::MouseButtons( event->buttons() ^ Qt::LeftButton ^ Qt::MidButton ),
+        event->modifiers() );
     QSlider::mousePressEvent( &newEvent );
 }
 
 void InputSlider::mouseMoveEvent(QMouseEvent *event)
 {
-    char psz_length[MSTRTIME_MAX_SIZE];
+    if( b_sliding )
+    {
+        QSlider::mouseMoveEvent( event );
+    }
+
     secstotimestr( psz_length, ( event->x() * inputLength) / size().width() );
     setToolTip( psz_length );
 }
index b9bc729839a25afc5a975cdb902b5706bb56f9dd..a06d93a2b3d34317da153f2264cd793dbba3e1f8 100644 (file)
@@ -24,6 +24,8 @@
 #ifndef _INPUTSLIDER_H_
 #define _INPUTSLIDER_H_
 
+#include "qt4.hpp"
+
 #include <QSlider>
 #include <QMouseEvent>
 
@@ -37,9 +39,11 @@ public:
 protected:
     virtual void mouseMoveEvent(QMouseEvent *event);
     virtual void mousePressEvent(QMouseEvent* event);
+    virtual void mouseReleaseEvent(QMouseEvent* event);
 private:
-    bool mymove;
+    bool b_sliding;
     int inputLength;
+    char psz_length[MSTRTIME_MAX_SIZE];
 public slots:
     void setPosition( float, int, int );
 private slots: