]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/main_interface.cpp
Qt: by default resize main interface so that it shows all MenuBar entries
[vlc] / modules / gui / qt4 / main_interface.cpp
index 355f7a3f3572f18ad737ef52b2be79f3fce56678..1c5a756a70f00a0be837fe75baad2f611a9ccff9 100644 (file)
@@ -57,7 +57,6 @@
 #include <QToolBar>
 #include <QGroupBox>
 #include <QDate>
-#include <QProgressBar>
 
 #include <assert.h>
 #include <vlc_keys.h>
@@ -81,13 +80,14 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 {
     /* Variables initialisation */
     // need_components_update = false;
-    bgWidget = NULL;
-    videoWidget = NULL;
-    playlistWidget = NULL;
-    sysTray = NULL;
-    videoIsActive = false;
-    playlistVisible = false;
-    input_name = "";
+    bgWidget             = NULL;
+    videoWidget          = NULL;
+    playlistWidget       = NULL;
+    sysTray              = NULL;
+    videoIsActive        = false;
+    playlistVisible      = false;
+    input_name           = "";
+    fullscreenControls   = NULL;
 
     /* Ask for privacy */
     askForPrivacy();
@@ -109,7 +109,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
 
     /* Set the other interface settings */
-    settings = new QSettings( "vlc", "vlc-qt-interface" );
+    settings = getSettings();
     settings->beginGroup( "MainWindow" );
 
     //TODO: I don't like that code
@@ -222,14 +222,8 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 
     CONNECT( this, askUpdate(), this, doComponentsUpdate() );
 
-    CONNECT( controls, advancedControlsToggled( bool ),
-             this, doComponentsUpdate() );
-
-    CONNECT( fullscreenControls, advancedControlsToggled( bool ),
-             this, doComponentsUpdate() );
-
     /* Size and placement of interface */
-    QVLCTools::restoreWidgetPosition(settings,this,QSize(350,60));
+    QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
 
 
     /* Playlist */
@@ -243,6 +237,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 
     /* Update the geometry TODO: is it useful ?*/
     updateGeometry();
+    resize( sizeHint() );
 
     /*****************************************************
      * End everything by creating the Systray Management *
@@ -255,7 +250,7 @@ MainInterface::~MainInterface()
     msg_Dbg( p_intf, "Destroying the main interface" );
 
     if( playlistWidget )
-        playlistWidget->savingSettings( settings );
+        playlistWidget->savingSettings();
 
     settings->beginGroup( "MainWindow" );
 
@@ -271,7 +266,6 @@ MainInterface::~MainInterface()
         settings->setValue( "backgroundSize", bgWidget->size() );
 
     settings->endGroup();
-    delete settings;
 
     var_DelCallback( p_intf->p_libvlc, "intf-show", IntfShowCB, p_intf );
 
@@ -298,10 +292,13 @@ inline void MainInterface::createStatusBar()
     timeLabel = new TimeLabel;
     timeLabel->setText( " --:--/--:-- " );
     timeLabel->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
+    timeLabel->setToolTip( qtr( "Toggle between elapsed and remaining time" ) );
     nameLabel = new QLabel;
     nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
                                       | Qt::TextSelectableByKeyboard );
     speedLabel = new SpeedLabel( p_intf, "1.00x" );
+    speedLabel->setToolTip(
+            qtr( "Current playback speed.\nRight click to adjust" ) );
     speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
 
     /* Styling those labels */
@@ -309,13 +306,10 @@ inline void MainInterface::createStatusBar()
     speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
     nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
 
-    pgBar = new QProgressBar;
-    pgBar->hide();
 
     /* and adding those */
     statusBar()->addWidget( nameLabel, 8 );
     statusBar()->addPermanentWidget( speedLabel, 0 );
-    statusBar()->addPermanentWidget( pgBar, 0 );
     statusBar()->addPermanentWidget( timeLabel, 0 );
 
     /* timeLabel behaviour:
@@ -383,16 +377,22 @@ void MainInterface::handleMainUi( QSettings *settings )
     mainLayout->setMargin( 0 );
 
     /* Create the CONTROLS Widget */
-    /* bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); */
+    bool b_shiny = config_GetInt( p_intf, "qt-blingbling" );
     controls = new ControlsWidget( p_intf, this,
                    settings->value( "adv-controls", false ).toBool(),
-                   config_GetInt( p_intf, "qt-blingbling" ) );
+                   b_shiny );
+    CONNECT( controls, advancedControlsToggled( bool ),
+             this, doComponentsUpdate() );
 
     /* Create the FULLSCREEN CONTROLS Widget */
