]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/main_interface.cpp
Always create a new object with the parent object
[vlc] / modules / gui / qt4 / main_interface.cpp
index ef0bce8782f899f28e1613010bf84b91e0d9ce91..b88f58680170894a9a8d879597f7034f89e82fdf 100644 (file)
@@ -102,6 +102,9 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     setWindowRole( "vlc-main" );
     setWindowIcon( QApplication::windowIcon() );
     setWindowOpacity( var_InheritFloat( p_intf, "qt-opacity" ) );
+#ifdef Q_WS_MAC
+    setAttribute( Qt::WA_MacBrushedMetal );
+#endif
 
     /* Is video in embedded in the UI or not */
     b_videoEmbedded = var_InheritBool( p_intf, "embedded-video" );
@@ -119,15 +122,20 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     settings = getSettings();
     settings->beginGroup( "MainWindow" );
 
+#ifdef WIN32
+    /* Volume keys */
+    p_intf->p_sys->disable_volume_keys = var_InheritBool( p_intf, "qt-disable-volume-keys" );
+#endif
+
     /* */
     b_plDocked = getSettings()->value( "pl-dock-status", true ).toBool();
 
     settings->endGroup( );
 
-    /**************
-     * Status Bar *
-     **************/
-    createStatusBar();
+    /*********************************
+     * Create the Systray Management *
+     *********************************/
+    initSystray();
 
     /**************************
      *  UI and Widgets design
@@ -142,10 +150,12 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
              this, destroyPopupMenu() );
 
     createMainWidget( settings );
-    /*********************************
-     * Create the Systray Management *
-     *********************************/
-    initSystray();
+
+    /**************
+     * Status Bar *
+     **************/
+    createStatusBar();
+    setStatusBarVisibility( getSettings()->value( "MainWindow/status-bar-visible", false ).toBool() );
 
     /********************
      * Input Manager    *
@@ -190,7 +200,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 #ifndef HAVE_MAEMO
     if( sysTray )
     {
-        CONNECT( THEMIM->getIM(), statusChanged( int ),
+        CONNECT( THEMIM->getIM(), playingStatusChanged( int ),
                  this, updateSystrayTooltipStatus( int ) );
     }
 #endif
@@ -199,7 +209,6 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 
     /* VideoWidget connects for asynchronous calls */
     b_videoFullScreen = false;
-    b_videoOnTop = false;
     connect( this, SIGNAL(askGetVideo(WId*,int*,int*,unsigned*,unsigned *)),
              this, SLOT(getVideoSlot(WId*,int*,int*,unsigned*,unsigned*)),
              Qt::BlockingQueuedConnection );
@@ -223,6 +232,8 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 
     CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
 
+    CONNECT( this, askToQuit(), THEDP, quit() );
+
     /** END of CONNECTS**/
 
 
@@ -241,7 +252,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 
     /**** FINAL SIZING and placement of interface */
     settings->beginGroup( "MainWindow" );
-    QVLCTools::restoreWidgetPosition( settings, this, QSize(400, 100) );
+    QVLCTools::restoreWidgetPosition( settings, this, QSize(600, 420) );
     settings->endGroup();
 
     b_interfaceFullScreen = isFullScreen();
@@ -249,12 +260,13 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /* Final sizing and showing */
     setVisible( !b_hideAfterCreation );
 
-    setMinimumWidth( __MAX( controls->sizeHint().width(),
-                            menuBar()->sizeHint().width() ) + 30 );
+    computeMinimumSize();
 
     /* Switch to minimal view if needed, must be called after the show() */
     if( b_minimalView )
         toggleMinimalView( true );
+
+    b_hasPausedWhenMinimized = false;
 }
 
 MainInterface::~MainInterface()
@@ -263,6 +275,9 @@ MainInterface::~MainInterface()
     if( stackCentralOldWidget == videoWidget )
         showTab( bgWidget );
 
+    if( videoWidget )
+        releaseVideoSlot();
+
 #ifdef WIN32
     if( himl )
         ImageList_Destroy( himl );
@@ -286,15 +301,11 @@ MainInterface::~MainInterface()
     settings->setValue( "pl-dock-status", b_plDocked );
     /* Save playlist state */
     if( playlistWidget )
-    {
-        settings->setValue( "playlist-visible",
-                            isPlDocked() ?
-                            playlistVisible :
-                            playlistWidget->isVisible() /* FIXME */ );
-    }
+        settings->setValue( "playlist-visible", playlistVisible );
 
     settings->setValue( "adv-controls",
                         getControlsVisibilityStatus() & CONTROLS_ADVANCED );
