[vlc-devel] [PATCH 2/3] Qt4: UI enhancements - Time

Edward Wang edward.c.wang at compdigitec.com
Sun Jan 1 20:04:58 CET 2012


---
 modules/gui/qt4/components/controller.cpp        |    6 ++
 modules/gui/qt4/components/controller.hpp        |    2 +
 modules/gui/qt4/components/interface_widgets.cpp |   58 +++++++++++++++++-----
 modules/gui/qt4/components/interface_widgets.hpp |   12 ++++-
 modules/gui/qt4/dialogs/toolbar.cpp              |    8 +++
 5 files changed, 73 insertions(+), 13 deletions(-)

diff --git a/modules/gui/qt4/components/controller.cpp b/modules/gui/qt4/components/controller.cpp
index d1fad22..e61a1b5 100644
--- a/modules/gui/qt4/components/controller.cpp
+++ b/modules/gui/qt4/components/controller.cpp
@@ -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;
diff --git a/modules/gui/qt4/components/controller.hpp b/modules/gui/qt4/components/controller.hpp
index 8052c75..2d5f1e4 100644
--- a/modules/gui/qt4/components/controller.hpp
+++ b/modules/gui/qt4/components/controller.hpp
@@ -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,
diff --git a/modules/gui/qt4/components/interface_widgets.cpp b/modules/gui/qt4/components/interface_widgets.cpp
index ccabd7c..3efc1ee 100644
--- a/modules/gui/qt4/components/interface_widgets.cpp
+++ b/modules/gui/qt4/components/interface_widgets.cpp
@@ -537,17 +537,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 ),
@@ -555,6 +571,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 )
@@ -564,7 +582,10 @@ void TimeLabel::setDisplayPosition( float pos, int64_t t, int length )
 
     if( pos == -1.f )
     {
-        setText( " --:--/--:-- " );
+        if( displayType == TimeLabel::Both )
+            setText( " --:--/--:-- " );
+        else
+            setText( " --:-- " );
         return;
     }
 
@@ -573,14 +594,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;
 }
 
diff --git a/modules/gui/qt4/components/interface_widgets.hpp b/modules/gui/qt4/components/interface_widgets.hpp
index 5de9b32..cd95276 100644
--- a/modules/gui/qt4/components/interface_widgets.hpp
+++ b/modules/gui/qt4/components/interface_widgets.hpp
@@ -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];
diff --git a/modules/gui/qt4/dialogs/toolbar.cpp b/modules/gui/qt4/dialogs/toolbar.cpp
index ce5194b..bd1e982 100644
--- a/modules/gui/qt4/dialogs/toolbar.cpp
+++ b/modules/gui/qt4/dialogs/toolbar.cpp
@@ -453,6 +453,14 @@ WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent )
             widget = new SpeedLabel( p_intf, this );
             widgetItem->setText( qtr("Speed selector") );
             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;
-- 
1.7.5.4




More information about the vlc-devel mailing list