[vlc-devel] commit: Qt: separate status bar label for "Buffering" + show time while seeking (close #2760) (Jakob Leben )

git version control git at videolan.org
Wed Feb 17 07:06:40 CET 2010


vlc | branch: master | Jakob Leben <jleben at videolan.org> | Wed Feb 17 07:04:15 2010 +0100| [0972b0824c8e7d68632bc4d8ee3072bad16f3a19] | committer: Jakob Leben 

Qt: separate status bar label for "Buffering" + show time while seeking (close #2760)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0972b0824c8e7d68632bc4d8ee3072bad16f3a19
---

 modules/gui/qt4/components/interface_widgets.cpp |   64 +++++++++++++++++++---
 modules/gui/qt4/components/interface_widgets.hpp |   19 ++++++-
 modules/gui/qt4/input_manager.cpp                |    1 +
 modules/gui/qt4/input_manager.hpp                |    1 +
 modules/gui/qt4/main_interface.cpp               |   13 +++++
 modules/gui/qt4/main_interface.hpp               |    2 +
 6 files changed, 91 insertions(+), 9 deletions(-)

diff --git a/modules/gui/qt4/components/interface_widgets.cpp b/modules/gui/qt4/components/interface_widgets.cpp
index 7f09e59..d4376f4 100644
--- a/modules/gui/qt4/components/interface_widgets.cpp
+++ b/modules/gui/qt4/components/interface_widgets.cpp
@@ -42,6 +42,7 @@
 #include <QMenu>
 #include <QWidgetAction>
 #include <QDesktopWidget>
+#include <QPainter>
 
 #ifdef Q_WS_X11
 # include <X11/Xlib.h>
@@ -594,9 +595,6 @@ TimeLabel::TimeLabel( intf_thread_t *_p_intf  ) :QLabel(), p_intf( _p_intf )
    setAlignment( Qt::AlignRight | Qt::AlignVCenter );
    setToolTip( qtr( "Toggle between elapsed and remaining time" ) );
 
-
-   CONNECT( THEMIM->getIM(), cachingChanged( float ),
-            this, setCaching( float ) );
    CONNECT( THEMIM->getIM(), positionUpdated( float, int64_t, int ),
              this, setDisplayPosition( float, int64_t, int ) );
 }
@@ -610,7 +608,7 @@ void TimeLabel::setDisplayPosition( float pos, int64_t t, int length )
     }
 
     int time = t / 1000000;
-    char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
+
     secstotimestr( psz_length, length );
     secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
                                                            : time );
@@ -620,18 +618,68 @@ void TimeLabel::setDisplayPosition( float pos, int64_t t, int length )
                      psz_time, ( !length && time ) ? "--:--" : psz_length );
 
     setText( timestr );
+
+    cachedLength = length;
+}
+
+void TimeLabel::setDisplayPosition( float pos )
+{
+    if( pos == -1.f || cachedLength == 0 )
+    {
+        setText( " --:--/--:-- " );
+        return;
+    }
+
+    int time = pos * cachedLength;
+    secstotimestr( psz_time,
+                   ( b_remainingTime && cachedLength ?
+                   cachedLength - time : time ) );
+    QString timestr;
+    timestr.sprintf( " %s%s/%s ", (b_remainingTime && cachedLength) ? "-" : "",
+                     psz_time, ( !cachedLength && time ) ? "--:--" : psz_length );
+
+    setText( timestr );
 }
 
+
 void TimeLabel::toggleTimeDisplay()
 {
     b_remainingTime = !b_remainingTime;
 }
 
-void TimeLabel::setCaching( float f_cache )
+CacheLabel::CacheLabel( intf_thread_t *_p_intf, QWidget *parent )
+  : QLabel( parent ), p_intf( _p_intf ), cached( 0.f )
 {
-    QString amount;
-    amount.sprintf("Buff: %i%%", (int)(100*f_cache) );
-    setText( amount );
+    setText( qtr( "Buffering..." ) );
+    setMinimumWidth( 70 );
+    setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred );
+    setAlignment( Qt::AlignCenter );
+
+    CONNECT( THEMIM->getIM(), cachingChanged( float ),
+              this, showCaching( float ) );
+    CONNECT( THEMIM->getIM(), positionUpdated( float, int64_t, int ),
+              this, hideCaching() );
 }
 
+void CacheLabel::showCaching( float _cached )
+{
+    cached = _cached;
+    show();
+    update(); //in case we are already visible
+}
 
