]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/main_interface.cpp
Don't show unsaveable options in the preferences
[vlc] / modules / gui / qt4 / main_interface.cpp
index 6c5a0be020e859f1525049fefef78afa0e512383..77982c11f8a98d1f343db33ec5371420b380d379 100644 (file)
@@ -42,6 +42,8 @@
 #include <QSize>
 #include <QMenu>
 #include <QLabel>
+#include <QSlider>
+#include <QWidgetAction>
 
 #include <assert.h>
 #include <vlc_keys.h>
 
 #ifdef WIN32
     #define PREF_W 410
-    #define PREF_H 121
+    #define PREF_H 151
 #else
-    #define PREF_W 450
-    #define PREF_H 160
+    #define PREF_W 400
+    #define PREF_H 140
 #endif
 
 #define SET_WIDTH(i,j) i->widgetSize.setWidth(j)
@@ -94,7 +96,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /**
      *  Configuration and settings
      **/
-    settings = new QSettings( "VideoLAN", "VLC" );
+    settings = new QSettings( "vlc", "vlc-qt-interface" );
     settings->beginGroup( "MainWindow" );
 
     /* Main settings */
@@ -125,7 +127,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 
     /* Menu Bar */
     QVLCMenu::createMenuBar( this, p_intf, playlistEmbeddedFlag,
-                             isAdvancedVisible(), visualSelectorEnabled );
+                             visualSelectorEnabled );
 
     /* Status Bar */
     /**
@@ -134,9 +136,10 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /**
      * TODO: do we add a label for the current Volume ?
      **/
-    timeLabel = new QLabel;
+    b_remainingTime = false;
+    timeLabel = new TimeLabel;
     nameLabel = new QLabel;
-    speedLabel = new QLabel( "1.0x" );
+    speedLabel = new QLabel( "1.00x" );
     timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
     speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
     statusBar()->addWidget( nameLabel, 8 );
@@ -144,6 +147,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     statusBar()->addPermanentWidget( timeLabel, 2 );
     speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
     timeLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
+    CONNECT( timeLabel, timeLabelClicked(), this, toggleTimeDisplay() );
     CONNECT( speedLabel, customContextMenuRequested( QPoint ),
              this, showSpeedMenu( QPoint ) );
     CONNECT( timeLabel, customContextMenuRequested( QPoint ),
@@ -181,7 +185,9 @@ 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, setDisplay( float, int, int ) );
+             this, setDisplayPosition( float, int, int ) );
+
+    CONNECT( THEMIM->getIM(), rateChanged( int ), this, setRate( int ) );
 
     /** Connects on nameChanged() */
     /* Naming in the controller statusbar */
@@ -241,7 +247,7 @@ MainInterface::~MainInterface()
     }
 
     settings->setValue( "playlist-embedded", playlistEmbeddedFlag );
-    settings->setValue( "adv-controls", isAdvancedVisible() );
+    settings->setValue( "adv-controls", getControlsVisibilityStatus() & 0x1 );
     settings->setValue( "pos", pos() );
     settings->endGroup();
     delete settings;
@@ -273,6 +279,7 @@ void MainInterface::setVLCWindowsTitle( QString aTitle )
     }
 }
 