+    settings->setValue( "status-bar-visible", b_statusbarVisible );
 
     /* Save the stackCentralW sizes */
     settings->setValue( "bgSize", stackWidgetsSizes[bgWidget] );
@@ -320,6 +331,15 @@ MainInterface::~MainInterface()
     p_intf->p_sys->p_mi = NULL;
 }
 
+void MainInterface::computeMinimumSize()
+{
+    int minWidth = 30;
+    if( menuBar()->isVisible() )
+        minWidth += __MAX( controls->sizeHint().width(), menuBar()->sizeHint().width() );
+
+    setMinimumWidth( minWidth );
+}
+
 /*****************************
  *   Main UI handling        *
  *****************************/
@@ -362,6 +382,11 @@ void MainInterface::createMainWidget( QSettings *settings )
     /* Bg Cone */
     bgWidget = new BackgroundWidget( p_intf );
     stackCentralW->addWidget( bgWidget );
+    if ( !var_InheritBool( p_intf, "qt-bgcone" ) )
+        bgWidget->setWithArt( false );
+    else
+        if ( var_InheritBool( p_intf, "qt-bgcone-expands" ) )
+            bgWidget->setExpandstoHeight( true );
 
     /* And video Outputs */
     if( b_videoEmbedded )
@@ -372,7 +397,7 @@ void MainInterface::createMainWidget( QSettings *settings )
     mainLayout->insertWidget( 1, stackCentralW );
 
     settings->beginGroup( "MainWindow" );
-    stackWidgetsSizes[bgWidget] = settings->value( "bgSize", QSize( 400, 0 ) ).toSize();
+    stackWidgetsSizes[bgWidget] = settings->value( "bgSize", QSize( 600, 0 ) ).toSize();
     /* Resize even if no-auto-resize, because we are at creation */
     resizeStack( stackWidgetsSizes[bgWidget].width(), stackWidgetsSizes[bgWidget].height() );
 
@@ -453,6 +478,8 @@ inline void MainInterface::createStatusBar()
             "QLabel:hover { background-color: rgba(255, 255, 255, 50%) }" );
     speedLabel->setStyleSheet(
             "QLabel:hover { background-color: rgba(255, 255, 255, 50%) }" );
+    /* pad both label and its tooltip */
+    nameLabel->setStyleSheet( "padding-left: 5px; padding-right: 5px;" );
 
     /* and adding those */
     statusBarr->addWidget( nameLabel, 8 );
@@ -470,6 +497,14 @@ inline void MainInterface::createStatusBar()
 
     CONNECT( THEMIM->getIM(), seekRequested( float ),
              timeLabel, setDisplayPosition( float ) );
+
+    /* This shouldn't be necessary, but for somehow reason, the statusBarr
+       starts at height of 20px and when a text is shown it needs more space.
+       But, as the QMainWindow policy doesn't allow statusBar to change QMW's
+       geometry, we need to force a height. If you have a better idea, please
+       tell me -- jb
+     */
+    statusBarr->setFixedHeight( statusBarr->sizeHint().height() + 2 );
 }
 
 /**********************************************************************
@@ -517,7 +552,7 @@ void MainInterface::destroyPopupMenu()
     QVLCMenu::PopupMenu( p_intf, false );
 }
 
-void MainInterface::popupMenu( const QPoint &p )
+void MainInterface::popupMenu( const QPoint & )
 {
     QVLCMenu::PopupMenu( p_intf, true );
 }
@@ -526,7 +561,7 @@ void MainInterface::toggleFSC()
 {
    if( !fullscreenControls ) return;
 
-   IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
+   IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type );
    QApplication::postEvent( fullscreenControls, eShow );
 }
 
@@ -557,6 +592,10 @@ WId MainInterface::getVideo( int *pi_x, int *pi_y,
 void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
                                   unsigned *pi_width, unsigned *pi_height )
 {
+    /* Hidden or minimized, activate */
+    if( isHidden() || isMinimized() )
+        toggleUpdateSystrayMenu();
+
     /* Request the videoWidget */
     WId ret = videoWidget->request( pi_x, pi_y,
                                     pi_width, pi_height, !b_autoresize );
@@ -581,6 +620,10 @@ void MainInterface::releaseVideo( void )
 /* Function that is CONNECTED to the previous emit */
 void MainInterface::releaseVideoSlot( void )
 {
+    /* This function is called when the embedded video window is destroyed,
+     * or in the rare case that the embedded window is still here but the
+     * Qt4 interface exits. */
+    assert( videoWidget );
     videoWidget->release();
     setVideoOnTop( false );
     setVideoFullScreen( false );
@@ -636,16 +679,14 @@ void MainInterface::setVideoFullScreen( bool fs )
  * Emit askVideoOnTop() to invoke this from other thread. */
 void MainInterface::setVideoOnTop( bool on_top )
 {
-    b_videoOnTop = on_top;
-
     Qt::WindowFlags oldflags = windowFlags(), newflags;
 
-    if( b_videoOnTop )
+    if( on_top )
         newflags = oldflags | Qt::WindowStaysOnTopHint;
     else
         newflags = oldflags & ~Qt::WindowStaysOnTopHint;
+    if( newflags != oldflags && !b_videoFullScreen )
 
-    if( newflags != oldflags )
     {
         setWindowFlags( newflags );
         show(); /* necessary to apply window flags */
@@ -699,7 +740,7 @@ void MainInterface::createPlaylist()
     if( b_plDocked )
     {
         stackCentralW->addWidget( playlistWidget );
-        stackWidgetsSizes[playlistWidget] = settings->value( "playlistSize", QSize( 500, 250 ) ).toSize();
+        stackWidgetsSizes[playlistWidget] = settings->value( "playlistSize", QSize( 600, 300 ) ).toSize();
     }
     else
     {
@@ -776,16 +817,22 @@ void MainInterface::dockPlaylist( bool p_docked )
     playlistVisible = true;
 }
 
+/*
+ * setMinimalView is the private function used by
+ * the SLOT toggleMinimalView and setVideoFullScreen
+ */
 void MainInterface::setMinimalView( bool b_minimal )
 {
     menuBar()->setVisible( !b_minimal );
     controls->setVisible( !b_minimal );
-    statusBar()->setVisible( !b_minimal );
+    statusBar()->setVisible( !b_minimal && b_statusbarVisible );
     inputC->setVisible( !b_minimal );
 }
 
 /*
-  If b_minimal is false, then we are normalView
+ * This public SLOT is used for moving to minimal View Mode
+ *
+ * If b_minimal is false, then we are normalView
  */
 void MainInterface::toggleMinimalView( bool b_minimal )
 {
@@ -801,7 +848,10 @@ void MainInterface::toggleMinimalView( bool b_minimal )
     }
     b_minimalView = b_minimal;
     if( !b_videoFullScreen )
+    {
         setMinimalView( b_minimalView );
+        computeMinimumSize();
+    }
 
     emit minimalViewToggled( b_minimalView );
 }
@@ -821,6 +871,13 @@ int MainInterface::getControlsVisibilityStatus()
                 + CONTROLS_ADVANCED * controls->b_advancedVisible );
 }
 
+void MainInterface::setStatusBarVisibility( bool b_visible )
+{
+    statusBar()->setVisible( b_visible );
+    b_statusbarVisible = b_visible;
+    if( controls ) controls->setGripVisible( !b_statusbarVisible );
+}
+
 #if 0
 void MainInterface::visual()
 {
@@ -850,8 +907,8 @@ void MainInterface::setName( const QString& name )
     input_name = name; /* store it for the QSystray use */
     /* Display it in the status bar, but also as a Tooltip in case it doesn't
        fit in the label */
-    nameLabel->setText( " " + name + " " );
-    nameLabel->setToolTip( " " + name +" " );
+    nameLabel->setText( name );
+    nameLabel->setToolTip( name );
 }
 
 /**
@@ -901,8 +958,8 @@ void MainInterface::showBuffering( float f_cache )
 void MainInterface::createSystray()
 {
     QIcon iconVLC;
-    if( QDate::currentDate().dayOfYear() >= 354 )
-        iconVLC =  QIcon( ":/logo/vlc128-christmas.png" );
+    if( QDate::currentDate().dayOfYear() >= QT_XMAS_JOKE_DAY && var_InheritBool( p_intf, "qt-icon-change" ) )
+        iconVLC =  QIcon( ":/logo/vlc128-xmas.png" );
     else
         iconVLC =  QIcon( ":/logo/vlc128.png" );
     sysTray = new QSystemTrayIcon( iconVLC, this );
@@ -915,7 +972,7 @@ void MainInterface::createSystray()
     sysTray->show();
 
     CONNECT( sysTray, activated( QSystemTrayIcon::ActivationReason ),
-            this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
+             this, handleSystrayClick( QSystemTrayIcon::ActivationReason ) );
 }
 
 /**
@@ -966,6 +1023,23 @@ void MainInterface::toggleUpdateSystrayMenu()
     QVLCMenu::updateSystrayMenu( this, p_intf );
 }
 
+void MainInterface::showUpdateSystrayMenu()
+{
+    if( isHidden() )
+        show();
+    if( isMinimized() )
+        showNormal();
+    activateWindow();
+
+    QVLCMenu::updateSystrayMenu( this, p_intf );
+}
+
+void MainInterface::hideUpdateSystrayMenu()
+{
+    hide();
+    QVLCMenu::updateSystrayMenu( this, p_intf );
+}
+
 void MainInterface::handleSystrayClick(
                                     QSystemTrayIcon::ActivationReason reason )
 {
@@ -973,7 +1047,11 @@ void MainInterface::handleSystrayClick(
     {
         case QSystemTrayIcon::Trigger:
         case QSystemTrayIcon::DoubleClick:
+#ifdef Q_WS_MAC
+            QVLCMenu::updateSystrayMenu( this, p_intf );
+#else
             toggleUpdateSystrayMenu();
+#endif
             break;
         case QSystemTrayIcon::MiddleClick:
             sysTray->showMessage( qtr( "VLC media player" ),
@@ -1030,6 +1108,39 @@ void MainInterface::updateSystrayTooltipStatus( int i_status )
 }
 #endif
 
+void MainInterface::changeEvent(QEvent *event)
+{
+    if( event->type() == QEvent::WindowStateChange )
+    {
+        QWindowStateChangeEvent *windowStateChangeEvent = static_cast<QWindowStateChangeEvent*>(event);
+        Qt::WindowStates newState = windowState();
+        Qt::WindowStates oldState = windowStateChangeEvent->oldState();
+
+        if( newState & Qt::WindowMinimized )
+        {
+            b_hasPausedWhenMinimized = false;
+
+            if( THEMIM->getIM()->playingStatus() == PLAYING_S &&
+                THEMIM->getIM()->hasVideo() &&
+                !THEMIM->getIM()->hasVisualisation() &&
+                var_InheritBool( p_intf, "qt-pause-minimized" ) )
+            {
+                b_hasPausedWhenMinimized = true;
+                THEMIM->pause();
+            }
+        }
+        else if( oldState & Qt::WindowMinimized && !( newState & Qt::WindowMinimized ) )
+        {
+            if( b_hasPausedWhenMinimized )
+            {
+                THEMIM->play();
+            }
+        }
+    }
+
+    QWidget::changeEvent(event);
+}
+
 /************************************************************************
  * D&D Events
  ************************************************************************/
