]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/interface_widgets.cpp
qt4 playlist: make popup Add Node and Sort operate on parent
[vlc] / modules / gui / qt4 / components / interface_widgets.cpp
index c0369d1f5511bb75eb5be05a2e7b95e029aaf509..05f8e2d73feff4208b5a8b1b9672899735cf1539 100644 (file)
@@ -41,6 +41,7 @@
 #include <QDate>
 #include <QMenu>
 #include <QWidgetAction>
+#include <QDesktopWidget>
 
 #ifdef Q_WS_X11
 # include <X11/Xlib.h>
@@ -58,6 +59,22 @@ static void videoSync( void )
 
 #include <math.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
@@ -111,7 +128,7 @@ WId VideoWidget::request( int *pi_x, int *pi_y,
      * reparentable widget, that will be within the VideoWidget in windowed
      * mode, and within the root window (NULL parent) in full-screen mode.
      */
-    reparentable = new QWidget();
+    reparentable = new ReparentableWidget( this );
     QLayout *innerLayout = new QHBoxLayout( reparentable );
     innerLayout->setContentsMargins( 0, 0, 0, 0 );
 
@@ -133,6 +150,18 @@ WId VideoWidget::request( int *pi_x, int *pi_y,
     reparentable->setLayout( innerLayout );
     layout->addWidget( reparentable );
 
+#ifdef Q_WS_X11
+    /* HACK: Only one X11 client can subscribe to mouse button press events.
+     * VLC currently handles those in the video display.
+     * Force Qt4 to unsubscribe from mouse press and release events. */
+    Display *dpy = QX11Info::display();
+    Window w = stable->winId();
+    XWindowAttributes attr;
+
+    XGetWindowAttributes( dpy, w, &attr );
+    attr.your_event_mask &= ~(ButtonPressMask|ButtonReleaseMask);
+    XSelectInput( dpy, w, attr.your_event_mask );
+#endif
     videoSync();
 #ifndef NDEBUG
     msg_Dbg( p_intf, "embedded video ready (handle %p)",
@@ -160,6 +189,7 @@ void VideoWidget::SetFullScreen( bool b_fs )
     Qt::WindowStates newstate = curstate;
     Qt::WindowFlags  newflags = reparentable->windowFlags();
 
+
     if( b_fs )
     {
         newstate |= Qt::WindowFullScreen;
@@ -175,9 +205,18 @@ void VideoWidget::SetFullScreen( bool b_fs )
 
     if( b_fs )
     {   /* Go full-screen */
+        int numscreen = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
+        QRect screenres = QApplication::desktop()->screenGeometry( numscreen );
+
         reparentable->setWindowState( newstate );
         reparentable->setParent( NULL );
         reparentable->setWindowFlags( newflags );
+        /* 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
@@ -234,6 +273,7 @@ BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
     label->setMaximumWidth( MAX_BG_SIZE );
     label->setMinimumHeight( MIN_BG_SIZE );
     label->setMinimumWidth( MIN_BG_SIZE );
+    label->setAlignment( Qt::AlignCenter );
     if( QDate::currentDate().dayOfYear() >= 354 )
         label->setPixmap( QPixmap( ":/logo/vlc128-christmas.png" ) );
     else
@@ -270,7 +310,15 @@ void BackgroundWidget::updateArt( const QString& url )
     }
     else
     {
-        label->setPixmap( QPixmap( url ) );
+        QPixmap pixmap( url );
+        if( pixmap.width() > label->maximumWidth() ||
+            pixmap.height() > label->maximumHeight() )
+        {
+            pixmap = pixmap.scaled( label->maximumWidth(),
+                          label->maximumHeight(), Qt::KeepAspectRatio );
+        }
+
+        label->setPixmap( pixmap );
     }
 }
 
@@ -468,14 +516,13 @@ CoverArtLabel::CoverArtLabel( QWidget *parent, intf_thread_t *_p_i )
 {
     setContextMenuPolicy( Qt::ActionsContextMenu );
     CONNECT( this, updateRequested(), this, askForUpdate() );
-    CONNECT( THEMIM->getIM(), artChanged( QString ),
-             this, showArtUpdate( const QString& ) );
 
     setMinimumHeight( 128 );
     setMinimumWidth( 128 );
     setMaximumHeight( 128 );
     setMaximumWidth( 128 );
-    setScaledContents( true );
+    setScaledContents( false );
+    setAlignment( Qt::AlignCenter );
 
     QList< QAction* > artActions = actions();
     QAction *action = new QAction( qtr( "Download cover art" ), this );
@@ -497,12 +544,14 @@ void CoverArtLabel::showArtUpdate( const QString& url )
     QPixmap pix;
     if( !url.isEmpty()  && pix.load( url ) )
     {
-        setPixmap( pix );
+        pix = pix.scaled( maximumWidth(), maximumHeight(),
+                          Qt::KeepAspectRatioByExpanding );
     }
     else
     {
-        setPixmap( QPixmap( ":/noart.png" ) );
+        pix = QPixmap( ":/noart.png" );
     }
+    setPixmap( pix );
 }
 
 void CoverArtLabel::askForUpdate()