]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/interface_widgets.cpp
Code Cosmetics
[vlc] / modules / gui / qt4 / components / interface_widgets.cpp
index d90ef7693cf9f8871f18640ff31d160ccf902302..8f77aaaf1ec121b4d694362709add8aa12596ac5 100644 (file)
 #include <QPalette>
 #include <QResizeEvent>
 #include <QDate>
+#ifdef Q_WS_X11
+# include <X11/Xlib.h>
+# include <qx11info_x11.h>
+#endif
 
 /**********************************************************************
  * 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 )
 {
@@ -65,17 +65,27 @@ VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
     hide(); setMinimumSize( 16, 16 );
     videoSize.rwidth() = -1;
     videoSize.rheight() = -1;
+    setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
 
     /* Black background is more coherent for a Video Widget IMVHO */
     QPalette plt =  palette();
     plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
     plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
     setPalette( plt );
+    setAttribute( Qt::WA_PaintOnScreen, true );
+
+    /* The core can ask through a callback to show the video. */
+    connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
+             this, SLOT(SetSizing(unsigned int, unsigned int )),
+             Qt::BlockingQueuedConnection );
+}
 
-    /* The core can ask through a callback to show the video */
-    CONNECT( this, askVideoWidgetToShow(), this, show() );
-    /* The core can ask through a callback to resize the video */
-   // CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) );
+void VideoWidget::paintEvent(QPaintEvent *ev)
+{
+    QFrame::paintEvent(ev);
+#ifdef Q_WS_X11
+    XFlush( QX11Info::display() );
+#endif
 }
 
 VideoWidget::~VideoWidget()
@@ -105,13 +115,14 @@ void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
                            unsigned int *pi_width, unsigned int *pi_height )
 {
     msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
-    emit askVideoWidgetToShow();
+    emit askVideoWidgetToShow( *pi_width, *pi_height );
     if( p_vout )
     {
         msg_Dbg( p_intf, "embedded video already in use" );
         return NULL;
     }
     p_vout = p_nvout;
+    msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
     return ( void* )winId();
 }
 
@@ -123,6 +134,7 @@ void VideoWidget::SetSizing( unsigned int w, unsigned int h )
     msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
     videoSize.rwidth() = w;
     videoSize.rheight() = h;
+    if( isHidden() ) show();
     updateGeometry(); // Needed for deinterlace
 }
 
@@ -388,11 +400,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 +476,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" ) );
+    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 );
@@ -497,18 +504,34 @@ ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
     telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
     telexLayout->addWidget( telexPage );
 
-    controlLayout->addWidget( telexFrame, 1, 10, 2, 3, Qt::AlignBottom );
-    telexFrame->hide();
+    if( !b_fsCreation )
+        controlLayout->addWidget( telexFrame, 1, 10, 2, 4, Qt::AlignBottom );
+    telexFrame->hide(); /* default hidden */
 
     CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
              telexGotoPage( int ) );
+    CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
+              telexPage, setValue( int ) );
+
+    BUTTON_SET_IMG( telexOn, "", tv.png, qtr( "Teletext on" ) );
+
+    CONNECT( telexOn, clicked(), THEMIM->getIM(),
+             telexToggleButtons() );
     CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
              telexToggle( bool ) );
+    CONNECT( THEMIM->getIM(), toggleTelexButtons(),
+              this, toggleTeletext() );
+    b_telexEnabled = false;
+    telexTransparent->setEnabled( false );
+    telexPage->setEnabled( false );
+
+    BUTTON_SET_IMG( telexTransparent, "", tvtelx.png, qtr( "Teletext" ) );
     CONNECT( telexTransparent, clicked( bool ),
-             THEMIM->getIM(), telexSetTransparency( bool ) );
+             THEMIM->getIM(), telexSetTransparency() );
+    CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
+              this, toggleTeletextTransparency() );
     CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
              telexFrame, setVisible( bool ) );
-#endif
 
     /** Play Buttons **/
     QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
@@ -637,6 +660,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 +883,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 +899,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 +1025,7 @@ void FullscreenControllerWidget::customEvent( QEvent *event )
         #endif
 
 #if HAVE_TRANSPARENCY
-        setWindowOpacity( 0.75 );
+        setWindowOpacity( DEFAULT_OPACITY );
 #endif
     }
     else if ( type == FullscreenControlHide_Type )
@@ -1106,9 +1156,11 @@ static int regMouseMoveCallback( vlc_object_t *vlc_object, const char *variable,
         var_DelCallback( p_vout, "mouse-moved",
                         showFullscreenControllCallback, (void *) p_fs );
         b_registered = false;
-        p_fs->hide();
     }
 
+    if ( !var_GetBool( p_vout, "fullscreen" ) )
+        p_fs->hide();
+
     return VLC_SUCCESS;
 }
 
@@ -1122,7 +1174,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) );