]> git.sesse.net Git - vlc/commitdiff
Qt: add a loading bar animation when the cache is empty
authorJonathan Calmels <jbjcalmels@gmail.com>
Thu, 29 Jan 2015 13:58:46 +0000 (14:58 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Thu, 29 Jan 2015 14:30:17 +0000 (15:30 +0100)
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/gui/qt4/styles/seekstyle.cpp
modules/gui/qt4/styles/seekstyle.hpp
modules/gui/qt4/util/input_slider.cpp
modules/gui/qt4/util/input_slider.hpp

index f3a5f69b9db02e95258a15959d86ebacc2fa2e63..031a2251fa84763f603bf1beef4422f2e81ab173 100644 (file)
@@ -127,6 +127,17 @@ void SeekStyle::drawComplexControl( ComplexControl cc, const QStyleOptionComplex
                     painter->drawRoundedRect( valueRect, RADIUS, RADIUS );
                 }
 
+                if ( slideroptions->buffering == 0.0 && slideroptions->animationloading > 0.0 )
+                {
+                    int width = groove.width() - groove.width() / 6;
+                    QRect innerRect = groove.adjusted( slideroptions->animationloading * width + 1, 1,
+                            width * ( -1.0 + slideroptions->animationloading ) - 1, 0);
+                    QColor overlayColor = QColor( "Orange" );
+                    overlayColor.setAlpha( 128 );
+                    painter->setBrush( overlayColor );
+                    painter->drawRoundedRect( innerRect, RADIUS, RADIUS );
+                }
+
                 /* draw buffering overlay */
                 if ( slideroptions->buffering > 0.0 && slideroptions->buffering < 1.0 )
                 {
index 953963db066de9e5534cfd2d448e7a79a4aafc41..ac142e098690d569802e7a1445913d84cee41b9d 100644 (file)
@@ -41,6 +41,7 @@ public:
         int length;
         bool animate;
         qreal animationopacity;
+        qreal animationloading;
         QList<int64_t> points;
     };
 
index 74faa4176d05435900183ef43b9188d63514284a..ee37a1cb71f7b2de3f6c0dfda3435c881a8f1352 100644 (file)
@@ -32,6 +32,7 @@
 #include "util/input_slider.hpp"
 #include "util/timetooltip.hpp"
 #include "adapters/seekpoints.hpp"
+#include "input_manager.hpp"
 
 #include <QPaintEvent>
 #include <QPainter>
@@ -48,6 +49,7 @@
 #include <QPropertyAnimation>
 #include <QApplication>
 #include <QDebug>
+#include <QSequentialAnimationGroup>
 
 #define MINIMUM 0
 #define MAXIMUM 1000
@@ -62,6 +64,7 @@ SeekSlider::SeekSlider( Qt::Orientation q, QWidget *_parent, bool _static )
     isJumping = false;
     f_buffering = 0.0;
     mHandleOpacity = 1.0;
+    mLoading = 0.0;
     chapters = NULL;
     mHandleLength = -1;
     b_seekable = true;
@@ -130,10 +133,27 @@ SeekSlider::SeekSlider( Qt::Orientation q, QWidget *_parent, bool _static )
     animHandle->setStartValue( 0.0 );
     animHandle->setEndValue( 1.0 );
 
+    QPropertyAnimation *animLoadingIn = new QPropertyAnimation( this, "loadingProperty", this );
+    animLoadingIn->setDuration( 2000 );
+    animLoadingIn->setStartValue( 0.0 );
+    animLoadingIn->setEndValue( 1.0 );
+    animLoadingIn->setEasingCurve( QEasingCurve::OutBounce );
+    QPropertyAnimation *animLoadingOut = new QPropertyAnimation( this, "loadingProperty", this );
+    animLoadingOut->setDuration( 2000 );
+    animLoadingOut->setStartValue( 1.0 );
+    animLoadingOut->setEndValue( 0.0 );
+    animLoadingOut->setEasingCurve( QEasingCurve::OutBounce );
+
+    animLoading = new QSequentialAnimationGroup();
+    animLoading->addAnimation( animLoadingIn );
+    animLoading->addAnimation( animLoadingOut );
+    animLoading->setLoopCount( -1 );
+
     hideHandleTimer = new QTimer( this );
     hideHandleTimer->setSingleShot( true );
     hideHandleTimer->setInterval( FADEOUTDELAY );
 
+    CONNECT( MainInputManager::getInstance(), inputChanged( input_thread_t * ), this , inputUpdated( input_thread_t * ) );
     CONNECT( this, sliderMoved( int ), this, startSeekTimer() );
     CONNECT( seekLimitTimer, timeout(), this, updatePos() );
     CONNECT( hideHandleTimer, timeout(), this, hideHandle() );
@@ -202,9 +222,24 @@ void SeekSlider::updateBuffering( float f_buffering_ )
     if ( f_buffering_ < f_buffering )
         bufferingStart = QTime::currentTime();
     f_buffering = f_buffering_;
+    if ( f_buffering > 0.0 || isEnabled() ) {
+        animLoading->stop();
+        mLoading = 0.0;
+    }
     repaint();
 }
 
