[vlc-commits] commit: Qt4: convert on top event to signal/slot model ( Rémi Denis-Courmont )

git at videolan.org git at videolan.org
Sun May 30 17:02:43 CEST 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun May 30 17:29:35 2010 +0300| [7e26f748884c337eeafdd55c403c5ebce7e90f80] | committer: Rémi Denis-Courmont 

Qt4: convert on top event to signal/slot model

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7e26f748884c337eeafdd55c403c5ebce7e90f80
---

 modules/gui/qt4/main_interface.cpp |   58 +++++++++++++----------------------
 modules/gui/qt4/main_interface.hpp |    3 +-
 2 files changed, 24 insertions(+), 37 deletions(-)

diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index 9869640..add973c 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -204,6 +204,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     connect( this, SIGNAL(askReleaseVideo( void )),
              this, SLOT(releaseVideoSlot( void )),
              Qt::BlockingQueuedConnection );
+    CONNECT( this, askVideoOnTop(bool), this, setVideoOnTop(bool));
 
     if( videoWidget )
     {
@@ -531,21 +532,6 @@ void MainInterface::toggleFSC()
  * Video Handling
  ****************************************************************************/
 
-/* This event is used to deal with the fullscreen and always on top
-   issue conflict (bug in wx) */
-class SetVideoOnTopQtEvent : public QEvent
-{
-public:
-    SetVideoOnTopQtEvent( bool _onTop ) :
-      QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
-    {}
-
-    bool OnTop() const { return onTop; }
-
-private:
-    bool onTop;
-};
-
 /**
  * NOTE:
  * You must not change the state of this object or other Qt4 UI objects,
@@ -588,13 +574,13 @@ void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
 void MainInterface::releaseVideo( void )
 {
     emit askReleaseVideo();
-    QApplication::postEvent( this, new SetVideoOnTopQtEvent( false ) );
 }
 
 /* Function that is CONNECTED to the previous emit */
 void MainInterface::releaseVideoSlot( void )
 {
     videoWidget->release();
+    setVideoOnTop( false );
 
     if( stackCentralW->currentWidget() == videoWidget )
         restoreStackOldWidget();
@@ -603,6 +589,24 @@ void MainInterface::releaseVideoSlot( void )
     stackCentralOldWidget = bgWidget;
 }
 
+/* Slot to change the video always-on-top flag.
+ * Emit askVideoOnTop() to invoke this from other thread. */
+void MainInterface::setVideoOnTop( bool on_top )
+{
+    Qt::WindowFlags oldflags = windowFlags(), newflags;
+
+    if( on_top )
+        newflags = oldflags | Qt::WindowStaysOnTopHint;
+    else
+        newflags = oldflags & ~Qt::WindowStaysOnTopHint;
+
+    if( newflags != oldflags )
+    {
+        setWindowFlags( newflags );
+        show(); /* necessary to apply window flags */
+    }
+}
+
 /* Asynchronous call from WindowControl function */
 int MainInterface::controlVideo( int i_query, va_list args )
 {
@@ -621,7 +625,8 @@ int MainInterface::controlVideo( int i_query, va_list args )
     {
         unsigned i_arg = va_arg( args, unsigned );
         unsigned on_top = i_arg & VOUT_WINDOW_STATE_ABOVE;
-        QApplication::postEvent( this, new SetVideoOnTopQtEvent( on_top ) );
+
+        emit askVideoOnTop( on_top != 0 );
         return VLC_SUCCESS;
     }
     case VOUT_WINDOW_SET_FULLSCREEN:
@@ -1035,25 +1040,6 @@ void MainInterface::dragLeaveEvent(QDragLeaveEvent *event)
 /************************************************************************
  * Events stuff
  ************************************************************************/
-void MainInterface::customEvent( QEvent *event )
-{
-    if ( event->type() == (int)SetVideoOnTopEvent_Type )
-    {
-        SetVideoOnTopQtEvent* p_event = (SetVideoOnTopQtEvent*)event;
-        Qt::WindowFlags oldflags = windowFlags(), newflags;
-
-        if( p_event->OnTop() )
-            newflags = oldflags | Qt::WindowStaysOnTopHint;
-        else
-            newflags = oldflags & ~Qt::WindowStaysOnTopHint;
-        if( newflags != oldflags )
-        {
-            setWindowFlags( newflags );
-            show(); /* necessary to apply window flags */
-        }
-    }
-}
-
 void MainInterface::keyPressEvent( QKeyEvent *e )
 {
     handleKeyPress( e );
diff --git a/modules/gui/qt4/main_interface.hpp b/modules/gui/qt4/main_interface.hpp
index 3390190..28c852e 100644
--- a/modules/gui/qt4/main_interface.hpp
+++ b/modules/gui/qt4/main_interface.hpp
@@ -97,7 +97,6 @@ protected:
     virtual void dragMoveEvent( QDragMoveEvent * );
     virtual void dragLeaveEvent( QDragLeaveEvent * );
     virtual void closeEvent( QCloseEvent *);
-    virtual void customEvent( QEvent *);
     virtual void keyPressEvent( QKeyEvent *);
     virtual void wheelEvent( QWheelEvent * );
 
@@ -215,6 +214,7 @@ private slots:
             else resize( size() - stackCentralW->size() + QSize( w, h ) );
         debug(); }
 
+    void setVideoOnTop( bool );
 
 signals:
     void askGetVideo( WId *p_id, int *pi_x, int *pi_y,
@@ -222,6 +222,7 @@ signals:
     void askReleaseVideo( );
     void askVideoToResize( unsigned int, unsigned int );
     void askVideoSetFullScreen( bool );
+    void askVideoOnTop( bool );
     void minimalViewToggled( bool );
     void fullscreenInterfaceToggled( bool );
 



More information about the vlc-commits mailing list