Commit a3ecaf15 authored by Jonathan Calmels's avatar Jonathan Calmels Committed by Jean-Baptiste Kempf

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

Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 9d679e90
...@@ -127,6 +127,17 @@ void SeekStyle::drawComplexControl( ComplexControl cc, const QStyleOptionComplex ...@@ -127,6 +127,17 @@ void SeekStyle::drawComplexControl( ComplexControl cc, const QStyleOptionComplex
painter->drawRoundedRect( valueRect, RADIUS, RADIUS ); 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 */ /* draw buffering overlay */
if ( slideroptions->buffering > 0.0 && slideroptions->buffering < 1.0 ) if ( slideroptions->buffering > 0.0 && slideroptions->buffering < 1.0 )
{ {
......
...@@ -41,6 +41,7 @@ public: ...@@ -41,6 +41,7 @@ public:
int length; int length;
bool animate; bool animate;
qreal animationopacity; qreal animationopacity;
qreal animationloading;
QList<int64_t> points; QList<int64_t> points;
}; };
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "util/input_slider.hpp" #include "util/input_slider.hpp"
#include "util/timetooltip.hpp" #include "util/timetooltip.hpp"
#include "adapters/seekpoints.hpp" #include "adapters/seekpoints.hpp"
#include "input_manager.hpp"
#include <QPaintEvent> #include <QPaintEvent>
#include <QPainter> #include <QPainter>
...@@ -48,6 +49,7 @@ ...@@ -48,6 +49,7 @@
#include <QPropertyAnimation> #include <QPropertyAnimation>
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
#include <QSequentialAnimationGroup>
#define MINIMUM 0 #define MINIMUM 0
#define MAXIMUM 1000 #define MAXIMUM 1000
...@@ -62,6 +64,7 @@ SeekSlider::SeekSlider( Qt::Orientation q, QWidget *_parent, bool _static ) ...@@ -62,6 +64,7 @@ SeekSlider::SeekSlider( Qt::Orientation q, QWidget *_parent, bool _static )
isJumping = false; isJumping = false;
f_buffering = 0.0; f_buffering = 0.0;
mHandleOpacity = 1.0; mHandleOpacity = 1.0;
mLoading = 0.0;
chapters = NULL; chapters = NULL;
mHandleLength = -1; mHandleLength = -1;
b_seekable = true; b_seekable = true;
...@@ -130,10 +133,27 @@ SeekSlider::SeekSlider( Qt::Orientation q, QWidget *_parent, bool _static ) ...@@ -130,10 +133,27 @@ SeekSlider::SeekSlider( Qt::Orientation q, QWidget *_parent, bool _static )
animHandle->setStartValue( 0.0 ); animHandle->setStartValue( 0.0 );
animHandle->setEndValue( 1.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 = new QTimer( this );
hideHandleTimer->setSingleShot( true ); hideHandleTimer->setSingleShot( true );
hideHandleTimer->setInterval( FADEOUTDELAY ); hideHandleTimer->setInterval( FADEOUTDELAY );
CONNECT( MainInputManager::getInstance(), inputChanged( input_thread_t * ), this , inputUpdated( input_thread_t * ) );
CONNECT( this, sliderMoved( int ), this, startSeekTimer() ); CONNECT( this, sliderMoved( int ), this, startSeekTimer() );
CONNECT( seekLimitTimer, timeout(), this, updatePos() ); CONNECT( seekLimitTimer, timeout(), this, updatePos() );
CONNECT( hideHandleTimer, timeout(), this, hideHandle() ); CONNECT( hideHandleTimer, timeout(), this, hideHandle() );
...@@ -202,9 +222,24 @@ void SeekSlider::updateBuffering( float f_buffering_ ) ...@@ -202,9 +222,24 @@ void SeekSlider::updateBuffering( float f_buffering_ )
if ( f_buffering_ < f_buffering ) if ( f_buffering_ < f_buffering )
bufferingStart = QTime::currentTime(); bufferingStart = QTime::currentTime();
f_buffering = f_buffering_; f_buffering = f_buffering_;
if ( f_buffering > 0.0 || isEnabled() ) {
animLoading->stop();
mLoading = 0.0;
}
repaint(); 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() void SeekSlider::processReleasedButton()
{ {
if ( !isSliding && !isJumping ) return; if ( !isSliding && !isJumping ) return;
...@@ -398,6 +433,7 @@ void SeekSlider::paintEvent( QPaintEvent *ev ) ...@@ -398,6 +433,7 @@ void SeekSlider::paintEvent( QPaintEvent *ev )
option.animate = ( animHandle->state() == QAbstractAnimation::Running option.animate = ( animHandle->state() == QAbstractAnimation::Running
|| hideHandleTimer->isActive() ); || hideHandleTimer->isActive() );
option.animationopacity = mHandleOpacity; option.animationopacity = mHandleOpacity;
option.animationloading = mLoading;
option.sliderPosition = sliderPosition(); option.sliderPosition = sliderPosition();
option.sliderValue = value(); option.sliderValue = value();
option.maximum = maximum(); option.maximum = maximum();
...@@ -446,6 +482,11 @@ qreal SeekSlider::handleOpacity() const ...@@ -446,6 +482,11 @@ qreal SeekSlider::handleOpacity() const
return mHandleOpacity; return mHandleOpacity;
} }
qreal SeekSlider::loading() const
{
return mLoading;
}
void SeekSlider::setHandleOpacity(qreal opacity) void SeekSlider::setHandleOpacity(qreal opacity)
{ {
mHandleOpacity = opacity; mHandleOpacity = opacity;
...@@ -453,6 +494,13 @@ void SeekSlider::setHandleOpacity(qreal opacity) ...@@ -453,6 +494,13 @@ void SeekSlider::setHandleOpacity(qreal opacity)
update(); update();
} }
void SeekSlider::setLoading(qreal loading)
{
mLoading = loading;
/* Request a new paintevent */
update();
}
inline int SeekSlider::handleLength() inline int SeekSlider::handleLength()
{ {
if ( mHandleLength > 0 ) if ( mHandleLength > 0 )
......
...@@ -46,12 +46,14 @@ class SeekPoints; ...@@ -46,12 +46,14 @@ class SeekPoints;
class QPropertyAnimation; class QPropertyAnimation;
class QCommonStyle; class QCommonStyle;
class TimeTooltip; class TimeTooltip;
class QSequentialAnimationGroup;
/* Input Slider derived from QSlider */ /* Input Slider derived from QSlider */
class SeekSlider : public QSlider class SeekSlider : public QSlider
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(qreal handleOpacity READ handleOpacity WRITE setHandleOpacity) Q_PROPERTY(qreal handleOpacity READ handleOpacity WRITE setHandleOpacity)
Q_PROPERTY(qreal loadingProperty READ loading WRITE setLoading)
public: public:
SeekSlider( Qt::Orientation q, QWidget *_parent = 0, bool _classic = false ); SeekSlider( Qt::Orientation q, QWidget *_parent = 0, bool _classic = false );
virtual ~SeekSlider(); virtual ~SeekSlider();
...@@ -73,7 +75,9 @@ protected: ...@@ -73,7 +75,9 @@ protected:
void processReleasedButton(); void processReleasedButton();
qreal handleOpacity() const; qreal handleOpacity() const;
qreal loading() const;
void setHandleOpacity( qreal opacity ); void setHandleOpacity( qreal opacity );
void setLoading( qreal loading );
int handleLength(); int handleLength();
private: private:
...@@ -102,7 +106,9 @@ private: ...@@ -102,7 +106,9 @@ private:
/* Handle's animation */ /* Handle's animation */
qreal mHandleOpacity; qreal mHandleOpacity;
qreal mLoading;
QPropertyAnimation *animHandle; QPropertyAnimation *animHandle;
QSequentialAnimationGroup *animLoading;
QTimer *hideHandleTimer; QTimer *hideHandleTimer;
public slots: public slots:
...@@ -114,6 +120,7 @@ public slots: ...@@ -114,6 +120,7 @@ public slots:
private slots: private slots:
void startSeekTimer(); void startSeekTimer();
void updatePos(); void updatePos();
void inputUpdated( input_thread_t *p_input );
signals: signals:
void sliderDragged( float ); void sliderDragged( float );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment