[vlc-devel] commit: Qt4: Really split the TimeLabel into its own class. ( Jean-Baptiste Kempf )

git version control git at videolan.org
Mon Sep 22 04:54:04 CEST 2008


vlc | branch: 0.9-bugfix | Jean-Baptiste Kempf <jb at videolan.org> | Sun Sep 21 19:46:42 2008 -0700| [4c8750b05bebd4611e80001d59ba21f2ee07c214] | committer: Jean-Baptiste Kempf 

Qt4: Really split the TimeLabel into its own class.

Code simplification and TimeLabel in the FSC.
(cherry picked from commit 44e31c0f861b90a01ff3239354d7b2bf43468d07)

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4c8750b05bebd4611e80001d59ba21f2ee07c214
---

 modules/gui/qt4/components/interface_widgets.cpp |   44 +++++++++++++++++++++-
 modules/gui/qt4/components/interface_widgets.hpp |   17 ++++++--
 modules/gui/qt4/main_interface.cpp               |   31 +---------------
 modules/gui/qt4/main_interface.hpp               |    3 -
 4 files changed, 56 insertions(+), 39 deletions(-)

diff --git a/modules/gui/qt4/components/interface_widgets.cpp b/modules/gui/qt4/components/interface_widgets.cpp
index 4f5b65f..afdffec 100644
--- a/modules/gui/qt4/components/interface_widgets.cpp
+++ b/modules/gui/qt4/components/interface_widgets.cpp
@@ -1040,6 +1040,7 @@ FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
     fsLayout->addWidget( slider, 0, 1, 1, 9 );
     fsLayout->addWidget( fasterButton, 0, 10 );
 
+    /* Second line */
     fsLayout->addWidget( playButton, 1, 0, 1, 2 );
     fsLayout->addLayout( controlButLayout, 1, 2 );
 
@@ -1049,8 +1050,12 @@ FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
     fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
 
     fsLayout->setColumnStretch( 7, 10 );
-    fsLayout->addWidget( volMuteLabel, 1, 8 );
-    fsLayout->addWidget( volumeSlider, 1, 9, 1, 2 );
+
+    TimeLabel *timeLabel = new TimeLabel( p_intf );
+
+    fsLayout->addWidget( timeLabel, 1, 8 );
+    fsLayout->addWidget( volMuteLabel, 1, 9 );
+    fsLayout->addWidget( volumeSlider, 1, 10,1, 2 );
 
     /* hiding timer */
     p_hideTimer = new QTimer( this );
@@ -1081,6 +1086,7 @@ FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
     fullscreenButton->setIcon( QIcon( ":/defullscreen" ) );
 
     vlc_mutex_init_recursive( &lock );
+    setMinimumWidth( 450 );
 }
 
 FullscreenControllerWidget::~FullscreenControllerWidget()
@@ -1619,3 +1625,37 @@ void CoverArtLabel::doUpdate()
     }
 }
 
+TimeLabel::TimeLabel( intf_thread_t *_p_intf  ) :QLabel(), p_intf( _p_intf )
+{
+   b_remainingTime = false;
+   setText( " --:--/--:-- " );
+   setAlignment( Qt::AlignRight | Qt::AlignVCenter );
+   setToolTip( qtr( "Toggle between elapsed and remaining time" ) );
+
+
+   CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
+             this, setDisplayPosition( float, int, int ) );
+}
+
+void TimeLabel::setDisplayPosition( float pos, int time, int length )
+{
+    char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
+    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 );
+
+    /* Add a minus to remaining time*/
+    if( b_remainingTime && length ) setText( " -"+timestr+" " );
+    else setText( " "+timestr+" " );
+}
+
+void TimeLabel::toggleTimeDisplay()
+{
+    b_remainingTime = !b_remainingTime;
+}
+
+
diff --git a/modules/gui/qt4/components/interface_widgets.hpp b/modules/gui/qt4/components/interface_widgets.hpp
index 8335be2..5bfcd1f 100644
--- a/modules/gui/qt4/components/interface_widgets.hpp
+++ b/modules/gui/qt4/components/interface_widgets.hpp
@@ -332,16 +332,25 @@ private:
 class TimeLabel : public QLabel
 {
     Q_OBJECT
-    void mousePressEvent( QMouseEvent *event )
+public:
+    TimeLabel( intf_thread_t *_p_intf );
+protected:
+    virtual void mousePressEvent( QMouseEvent *event )
     {
-        emit timeLabelClicked();
+        toggleTimeDisplay();
     }
-    void mouseDoubleClickEvent( QMouseEvent *event )
+    virtual void mouseDoubleClickEvent( QMouseEvent *event )
     {
+        toggleTimeDisplay();
         emit timeLabelDoubleClicked();
     }
+private slots:
+    void setDisplayPosition( float pos, int time, int length );
+private:
+    intf_thread_t *p_intf;
+    bool b_remainingTime;
+    void toggleTimeDisplay();
 signals:
-    void timeLabelClicked();
     void timeLabelDoubleClicked();
 };
 
diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index 94df454..d629c0d 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -146,8 +146,6 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /* Connect the input manager to the GUI elements it manages */
 
     /* It is also connected to the control->slider, see the ControlsWidget */
-    CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
-             this, setDisplayPosition( float, int, int ) );
     /* Change the SpeedRate in the Status */
     CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
 
@@ -300,11 +298,7 @@ inline void MainInterface::createStatusBar()
      *  Status Bar  *
      ****************/
     /* Widgets Creation*/
-    b_remainingTime = false;
-    timeLabel = new TimeLabel;
-    timeLabel->setText( " --:--/--:-- " );
-    timeLabel->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
-    timeLabel->setToolTip( qtr( "Toggle between elapsed and remaining time" ) );
+    timeLabel = new TimeLabel( p_intf );
     nameLabel = new QLabel;
     nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
                                       | Qt::TextSelectableByKeyboard );
@@ -327,9 +321,7 @@ inline void MainInterface::createStatusBar()
        - double clicking opens the goto time dialog
        - right-clicking and clicking just toggle between remaining and
          elapsed time.*/
-    CONNECT( timeLabel, timeLabelClicked(), this, toggleTimeDisplay() );
     CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
-    CONNECT( timeLabel, timeLabelDoubleClicked(), this, toggleTimeDisplay() );
 
     /* Speed Label behaviour:
        - right click gives the vertical speed slider */
@@ -863,27 +855,6 @@ void MainInterface::visual()
 /************************************************************************
  * Other stuff
  ************************************************************************/
-void MainInterface::setDisplayPosition( float pos, int time, int length )
-{
-    char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
-    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 );
-
-    /* Add a minus to remaining time*/
-    if( b_remainingTime && length ) timeLabel->setText( " -"+timestr+" " );
-    else timeLabel->setText( " "+timestr+" " );
-}
-
-void MainInterface::toggleTimeDisplay()
-{
-    b_remainingTime = !b_remainingTime;
-}
-
 void MainInterface::setName( QString name )
 {
     input_name = name; /* store it for the QSystray use */
diff --git a/modules/gui/qt4/main_interface.hpp b/modules/gui/qt4/main_interface.hpp
index 65c61a3..2d4f57d 100644
--- a/modules/gui/qt4/main_interface.hpp
+++ b/modules/gui/qt4/main_interface.hpp
@@ -133,7 +133,6 @@ private:
     bool                 playlistVisible; ///< Is the playlist visible ?
     bool                 visualSelectorEnabled;
     bool                 notificationEnabled; /// Systray Notifications
-    bool                 b_remainingTime; /* Show elapsed or remaining time */
     bool                 bgWasVisible;
     int                  i_visualmode; ///< Visual Mode
     pl_dock_e            i_pl_dock;
@@ -171,8 +170,6 @@ private slots:
     void setRate( int );
     void setName( QString );
     void setVLCWindowsTitle( QString title = "" );
-    void setDisplayPosition( float, int, int );
-    void toggleTimeDisplay();
 #if 0
     void visual();
 #endif




More information about the vlc-devel mailing list