[vlc-commits] Qt: Make chapters marks clickable
Francois Cartegnie
git at videolan.org
Mon Jul 11 23:14:23 CEST 2011
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sun Jul 3 21:33:06 2011 +0200| [c0670fd9ce5c2b0629f427e251fb6ab35bf5eaf9] | committer: Francois Cartegnie
Qt: Make chapters marks clickable
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c0670fd9ce5c2b0629f427e251fb6ab35bf5eaf9
---
modules/gui/qt4/util/input_slider.cpp | 47 +++++++++++++++++++++++++++++++-
modules/gui/qt4/util/input_slider.hpp | 1 +
2 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/modules/gui/qt4/util/input_slider.cpp b/modules/gui/qt4/util/input_slider.cpp
index 1ea5b5d..d8de45a 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 <stdlib.h>
+
#include <QPaintEvent>
#include <QPainter>
#include <QBitmap>
@@ -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<SeekPoint> 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 354bc28..f64dcc3 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;
More information about the vlc-commits
mailing list