-    /* bool b_shiny = config_GetInt( p_intf, "qt-blingbling" ); */
-    fullscreenControls = new FullscreenControllerWidget( p_intf, this,
-                   settings->value( "adv-controls", false ).toBool(),
-                   config_GetInt( p_intf, "qt-blingbling" ) );
+    if( config_GetInt( p_intf, "qt-fs-controller" ) )
+    {
+        fullscreenControls = new FullscreenControllerWidget( p_intf, this,
+                settings->value( "adv-controls", false ).toBool(),
+                b_shiny );
+        CONNECT( fullscreenControls, advancedControlsToggled( bool ),
+                this, doComponentsUpdate() );
+    }
 
     /* Add the controls Widget to the main Widget */
     mainLayout->insertWidget( 0, controls, 0, Qt::AlignBottom );
@@ -413,18 +413,21 @@ void MainInterface::handleMainUi( QSettings *settings )
     visualSelector->hide();
     #endif
 
-    /* And video Outputs */
-    if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
-        i_visualmode == QT_MINIMAL_MODE )
+    /* Bg Cone */
+    bgWidget = new BackgroundWidget( p_intf );
+    bgWidget->resize(
+            settings->value( "backgroundSize", QSize( 300, 200 ) ).toSize() );
+    bgWidget->updateGeometry();
+    mainLayout->insertWidget( 0, bgWidget );
+    CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
+
+    if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
+        i_visualmode != QT_MINIMAL_MODE )
     {
-        bgWidget = new BackgroundWidget( p_intf );
-        bgWidget->resize(
-             settings->value( "backgroundSize", QSize( 300, 150 ) ).toSize() );
-        bgWidget->updateGeometry();
-        mainLayout->insertWidget( 0, bgWidget );
-        CONNECT( this, askBgWidgetToToggle(), bgWidget, toggle() );
+        bgWidget->hide();
     }
 
+    /* And video Outputs */
     if( videoEmbeddedFlag )
     {
         videoWidget = new VideoWidget( p_intf );
@@ -443,7 +446,7 @@ inline void MainInterface::askForPrivacy()
     if( config_GetInt( p_intf, "qt-privacy-ask") )
     {
         QList<ConfigControl *> controls;
-        if( privacyDialog( controls ) == QDialog::Accepted )
+        if( privacyDialog( &controls ) == QDialog::Accepted )
         {
             QList<ConfigControl *>::Iterator i;
             for(  i = controls.begin() ; i != controls.end() ; i++ )
@@ -459,7 +462,7 @@ inline void MainInterface::askForPrivacy()
     }
 }
 
-int MainInterface::privacyDialog( QList<ConfigControl *> controls )
+int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
 {
     QDialog *privacy = new QDialog();
 
@@ -499,7 +502,7 @@ int MainInterface::privacyDialog( QList<ConfigControl *> controls )
     {                                                             \
         control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
                 p_config, options, false, optionsLayout, line );  \
-        controls.append( control );                               \
+        controls->append( control );                               \
     }
 
 #define CONFIG_GENERIC_NOBOOL( option, type )                     \
@@ -508,7 +511,7 @@ int MainInterface::privacyDialog( QList<ConfigControl *> controls )
     {                                                             \
         control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
                 p_config, options, optionsLayout, line );  \
-        controls.append( control );                               \
+        controls->append( control );                               \
     }
 
     CONFIG_GENERIC( "album-art", IntegerList ); line++;
@@ -538,10 +541,11 @@ int MainInterface::privacyDialog( QList<ConfigControl *> controls )
    ask _parent->isFloating()...
    If you think this would be better, please FIXME it...
 */
-#if 0
+
 QSize MainInterface::sizeHint() const
 {
-    int nwidth  = controls->sizeHint().width();
+    int nwidth  = __MAX( controls->sizeHint().width(),
+                         menuBar()->sizeHint().width() );
     int nheight = controls->isVisible() ?
                   controls->size().height()
                   + menuBar()->size().height()
@@ -557,20 +561,22 @@ QSize MainInterface::sizeHint() const
     }
     else if( videoIsActive )
     {
-        nheight += videoWidget->size().height();
-        nwidth  = videoWidget->size().width();
+        nheight += videoWidget->sizeHint().height();
+        nwidth  = videoWidget->sizeHint().width();
         msg_Dbg( p_intf, "2 %i %i", nheight, nwidth );
     }
-/*    if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget()  )
+#if 0
+    if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget()  )
     {
         nheight += dockPL->size().height();
         nwidth = __MAX( nwidth, dockPL->size().width() );
         msg_Dbg( p_intf, "3 %i %i", nheight, nwidth );
-    }*/
+    }
+#endif
     msg_Dbg( p_intf, "4 %i %i", nheight, nwidth );
     return QSize( nwidth, nheight );
 }
