]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/interface_widgets.cpp
Qt4: Fix a warning.
[vlc] / modules / gui / qt4 / components / interface_widgets.cpp
index 988b95dd9b80f7474f4ed7db1659d0e7b01adec5..e6ea283ec2cb7f48ebb2abd2ab21d8bfe5a0c9d9 100644 (file)
 #include <QBitmap>
 
 #ifdef Q_WS_X11
-# include <X11/Xlib.h>
-# include <qx11info_x11.h>
-static void videoSync( void )
-{
-    /* Make sure the X server has processed all requests.
-     * This protects other threads using distinct connections from getting
-     * the video widget window in an inconsistent states. */
-    XSync( QX11Info::display(), False );
-}
-#else
-# define videoSync() (void)0
+#   include <X11/Xlib.h>
+#   include <qx11info_x11.h>
 #endif
 
 #include <math.h>
 #include <assert.h>
 
-class ReparentableWidget : public QWidget
-{
-private:
-    VideoWidget *owner;
-public:
-    ReparentableWidget( VideoWidget *owner ) : owner( owner )
-    {}
-};
-
 /**********************************************************************
  * Video Widget. A simple frame on which video is drawn
  * This class handles resize issues
  **********************************************************************/
 
 VideoWidget::VideoWidget( intf_thread_t *_p_i )
-    : QFrame( NULL )
-      , p_intf( _p_i )
-      , reparentable( NULL )
+            : QFrame( NULL ) , p_intf( _p_i )
 {
     /* Set the policy to expand in both directions */
     // setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
 
     layout = new QHBoxLayout( this );
     layout->setContentsMargins( 0, 0, 0, 0 );
-    setLayout( layout );
+    stable = NULL;
+    show();
 }
 
 VideoWidget::~VideoWidget()
 {
     /* Ensure we are not leaking the video output. This would crash. */
-    assert( reparentable == NULL );
+    assert( !stable );
+}
+
+void VideoWidget::sync( void )
+{
+#ifdef Q_WS_X11
+    /* Make sure the X server has processed all requests.
+     * This protects other threads using distinct connections from getting
+     * the video widget window in an inconsistent states. */
+    XSync( QX11Info::display(), False );
+#endif
 }
 
 /**
@@ -109,10 +100,10 @@ WId VideoWidget::request( int *pi_x, int *pi_y,
 {
     msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
 
-    if( reparentable != NULL )
+    if( stable )
     {
         msg_Dbg( p_intf, "embedded video already in use" );
-        return NULL;
+        return 0;
     }
     if( b_keep_size )
     {
@@ -120,20 +111,10 @@ WId VideoWidget::request( int *pi_x, int *pi_y,
         *pi_height = size().height();
     }
 
-    /* The Qt4 UI needs a fixed a widget ("this"), so that the parent layout is
-     * not messed up when we the video is reparented. Hence, we create an extra
-     * reparentable widget, that will be within the VideoWidget in windowed
-     * mode, and within the root window (NULL parent) in full-screen mode.
-     */
-    reparentable = new ReparentableWidget( this );
-    reparentable->installEventFilter(this );
-    QLayout *innerLayout = new QHBoxLayout( reparentable );
-    innerLayout->setContentsMargins( 0, 0, 0, 0 );
-
     /* The owner of the video window needs a stable handle (WinId). Reparenting
      * in Qt4-X11 changes the WinId of the widget, so we need to create another
      * dummy widget that stays within the reparentable widget. */
-    QWidget *stable = new QWidget();
+    stable = new QWidget();
     QPalette plt = palette();
     plt.setColor( QPalette::Window, Qt::black );
     stable->setPalette( plt );
