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