]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/interface_widgets.cpp
Qt4: wait until the video output is ready
[vlc] / modules / gui / qt4 / components / interface_widgets.cpp
index d90ef7693cf9f8871f18640ff31d160ccf902302..f31e75b8d826b3d9e876b9bdaf571c3a05929696 100644 (file)
  * Video Widget. A simple frame on which video is drawn
  * This class handles resize issues
  **********************************************************************/
-static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
-                        unsigned int *, unsigned int * );
-static void DoRelease( intf_thread_t *, void * );
-static int DoControl( intf_thread_t *, void *, int, va_list );
 
 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
 {
@@ -72,8 +68,14 @@ VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
     plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
     setPalette( plt );
 
-    /* The core can ask through a callback to show the video */
-    CONNECT( this, askVideoWidgetToShow(), this, show() );
+    /* The core can ask through a callback to show the video.
+     * NOTE: We need to block the video output core until the window handle
+     * is ready for use (otherwise an X11 invalid handle failure may occur).
+     * As a side effect, it is illegal to emit askVideoWidgetToShow from
+     * the same thread as the Qt4 thread that owns this. */
+    QObject::connect( this, SIGNAL(askVideoWidgetToShow()), this, SLOT(show()),
+                      Qt::BlockingQueuedConnection );
+
     /* The core can ask through a callback to resize the video */
    // CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) );
 }
@@ -112,6 +114,7 @@ void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
         return NULL;
     }
     p_vout = p_nvout;
+    msg_Dbg( p_intf, "embedded video handle %p", winId() );
     return ( void* )winId();
 }
 
@@ -388,11 +391,7 @@ ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
     controlLayout = new QGridLayout( );
 
     controlLayout->setSpacing( 0 );
-#if QT43
-    controlLayout->setContentsMargins( 9, 6, 9, 6 );
-#else
-    controlLayout->setMargin( 6 );
-#endif
+    controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
 
     if( !b_fsCreation )
         setLayout( controlLayout );
@@ -468,27 +467,26 @@ ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
              sectionNext() );
     CONNECT( menuButton, clicked(), THEMIM->getIM(),
              sectionMenu() );
+
     /**
      * Telextext QFrame
      * TODO: Merge with upper menu in a StackLayout
      **/
-#ifdef ZVBI_COMPILED
     telexFrame = new QWidget( this );
     QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
     telexLayout->setSpacing( 0 );
     telexLayout->setMargin( 0 );
 
-    QToolButton *telexOn = new QToolButton;
-    telexOn->setText( qtr( "On" ) );
+    QPushButton  *telexOn = new QPushButton;
     setupSmallButton( telexOn );
     telexLayout->addWidget( telexOn );
 
-    QToolButton *telexTransparent = new QToolButton;
-    telexTransparent->setText( qtr( "Transparent" ) );
+    telexTransparent = new QPushButton;
     setupSmallButton( telexTransparent );
     telexLayout->addWidget( telexTransparent );
+    b_telexTransparent = false;
 
-    QSpinBox *telexPage = new QSpinBox;
+    telexPage = new QSpinBox;
     telexPage->setRange( 0, 999 );
     telexPage->setValue( 100 );
     telexPage->setAccelerated( true );
@@ -498,17 +496,24 @@ ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
     telexLayout->addWidget( telexPage );
 
     controlLayout->addWidget( telexFrame, 1, 10, 2, 3, Qt::AlignBottom );
-    telexFrame->hide();
+    telexFrame->hide(); /* default hidden */
 
     CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
              telexGotoPage( int ) );
+
+    BUTTON_SET_ACT_I( telexOn, "", tv.png, qtr( "Teletext on" ),
+                      toggleTeletext() );
     CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
              telexToggle( bool ) );
+    telexTransparent->setEnabled( false );
+    telexPage->setEnabled( false );
+
+    BUTTON_SET_ACT_I( telexTransparent, "", tvtelx.png, qtr( "Teletext" ),
+                      toggleTeletextTransparency() );
     CONNECT( telexTransparent, clicked( bool ),
-             THEMIM->getIM(), telexSetTransparency( bool ) );
+             THEMIM->getIM(), telexSetTransparency() );
     CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
              telexFrame, setVisible( bool ) );
-#endif
 
     /** Play Buttons **/
     QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
@@ -637,6 +642,39 @@ ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
 ControlsWidget::~ControlsWidget()
 {}
 
+void ControlsWidget::toggleTeletext()
+{
+    bool b_enabled = THEMIM->teletextState();
+    if( b_telexEnabled )
+    {
+        telexTransparent->setEnabled( false );
+        telexPage->setEnabled( false );
+        b_telexEnabled = false;
+    }
+    else if( b_enabled )
+    {
+        telexTransparent->setEnabled( true );
+        telexPage->setEnabled( true );
+        b_telexEnabled = true;
+    }
+}
+
+void ControlsWidget::toggleTeletextTransparency()
+{
+    if( b_telexTransparent )
+    {
+        telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx.png" ) );
+        telexTransparent->setToolTip( qtr( "Teletext" ) );
+        b_telexTransparent = false;
+    }
+    else
+    {
+        telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx-transparent.png" ) );
+        telexTransparent->setToolTip( qtr( "Transparent" ) );
+        b_telexTransparent = true;
+    }
+}
+
 void ControlsWidget::stop()
 {
     THEMIM->stop();
@@ -827,11 +865,7 @@ FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
 
     QGridLayout *fsLayout = new QGridLayout( this );
     controlLayout->setSpacing( 0 );
-    #if QT43
-    controlLayout->setContentsMargins( 5, 1, 5, 1 );
-    #else
-    controlLayout->setMargin( 5 );
-    #endif
+    controlLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
 
     fsLayout->addWidget( slowerButton, 0, 0 );
     slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
@@ -847,9 +881,7 @@ FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
 
     fsLayout->addWidget( discFrame, 1, 4 );
 
-    #ifdef ZVBI_COMPILED
     fsLayout->addWidget( telexFrame, 1, 5 );
-    #endif
 
     fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
 
@@ -975,7 +1007,7 @@ void FullscreenControllerWidget::customEvent( QEvent *event )
         #endif
 
 #if HAVE_TRANSPARENCY
-        setWindowOpacity( 0.75 );
+        setWindowOpacity( DEFAULT_OPACITY );
 #endif
     }
     else if ( type == FullscreenControlHide_Type )
@@ -1122,7 +1154,7 @@ static int showFullscreenControllCallback( vlc_object_t *vlc_object, const char
 {
     FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
 
-    if ( p_fs->isFSCHidden() )
+    if ( p_fs->isFSCHidden() || p_fs->windowOpacity() < DEFAULT_OPACITY )
     {
         IMEvent *event = new IMEvent( FullscreenControlShow_Type, 0 );
         QApplication::postEvent( p_fs, static_cast<QEvent *>(event) );