+
 void MainInterface::handleMainUi( QSettings *settings )
 {
     /* Create the main Widget and the mainLayout */
@@ -297,6 +304,12 @@ void MainInterface::handleMainUi( QSettings *settings )
     /* Add the controls Widget to the main Widget */
     mainLayout->addWidget( controls );
 
+    /* Create the Speed Control Widget */
+    speedControl = new SpeedControlWidget( p_intf );
+    speedControlMenu = new QMenu( this );
+    QWidgetAction *widgetAction = new QWidgetAction( this );
+    widgetAction->setDefaultWidget( speedControl );
+    speedControlMenu->addAction( widgetAction );
 
     /* Set initial size */
     resize( PREF_W, PREF_H );
@@ -392,16 +405,15 @@ void MainInterface::resizeEvent( QResizeEvent *e )
  ****************************************************************************/
 void MainInterface::showSpeedMenu( QPoint pos )
 {
-    QMenu menu( this );
-    menu.addAction( "Not Implemented Yet" );
-    menu.exec( QCursor::pos() );
+    speedControlMenu->exec( QCursor::pos() - pos + QPoint( 0, speedLabel->height() ) );
 }
 
 void MainInterface::showTimeMenu( QPoint pos )
 {
     QMenu menu( this );
-    menu.addAction( "Not Implemented Yet" );
-    menu.exec( QCursor::pos() );
+    menu.addAction(  qtr("Elapsed Time") , this, SLOT( setElapsedTime() ) );
+    menu.addAction(  qtr("Remaining Time") , this, SLOT( setRemainTime() ) );
+    menu.exec( QCursor::pos() - pos +QPoint( 0, timeLabel->height() ) );
 }
 
 /****************************************************************************
@@ -437,7 +449,7 @@ void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
             // videoWidget->widgetSize = bgWidget->widgeTSize;
             videoWidget->widgetSize = QSize( *pi_width, *pi_height );
         }
-//        videoWidget->updateGeometry(); /// FIXME: Needed ?
+        videoWidget->updateGeometry(); // Needed for deinterlace
         need_components_update = true;
     }
     return ret;
@@ -585,8 +597,7 @@ void MainInterface::undockPlaylist()
         playlistEmbeddedFlag = false;
 
         menuBar()->clear();
-        QVLCMenu::createMenuBar( this, p_intf, false, isAdvancedVisible(),
-                                 visualSelectorEnabled);
+        QVLCMenu::createMenuBar( this, p_intf, false, visualSelectorEnabled);
 
         if( videoIsActive )
         {
@@ -624,7 +635,6 @@ void MainInterface::visual()
 
 void MainInterface::toggleMenus()
 {
-    msg_Dbg( p_intf, "I HAS HERE, HIDING YOUR MENUZ: \\_o<~~ coin coin" );
     TOGGLEV( controls );
     TOGGLEV( statusBar() );
     updateGeometry();
@@ -643,24 +653,33 @@ void MainInterface::toggleAdvanced()
     controls->toggleAdvanced();
 }
 
-bool MainInterface::isAdvancedVisible()
+int MainInterface::getControlsVisibilityStatus()
 {
-    return controls->b_advancedVisible;
+    return( (controls->isVisible() ? 0x2 : 0x0 )
+                + controls->b_advancedVisible );
 }
 
 /************************************************************************
  * Other stuff
  ************************************************************************/
-void MainInterface::setDisplay( float pos, int time, int length )
+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, 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;
@@ -674,6 +693,15 @@ void MainInterface::setStatus( int status )
         updateSystrayMenu( status );
 }
 
+void MainInterface::setRate( int rate )
+{
+    QString str;
+    str.setNum( ( 1000 / (double)rate), 'f', 2 );
+    str.append( "x" );
+    speedLabel->setText( str );
+    speedControl->updateControls( rate );
+}
+
 void MainInterface::updateOnTimer()
 {
     /* \todo Make this event-driven */
@@ -711,7 +739,7 @@ void MainInterface::createSystray()
     QVLCMenu::updateSystrayMenu( this, p_intf, true );
     sysTray->show();
 
-    CONNECT( sysTray, activated(  QSystemTrayIcon::ActivationReason ),
+    CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
             this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
 }
 
@@ -735,6 +763,11 @@ void MainInterface::toggleUpdateSystrayMenu()
         show();
         activateWindow();
     }
+    else if( isMinimized() )
+    {
+        showNormal();
+        activateWindow();
+    }
     else
     {
 #ifdef WIN32
@@ -884,8 +917,7 @@ void MainInterface::customEvent( QEvent *event )
         PlaylistDialog::killInstance();
         playlistEmbeddedFlag = true;
         menuBar()->clear();
-        QVLCMenu::createMenuBar(this, p_intf, true, isAdvancedVisible(),
-                                visualSelectorEnabled);
+        QVLCMenu::createMenuBar(this, p_intf, true, visualSelectorEnabled);
         togglePlaylist();
     }
     else if ( event->type() == SetVideoOnTopEvent_Type )