]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/main_interface.cpp
Qt4 - MI: Install an event filter to make click on timeLabel automatically switch...
[vlc] / modules / gui / qt4 / main_interface.cpp
index 0dd678cb5a4ba8cdd4f9d04579664dc4588645c1..e2248c0225e38bc460639be56f9d7bf46f867bb8 100644 (file)
@@ -134,6 +134,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /**
      * TODO: do we add a label for the current Volume ?
      **/
+    b_remainingTime = false;
     timeLabel = new QLabel;
     nameLabel = new QLabel;
     speedLabel = new QLabel( "1.0x" );
@@ -144,6 +145,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     statusBar()->addPermanentWidget( timeLabel, 2 );
     speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
     timeLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
+    timeLabel->installEventFilter( this );
     CONNECT( speedLabel, customContextMenuRequested( QPoint ),
              this, showSpeedMenu( QPoint ) );
     CONNECT( timeLabel, customContextMenuRequested( QPoint ),
@@ -273,6 +275,7 @@ void MainInterface::setVLCWindowsTitle( QString aTitle )
     }
 }
 
+
 void MainInterface::handleMainUi( QSettings *settings )
 {
     /* Create the main Widget and the mainLayout */
@@ -400,7 +403,8 @@ void MainInterface::showSpeedMenu( QPoint pos )
 void MainInterface::showTimeMenu( QPoint pos )
 {
     QMenu menu( this );
-    menu.addAction( "Not Implemented Yet" );
+    menu.addAction(  qtr("Elapsed Time") , this, SLOT( setElapsedTime() ) );
+    menu.addAction(  qtr("Remaining Time") , this, SLOT( setRemainTime() ) );
     menu.exec( QCursor::pos() );
 }
 
@@ -655,12 +659,20 @@ void MainInterface::setDisplay( float pos, int time, int length )
 {
     char psz_length[MSTRTIME_MAX_SIZE], psz_time[MSTRTIME_MAX_SIZE];
     secstotimestr( psz_length, length );
-    secstotimestr( psz_time, time );
-    QString title;
-    title.sprintf( "%s/%s", psz_time, psz_length );
-    timeLabel->setText( " "+title+" " );
+    secstotimestr( psz_time, b_remainingTime ? length - time : time );
+    QString title; title.sprintf( "%s/%s", psz_time, psz_length );
+    if( b_remainingTime ) timeLabel->setText( " -"+title+" " );
+    else timeLabel->setText( " "+title+" " );
+}
+
+void MainInterface::toggleTimeDisplay()
+{
+    b_remainingTime = ( b_remainingTime ? false : true );
 }
 
+void MainInterface::setElapsedTime(){ b_remainingTime = false; }
+void MainInterface::setRemainTime(){ b_remainingTime = true; }
+
 void MainInterface::setName( QString name )
 {
     input_name = name;
@@ -899,6 +911,12 @@ void MainInterface::customEvent( QEvent *event )
     }
 }
 
+bool MainInterface::eventFilter(QObject *obj, QEvent *event)
+{
+    if( (obj == timeLabel) && (event->type() == QEvent::MouseButtonPress) ) toggleTimeDisplay();
+}
+
+
 void MainInterface::keyPressEvent( QKeyEvent *e )
 {
     int i_vlck = qtEventToVLCKey( e );