#include <QPalette>
#include <QColor>
#include <QPoint>
+#include <QPropertyAnimation>
#define MINIMUM 0
#define MAXIMUM 1000
#define CHAPTERSSPOTSIZE 3
+#define FADEDURATION 300
+#define FADEOUTDELAY 2000
SeekSlider::SeekSlider( QWidget *_parent ) : QSlider( _parent )
{
{
b_isSliding = false;
f_buffering = 1.0;
+ mHandleOpacity = 1.0;
chapters = NULL;
/* Timer used to fire intermediate updatePos() when sliding */
setPosition( -1.0, 0, 0 );
secstotimestr( psz_length, 0 );
+ animHandle = new QPropertyAnimation( this, "handleOpacity", this );
+ animHandle->setDuration( FADEDURATION );
+ animHandle->setStartValue( 0.0 );
+ animHandle->setEndValue( 1.0 );
+
+ hideHandleTimer = new QTimer( this );
+ hideHandleTimer->setSingleShot( true );
+ hideHandleTimer->setInterval( FADEOUTDELAY );
+
CONNECT( this, sliderMoved( int ), this, startSeekTimer() );
CONNECT( seekLimitTimer, timeout(), this, updatePos() );
+ CONNECT( hideHandleTimer, timeout(), this, hideHandle() );
mTimeTooltip->installEventFilter( this );
}
void SeekSlider::enterEvent( QEvent * )
{
+ /* Cancel the fade-out timer */
+ hideHandleTimer->stop();
+ /* Only start the fade-in if needed */
+ if( animHandle->direction() != QAbstractAnimation::Forward )
+ {
+ /* If pause is called while not running Qt will complain */
+ if( animHandle->state() == QAbstractAnimation::Running )
+ animHandle->pause();
+ animHandle->setDirection( QAbstractAnimation::Forward );
+ animHandle->start();
+ }
/* Don't show the tooltip if the slider is disabled */
if( isEnabled() && inputLength > 0 )
mTimeTooltip->show();
void SeekSlider::leaveEvent( QEvent * )
{
+ hideHandleTimer->start();
if( !rect().contains( mapFromGlobal( QCursor::pos() ) ) )
mTimeTooltip->hide();
}
painter.drawRoundedRect( innerRect, barCorner, barCorner );
}
- if ( option.state & QStyle::State_MouseOver )
+ if ( option.state & QStyle::State_MouseOver || isAnimationRunning() )
{
/* draw chapters tickpoints */
if ( chapters && inputLength && size().width() )
shadowGradient.setColorAt( 1.0, shadowLight );
painter.setPen( Qt::NoPen );
+ painter.setOpacity( mHandleOpacity );
// draw the handle's shadow
painter.setBrush( shadowGradient );
}
}
+qreal SeekSlider::handleOpacity() const
+{
+ return mHandleOpacity;
+}
+
+void SeekSlider::setHandleOpacity(qreal opacity)
+{
+ mHandleOpacity = opacity;
+ /* Request a new paintevent */
+ update();
+}
+
+void SeekSlider::hideHandle()
+{
+ /* If pause is called while not running Qt will complain */
+ if( animHandle->state() == QAbstractAnimation::Running )
+ animHandle->pause();
+ /* Play the animation backward */
+ animHandle->setDirection( QAbstractAnimation::Backward );
+ animHandle->start();
+}
+
+bool SeekSlider::isAnimationRunning() const
+{
+ return animHandle->state() == QAbstractAnimation::Running
+ || hideHandleTimer->isActive();
+}
/* This work is derived from Amarok's work under GPLv2+
- Mark Kretschmann
painter.end();
e->accept();
}
-
class QHideEvent;
class QTimer;
class SeekPoints;
+class QPropertyAnimation;
/* Input Slider derived from QSlider */
class SeekSlider : public QSlider
{
Q_OBJECT
+ Q_PROPERTY(qreal handleOpacity READ handleOpacity WRITE setHandleOpacity)
public:
SeekSlider( QWidget *_parent );
SeekSlider( Qt::Orientation q, QWidget *_parent );
QSize handleSize() const;
QSize sizeHint() const;
+ bool isAnimationRunning() const;
+ qreal handleOpacity() const;
+ void setHandleOpacity( qreal opacity );
private:
bool b_isSliding; /* Whether we are currently sliding by user action */
float f_buffering;
SeekPoints* chapters;
+ /* Handle's animation */
+ qreal mHandleOpacity;
+ QPropertyAnimation *animHandle;
+ QTimer *hideHandleTimer;
+
public slots:
void setPosition( float, int64_t, int );
void updateBuffering( float );
+ void hideHandle();
private slots:
void startSeekTimer();