[vlc-devel] [RFC 36/82] qt: update input_slider to use new player/playlist API

Pierre Lamot pierre at videolabs.io
Fri Feb 1 14:01:40 CET 2019


---
 modules/gui/qt/util/input_slider.cpp | 50 ++++++++++------------------
 modules/gui/qt/util/input_slider.hpp |  4 +--
 2 files changed, 19 insertions(+), 35 deletions(-)

diff --git a/modules/gui/qt/util/input_slider.cpp b/modules/gui/qt/util/input_slider.cpp
index 3060163b5e..26ad487328 100644
--- a/modules/gui/qt/util/input_slider.cpp
+++ b/modules/gui/qt/util/input_slider.cpp
@@ -30,9 +30,9 @@
 
 #include "util/input_slider.hpp"
 #include "util/timetooltip.hpp"
-#include "adapters/seekpoints.hpp"
-#include "input_manager.hpp"
+#include "components/player_controler.hpp"
 #include "imagehelper.hpp"
+#include "input_models.hpp"
 
 #include <QPaintEvent>
 #include <QPainter>
@@ -72,7 +72,7 @@ SeekSlider::SeekSlider( intf_thread_t *p_intf, Qt::Orientation q, QWidget *_pare
     f_buffering = 0.0;
     mHandleOpacity = 1.0;
     mLoading = 0.0;
-    chapters = NULL;
+    chapters = THEMIM->getChapters();
     mHandleLength = -1;
     b_seekable = true;
     alternativeStyle = NULL;
@@ -164,7 +164,7 @@ SeekSlider::SeekSlider( intf_thread_t *p_intf, Qt::Orientation q, QWidget *_pare
     startAnimLoadingTimer->setSingleShot( true );
     startAnimLoadingTimer->setInterval( 500 );
 
-    CONNECT( MainInputManager::getInstance(), inputChanged( bool ), this , inputUpdated( bool ) );
+    connect( THEMIM, &PlayerControler::inputChanged, this , &SeekSlider::inputUpdated );
     CONNECT( this, sliderMoved( int ), this, startSeekTimer() );
     CONNECT( seekLimitTimer, timeout(), this, updatePos() );
     CONNECT( hideHandleTimer, timeout(), this, hideHandle() );
@@ -174,24 +174,11 @@ SeekSlider::SeekSlider( intf_thread_t *p_intf, Qt::Orientation q, QWidget *_pare
 
 SeekSlider::~SeekSlider()
 {
-    delete chapters;
     if ( alternativeStyle )
         delete alternativeStyle;
     delete mTimeTooltip;
 }
 
-/***
- * \brief Sets the chapters seekpoints adapter
- *
- * \params SeekPoints initilized with current intf thread
-***/
-void SeekSlider::setChapters( SeekPoints *chapters_ )
-{
-    delete chapters;
-    chapters = chapters_;
-    chapters->setParent( this );
-}
-
 /***
  * \brief Main public method, superseeding setValue. Disabling the slider when neeeded
  *
@@ -305,7 +292,7 @@ void SeekSlider::mousePressEvent( QMouseEvent* event )
     isJumping = false;
     /* handle chapter clicks */
     int i_width = size().width();
-    if ( chapters && inputLength && i_width)
+    if ( chapters->rowCount() != 0 && inputLength && i_width)
     {
         if ( orientation() == Qt::Horizontal ) /* TODO: vertical */
         {
@@ -313,15 +300,14 @@ void SeekSlider::mousePressEvent( QMouseEvent* event )
             if ( event->y() < CHAPTER_SPOT_SIZE ||
                  event->y() > ( size().height() - CHAPTER_SPOT_SIZE ) )
             {
-                QList<SeekPoint> points = chapters->getPoints();
                 int i_selected = -1;
-                bool b_startsnonzero = false; /* as we always starts at 1 */
-                if ( points.count() > 0 ) /* do we need an extra offset ? */
-                    b_startsnonzero = ( points.at(0).time > 0 );
+                vlc_tick_t first_chapter = chapters->data(chapters->index(0), ChapterListModel::TimeRole).value<vlc_tick_t>();
+                bool b_startsnonzero = first_chapter > 0; /* as we always starts at 1 */
                 int i_min_diff = i_width + 1;
-                for( int i = 0 ; i < points.count() ; i++ )
+                for( int i = 0 ; i < chapters->rowCount() ; i++ )
                 {
-                    int x = points.at(i).time / (double)CLOCK_FREQ / inputLength * i_width;
+                    vlc_tick_t chaptertime = chapters->data(chapters->index(i), ChapterListModel::TimeRole).value<vlc_tick_t>();
+                    int x = chaptertime / (double)CLOCK_FREQ / inputLength * i_width;
                     int diff_x = abs( x - event->x() );
                     if ( diff_x < i_min_diff )
                     {
@@ -331,7 +317,7 @@ void SeekSlider::mousePressEvent( QMouseEvent* event )
                 }
                 if ( i_selected && i_min_diff < 4 ) // max 4px around mark
                 {
-                    chapters->jumpTo( i_selected );
+                    chapters->setData(chapters->index(i_selected) , true, ChapterListModel::TimeRole);
                     event->accept();
                     isJumping = true;
                     return;
@@ -373,17 +359,17 @@ void SeekSlider::mouseMoveEvent( QMouseEvent *event )
 
         if ( orientation() == Qt::Horizontal ) /* TODO: vertical */
         {
-            QList<SeekPoint> points = chapters->getPoints();
             int i_selected = -1;
-            for( int i = 0 ; i < points.count() ; i++ )
+            for( int i = 0 ; i < chapters->rowCount() ; i++ )
             {
-                int x = margin + points.at(i).time / (double)CLOCK_FREQ / inputLength * (size().width() - 2*margin);
+                vlc_tick_t chaptertime = chapters->data(  chapters->index(i), ChapterListModel::TimeRole ).value<vlc_tick_t>();
+                int x = margin + chaptertime / (double)CLOCK_FREQ / inputLength * (size().width() - 2*margin);
                 if ( event->x() >= x )
                     i_selected = i;
             }
-            if ( i_selected >= 0 && i_selected < points.size() )
+            if ( i_selected >= 0 && i_selected < chapters->rowCount() )
             {
-                chapterLabel = points.at( i_selected ).name;
+                chapterLabel = chapters->data(chapters->index(i_selected), Qt::DisplayRole ).toString();
             }
         }
 
@@ -464,8 +450,8 @@ void SeekSlider::paintEvent( QPaintEvent *ev )
         option.sliderValue = value();
         option.maximum = maximum();
         option.minimum = minimum();
-        if ( chapters ) foreach( const SeekPoint &point, chapters->getPoints() )
-            option.points << point.time;
+        for (int i = 0; i < chapters->rowCount(); i++)
+            option.points << chapters->data(chapters->index(i), ChapterListModel::TimeRole).value<vlc_tick_t>();
         QPainter painter( this );
         style()->drawComplexControl( QStyle::CC_Slider, &option, &painter, this );
     }
diff --git a/modules/gui/qt/util/input_slider.hpp b/modules/gui/qt/util/input_slider.hpp
index 7a64073450..bc44e578d7 100644
--- a/modules/gui/qt/util/input_slider.hpp
+++ b/modules/gui/qt/util/input_slider.hpp
@@ -41,7 +41,6 @@ class QMouseEvent;
 class QWheelEvent;
 class QHideEvent;
 class QTimer;
-class SeekPoints;
 class QPropertyAnimation;
 class QCommonStyle;
 class TimeTooltip;
@@ -57,7 +56,6 @@ public:
     SeekSlider( intf_thread_t *p_intf, Qt::Orientation q, QWidget *_parent = 0,
                 bool _classic = false );
     virtual ~SeekSlider();
-    void setChapters( SeekPoints * );
 
 protected:
     void mouseMoveEvent( QMouseEvent *event ) Q_DECL_OVERRIDE;
@@ -93,7 +91,7 @@ private:
     TimeTooltip *mTimeTooltip;
     float f_buffering;
     QTime bufferingStart;
-    SeekPoints* chapters;
+    QAbstractListModel* chapters;
     bool b_classic;
     bool b_seekable;
     int mHandleLength;
-- 
2.19.1



More information about the vlc-devel mailing list