/*****************************************************************************
* interface_widgets.cpp : Custom widgets for the main interface
****************************************************************************
- * Copyright ( C ) 2006 the VideoLAN team
+ * Copyright (C) 2006-2010 the VideoLAN team
* $Id$
*
* Authors: Clément Stenac <zorglub@videolan.org>
# include "config.h"
#endif
-#include <vlc_vout.h>
-
-#include "dialogs_provider.hpp"
#include "components/interface_widgets.hpp"
-#include "main_interface.hpp"
-#include "input_manager.hpp"
-#include "menus.hpp"
-#include "util/input_slider.hpp"
-#include "util/customwidgets.hpp"
+#include "dialogs_provider.hpp"
+#include "util/customwidgets.hpp" // qtEventToVLCKey, QVLCStackedWidget
+
+#include "menus.hpp" /* Popup menu on bgWidget */
+
+#include <vlc_vout.h>
#include <QLabel>
-#include <QSpacerItem>
-#include <QCursor>
-#include <QPushButton>
#include <QToolButton>
-#include <QHBoxLayout>
-#include <QMenu>
#include <QPalette>
+#include <QEvent>
#include <QResizeEvent>
#include <QDate>
+#include <QMenu>
+#include <QWidgetAction>
+#include <QDesktopWidget>
+#include <QPainter>
+#include <QTimer>
+#include <QSlider>
+#include <QBitmap>
#ifdef Q_WS_X11
-# include <X11/Xlib.h>
-# include <qx11info_x11.h>
+# include <X11/Xlib.h>
+# include <qx11info_x11.h>
#endif
#include <math.h>
-
-#define I_PLAY_TOOLTIP N_("Play\nIf the playlist is empty, open a media")
+#include <assert.h>
/**********************************************************************
* Video Widget. A simple frame on which video is drawn
* This class handles resize issues
**********************************************************************/
-VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
+VideoWidget::VideoWidget( intf_thread_t *_p_i )
+ : QFrame( NULL ) , p_intf( _p_i )
{
- /* Init */
- p_vout = NULL;
- videoSize.rwidth() = -1;
- videoSize.rheight() = -1;
-
- hide();
-
/* Set the policy to expand in both directions */
-// setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
-
- /* Black background is more coherent for a Video Widget */
- QPalette plt = palette();
- plt.setColor( QPalette::Window, Qt::black );
- setPalette( plt );
- setAutoFillBackground(true);
-
- /* Indicates that the widget wants to draw directly onto the screen.
- Widgets with this attribute set do not participate in composition
- management */
- setAttribute( Qt::WA_PaintOnScreen, true );
+ // setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
- /* The core can ask through a callback to show the video. */
- connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
- this, SLOT(SetSizing(unsigned int, unsigned int )),
- Qt::BlockingQueuedConnection );
+ layout = new QHBoxLayout( this );
+ layout->setContentsMargins( 0, 0, 0, 0 );
+ stable = NULL;
+ show();
}
-void VideoWidget::paintEvent(QPaintEvent *ev)
+VideoWidget::~VideoWidget()
{
- QFrame::paintEvent(ev);
-#ifdef Q_WS_X11
- XFlush( QX11Info::display() );
-#endif
+ /* Ensure we are not leaking the video output. This would crash. */
+ assert( !stable );
}
-VideoWidget::~VideoWidget()
+void VideoWidget::sync( void )
{
- /* Ensure we are not leaking the video output. This would crash. */
- assert( !p_vout );
+#ifdef Q_WS_X11
+ /* Make sure the X server has processed all requests.
+ * This protects other threads using distinct connections from getting
+ * the video widget window in an inconsistent states. */
+ XSync( QX11Info::display(), False );
+#endif
}
/**
* Request the video to avoid the conflicts
**/
-void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
- unsigned int *pi_width, unsigned int *pi_height )
+WId VideoWidget::request( int *pi_x, int *pi_y,
+ unsigned int *pi_width, unsigned int *pi_height,
+ bool b_keep_size )
{
msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
- emit askVideoWidgetToShow( *pi_width, *pi_height );
- if( p_vout )
+
+ if( stable )
{
msg_Dbg( p_intf, "embedded video already in use" );
- return NULL;
+ return 0;
+ }
+ if( b_keep_size )
+ {
+ *pi_width = size().width();
+ *pi_height = size().height();
}
- p_vout = p_nvout;
+
+ /* The owner of the video window needs a stable handle (WinId). Reparenting
+ * in Qt4-X11 changes the WinId of the widget, so we need to create another
+ * dummy widget that stays within the reparentable widget. */
+ stable = new QWidget();
+ QPalette plt = palette();
+ plt.setColor( QPalette::Window, Qt::black );
+ stable->setPalette( plt );
+ stable->setAutoFillBackground(true);
+ /* Indicates that the widget wants to draw directly onto the screen.
+ Widgets with this attribute set do not participate in composition
+ management */
+ /* This is currently disabled on X11 as it does not seem to improve
+ * performance, but causes the video widget to be transparent... */
+#ifndef Q_WS_X11
+ stable->setAttribute( Qt::WA_PaintOnScreen, true );
+#endif
+
+ layout->addWidget( stable );
+
+#ifdef Q_WS_X11
+ /* HACK: Only one X11 client can subscribe to mouse button press events.
+ * VLC currently handles those in the video display.
+ * Force Qt4 to unsubscribe from mouse press and release events. */
+ Display *dpy = QX11Info::display();
+ Window w = stable->winId();
+ XWindowAttributes attr;
+
+ XGetWindowAttributes( dpy, w, &attr );
+ attr.your_event_mask &= ~(ButtonPressMask|ButtonReleaseMask);
+ XSelectInput( dpy, w, attr.your_event_mask );
+#endif
+ sync();
#ifndef NDEBUG
- msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
+ msg_Dbg( p_intf, "embedded video ready (handle %p)",
+ (void *)stable->winId() );
#endif
- return ( void* )winId();
+ return stable->winId();
}
/* Set the Widget to the correct Size */
/* Function has to be called by the parent
- Parent has to care about resizing himself*/
+ Parent has to care about resizing itself */
void VideoWidget::SetSizing( unsigned int w, unsigned int h )
{
- msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
- videoSize.rwidth() = w;
- videoSize.rheight() = h;
- if( isHidden() ) show();
- updateGeometry(); // Needed for deinterlace
+ resize( w, h );
+ emit sizeChanged( w, h );
+ /* Work-around a bug?misconception? that would happen when vout core resize
+ twice to the same size and would make the vout not centered.
+ This cause a small flicker.
+ See #3621
+ */
+ if( size().width() == w && size().height() == h )
+ updateGeometry();
+ sync();
}
void VideoWidget::release( void )
{
msg_Dbg( p_intf, "Video is not needed anymore" );
- p_vout = NULL;
- videoSize.rwidth() = 0;
- videoSize.rheight() = 0;
- updateGeometry();
- hide();
-}
-QSize VideoWidget::sizeHint() const
-{
- return videoSize;
+ assert( stable );
+ layout->removeWidget( stable );
+ stable->deleteLater();
+ stable = NULL;
+
+ updateGeometry();
}
/**********************************************************************
* Background Widget. Show a simple image background. Currently,
* it's album art if present or cone.
**********************************************************************/
-#define ICON_SIZE 128
-#define MAX_BG_SIZE 400
-#define MIN_BG_SIZE 128
BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
- :QWidget( NULL ), p_intf( _p_i )
+ :QWidget( NULL ), p_intf( _p_i ), b_expandPixmap( false )
{
- /* We should use that one to take the more size it can */
- setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding);
-
/* A dark background */
setAutoFillBackground( true );
- plt = palette();
+ QPalette plt = palette();
plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
setPalette( plt );
- /* A cone in the middle */
- label = new QLabel;
- label->setMargin( 5 );
- label->setMaximumHeight( MAX_BG_SIZE );
- label->setMaximumWidth( MAX_BG_SIZE );
- label->setMinimumHeight( MIN_BG_SIZE );
- label->setMinimumWidth( MIN_BG_SIZE );
- if( QDate::currentDate().dayOfYear() >= 354 )
- label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
- else
- label->setPixmap( QPixmap( ":/vlc128.png" ) );
-
- QGridLayout *backgroundLayout = new QGridLayout( this );
- backgroundLayout->addWidget( label, 0, 1 );
- backgroundLayout->setColumnStretch( 0, 1 );
- backgroundLayout->setColumnStretch( 2, 1 );
+ /* Init the cone art */
+ updateArt( "" );
- CONNECT( THEMIM->getIM(), artChanged( input_item_t* ),
- this, updateArt( input_item_t* ) );
+ CONNECT( THEMIM->getIM(), artChanged( QString ),
+ this, updateArt( const QString& ) );
}
-BackgroundWidget::~BackgroundWidget()
-{}
-
-void BackgroundWidget::resizeEvent( QResizeEvent * event )
+void BackgroundWidget::updateArt( const QString& url )
{
- if( event->size().height() <= MIN_BG_SIZE )
- label->hide();
+ if ( !url.isEmpty() )
+ {
+ pixmapUrl = url;
+ }
else
- label->show();
+ { /* Xmas joke */
+ if( QDate::currentDate().dayOfYear() >= 354 )
+ pixmapUrl = QString( ":/logo/vlc128-christmas.png" );
+ else
+ pixmapUrl = QString( ":/logo/vlc128.png" );
+ }
+ update();
}
-void BackgroundWidget::updateArt( input_item_t *p_item )
+void BackgroundWidget::paintEvent( QPaintEvent *e )
{
- QString url;
- if( p_item )
- {
- char *psz_art = input_item_GetArtURL( p_item );
- url = psz_art;
- free( psz_art );
- }
+ int i_maxwidth, i_maxheight;
+ QPixmap pixmap = QPixmap( pixmapUrl );
+ QPainter painter(this);
+ QBitmap pMask;
+ float f_alpha = 1.0;
- if( url.isEmpty() )
+ i_maxwidth = std::min( maximumWidth(), width() ) - MARGIN * 2;
+ i_maxheight = std::min( maximumHeight(), height() ) - MARGIN * 2;
+
+ if ( height() > MARGIN * 2 )
{
- if( QDate::currentDate().dayOfYear() >= 354 )
- label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
+ /* Scale down the pixmap if the widget is too small */
+ if( pixmap.width() > i_maxwidth || pixmap.height() > i_maxheight )
+ {
+ pixmap = pixmap.scaled( i_maxwidth, i_maxheight,
+ Qt::KeepAspectRatio, Qt::SmoothTransformation );
+ }
else
- label->setPixmap( QPixmap( ":/vlc128.png" ) );
- }
- else
- {
- url = url.replace( "file://", QString("" ) );
- /* Taglib seems to define a attachment://, It won't work yet */
- url = url.replace( "attachment://", QString("" ) );
- label->setPixmap( QPixmap( url ) );
+ if ( b_expandPixmap &&
+ pixmap.width() < width() && pixmap.height() < height() )
+ {
+ /* Scale up the pixmap to fill widget's size */
+ f_alpha = ( (float) pixmap.height() / (float) height() );
+ pixmap = pixmap.scaled(
+ width() - MARGIN * 2,
+ height() - MARGIN * 2,
+ Qt::KeepAspectRatio,
+ ( f_alpha < .2 )? /* Don't waste cpu when not visible */
+ Qt::SmoothTransformation:
+ Qt::FastTransformation
+ );
+ /* Non agressive alpha compositing when sizing up */
+ pMask = QBitmap( pixmap.width(), pixmap.height() );
+ pMask.fill( QColor::fromRgbF( 1.0, 1.0, 1.0, f_alpha ) );
+ pixmap.setMask( pMask );
+ }
+
+ painter.drawPixmap(
+ MARGIN + ( i_maxwidth - pixmap.width() ) /2,
+ MARGIN + ( i_maxheight - pixmap.height() ) /2,
+ pixmap);
}
+ QWidget::paintEvent( e );
}
void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
{
QVLCMenu::PopupMenu( p_intf, true );
+ event->accept();
}
#if 0
+#include <QPushButton>
+#include <QHBoxLayout>
+
/**********************************************************************
* Visualization selector panel
**********************************************************************/
}
#endif
+SpeedLabel::SpeedLabel( intf_thread_t *_p_intf, QWidget *parent )
+ : QLabel( parent ), p_intf( _p_intf )
+{
+ tooltipStringPattern = qtr( "Current playback speed: %1\nClick to adjust" );
+
+ /* Create the Speed Control Widget */
+ speedControl = new SpeedControlWidget( p_intf, this );
+ speedControlMenu = new QMenu( this );
+
+ QWidgetAction *widgetAction = new QWidgetAction( speedControl );
+ widgetAction->setDefaultWidget( speedControl );
+ speedControlMenu->addAction( widgetAction );
+
+ /* Change the SpeedRate in the Status Bar */
+ CONNECT( THEMIM->getIM(), rateChanged( float ), this, setRate( float ) );
+
+ DCONNECT( THEMIM, inputChanged( input_thread_t * ),
+ speedControl, activateOnState() );
+ setRate( var_InheritFloat( p_intf, "rate" ) );
+}
+
+SpeedLabel::~SpeedLabel()
+{
+ delete speedControl;
+ delete speedControlMenu;
+}
+
+/****************************************************************************
+ * Small right-click menu for rate control
+ ****************************************************************************/
+
+void SpeedLabel::showSpeedMenu( QPoint pos )
+{
+ speedControlMenu->exec( QCursor::pos() - pos
+ + QPoint( 0, height() ) );
+}
+
+void SpeedLabel::setRate( float rate )
+{
+ QString str;
+ str.setNum( rate, 'f', 2 );
+ str.append( "x" );
+ setText( str );
+ setToolTip( tooltipStringPattern.arg( str ) );
+ speedControl->updateControls( rate );
+}
+
/**********************************************************************
* Speed control widget
**********************************************************************/
-SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
- QFrame( NULL ), p_intf( _p_i )
+SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i, QWidget *_parent )
+ : QFrame( _parent ), p_intf( _p_i )
{
QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
sizePolicy.setHorizontalStretch( 0 );
sizePolicy.setVerticalStretch( 0 );
- speedSlider = new QSlider;
+ speedSlider = new QSlider( this );
speedSlider->setSizePolicy( sizePolicy );
speedSlider->setMaximumSize( QSize( 80, 200 ) );
speedSlider->setOrientation( Qt::Vertical );
speedSlider->setTickPosition( QSlider::TicksRight );
- speedSlider->setRange( -24, 24 );
+ speedSlider->setRange( -34, 34 );
speedSlider->setSingleStep( 1 );
speedSlider->setPageStep( 1 );
- speedSlider->setTickInterval( 12 );
+ speedSlider->setTickInterval( 17 );
CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
CONNECT( normalSpeedButton, clicked(), this, resetRate() );
- QVBoxLayout *speedControlLayout = new QVBoxLayout;
- speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
+ QVBoxLayout *speedControlLayout = new QVBoxLayout( this );
+ speedControlLayout->setContentsMargins( 4, 4, 4, 4 );
speedControlLayout->setSpacing( 4 );
speedControlLayout->addWidget( speedSlider );
speedControlLayout->addWidget( normalSpeedButton );
- setLayout( speedControlLayout );
-}
-SpeedControlWidget::~SpeedControlWidget()
-{}
+ lastValue = 0;
-void SpeedControlWidget::setEnable( bool b_enable )
+ activateOnState();
+}
+
+void SpeedControlWidget::activateOnState()
{
- speedSlider->setEnabled( b_enable );
+ speedSlider->setEnabled( THEMIM->getIM()->hasInput() );
}
-void SpeedControlWidget::updateControls( int rate )
+void SpeedControlWidget::updateControls( float rate )
{
if( speedSlider->isSliderDown() )
{
return;
}
- double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
+ double value = 17 * log( rate ) / log( 2. );
int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
if( sliderValue < speedSlider->minimum() )
{
sliderValue = speedSlider->maximum();
}
+ lastValue = sliderValue;
- //Block signals to avoid feedback loop
- speedSlider->blockSignals( true );
speedSlider->setValue( sliderValue );
- speedSlider->blockSignals( false );
}
void SpeedControlWidget::updateRate( int sliderValue )
{
- double speed = pow( 2, (double)sliderValue / 12 );
+ if( sliderValue == lastValue )
+ return;
+
+ double speed = pow( 2, (double)sliderValue / 17 );
int rate = INPUT_RATE_DEFAULT / speed;
THEMIM->getIM()->setRate(rate);
void SpeedControlWidget::resetRate()
{
- THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
-}
-
-
-
-static int downloadCoverCallback( vlc_object_t *p_this,
- char const *psz_var,
- vlc_value_t oldvar, vlc_value_t newvar,
- void *data )
-{
- if( !strcmp( psz_var, "item-change" ) )
- {
- CoverArtLabel *art = static_cast< CoverArtLabel* >( data );
- if( art )
- art->requestUpdate();
- }
- return VLC_SUCCESS;
+ THEMIM->getIM()->setRate( INPUT_RATE_DEFAULT );
}
-CoverArtLabel::CoverArtLabel( QWidget *parent,
- vlc_object_t *_p_this,
- input_item_t *_p_input )
- : QLabel( parent ), p_this( _p_this), p_input( _p_input ), prevArt()
+CoverArtLabel::CoverArtLabel( QWidget *parent, intf_thread_t *_p_i )
+ : QLabel( parent ), p_intf( _p_i )
{
setContextMenuPolicy( Qt::ActionsContextMenu );
- CONNECT( this, updateRequested(), this, doUpdate() );
-
- playlist_t *p_playlist = pl_Hold( p_this );
- var_AddCallback( p_playlist, "item-change",
- downloadCoverCallback, this );
- pl_Release( p_this );
+ CONNECT( this, updateRequested(), this, askForUpdate() );
setMinimumHeight( 128 );
setMinimumWidth( 128 );
setMaximumHeight( 128 );
setMaximumWidth( 128 );
- setScaledContents( true );
+ setScaledContents( false );
+ setAlignment( Qt::AlignCenter );
- doUpdate();
+ QList< QAction* > artActions = actions();
+ QAction *action = new QAction( qtr( "Download cover art" ), this );
+ CONNECT( action, triggered(), this, askForUpdate() );
+ addAction( action );
+
+ showArtUpdate( "" );
}
-void CoverArtLabel::downloadCover()
+CoverArtLabel::~CoverArtLabel()
{
- if( p_input )
- {
- playlist_t *p_playlist = pl_Hold( p_this );
- playlist_AskForArtEnqueue( p_playlist, p_input );
- pl_Release( p_this );
- }
+ QList< QAction* > artActions = actions();
+ foreach( QAction *act, artActions )
+ removeAction( act );
}
-void CoverArtLabel::doUpdate()
+void CoverArtLabel::showArtUpdate( const QString& url )
{
- if( !p_input )
+ QPixmap pix;
+ if( !url.isEmpty() && pix.load( url ) )
{
- setPixmap( QPixmap( ":/noart.png" ) );
- QList< QAction* > artActions = actions();
- if( !artActions.isEmpty() )
- foreach( QAction *act, artActions )
- removeAction( act );
- prevArt = "";
+ pix = pix.scaled( maximumWidth(), maximumHeight(),
+ Qt::KeepAspectRatioByExpanding,
+ Qt::SmoothTransformation );
}
else
{
- char *psz_meta = input_item_GetArtURL( p_input );
- if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
- {
- QString artUrl = qfu( psz_meta ).replace( "file://", "" );
- if( artUrl != prevArt )
- {
- QPixmap pix;
- if( pix.load( artUrl ) )
- setPixmap( pix );
- else
- {
- msg_Dbg( p_this, "Qt could not load image '%s'",
- qtu( artUrl ) );
- setPixmap( QPixmap( ":/noart.png" ) );
- }
- }
- QList< QAction* > artActions = actions();
- if( !artActions.isEmpty() )
- {
- foreach( QAction *act, artActions )
- removeAction( act );
- }
- prevArt = artUrl;
- }
- else
- {
- if( prevArt != "" )
- setPixmap( QPixmap( ":/noart.png" ) );
- prevArt = "";
- QList< QAction* > artActions = actions();
- if( artActions.isEmpty() )
- {
- QAction *action = new QAction( qtr( "Download cover art" ),
- this );
- addAction( action );
- CONNECT( action, triggered(),
- this, downloadCover() );
- }
- }
- free( psz_meta );
+ pix = QPixmap( ":/noart.png" );
}
+ setPixmap( pix );
}
-TimeLabel::TimeLabel( intf_thread_t *_p_intf ) :QLabel(), p_intf( _p_intf )
+void CoverArtLabel::askForUpdate()
{
- b_remainingTime = false;
- setText( " --:--/--:-- " );
- setAlignment( Qt::AlignRight | Qt::AlignVCenter );
- setToolTip( qtr( "Toggle between elapsed and remaining time" ) );
-
+ THEMIM->getIM()->requestArtUpdate();
+}
- CONNECT( THEMIM->getIM(), statusChanged( int ),
- this, setStatus( int ) );
- CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
- this, setDisplayPosition( float, int, int ) );
+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( QString( "- " )
+ + qtr( "Click to toggle between elapsed and remaining time" )
+ + QString( "\n- " )
+ + qtr( "Double click to jump to a chosen time position" ) );
+ bufTimer->setSingleShot( true );
+
+ 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, int time, int length )
+void TimeLabel::setDisplayPosition( float pos, int64_t t, int length )
{
- char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
+ showBuffering = false;
+ bufTimer->stop();
+
+ if( pos == -1.f )
+ {
+ setText( " --:--/--:-- " );
+ return;
+ }
+
+ int time = t / 1000000;
+
secstotimestr( psz_length, length );
secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
: time );
- QString timestr;
- timestr.sprintf( "%s/%s", psz_time,
- ( !length && time ) ? "--:--" : psz_length );
+ QString timestr = QString( " %1%2/%3 " )
+ .arg( QString( (b_remainingTime && length) ? "-" : "" ) )
+ .arg( QString( psz_time ) )
+ .arg( QString( ( !length && time ) ? "--:--" : psz_length ) );
+
+ setText( timestr );
- /* Add a minus to remaining time*/
- if( b_remainingTime && length ) setText( " -"+timestr+" " );
- else setText( " "+timestr+" " );
+ cachedLength = length;
}
+void TimeLabel::setDisplayPosition( float pos )
+{
+ if( pos == -1.f || cachedLength == 0 )
+ {
+ setText( " --:--/--:-- " );
+ return;
+ }
+
+ int time = pos * cachedLength;
+ secstotimestr( psz_time,
+ ( b_remainingTime && cachedLength ?
+ cachedLength - time : time ) );
+ QString timestr = QString( " %1%2/%3 " )
+ .arg( QString( (b_remainingTime && cachedLength) ? "-" : "" ) )
+ .arg( QString( psz_time ) )
+ .arg( QString( ( !cachedLength && time ) ? "--:--" : psz_length ) );
+
+ setText( timestr );
+}
+
+
void TimeLabel::toggleTimeDisplay()
{
b_remainingTime = !b_remainingTime;
}
-void TimeLabel::setStatus( int i_status )
-{
- msg_Warn( p_intf, "Status: %i", i_status );
- if( i_status == OPENING_S )
- setText( "Buffering" );
+void TimeLabel::updateBuffering( float _buffered )
+{
+ bufVal = _buffered;
+ if( !buffering || bufVal == 0 )
+ {
+ showBuffering = false;
+ buffering = true;
+ bufTimer->start(200);
+ }
+ else if( bufVal == 1 )
+ {
+ showBuffering = buffering = false;
+ bufTimer->stop();
+ }
+ update();
}
+void TimeLabel::updateBuffering()
+{
+ showBuffering = true;
+ update();
+}
+void TimeLabel::paintEvent( QPaintEvent* event )
+{
+ 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 );
+}