[vlc-commits] Qt: add a loading bar animation when the cache is empty

Jonathan Calmels git at videolan.org
Thu Jan 29 15:59:23 CET 2015


vlc | branch: master | Jonathan Calmels <jbjcalmels at gmail.com> | Thu Jan 29 14:58:46 2015 +0100| [a3ecaf152efa70271162031dd72d0e97225d55bd] | committer: Jean-Baptiste Kempf

Qt: add a loading bar animation when the cache is empty

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/gui/qt4/styles/seekstyle.cpp  |   11 ++++++++
 modules/gui/qt4/styles/seekstyle.hpp  |    1 +
 modules/gui/qt4/util/input_slider.cpp |   48 +++++++++++++++++++++++++++++++++
 modules/gui/qt4/util/input_slider.hpp |    7 +++++
 4 files changed, 67 insertions(+)

diff --git a/modules/gui/qt4/styles/seekstyle.cpp b/modules/gui/qt4/styles/seekstyle.cpp
index f3a5f69..031a225 100644
--- a/modules/gui/qt4/styles/seekstyle.cpp
+++ b/modules/gui/qt4/styles/seekstyle.cpp
@@ -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 )
                 {
diff --git a/modules/gui/qt4/styles/seekstyle.hpp b/modules/gui/qt4/styles/seekstyle.hpp
index 953963d..ac142e0 100644
--- a/modules/gui/qt4/styles/seekstyle.hpp
+++ b/modules/gui/qt4/styles/seekstyle.hpp
@@ -41,6 +41,7 @@ public:
         int length;
         bool animate;
         qreal animationopacity;
+        qreal animationloading;
         QList<int64_t> points;
     };
 
diff --git a/modules/gui/qt4/util/input_slider.cpp b/modules/gui/qt4/util/input_slider.cpp
index 74faa41..ee37a1c 100644
--- a/modules/gui/qt4/util/input_slider.cpp
+++ b/modules/gui/qt4/util/input_slider.cpp
@@ -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 )
diff --git a/modules/gui/qt4/util/input_slider.hpp b/modules/gui/qt4/util/input_slider.hpp
index ef3ae3d..a95adbb 100644
--- a/modules/gui/qt4/util/input_slider.hpp
+++ b/modules/gui/qt4/util/input_slider.hpp
@@ -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 );



More information about the vlc-commits mailing list