+void CacheLabel::hideCaching()
+{
+    hide();
+}
+
+void CacheLabel::paintEvent( QPaintEvent* event )
+{
+    QRect r( rect() );
+    r.setWidth( r.width() * cached );
+    QPainter p( this );
+    p.setOpacity( 0.4 );
+    p.fillRect( r, palette().color( QPalette::Highlight ) );
+
+    QLabel::paintEvent( event );
+}
diff --git a/modules/gui/qt4/components/interface_widgets.hpp b/modules/gui/qt4/components/interface_widgets.hpp
index 12484f2..17fdfd8 100644
--- a/modules/gui/qt4/components/interface_widgets.hpp
+++ b/modules/gui/qt4/components/interface_widgets.hpp
@@ -140,12 +140,15 @@ protected:
 private:
     intf_thread_t *p_intf;
     bool b_remainingTime;
+    int cachedLength;
+    char psz_length[MSTRTIME_MAX_SIZE];
+    char psz_time[MSTRTIME_MAX_SIZE];
     void toggleTimeDisplay();
 signals:
     void timeLabelDoubleClicked();
 private slots:
     void setDisplayPosition( float pos, int64_t time, int length );
-    void setCaching( float );
+    void setDisplayPosition( float pos );
 };
 
 class SpeedLabel : public QLabel
@@ -169,6 +172,20 @@ private:
     SpeedControlWidget *speedControl;
 };
 
+class CacheLabel : public QLabel
+{
+    Q_OBJECT
+public:
+    CacheLabel( intf_thread_t *, QWidget * );
+private slots:
+    void showCaching( float );
+    void hideCaching();
+private:
+    void paintEvent( QPaintEvent* );
+    intf_thread_t *p_intf;
+    float cached;
+};
+
 /******************** Speed Control Widgets ****************/
 class SpeedControlWidget : public QFrame
 {
diff --git a/modules/gui/qt4/input_manager.cpp b/modules/gui/qt4/input_manager.cpp
index 85e2bb4..43beda0 100644
--- a/modules/gui/qt4/input_manager.cpp
+++ b/modules/gui/qt4/input_manager.cpp
@@ -683,6 +683,7 @@ void InputManager::sliderUpdate( float new_pos )
 {
     if( hasInput() )
         var_SetFloat( p_input, "position", new_pos );
+    emit seekRequested( new_pos );
 }
 
 /* User togglePlayPause */
diff --git a/modules/gui/qt4/input_manager.hpp b/modules/gui/qt4/input_manager.hpp
index 726c6bd..6a856f1 100644
--- a/modules/gui/qt4/input_manager.hpp
+++ b/modules/gui/qt4/input_manager.hpp
@@ -203,6 +203,7 @@ private slots:
 signals:
     /// Send new position, new time and new length
     void positionUpdated( float , int64_t, int );
+    void seekRequested( float pos );
     void rateChanged( int );
     void nameChanged( const QString& );
     /// Used to signal whether we should show navigation buttons
diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index 9ced197..c63b752 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -497,14 +497,18 @@ inline void MainInterface::createStatusBar()
     nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
                                       | Qt::TextSelectableByKeyboard );
     SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
+    CacheLabel *cacheLabel = new CacheLabel( p_intf, this );
+    cacheLabel->hide();
 
     /* Styling those labels */
     timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
     speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
+    cacheLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
     nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
 
     /* and adding those */
     statusBarr->addWidget( nameLabel, 8 );
+    statusBarr->addPermanentWidget( cacheLabel, 0 );
     statusBarr->addPermanentWidget( speedLabel, 0 );
     statusBarr->addPermanentWidget( timeLabel, 0 );
 
@@ -516,6 +520,9 @@ inline void MainInterface::createStatusBar()
 
     CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
              this, showCryptedLabel( bool ) );
+
+    connect( THEMIM->getIM(), SIGNAL(seekRequested(float)),
+             timeLabel, SLOT(setDisplayPosition(float)) );
 }
 
 #ifdef WIN32
@@ -1180,6 +1187,12 @@ void MainInterface::showCryptedLabel( bool b_show )
     cryptedLabel->setVisible( b_show );
 }
 
+void MainInterface::showBuffering( float f_cache )
+{
+    QString amount = QString("Buffering: %1%").arg( (int)(100*f_cache) );
+    statusBar()->showMessage( amount, 1000 );
+}
+
 /*****************************************************************************
  * Systray Icon and Systray Menu
  *****************************************************************************/
diff --git a/modules/gui/qt4/main_interface.hpp b/modules/gui/qt4/main_interface.hpp
index a808425..bf5a09b 100644
--- a/modules/gui/qt4/main_interface.hpp
+++ b/modules/gui/qt4/main_interface.hpp
@@ -217,6 +217,8 @@ private slots:
 
     void handleKeyPress( QKeyEvent * );
 
+    void showBuffering( float );
+
 signals:
     void askGetVideo( WId *p_id, int *pi_x, int *pi_y,
                       unsigned *pi_width, unsigned *pi_height );




More information about the vlc-devel mailing list