+void SeekSlider::inputUpdated( input_thread_t *p_input )
+{
+    if ( p_input == NULL ) {
+        animLoading->stop();
+        mLoading = 0.0;
+        repaint();
+    }
+    else if ( f_buffering == 0.0 && !isEnabled() )
+        animLoading->start();
+}
+
 void SeekSlider::processReleasedButton()
 {
     if ( !isSliding && !isJumping ) return;
@@ -398,6 +433,7 @@ void SeekSlider::paintEvent( QPaintEvent *ev )
         option.animate = ( animHandle->state() == QAbstractAnimation::Running
                            || hideHandleTimer->isActive() );
         option.animationopacity = mHandleOpacity;
+        option.animationloading = mLoading;
         option.sliderPosition = sliderPosition();
         option.sliderValue = value();
         option.maximum = maximum();
@@ -446,6 +482,11 @@ qreal SeekSlider::handleOpacity() const
     return mHandleOpacity;
 }
 
+qreal SeekSlider::loading() const
+{
+    return mLoading;
+}
+
 void SeekSlider::setHandleOpacity(qreal opacity)
 {
     mHandleOpacity = opacity;
@@ -453,6 +494,13 @@ void SeekSlider::setHandleOpacity(qreal opacity)
     update();
 }
 
+void SeekSlider::setLoading(qreal loading)
+{
+    mLoading = loading;
+    /* Request a new paintevent */
+    update();
+}
+
 inline int SeekSlider::handleLength()
 {
     if ( mHandleLength > 0 )
index ef3ae3d7b87340bc2e83973fbae873f1248dd599..a95adbbd01b9f3f095948369ec554c542cabc18e 100644 (file)
@@ -46,12 +46,14 @@ class SeekPoints;
 class QPropertyAnimation;
 class QCommonStyle;
 class TimeTooltip;
+class QSequentialAnimationGroup;
 
 /* Input Slider derived from QSlider */
 class SeekSlider : public QSlider
 {
     Q_OBJECT
     Q_PROPERTY(qreal handleOpacity READ handleOpacity WRITE setHandleOpacity)
+    Q_PROPERTY(qreal loadingProperty READ loading WRITE setLoading)
 public:
     SeekSlider( Qt::Orientation q, QWidget *_parent = 0, bool _classic = false );
     virtual ~SeekSlider();
@@ -73,7 +75,9 @@ protected:
 
     void processReleasedButton();
     qreal handleOpacity() const;
+    qreal loading() const;
     void setHandleOpacity( qreal opacity );
+    void setLoading( qreal loading );
     int handleLength();
 
 private:
@@ -102,7 +106,9 @@ private:
 
     /* Handle's animation */
     qreal mHandleOpacity;
+    qreal mLoading;
     QPropertyAnimation *animHandle;
+    QSequentialAnimationGroup *animLoading;
     QTimer *hideHandleTimer;
 
 public slots:
@@ -114,6 +120,7 @@ public slots:
 private slots:
     void startSeekTimer();
     void updatePos();
+    void inputUpdated( input_thread_t *p_input );
 
 signals:
     void sliderDragged( float );