]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/main_interface.cpp
Qt4 - popupMenu and AlwaysOnTop. Needs testing.
[vlc] / modules / gui / qt4 / main_interface.cpp
index 6b0a77ae29c46bc1b5e70ba9faa8e7931dddad7f..16bb64003b79eb4ba455dc4d0d2e254cb6292d04 100644 (file)
 
 #define DS(i) i.width(),i.height()
 
+/* Callback prototypes */
+static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
+                        vlc_value_t old_val, vlc_value_t new_val, void *param );
+static int IntfShowCB( vlc_object_t *p_this, const char *psz_variable,
+                       vlc_value_t old_val, vlc_value_t new_val, void *param );
 static int InteractCallback( vlc_object_t *, const char *, vlc_value_t,
                              vlc_value_t, void *);
 /* Video handling */
@@ -75,16 +80,14 @@ static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
     return p_intf->p_sys->p_mi->controlVideo( p_win, i_q, a );
 }
 
-bool embeddedPlaylistWasActive;
-bool videoIsActive;
-QSize savedVideoSize;
-
 MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 {
     /* Configuration */
     settings = new QSettings( "VideoLAN", "VLC" );
     settings->beginGroup( "MainWindow" );
 
+    setWindowIcon( QApplication::windowIcon() );
+
     need_components_update = false;
     bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL;
     embeddedPlaylistWasActive = videoIsActive = false;
@@ -140,10 +143,30 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
     var_AddCallback( p_intf, "interaction", InteractCallback, this );
     p_intf->b_interaction = VLC_TRUE;
+
+    /* Register callback for the intf-popupmenu variable */
+    playlist_t *p_playlist =
+        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
+    if( p_playlist != NULL )
+    {
+        var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
+        var_AddCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
+        vlc_object_release( p_playlist );
+    }
 }
 
 MainInterface::~MainInterface()
 {
+    /* Unregister callback for the intf-popupmenu variable */
+    playlist_t *p_playlist =
+        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
+    if( p_playlist != NULL )
+    {
+        var_DelCallback( p_playlist, "intf-popupmenu", PopupMenuCB, p_intf );
+        var_DelCallback( p_playlist, "intf-show", IntfShowCB, p_intf );
+        vlc_object_release( p_playlist );
+    }
+
     settings->setValue( "playlist-embedded", playlistEmbeddedFlag );
     settings->setValue( "adv-controls", advControlsEnabled );
     settings->setValue( "pos", pos() );
@@ -292,13 +315,13 @@ void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
         if( VISIBLE( playlistWidget ) )
         {
             embeddedPlaylistWasActive = true;
-            playlistWidget->hide();
+//            playlistWidget->hide();
         }
         bool bgWasVisible = false;
         if( VISIBLE( bgWidget) )
         {
             bgWasVisible = true;
-            bgWidget->hide();
+//            bgWidget->hide();
         }
         if( THEMIM->getIM()->hasVideo() || !bgWasVisible )
         {
@@ -311,7 +334,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(); /// FIXME: Needed ?
         need_components_update = true;
     }
     return ret;
@@ -324,14 +347,31 @@ void MainInterface::releaseVideo( void *p_win )
     videoWidget->resize( videoWidget->widgetSize );
 
     if( embeddedPlaylistWasActive )
-        playlistWidget->show();
+        ;//playlistWidget->show();
     else if( bgWidget )
-        bgWidget->show();
+        ;//bgWidget->show();
 
     videoIsActive = false;
     need_components_update = true;
 }
 
+class SetVideoOnTopQtEvent : public QEvent
+{
+public:
+    SetVideoOnTopQtEvent( bool _onTop ) :
+      QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
+    {
+    }
+
+    bool OnTop() const
+    {
+        return onTop;
+    }
+
+private:
+    bool onTop;
+};
+
 int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
 {
     int i_ret = VLC_EGENERIC;
@@ -351,12 +391,18 @@ int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
             unsigned int i_width  = va_arg( args, unsigned int );
             unsigned int i_height = va_arg( args, unsigned int );
             videoWidget->widgetSize = QSize( i_width, i_height );
-            videoWidget->updateGeometry();
+            // videoWidget->updateGeometry();
             need_components_update = true;
             i_ret = VLC_SUCCESS;
             break;
         }
         case VOUT_SET_STAY_ON_TOP:
+        {
+            int i_arg = va_arg( args, int );
+            QApplication::postEvent( this, new SetVideoOnTopQtEvent( i_arg ) );
+            i_ret = VLC_SUCCESS;
+            break;
+        }
         default:
             msg_Warn( p_intf, "unsupported control query" );
             break;
@@ -491,6 +537,15 @@ void MainInterface::customEvent( QEvent *event )
                                 visualSelectorEnabled);
         playlist();
     }
+    else if ( event->type() == SetVideoOnTopEvent_Type )
+    {
+        SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
+        if( p_event->OnTop() )
+            setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
+        else
+            setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);            
+        show(); /* necessary to apply window flags?? */
+    }
 }
 
 
@@ -555,9 +610,16 @@ void MainInterface::keyPressEvent( QKeyEvent *e )
         e->ignore();
 }
 
+void MainInterface::wheelEvent( QWheelEvent *e )
+{
+    int i_vlckey = qtWheelEventToVLCKey( e );
+    var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
+    e->accept();
+}
+
 void MainInterface::stop()
 {
-    playlist_Stop( THEPL );
+    THEMIM->stop();
 }
 void MainInterface::play()
 {
@@ -572,11 +634,11 @@ void MainInterface::play()
 }
 void MainInterface::prev()
 {
-    playlist_Prev( THEPL );
+    THEMIM->prev();
 }
 void MainInterface::next()
 {
-    playlist_Next( THEPL );
+    THEMIM->next();
 }
 
 void MainInterface::setDisplay( float pos, int time, int length )
@@ -689,3 +751,34 @@ static int InteractCallback( vlc_object_t *p_this,
     QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
     return VLC_SUCCESS;
 }
+
+/*****************************************************************************
+ * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
+ *  We don't show the menu directly here because we don't want the
+ *  caller to block for a too long time.
+ *****************************************************************************/
+static int PopupMenuCB( 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;
+
+    if( p_intf->pf_show_dialog )
+    {
+        p_intf->pf_show_dialog( p_intf, INTF_DIALOG_POPUPMENU,
+                                new_val.b_bool, 0 );
+    }
+
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * IntfShowCB: callback triggered by the intf-show playlist 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 )
+{
+    intf_thread_t *p_intf = (intf_thread_t *)param;
+    //p_intf->p_sys->b_intf_show = VLC_TRUE;
+
+    return VLC_SUCCESS;
+}