#include <QWidgetAction>
#include <QDesktopWidget>
#include <QPainter>
+#include <QTimer>
#ifdef Q_WS_X11
# include <X11/Xlib.h>
CONNECT( THEMIM, inputChanged( input_thread_t * ),
speedControl, activateOnState() );
-
}
+
SpeedLabel::~SpeedLabel()
{
- delete speedControl;
- delete speedControlMenu;
+ delete speedControl;
+ delete speedControlMenu;
}
+
/****************************************************************************
* Small right-click menu for rate control
****************************************************************************/
+
void SpeedLabel::showSpeedMenu( QPoint pos )
{
speedControlMenu->exec( QCursor::pos() - pos
speedSlider->setPageStep( 1 );
speedSlider->setTickInterval( 17 );
- CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
+ CONNECT( speedSlider, sliderMoved( int ), this, updateRate( int ) );
QToolButton *normalSpeedButton = new QToolButton( this );
normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
sliderValue = speedSlider->maximum();
}
- //Block signals to avoid feedback loop
- speedSlider->blockSignals( true );
speedSlider->setValue( sliderValue );
- speedSlider->blockSignals( false );
}
void SpeedControlWidget::updateRate( int sliderValue )
THEMIM->getIM()->requestArtUpdate();
}
-TimeLabel::TimeLabel( intf_thread_t *_p_intf ) :QLabel(), p_intf( _p_intf )
+TimeLabel::TimeLabel( intf_thread_t *_p_intf )
+ : QLabel(), p_intf( _p_intf ), bufTimer( new QTimer(this) ),
+ buffering( false ), showBuffering(false), bufVal( -1 )
{
- b_remainingTime = false;
- setText( " --:--/--:-- " );
- setAlignment( Qt::AlignRight | Qt::AlignVCenter );
- setToolTip( qtr( "Toggle between elapsed and remaining time" ) );
+ b_remainingTime = false;
+ setText( " --:--/--:-- " );
+ setAlignment( Qt::AlignRight | Qt::AlignVCenter );
+ setToolTip( qtr( "Toggle between elapsed and remaining time" ) );
+ bufTimer->setSingleShot( true );
- CONNECT( THEMIM->getIM(), positionUpdated( float, int64_t, int ),
- this, setDisplayPosition( float, int64_t, int ) );
+ CONNECT( THEMIM->getIM(), positionUpdated( float, int64_t, int ),
+ this, setDisplayPosition( float, int64_t, int ) );
+ CONNECT( THEMIM->getIM(), cachingChanged( float ),
+ this, updateBuffering( float ) );
+ CONNECT( bufTimer, timeout(), this, updateBuffering() );
}
void TimeLabel::setDisplayPosition( float pos, int64_t t, int length )
b_remainingTime = !b_remainingTime;
}
-CacheLabel::CacheLabel( intf_thread_t *_p_intf, QWidget *parent )
- : QLabel( parent ), p_intf( _p_intf ), cached( 0.f )
-{
- setText( qtr( "Buffering..." ) );
- setMinimumWidth( 70 );
- setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred );
- setAlignment( Qt::AlignCenter );
-
- CONNECT( THEMIM->getIM(), cachingChanged( float ),
- this, showCaching( float ) );
- CONNECT( THEMIM->getIM(), positionUpdated( float, int64_t, int ),
- this, hideCaching() );
-}
-void CacheLabel::showCaching( float _cached )
+void TimeLabel::updateBuffering( float _buffered )
{
- cached = _cached;
- show();
- update(); //in case we are already visible
+ bufVal = _buffered;
+ if( !buffering || bufVal == 0 )
+ {
+ showBuffering = false;
+ buffering = true;
+ bufTimer->start(200);
+ }
+ else if( bufVal == 1 )
+ {
+ showBuffering = buffering = false;
+ }
+ update();
}
-void CacheLabel::hideCaching()
+void TimeLabel::updateBuffering()
{
- hide();
+ showBuffering = true;
+ update();
}
-void CacheLabel::paintEvent( QPaintEvent* event )
+void TimeLabel::paintEvent( QPaintEvent* event )
{
- QRect r( rect() );
- r.setWidth( r.width() * cached );
- QPainter p( this );
- p.setOpacity( 0.4 );
- p.fillRect( r, palette().color( QPalette::Highlight ) );
-
+ if( showBuffering )
+ {
+ QRect r( rect() );
+ r.setLeft( r.width() * bufVal );
+ QPainter p( this );
+ p.setOpacity( 0.4 );
+ p.fillRect( r, palette().color( QPalette::Highlight ) );
+ }
QLabel::paintEvent( event );
}
intf_thread_t *p_intf;
bool b_remainingTime;
int cachedLength;
+ QTimer *bufTimer;
+ float bufVal;
+ bool buffering;
+ bool showBuffering;
char psz_length[MSTRTIME_MAX_SIZE];
char psz_time[MSTRTIME_MAX_SIZE];
void toggleTimeDisplay();
+ void paintEvent( QPaintEvent* );
signals:
void timeLabelDoubleClicked();
private slots:
void setDisplayPosition( float pos, int64_t time, int length );
void setDisplayPosition( float pos );
+ void updateBuffering( float );
+ void updateBuffering();
};
class SpeedLabel : public QLabel
SpeedControlWidget *speedControl;
};
-class CacheLabel : public QLabel
-{
- Q_OBJECT
-public:
- CacheLabel( intf_thread_t *, QWidget * );
-private slots:
- void showCaching( float );
- void hideCaching();
-private:
- void paintEvent( QPaintEvent* );
- intf_thread_t *p_intf;
- float cached;
-};
-
/******************** Speed Control Widgets ****************/
class SpeedControlWidget : public QFrame
{