@@ -141,11 +122,13 @@ WId VideoWidget::request( int *pi_x, int *pi_y,
     /* Indicates that the widget wants to draw directly onto the screen.
        Widgets with this attribute set do not participate in composition
        management */
+    /* This is currently disabled on X11 as it does not seem to improve
+     * performance, but causes the video widget to be transparent... */
+#ifndef Q_WS_X11
     stable->setAttribute( Qt::WA_PaintOnScreen, true );
+#endif
 
-    innerLayout->addWidget( stable );
-
-    layout->addWidget( reparentable );
+    layout->addWidget( stable );
 
 #ifdef Q_WS_X11
     /* HACK: Only one X11 client can subscribe to mouse button press events.
@@ -159,7 +142,7 @@ WId VideoWidget::request( int *pi_x, int *pi_y,
     attr.your_event_mask &= ~(ButtonPressMask|ButtonReleaseMask);
     XSelectInput( dpy, w, attr.your_event_mask );
 #endif
-    videoSync();
+    sync();
 #ifndef NDEBUG
     msg_Dbg( p_intf, "embedded video ready (handle %p)",
              (void *)stable->winId() );
@@ -172,9 +155,6 @@ WId VideoWidget::request( int *pi_x, int *pi_y,
    Parent has to care about resizing itself */
 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
 {
-    if (reparentable->windowState() & Qt::WindowFullScreen )
-        return;
-    if( !isVisible() ) show();
     resize( w, h );
     emit sizeChanged( w, h );
     /* Work-around a bug?misconception? that would happen when vout core resize
@@ -184,88 +164,19 @@ void VideoWidget::SetSizing( unsigned int w, unsigned int h )
      */
     if( size().width() == w && size().height() == h )
         updateGeometry();
-    videoSync();
-}
-
-void VideoWidget::SetFullScreen( bool b_fs )
-{
-    const Qt::WindowStates curstate = reparentable->windowState();
-    Qt::WindowStates newstate = curstate;
-    Qt::WindowFlags  newflags = reparentable->windowFlags();
-
-
-    if( b_fs )
-    {
-        newstate |= Qt::WindowFullScreen;
-        newflags |= Qt::WindowStaysOnTopHint;
-    }
-    else
-    {
-        newstate &= ~Qt::WindowFullScreen;
-        newflags &= ~Qt::WindowStaysOnTopHint;
-    }
-    if( newstate == curstate )
-        return; /* no changes needed */
-
-    if( b_fs )
-    {   /* Go full-screen */
-        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( reparentable->pos() ) )
-        {
-            msg_Dbg( p_intf, "Moving video to correct screen");
-            reparentable->move( QPoint( screenres.x(), screenres.y() ) );
-        }
-        reparentable->setParent( NULL, newflags );
-        reparentable->setWindowState( newstate );
-        reparentable->show();
-    }
-    else
-    {   /* Go windowed */
-        reparentable->setWindowFlags( newflags );
-        reparentable->setWindowState( newstate );
-        layout->addWidget( reparentable );
-    }
-    videoSync();
+    sync();
 }
 
 void VideoWidget::release( void )
 {
     msg_Dbg( p_intf, "Video is not needed anymore" );
-    //layout->removeWidget( reparentable );
 
-    reparentable->deleteLater();
-    reparentable = NULL;
-    updateGeometry();
-    hide();
-}
+    assert( stable );
+    layout->removeWidget( stable );
+    stable->deleteLater();
+    stable = NULL;
 
-#undef KeyPress
-bool VideoWidget::eventFilter(QObject *obj, QEvent *event)
-{
-    if( obj == reparentable )
-    {
-        if (event->type() == QEvent::Close)
-        {
-            THEDP->quit();
-            return true;
-        }
-        else if( event->type() == QEvent::KeyPress )
-        {
-            emit keyPressed( static_cast<QKeyEvent *>(event) );
-            return true;
-        }
-    }
-    return false;
+    updateGeometry();
 }
 
 /**********************************************************************
@@ -515,7 +426,7 @@ void SpeedControlWidget::updateControls( float rate )
         return;
     }
 
-    double value = 17 * log( rate ) / log( 2 );
+    double value = 17 * log( rate ) / log( 2. );
     int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
 
     if( sliderValue < speedSlider->minimum() )
@@ -581,7 +492,8 @@ void CoverArtLabel::showArtUpdate( const QString& url )
     if( !url.isEmpty() && pix.load( url ) )
     {
         pix = pix.scaled( maximumWidth(), maximumHeight(),
-                          Qt::KeepAspectRatioByExpanding );
+                          Qt::KeepAspectRatioByExpanding,
+                          Qt::SmoothTransformation );
     }
     else
     {