]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/main_interface.cpp
Qt4: fix a minor (but annoying) UI glitch on restart
[vlc] / modules / gui / qt4 / main_interface.cpp
index bbb6014ac3d50c37f3f190f1113d7dbda2e40708..17810d90963031d0e7e49a929697a052bf04b00f 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" );
@@ -110,7 +113,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     b_autoresize = var_InheritBool( p_intf, "qt-video-autoresize" );
 
     /* Are we in the enhanced always-video mode or not ? */
-    i_visualmode = var_InheritInteger( p_intf, "qt-minimal-view" );
+    b_minimalView = var_InheritBool( p_intf, "qt-minimal-view" );
 
     /* Do we want anoying popups or not */
     b_notificationEnabled = var_InheritBool( p_intf, "qt-notification" );
@@ -219,8 +222,6 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
         }
         CONNECT( this, askVideoSetFullScreen( bool ),
                  this, setVideoFullScreen( bool ) );
-        CONNECT( videoWidget, keyPressed( QKeyEvent * ),
-                 this, handleKeyPress( QKeyEvent * ) );
     }
 
     CONNECT( THEDP, toolBarConfUpdated(), this, recreateToolbars() );
@@ -246,6 +247,8 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     QVLCTools::restoreWidgetPosition( settings, this, QSize(400, 100) );
     settings->endGroup();
 
+    b_interfaceFullScreen = isFullScreen();
+
     /* Final sizing and showing */
     setVisible( !b_hideAfterCreation );
 
@@ -253,7 +256,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
                             menuBar()->sizeHint().width() ) + 30 );
 
     /* Switch to minimal view if needed, must be called after the show() */
-    if( i_visualmode )
+    if( b_minimalView )
         toggleMinimalView( true );
 }
 
@@ -286,12 +289,7 @@ 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 );
@@ -470,6 +468,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 );
 }
 
 /**********************************************************************
@@ -583,6 +589,7 @@ void MainInterface::releaseVideoSlot( void )
 {
     videoWidget->release();
     setVideoOnTop( false );
+    setVideoFullScreen( false );
 
     if( stackCentralW->currentWidget() == videoWidget )
         restoreStackOldWidget();
@@ -593,17 +600,42 @@ void MainInterface::releaseVideoSlot( void )
 
 void MainInterface::setVideoSize( unsigned int w, unsigned int h )
 {
-    if( isFullScreen() || isMaximized() )
-        showNormal();
-    videoWidget->SetSizing( w, h );
+    if( !isFullScreen() && !isMaximized() )
+        videoWidget->SetSizing( w, h );
 }
 
 void MainInterface::setVideoFullScreen( bool fs )
 {
     b_videoFullScreen = fs;
-    /* refresh main interface on-top status if needed */
-    setVideoOnTop( b_videoOnTop );
-    videoWidget->SetFullScreen( fs );
+    if( fs )
+    {
+        int numscreen = var_InheritInteger( p_intf, "qt-fullscreen-screennumber" );
+        /* if user hasn't defined screennumber, or screennumber that is bigger
+         * than current number of screens, take screennumber where current interface
+         * is
+         */
+        if( numscreen == -1 || numscreen > QApplication::desktop()->numScreens() )
+            numscreen = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
+
+        QRect screenres = QApplication::desktop()->screenGeometry( numscreen );
+
+        /* To be sure window is on proper-screen in xinerama */
+        if( !screenres.contains( pos() ) )
+        {
+            msg_Dbg( p_intf, "Moving video to correct screen");
+            move( QPoint( screenres.x(), screenres.y() ) );
+        }
+        setMinimalView( true );
+        setInterfaceFullScreen( true );
+    }
+    else
+    {
+        /* TODO do we want to restore screen and position ? (when
+         * qt-fullscreen-screennumber is forced) */
+        setMinimalView( b_minimalView );
+        setInterfaceFullScreen( b_interfaceFullScreen );
+    }
+    videoWidget->sync();
 }
 
 /* Slot to change the video always-on-top flag.
@@ -611,14 +643,10 @@ void MainInterface::setVideoFullScreen( bool fs )
 void MainInterface::setVideoOnTop( bool on_top )
 {
     b_videoOnTop = on_top;
-    /* The main interface is not always-on-top if it does not contain
-     * the video (which is to say in fullscreen mode). */
-    if( b_videoFullScreen )
-        on_top = false;
 
     Qt::WindowFlags oldflags = windowFlags(), newflags;
 
-    if( on_top )
+    if( b_videoOnTop )
         newflags = oldflags | Qt::WindowStaysOnTopHint;
     else
         newflags = oldflags & ~Qt::WindowStaysOnTopHint;
@@ -754,12 +782,20 @@ void MainInterface::dockPlaylist( bool p_docked )
     playlistVisible = true;
 }
 
