From: Francois Cartegnie Date: Sun, 3 Jul 2011 19:33:06 +0000 (+0200) Subject: Qt: Make chapters marks clickable X-Git-Tag: 1.2.0-pre1~1811 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=c0670fd9ce5c2b0629f427e251fb6ab35bf5eaf9;p=vlc Qt: Make chapters marks clickable --- diff --git a/modules/gui/qt4/util/input_slider.cpp b/modules/gui/qt4/util/input_slider.cpp index 1ea5b5de77..d8de45a368 100644 --- a/modules/gui/qt4/util/input_slider.cpp +++ b/modules/gui/qt4/util/input_slider.cpp @@ -31,6 +31,8 @@ #include "util/input_slider.hpp" #include "adapters/seekpoints.hpp" +#include + #include #include #include @@ -42,6 +44,7 @@ #define MINIMUM 0 #define MAXIMUM 1000 +#define CHAPTERSSPOTSIZE 3 SeekSlider::SeekSlider( QWidget *_parent ) : QSlider( _parent ) { @@ -145,6 +148,11 @@ void SeekSlider::mouseReleaseEvent( QMouseEvent *event ) event->accept(); b_isSliding = false; seekLimitTimer->stop(); /* We're not sliding anymore: only last seek on release */ + if ( b_is_jumping ) + { + b_is_jumping = false; + return; + } QSlider::mouseReleaseEvent( event ); updatePos(); } @@ -159,6 +167,41 @@ void SeekSlider::mousePressEvent( QMouseEvent* event ) return; } + b_is_jumping = false; + /* handle chapter clicks */ + int i_width = size().width(); + if ( chapters && inputLength && i_width) + { + if ( orientation() == Qt::Horizontal ) /* TODO: vertical */ + { + /* only on chapters zone */ + if ( event->y() < CHAPTERSSPOTSIZE || + event->y() > ( size().height() - CHAPTERSSPOTSIZE ) ) + { + QList points = chapters->getPoints(); + int i_selected = -1; + int i_min_diff = i_width + 1; + for( int i = 0 ; i < points.count() ; i++ ) + { + int x = points.at(i).time / 1000000.0 / inputLength * i_width; + int diff_x = abs( x - event->x() ); + if ( diff_x < i_min_diff ) + { + i_min_diff = diff_x; + i_selected = i; + } else break; + } + if ( i_selected && i_min_diff < 4 ) // max 4px around mark + { + chapters->jumpTo( i_selected ); + event->accept(); + b_is_jumping = true; + return; + } + } + } + } + b_isSliding = true ; setValue( QStyle::sliderValueFromPosition( MINIMUM, MAXIMUM, event->x(), width(), false ) ); event->accept(); @@ -362,8 +405,8 @@ void SeekSlider::paintEvent( QPaintEvent *event ) int x = point.time / 1000000.0 / inputLength * size().width(); painter.setPen( QColor( 80, 80, 80 ) ); painter.setBrush( Qt::NoBrush ); - painter.drawLine( x, 0, x, 3 ); - painter.drawLine( x, height(), x, height() - 3 ); + painter.drawLine( x, 0, x, CHAPTERSSPOTSIZE ); + painter.drawLine( x, height(), x, height() - CHAPTERSSPOTSIZE ); } } } diff --git a/modules/gui/qt4/util/input_slider.hpp b/modules/gui/qt4/util/input_slider.hpp index 354bc28837..f64dcc3bcb 100644 --- a/modules/gui/qt4/util/input_slider.hpp +++ b/modules/gui/qt4/util/input_slider.hpp @@ -65,6 +65,7 @@ protected: private: bool b_isSliding; /* Whether we are currently sliding by user action */ + bool b_is_jumping; /* if we requested a jump to another chapter */ int inputLength; /* InputLength that can change */ char psz_length[MSTRTIME_MAX_SIZE]; /* Used for the ToolTip */ QTimer *seekLimitTimer;