Commit 0972b082 authored by Jakob Leben's avatar Jakob Leben

Qt: separate status bar label for "Buffering" + show time while seeking (close #2760)

parent 2f75620a
......@@ -42,6 +42,7 @@
#include <QMenu>
#include <QWidgetAction>
#include <QDesktopWidget>
#include <QPainter>
#ifdef Q_WS_X11
# include <X11/Xlib.h>
......@@ -594,9 +595,6 @@ TimeLabel::TimeLabel( intf_thread_t *_p_intf ) :QLabel(), p_intf( _p_intf )
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
setToolTip( qtr( "Toggle between elapsed and remaining time" ) );
CONNECT( THEMIM->getIM(), cachingChanged( float ),
this, setCaching( float ) );
CONNECT( THEMIM->getIM(), positionUpdated( float, int64_t, int ),
this, setDisplayPosition( float, int64_t, int ) );
}
......@@ -610,7 +608,7 @@ void TimeLabel::setDisplayPosition( float pos, int64_t t, int length )
}
int time = t / 1000000;
char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
secstotimestr( psz_length, length );
secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
: time );
......@@ -620,18 +618,68 @@ void TimeLabel::setDisplayPosition( float pos, int64_t t, int length )
psz_time, ( !length && time ) ? "--:--" : psz_length );
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;
timestr.sprintf( " %s%s/%s ", (b_remainingTime && cachedLength) ? "-" : "",
psz_time, ( !cachedLength && time ) ? "--:--" : psz_length );
setText( timestr );
}
void TimeLabel::toggleTimeDisplay()
{
b_remainingTime = !b_remainingTime;
}
void TimeLabel::setCaching( float f_cache )
CacheLabel::CacheLabel( intf_thread_t *_p_intf, QWidget *parent )
: QLabel( parent ), p_intf( _p_intf ), cached( 0.f )
{
QString amount;
amount.sprintf("Buff: %i%%", (int)(100*f_cache) );
setText( amount );
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 )
{
cached = _cached;
show();
update(); //in case we are already visible
}
void CacheLabel::hideCaching()
{
hide();
}
void CacheLabel::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 ) );
QLabel::paintEvent( event );
}
......@@ -140,12 +140,15 @@ protected:
private:
intf_thread_t *p_intf;
bool b_remainingTime;
int cachedLength;
char psz_length[MSTRTIME_MAX_SIZE];
char psz_time[MSTRTIME_MAX_SIZE];
void toggleTimeDisplay();
signals:
void timeLabelDoubleClicked();
private slots:
void setDisplayPosition( float pos, int64_t time, int length );
void setCaching( float );
void setDisplayPosition( float pos );
};
class SpeedLabel : public QLabel
......@@ -169,6 +172,20 @@ private:
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
{
......
......@@ -683,6 +683,7 @@ void InputManager::sliderUpdate( float new_pos )
{
if( hasInput() )
var_SetFloat( p_input, "position", new_pos );
emit seekRequested( new_pos );
}
/* User togglePlayPause */
......
......@@ -203,6 +203,7 @@ private slots:
signals:
/// Send new position, new time and new length
void positionUpdated( float , int64_t, int );
void seekRequested( float pos );
void rateChanged( int );
void nameChanged( const QString& );
/// Used to signal whether we should show navigation buttons
......
......@@ -497,14 +497,18 @@ inline void MainInterface::createStatusBar()
nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
| Qt::TextSelectableByKeyboard );
SpeedLabel *speedLabel = new SpeedLabel( p_intf, "1.00x", this );
CacheLabel *cacheLabel = new CacheLabel( p_intf, this );
cacheLabel->hide();
/* Styling those labels */
timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
cacheLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
/* and adding those */
statusBarr->addWidget( nameLabel, 8 );
statusBarr->addPermanentWidget( cacheLabel, 0 );
statusBarr->addPermanentWidget( speedLabel, 0 );
statusBarr->addPermanentWidget( timeLabel, 0 );
......@@ -516,6 +520,9 @@ inline void MainInterface::createStatusBar()
CONNECT( THEMIM->getIM(), encryptionChanged( bool ),
this, showCryptedLabel( bool ) );
connect( THEMIM->getIM(), SIGNAL(seekRequested(float)),
timeLabel, SLOT(setDisplayPosition(float)) );
}
#ifdef WIN32
......@@ -1180,6 +1187,12 @@ void MainInterface::showCryptedLabel( bool b_show )
cryptedLabel->setVisible( b_show );
}
void MainInterface::showBuffering( float f_cache )
{
QString amount = QString("Buffering: %1%").arg( (int)(100*f_cache) );
statusBar()->showMessage( amount, 1000 );
}
/*****************************************************************************
* Systray Icon and Systray Menu
*****************************************************************************/
......
......@@ -217,6 +217,8 @@ private slots:
void handleKeyPress( QKeyEvent * );
void showBuffering( float );
signals:
void askGetVideo( WId *p_id, int *pi_x, int *pi_y,
unsigned *pi_width, unsigned *pi_height );
......
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