@@ -1064,11 +1175,10 @@ void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
     {
         if( url.isValid() )
         {
-            char* psz_uri = make_URI( qtu( url.toString() ) );
-            playlist_Add( THEPL, psz_uri, NULL,
+            QString mrl = toURI( url.toEncoded().constData() );
+            playlist_Add( THEPL, qtu(mrl), NULL,
                           PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
                           PLAYLIST_END, true, pl_Unlocked );
-            free( psz_uri );
             first = false;
             RecentsMRL::getInstance( p_intf )->addRecent( url.toString() );
         }
@@ -1080,11 +1190,10 @@ void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
     if( !mimeData->hasUrls() && mimeData->hasText() &&
         QUrl(mimeData->text()).isValid() )
     {
-        char *psz_uri = make_URI( qtu( mimeData->text() ) );
-        playlist_Add( THEPL, psz_uri, NULL,
+        QString mrl = toURI( mimeData->text() );
+        playlist_Add( THEPL, qtu(mrl), NULL,
                       PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
                       PLAYLIST_END, true, pl_Unlocked );
-        free( psz_uri );
     }
     event->accept();
 }
@@ -1136,9 +1245,9 @@ void MainInterface::wheelEvent( QWheelEvent *e )
 
 void MainInterface::closeEvent( QCloseEvent *e )
 {
-    e->accept();
-    hide();
-    THEDP->quit();
+    e->ignore();      /* Do not quit */
+//  hide();
+    emit askToQuit(); /* ask THEDP to quit, so we have a unique method */
 }
 
 void MainInterface::setInterfaceFullScreen( bool fs )
@@ -1164,6 +1273,8 @@ void MainInterface::toggleInterfaceFullScreen()
 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
                         vlc_value_t old_val, vlc_value_t new_val, void *param )
 {
+    VLC_UNUSED( p_this ); VLC_UNUSED( psz_variable ); VLC_UNUSED( old_val );
+
     intf_thread_t *p_intf = (intf_thread_t *)param;
 
     if( p_intf->pf_show_dialog )
@@ -1181,6 +1292,9 @@ static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
 static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
                        vlc_value_t old_val, vlc_value_t new_val, void *param )
 {
+    VLC_UNUSED( p_this ); VLC_UNUSED( psz_variable ); VLC_UNUSED( old_val );
+    VLC_UNUSED( new_val );
+
     intf_thread_t *p_intf = (intf_thread_t *)param;
     p_intf->p_sys->p_mi->toggleFSC();