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
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 )
{
......
......@@ -41,6 +41,7 @@ public:
int length;
bool animate;
qreal animationopacity;
qreal animationloading;
QList<int64_t> points;
};
......
......@@ -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 )
......
......@@ -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 );
......
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