-#endif
+
 #if 0
 /* FIXME This is dead code and need to be removed AT THE END */
 void MainInterface::resizeEvent( QResizeEvent *e )
@@ -592,10 +598,19 @@ void MainInterface::resizeEvent( QResizeEvent *e )
 }
 #endif
 
+void MainInterface::toggleFSC()
+{
+   if( !fullscreenControls ) return;
+
+   IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
+   QApplication::postEvent( fullscreenControls, static_cast<QEvent *>(eShow) );
+}
+#if 0
 void MainInterface::requestLayoutUpdate()
 {
     emit askUpdate();
 }
+#endif
 
 //FIXME remove me at the end...
 void MainInterface::debug()
@@ -649,7 +664,7 @@ void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
                                    int *pi_y, unsigned int *pi_width,
                                    unsigned int *pi_height )
 {
-    bool bgWasVisible = false;
+    bgWasVisible = false;
 
     /* Request the videoWidget */
     void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
@@ -679,17 +694,16 @@ void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
 //        emit askVideoToResize( *pi_width, *pi_height );
         emit askUpdate();
 
-        //XXX uncomment for fullscreen controler
-        //fullscreenControls->attachVout( p_nvout );
+        if( fullscreenControls ) fullscreenControls->attachVout( p_nvout );
     }
     return ret;
 }
 
-void MainInterface::releaseVideo( vout_thread_t *p_vout, void *p_win )
+void MainInterface::releaseVideo( void *p_win )
 {
-    //XXX uncomment for fullscreen controler
-    //fullscreenControls->detachVout( p_vout );
-    emit askReleaseVideo( p_win );
+    if( fullscreenControls ) fullscreenControls->detachVout();
+    if( p_win )
+        emit askReleaseVideo( p_win );
 }
 
 void MainInterface::releaseVideoSlot( void *p_win )
@@ -697,11 +711,14 @@ void MainInterface::releaseVideoSlot( void *p_win )
     videoWidget->release( p_win );
     videoWidget->hide();
 
-    if( bgWidget )// WRONG
+    if( bgWasVisible )
+    {
+        bgWasVisible = false;
         bgWidget->show();
+    }
 
-    adjustSize();
     videoIsActive = false;
+    if( !isFullScreen() ) adjustSize();
 }
 
 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
@@ -798,6 +815,20 @@ void MainInterface::undockPlaylist()
 
 void MainInterface::toggleMinimalView()
 {
+    /* HACK for minimalView, see menus.cpp */
+    if( !menuBar()->isVisible() ) QVLCMenu::minimalViewAction->toggle();
+
+    if( i_visualmode != QT_ALWAYS_VIDEO_MODE &&
+        i_visualmode != QT_MINIMAL_MODE )
+    { /* NORMAL MODE then */
+        if( videoWidget->isHidden() ) emit askBgWidgetToToggle();
+        else
+        {
+            /* If video is visible, then toggle the status of bgWidget */
+            bgWasVisible = !bgWasVisible;      
+        }
+    }
+
     TOGGLEV( menuBar() );
     TOGGLEV( controls );
     TOGGLEV( statusBar() );
@@ -817,6 +848,7 @@ void MainInterface::doComponentsUpdate()
 void MainInterface::toggleAdvanced()
 {
     controls->toggleAdvanced();
+    if( fullscreenControls ) fullscreenControls->toggleAdvanced();
 }
 
 /* Get the visibility status of the controls (hidden or not, advanced or not) */
@@ -883,13 +915,18 @@ void MainInterface::setName( QString name )
 
 void MainInterface::setStatus( int status )
 {
-    msg_Dbg( p_intf, "I was here, updating your status" );
+    msg_Dbg( p_intf, "Updating the stream status: %i", status );
+
     /* Forward the status to the controls to toggle Play/Pause */
     controls->setStatus( status );
-    fullscreenControls->setStatus( status );
-
     controls->updateInput();
-    fullscreenControls->updateInput();
+
+    if( fullscreenControls )
+    {
+        fullscreenControls->setStatus( status );
+        fullscreenControls->updateInput();
+    }
+
     speedControl->setEnable( THEMIM->getIM()->hasInput() );
 
     /* And in the systray for the menu */
@@ -1209,7 +1246,8 @@ static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
                        vlc_value_t old_val, vlc_value_t new_val, void *param )
 {
     intf_thread_t *p_intf = (intf_thread_t *)param;
-    p_intf->p_sys->p_mi->requestLayoutUpdate();
+    p_intf->p_sys->p_mi->toggleFSC();
 
-    return VLC_SUCCESS;
+    /* Show event */
+     return VLC_SUCCESS;
 }