]> git.sesse.net Git - vlc/commitdiff
Qt: separate status bar label for "Buffering" + show time while seeking (close #2760)
authorJakob Leben <jleben@videolan.org>
Wed, 17 Feb 2010 06:04:15 +0000 (07:04 +0100)
committerJakob Leben <jleben@videolan.org>
Wed, 17 Feb 2010 06:06:31 +0000 (07:06 +0100)
modules/gui/qt4/components/interface_widgets.cpp
modules/gui/qt4/components/interface_widgets.hpp
modules/gui/qt4/input_manager.cpp
modules/gui/qt4/input_manager.hpp
modules/gui/qt4/main_interface.cpp
modules/gui/qt4/main_interface.hpp

index 7f09e59872e72249dd4dfff85e4fb2ebf8427b22..d4376f4df0584dc4cda0cd86f4c187dea299f67f 100644 (file)
@@ -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 );
+}
index 12484f2a68ba54729c41b86390d3260ab1666d4a..17fdfd8ebd50c3873e73b1d02c8992ccfcab8afb 100644 (file)
@@ -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
 {
index 85e2bb440aaea31b40372f8886c90d2720467746..43beda0d8f1f2545e17fcfb3776539bb362712b1 100644 (file)
@@ -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 */
index 726c6bdea0bf00db4ef755eaf669b1aaf3ed24e7..6a856f151890882ceec39a3407569627b7bb0d32 100644 (file)
@@ -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
index 9ced19714b81ffd888192b674677c95805ad1272..c63b752b72635ace282928c8215fff2a6952c499 100644 (file)
@@ -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
  *****************************************************************************/
index a808425ee3979cacf79bdcfc4dc25b53fd546fb2..bf5a09b2ab638171b37124fac5ce6e1255b4ca88 100644 (file)
@@ -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 );