]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/interface_widgets.cpp
Simplified/fixed qt4 fullscreen implementation.
[vlc] / modules / gui / qt4 / components / interface_widgets.cpp
index ec5f29e9c24e851446ae03769c3eb4a78215496d..60b844b7b69a223681e7970977605f84c2c5c301 100644 (file)
@@ -29,6 +29,8 @@
 #endif
 
 #include "components/interface_widgets.hpp"
+#include "dialogs_provider.hpp"
+#include "util/customwidgets.hpp"               // qtEventToVLCKey, QVLCStackedWidget
 
 #include "menus.hpp"             /* Popup menu on bgWidget */
 
@@ -37,6 +39,7 @@
 #include <QLabel>
 #include <QToolButton>
 #include <QPalette>
+#include <QEvent>
 #include <QResizeEvent>
 #include <QDate>
 #include <QMenu>
 #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 )
-    {
-    }
-
-protected:
-    void keyPressEvent( QKeyEvent *e )
-    {
-        emit owner->keyPressed( e );
-    }
-};
-
 /**********************************************************************
  * Video Widget. A simple frame on which video is drawn
  * This class handles resize issues
@@ -88,7 +66,6 @@ protected:
 VideoWidget::VideoWidget( intf_thread_t *_p_i )
     : QFrame( NULL )
       , p_intf( _p_i )
-      , reparentable( NULL )
 {
     /* Set the policy to expand in both directions */
     // setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
@@ -96,12 +73,23 @@ VideoWidget::VideoWidget( intf_thread_t *_p_i )
     layout = new QHBoxLayout( this );
     layout->setContentsMargins( 0, 0, 0, 0 );
     setLayout( layout );
+    stable = NULL;
 }
 
 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
 }
 
 /**
@@ -113,7 +101,7 @@ 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;
@@ -124,19 +112,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 );
-    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 );
@@ -144,11 +123,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.
@@ -162,7 +143,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() );
@@ -175,96 +156,28 @@ 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 );
-    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 );
-
-        reparentable->setParent( NULL, newflags );
-        reparentable->setWindowState( newstate );
-        /* 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->show();
-    }
-    else
-    {   /* Go windowed */
-        reparentable->setWindowFlags( newflags );
-        reparentable->setWindowState( newstate );
-        layout->addWidget( reparentable );
-    }
-    videoSync();
+    /* Work-around a bug?misconception? that would happen when vout core resize
+       twice to the same size and would make the vout not centered.
+       This cause a small flicker.
+       See #3621
+     */
+    if( size().width() == w && size().height() == h )
+        updateGeometry();
+    sync();
 }
 
 void VideoWidget::release( void )
 {
     msg_Dbg( p_intf, "Video is not needed anymore" );
-    //layout->removeWidget( reparentable );
-
-#ifdef WIN32
-    /* Come back to default thumbnail for Windows 7 taskbar */
-    LPTASKBARLIST3 p_taskbl;
-
-    CoInitialize( 0 );
-
-    if( S_OK == CoCreateInstance( &clsid_ITaskbarList,
-                NULL, CLSCTX_INPROC_SERVER,
-                &IID_ITaskbarList3,
-                (void **)&p_taskbl) )
-    {
-        p_taskbl->vt->HrInit(p_taskbl);
-
-        HWND hroot = GetAncestor(reparentable->winId(),GA_ROOT);
-
-        if (S_OK != p_taskbl->vt->SetThumbnailClip(p_taskbl, hroot, NULL))
-            msg_Err(p_intf, "SetThumbNailClip failed");
-        msg_Err(p_intf, "Releasing taskbar | root handle = %08x", hroot);
-        p_taskbl->vt->Release(p_taskbl);
-    }
-    CoUninitialize();
 
-#endif
+    assert( stable );
+    layout->removeWidget( stable );
+    stable->deleteLater();
+    stable = NULL;
 
-    delete reparentable;
-    reparentable = NULL;
     updateGeometry();
     hide();
 }
@@ -291,12 +204,6 @@ BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
              this, updateArt( const QString& ) );
 }
 
-void BackgroundWidget::resizeEvent( QResizeEvent * event )
-{
-    updateArt( "" );
-    QWidget::resizeEvent( event );
-}
-
 void BackgroundWidget::updateArt( const QString& url )
 {
     if ( !url.isEmpty() )
@@ -310,6 +217,7 @@ void BackgroundWidget::updateArt( const QString& url )
         else
             pixmapUrl = QString( ":/logo/vlc128.png" );
     }
+    update();
 }
 
 void BackgroundWidget::paintEvent( QPaintEvent *e )
@@ -422,7 +330,7 @@ void VisualSelector::next()
 SpeedLabel::SpeedLabel( intf_thread_t *_p_intf, QWidget *parent )
            : QLabel( parent ), p_intf( _p_intf )
 {
-    setToolTip( qtr( "Current playback speed.\nClick to adjust" ) );
+    tooltipStringPattern = qtr( "Current playback speed: %1\nClick to adjust" );
 
     /* Create the Speed Control Widget */
     speedControl = new SpeedControlWidget( p_intf, this );
@@ -462,7 +370,7 @@ void SpeedLabel::setRate( float rate )
     str.setNum( rate, 'f', 2 );
     str.append( "x" );
     setText( str );
-    setToolTip( str );
+    setToolTip( tooltipStringPattern.arg( str ) );
     speedControl->updateControls( rate );
 }
 
@@ -587,7 +495,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
     {
@@ -608,7 +517,10 @@ TimeLabel::TimeLabel( intf_thread_t *_p_intf  )
     b_remainingTime = false;
     setText( " --:--/--:-- " );
     setAlignment( Qt::AlignRight | Qt::AlignVCenter );
-    setToolTip( qtr( "Toggle between elapsed and remaining time" ) );
+    setToolTip( QString( "- " )
+        + qtr( "Click to toggle between elapsed and remaining time" )
+        + QString( "\n- " )
+        + qtr( "Double click to jump to a chosen time position" ) );
     bufTimer->setSingleShot( true );
 
     CONNECT( THEMIM->getIM(), positionUpdated( float, int64_t, int ),
@@ -635,9 +547,10 @@ void TimeLabel::setDisplayPosition( float pos, int64_t t, int length )
     secstotimestr( psz_time, ( b_remainingTime && length ) ? length - time
                                                            : time );
 
-    QString timestr;
-    timestr.sprintf( " %s%s/%s ", (b_remainingTime && length) ? "-" : "",
-                     psz_time, ( !length && time ) ? "--:--" : psz_length );
+    QString timestr = QString( " %1%2/%3 " )
+            .arg( QString( (b_remainingTime && length) ? "-" : "" ) )
+            .arg( QString( psz_time ) )
+            .arg( QString( ( !length && time ) ? "--:--" : psz_length ) );
 
     setText( timestr );
 
@@ -656,9 +569,10 @@ void TimeLabel::setDisplayPosition( float pos )
     secstotimestr( psz_time,
                    ( b_remainingTime && cachedLength ?
                    cachedLength - time : time ) );
-    QString timestr;
-    timestr.sprintf( " %s%s/%s ", (b_remainingTime && cachedLength) ? "-" : "",
-                     psz_time, ( !cachedLength && time ) ? "--:--" : psz_length );
+    QString timestr = QString( " %1%2/%3 " )
+        .arg( QString( (b_remainingTime && cachedLength) ? "-" : "" ) )
+        .arg( QString( psz_time ) )
+        .arg( QString( ( !cachedLength && time ) ? "--:--" : psz_length ) );
 
     setText( timestr );
 }