+void MainInterface::setMinimalView( bool b_minimal )
+{
+    menuBar()->setVisible( !b_minimal );
+    controls->setVisible( !b_minimal );
+    statusBar()->setVisible( !b_minimal );
+    inputC->setVisible( !b_minimal );
+}
+
 /*
-  If b_switch is false, then we are normalView
+  If b_minimal is false, then we are normalView
  */
-void MainInterface::toggleMinimalView( bool b_switch )
+void MainInterface::toggleMinimalView( bool b_minimal )
 {
-    if( i_visualmode == 0 && b_autoresize ) /* Normal mode */
+    if( !b_minimalView && b_autoresize ) /* Normal mode */
     {
         if( stackCentralW->currentWidget() == bgWidget )
         {
@@ -769,13 +805,11 @@ void MainInterface::toggleMinimalView( bool b_switch )
             }
         }
     }
+    b_minimalView = b_minimal;
+    if( !b_videoFullScreen )
+        setMinimalView( b_minimalView );
 
-    menuBar()->setVisible( !b_switch );
-    controls->setVisible( !b_switch );
-    statusBar()->setVisible( !b_switch );
-    inputC->setVisible( !b_switch );
-
-    emit minimalViewToggled( b_switch );
+    emit minimalViewToggled( b_minimalView );
 }
 
 /* toggling advanced controls buttons */
@@ -945,7 +979,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" ),
@@ -1012,8 +1050,9 @@ void MainInterface::dropEvent(QDropEvent *event)
 
 void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
 {
-    event->setDropAction( Qt::CopyAction );
-    if( !event->possibleActions() & Qt::CopyAction )
+    if( event->possibleActions() & Qt::CopyAction )
+       event->setDropAction( Qt::CopyAction );
+    else
         return;
 
     const QMimeData *mimeData = event->mimeData();
@@ -1033,18 +1072,30 @@ void MainInterface::dropEventPlay( QDropEvent *event, bool b_play )
     bool first = b_play;
     foreach( const QUrl &url, mimeData->urls() )
     {
-        QString s = toNativeSeparators( url.toLocalFile() );
-
-        if( s.length() > 0 ) {
-            char* psz_uri = make_URI( qtu(s) );
+        if( url.isValid() )
+        {
+            char* psz_uri = make_URI( qtu( url.toString() ), NULL );
             playlist_Add( THEPL, psz_uri, NULL,
                           PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
                           PLAYLIST_END, true, pl_Unlocked );
             free( psz_uri );
             first = false;
-            RecentsMRL::getInstance( p_intf )->addRecent( s );
+            RecentsMRL::getInstance( p_intf )->addRecent( url.toString() );
         }
     }
+
+    /* Browsers give content as text if you dnd the addressbar,
+       so check if mimedata has valid url in text and use it
+       if we didn't get any normal Urls()*/
+    if( !mimeData->hasUrls() && mimeData->hasText() &&
+        QUrl(mimeData->text()).isValid() )
+    {
+        char *psz_uri = make_URI( qtu( mimeData->text() ), NULL );
+        playlist_Add( THEPL, psz_uri, NULL,
+                      PLAYLIST_APPEND | (first ? PLAYLIST_GO: PLAYLIST_PREPARSE),
+                      PLAYLIST_END, true, pl_Unlocked );
+        free( psz_uri );
+    }
     event->accept();
 }
 void MainInterface::dragEnterEvent(QDragEnterEvent *event)
@@ -1070,10 +1121,9 @@ void MainInterface::keyPressEvent( QKeyEvent *e )
 
 void MainInterface::handleKeyPress( QKeyEvent *e )
 {
-    if( ( e->modifiers() &  Qt::ControlModifier ) && ( e->key() == Qt::Key_H )
-          && !menuBar()->isVisible() )
+    if( ( e->modifiers() &  Qt::ControlModifier ) && ( e->key() == Qt::Key_H ) )
     {
-        toggleMinimalView( false );
+        toggleMinimalView( !b_minimalView );
         e->accept();
     }
 
@@ -1101,18 +1151,19 @@ void MainInterface::closeEvent( QCloseEvent *e )
     THEDP->quit();
 }
 
-void MainInterface::toggleFullScreen()
+void MainInterface::setInterfaceFullScreen( bool fs )
 {
-    if( isFullScreen() )
-    {
-        showNormal();
-        emit fullscreenInterfaceToggled( false );
-    }
+    if( fs )
+        setWindowState( windowState() | Qt::WindowFullScreen );
     else
-    {
-        showFullScreen();
-        emit fullscreenInterfaceToggled( true );
-    }
+        setWindowState( windowState() & ~Qt::WindowFullScreen );
+}
+void MainInterface::toggleInterfaceFullScreen()
+{
+    b_interfaceFullScreen = !b_interfaceFullScreen;
+    if( !b_videoFullScreen )
+        setInterfaceFullScreen( b_interfaceFullScreen );
+    emit fullscreenInterfaceToggled( b_interfaceFullScreen );
 }
 
 /*****************************************************************************