Commit c0670fd9 authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: Make chapters marks clickable

parent 0f762cdd
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#include "util/input_slider.hpp" #include "util/input_slider.hpp"
#include "adapters/seekpoints.hpp" #include "adapters/seekpoints.hpp"
#include <stdlib.h>
#include <QPaintEvent> #include <QPaintEvent>
#include <QPainter> #include <QPainter>
#include <QBitmap> #include <QBitmap>
...@@ -42,6 +44,7 @@ ...@@ -42,6 +44,7 @@
#define MINIMUM 0 #define MINIMUM 0
#define MAXIMUM 1000 #define MAXIMUM 1000
#define CHAPTERSSPOTSIZE 3
SeekSlider::SeekSlider( QWidget *_parent ) : QSlider( _parent ) SeekSlider::SeekSlider( QWidget *_parent ) : QSlider( _parent )
{ {
...@@ -145,6 +148,11 @@ void SeekSlider::mouseReleaseEvent( QMouseEvent *event ) ...@@ -145,6 +148,11 @@ void SeekSlider::mouseReleaseEvent( QMouseEvent *event )
event->accept(); event->accept();
b_isSliding = false; b_isSliding = false;
seekLimitTimer->stop(); /* We're not sliding anymore: only last seek on release */ seekLimitTimer->stop(); /* We're not sliding anymore: only last seek on release */
if ( b_is_jumping )
{
b_is_jumping = false;
return;
}
QSlider::mouseReleaseEvent( event ); QSlider::mouseReleaseEvent( event );
updatePos(); updatePos();
} }
...@@ -159,6 +167,41 @@ void SeekSlider::mousePressEvent( QMouseEvent* event ) ...@@ -159,6 +167,41 @@ void SeekSlider::mousePressEvent( QMouseEvent* event )
return; 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 ; b_isSliding = true ;
setValue( QStyle::sliderValueFromPosition( MINIMUM, MAXIMUM, event->x(), width(), false ) ); setValue( QStyle::sliderValueFromPosition( MINIMUM, MAXIMUM, event->x(), width(), false ) );
event->accept(); event->accept();
...@@ -362,8 +405,8 @@ void SeekSlider::paintEvent( QPaintEvent *event ) ...@@ -362,8 +405,8 @@ void SeekSlider::paintEvent( QPaintEvent *event )
int x = point.time / 1000000.0 / inputLength * size().width(); int x = point.time / 1000000.0 / inputLength * size().width();
painter.setPen( QColor( 80, 80, 80 ) ); painter.setPen( QColor( 80, 80, 80 ) );
painter.setBrush( Qt::NoBrush ); painter.setBrush( Qt::NoBrush );
painter.drawLine( x, 0, x, 3 ); painter.drawLine( x, 0, x, CHAPTERSSPOTSIZE );
painter.drawLine( x, height(), x, height() - 3 ); painter.drawLine( x, height(), x, height() - CHAPTERSSPOTSIZE );
} }
} }
} }
......
...@@ -65,6 +65,7 @@ protected: ...@@ -65,6 +65,7 @@ protected:
private: private:
bool b_isSliding; /* Whether we are currently sliding by user action */ 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 */ 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 */
QTimer *seekLimitTimer; QTimer *seekLimitTimer;
......
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