Commit 15288858 authored by Jakob Leben's avatar 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.
parent d8efdc14
...@@ -41,6 +41,9 @@ InputSlider::InputSlider( Qt::Orientation q, QWidget *_parent ) : ...@@ -41,6 +41,9 @@ InputSlider::InputSlider( Qt::Orientation q, QWidget *_parent ) :
QSlider( q, _parent ) QSlider( q, _parent )
{ {
b_isSliding = false; b_isSliding = false;
lastSeeked = 0;
timer = new QTimer(this);
timer->setSingleShot(true);
setMinimum( 0 ); setMinimum( 0 );
setMouseTracking(true); setMouseTracking(true);
setMaximum( 1000 ); setMaximum( 1000 );
...@@ -51,6 +54,7 @@ InputSlider::InputSlider( Qt::Orientation q, QWidget *_parent ) : ...@@ -51,6 +54,7 @@ InputSlider::InputSlider( Qt::Orientation q, QWidget *_parent ) :
secstotimestr( psz_length, 0 ); secstotimestr( psz_length, 0 );
setFocusPolicy( Qt::NoFocus ); setFocusPolicy( Qt::NoFocus );
CONNECT( this, valueChanged(int), this, userDrag( int ) ); CONNECT( this, valueChanged(int), this, userDrag( int ) );
CONNECT( timer, timeout(), this, seekTick() );
} }
void InputSlider::setPosition( float pos, int a, int b ) void InputSlider::setPosition( float pos, int a, int b )
...@@ -68,9 +72,15 @@ 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 ) void InputSlider::userDrag( int new_value )
{ {
if( b_isSliding ) if( b_isSliding && !timer->isActive() )
{ timer->start( 150 );
float f_pos = (float)(new_value)/1000.0; }
void InputSlider::seekTick()
{
if( value() != lastSeeked ) {
lastSeeked = value();
float f_pos = (float)(lastSeeked)/1000.0;
emit sliderDragged( f_pos ); emit sliderDragged( f_pos );
} }
} }
...@@ -97,6 +107,8 @@ void InputSlider::mousePressEvent(QMouseEvent* event) ...@@ -97,6 +107,8 @@ void InputSlider::mousePressEvent(QMouseEvent* event)
Qt::MouseButtons( event->buttons() ^ Qt::LeftButton ^ Qt::MidButton ), Qt::MouseButtons( event->buttons() ^ Qt::LeftButton ^ Qt::MidButton ),
event->modifiers() ); event->modifiers() );
QSlider::mousePressEvent( &newEvent ); QSlider::mousePressEvent( &newEvent );
seekTick();
} }
void InputSlider::mouseMoveEvent(QMouseEvent *event) void InputSlider::mouseMoveEvent(QMouseEvent *event)
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <QMouseEvent> #include <QMouseEvent>
#include <QWheelEvent> #include <QWheelEvent>
#include <QTimer>
/* Input Slider derived from QSlider */ /* Input Slider derived from QSlider */
class InputSlider : public QSlider class InputSlider : public QSlider
...@@ -49,11 +50,14 @@ private: ...@@ -49,11 +50,14 @@ private:
bool b_isSliding; /* Whether we are currently sliding by user action */ bool b_isSliding; /* Whether we are currently sliding by user action */
int inputLength; /* InputLength that can change */ int inputLength; /* InputLength that can change */
char psz_length[MSTRTIME_MAX_SIZE]; /* Used for the ToolTip */ char psz_length[MSTRTIME_MAX_SIZE]; /* Used for the ToolTip */
int lastSeeked;
QTimer *timer;
public slots: public slots:
void setPosition( float, int, int ); void setPosition( float, int, int );
private slots: private slots:
void userDrag( int ); void userDrag( int );
void seekTick();
signals: signals:
void sliderDragged( float ); void sliderDragged( float );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment