Commit fa557863 authored by Edward Wang's avatar Edward Wang Committed by Jean-Baptiste Kempf

Qt4: allow more types of timeLabel in toolbars

Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
(cherry picked from commit abfcd0d5d391256477a45e0b3d07b90ce924e561)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 527681a3
......@@ -471,6 +471,12 @@ QWidget *AbstractController::createWidget( buttonType_e button, int options )
case SPEED_LABEL:
widget = new SpeedLabel( p_intf, this );
break;
case TIME_LABEL_ELAPSED:
widget = new TimeLabel( p_intf, TimeLabel::Elapsed );
break;
case TIME_LABEL_REMAINING:
widget = new TimeLabel( p_intf, TimeLabel::Remaining );
break;
default:
msg_Warn( p_intf, "This should not happen %i", button );
break;
......
......@@ -101,6 +101,8 @@ typedef enum buttonType_e
PLAYBACK_BUTTONS,
ASPECT_RATIO_COMBOBOX,
SPEED_LABEL,
TIME_LABEL_ELAPSED,
TIME_LABEL_REMAINING,
SPECIAL_MAX,
WIDGET_SPACER = 0x40,
......
......@@ -549,17 +549,33 @@ void CoverArtLabel::askForUpdate()
THEMIM->getIM()->requestArtUpdate();
}
TimeLabel::TimeLabel( intf_thread_t *_p_intf )
TimeLabel::TimeLabel( intf_thread_t *_p_intf, TimeLabel::Display _displayType )
: QLabel(), p_intf( _p_intf ), bufTimer( new QTimer(this) ),
buffering( false ), showBuffering(false), bufVal( -1 )
buffering( false ), showBuffering(false), bufVal( -1 ), displayType( _displayType )
{
b_remainingTime = false;
setText( " --:--/--:-- " );
switch( _displayType ) {
case TimeLabel::Elapsed:
setText( " --:-- " );
setToolTip( qtr("Elapsed time") );
break;
case TimeLabel::Remaining:
setText( " --:-- " );
setToolTip( qtr("Total/Remaining time")
+ QString("\n-")
+ qtr("Click to toggle between total and remaining time")
);
break;
case TimeLabel::Both:
setText( " --:--/--:-- " );
setToolTip( QString( "- " )
+ qtr( "Click to toggle between elapsed and remaining time" )
+ QString( "\n- " )
+ qtr( "Double click to jump to a chosen time position" ) );
break;
}
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 ),
......@@ -567,6 +583,8 @@ TimeLabel::TimeLabel( intf_thread_t *_p_intf )
CONNECT( THEMIM->getIM(), cachingChanged( float ),
this, updateBuffering( float ) );
CONNECT( bufTimer, timeout(), this, updateBuffering() );
this->setContentsMargins( 4, 0, 4, 0 );
}
void TimeLabel::setDisplayPosition( float pos, int64_t t, int length )
......@@ -576,7 +594,10 @@ void TimeLabel::setDisplayPosition( float pos, int64_t t, int length )
if( pos == -1.f )
{
setText( " --:--/--:-- " );
if( displayType == TimeLabel::Both )
setText( " --:--/--:-- " );
else
setText( " --:-- " );
return;
}
......@@ -585,14 +606,27 @@ void TimeLabel::setDisplayPosition( float pos, int64_t t, int length )
secstotimestr( psz_length, length );
secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
: time );
QString timestr = QString( " %1%2/%3 " )
switch( displayType )
{
case TimeLabel::Elapsed:
setText( QString(" ") + QString( psz_time ) + QString(" ") );
break;
case TimeLabel::Remaining:
if( b_remainingTime )
setText( QString(" -") + QString( psz_time ) + QString(" ") );
else
setText( QString(" ") + QString( psz_length ) + QString(" ") );
break;
case TimeLabel::Both:
default:
QString timestr = QString( " %1%2/%3 " )
.arg( QString( (b_remainingTime && length) ? "-" : "" ) )
.arg( QString( psz_time ) )
.arg( QString( ( !length && time ) ? "--:--" : psz_length ) );
setText( timestr );
setText( timestr );
break;
}
cachedLength = length;
}
......
......@@ -122,15 +122,24 @@ class TimeLabel : public QLabel
{
Q_OBJECT
public:
TimeLabel( intf_thread_t *_p_intf );
enum Display
{
Elapsed,
Remaining,
Both
};
TimeLabel( intf_thread_t *_p_intf, TimeLabel::Display _displayType = TimeLabel::Both );
protected:
virtual void mousePressEvent( QMouseEvent *event )
{
if( displayType == TimeLabel::Elapsed ) return;
toggleTimeDisplay();
event->accept();
}
virtual void mouseDoubleClickEvent( QMouseEvent *event )
{
if( displayType != TimeLabel::Both ) return;
event->accept();
toggleTimeDisplay();
emit timeLabelDoubleClicked();
......@@ -144,6 +153,7 @@ private:
bool buffering;
bool showBuffering;
float bufVal;
TimeLabel::Display displayType;
char psz_length[MSTRTIME_MAX_SIZE];
char psz_time[MSTRTIME_MAX_SIZE];
......
......@@ -453,6 +453,14 @@ WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent )
widget = new SpeedLabel( p_intf, this );
widgetItem->setText( qtr("Playback speed") );
break;
case TIME_LABEL_ELAPSED:
widget = new QLabel( "2:42", this );
widgetItem->setText( qtr("Elasped time") );
break;
case TIME_LABEL_REMAINING:
widget = new QLabel( "-2:42", this );
widgetItem->setText( qtr("Total/Remaining time") );
break;
default:
msg_Warn( p_intf, "This should not happen %i", i );
break;
......
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