[vlc-devel] [PATCH] Constrain Qt interface to desktop size on video resize

Mario Speiß 1034-135 at online.de
Sun Feb 10 22:34:22 CET 2013


This patch allows VLC to handle large videos on small desktops better now.
Three options are given:
Do nothing: VLC is allowed to outgrow the desktop
Resize: VLC will resize the video to stay within the desktop without moving
Resize/Move: VLC uses the largest possible resolution to stay on the desktop

Regards,
Mario
---
 modules/gui/qt4/main_interface.cpp |   41 +++++++++++++++++++++++++++++++++++-
 modules/gui/qt4/qt4.cpp            |   14 ++++++++++++
 modules/gui/qt4/qt4.hpp            |    6 +++++
 3 files changed, 60 insertions(+), 1 deletions(-)

diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index 82008cb..4291dd8 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -715,8 +715,47 @@ void MainInterface::setVideoSize( unsigned int w, unsigned int h )
 
 void MainInterface::videoSizeChanged( int w, int h )
 {
-    if( !playlistWidget || playlistWidget->artContainer->currentWidget() != videoWidget )
+    if( b_autoresize && ( !playlistWidget || playlistWidget->artContainer->currentWidget() != videoWidget ) )
+    {
+        /* Calculate the future video widget position-
+           If it exceeds the current screen, rescale it to fit the screen */
+        if( var_InheritInteger( p_intf, "qt-constrain-to-screen" ) > CONSTRAIN_INTF_DO_NOTHING )
+        {
+            QPoint pt( 0, 0 );
+            pt = stackCentralW->mapToGlobal( pt );
+            QRect rc_video = stackCentralW->rect().translated( pt );
+            QRect rc_frame = frameGeometry();
+            msg_Dbg( p_intf, "videoSizeChanged: video=(%d/%d)x(%d/%d), this=(%d/%d)x(%d/%d)",
+                    rc_video.left(), rc_video.top(), rc_video.width(), rc_video.height(),
+                    rc_frame.left(), rc_frame.top(), rc_frame.width(), rc_frame.height() );
+            QRect rc = QApplication::desktop()->availableGeometry( QApplication::desktop()->screenNumber( videoWidget ) );
+            int pixel_to_left = 0, pixel_to_top = 0;
+            if( var_InheritInteger( p_intf, "qt-constrain-to-screen" ) == CONSTRAIN_INTF_RESIZE_AND_MOVE )
+            {
+                pixel_to_left   =      pt.x() - rc.left() -   ( rc_video.left() - rc_frame.left() );
+                pixel_to_top    =      pt.y() - rc.top()  -    ( rc_video.top() - rc_frame.top() );
+            }
+            int pixel_to_right  =  rc.width() - pt.x()    -  ( rc_frame.right() - rc_video.right() );
+            int pixel_to_bottom = rc.height() - pt.y()    - ( rc_frame.bottom() - rc_video.bottom() );
+            float sx = (float)( pixel_to_left + pixel_to_right )/(float)w;
+            float sy = (float)( pixel_to_top + pixel_to_bottom )/(float)h;
+            if( sx < 1 || sy < 1 )
+            {
+                if( sx < sy )
+                    w *= sx, h *= sx;
+                else
+                    w *= sy, h *= sy;
+            }
+            int dx = 0, dy = 0;
+            if( w > pixel_to_right )
+                dx = pixel_to_right - w;
+            if( h > pixel_to_bottom )
+                dy = pixel_to_bottom - h;
+            if( dx || dy )
+                move( x() + dx, y() + dy );
+        }
         resizeStack( w, h );
+    }
 }
 
 void MainInterface::setVideoFullScreen( bool fs )
diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp
index 11ae967..6f123e8 100644
--- a/modules/gui/qt4/qt4.cpp
+++ b/modules/gui/qt4/qt4.cpp
@@ -182,6 +182,16 @@ static void ShowDialog   ( intf_thread_t *, int, int, intf_dialog_args_t * );
 
 #define VOLUME_MAX_TEXT N_( "Maximum Volume displayed" )
 
+#define QT_CONSTRAIN_TO_SCREEN_TEXT N_( "Constrain video widget to the current screen." )
+#define QT_CONSTRAIN_TO_SCREEN_LONGTEXT N_( "Constrain the video widget size to fit "\
+                                            "onto the current desktop." )
+
+static const int constrain_list[] =
+    { CONSTRAIN_INTF_DO_NOTHING, CONSTRAIN_INTF_RESIZE, CONSTRAIN_INTF_RESIZE_AND_MOVE };
+static const char *const constrain_list_text[] = { N_("do nothing"),
+                                                   N_("resize to fit"),
+                                                   N_("move/resize to fit") };
+
 static const int i_notification_list[] =
     { NOTIFICATION_NEVER, NOTIFICATION_MINIMIZED, NOTIFICATION_ALWAYS };
 
@@ -221,6 +231,10 @@ vlc_module_begin ()
 
     add_bool( "qt-video-autoresize", true, KEEPSIZE_TEXT,
               KEEPSIZE_LONGTEXT, false )
+    add_integer( "qt-constrain-to-screen", CONSTRAIN_INTF_RESIZE, QT_CONSTRAIN_TO_SCREEN_TEXT,
+                QT_CONSTRAIN_TO_SCREEN_LONGTEXT, false )
+        change_integer_list( constrain_list, constrain_list_text )
+        change_safe ()
     add_bool( "qt-name-in-title", true, TITLE_TEXT,
               TITLE_LONGTEXT, false )
     add_bool( "qt-fs-controller", true, QT_FULLSCREEN_TEXT,
diff --git a/modules/gui/qt4/qt4.hpp b/modules/gui/qt4/qt4.hpp
index b048e5a..62cd047 100644
--- a/modules/gui/qt4/qt4.hpp
+++ b/modules/gui/qt4/qt4.hpp
@@ -55,6 +55,12 @@ enum{
     NOTIFICATION_ALWAYS = 2,
 };
 
+enum{
+    CONSTRAIN_INTF_DO_NOTHING = 0,
+    CONSTRAIN_INTF_RESIZE = 1,
+    CONSTRAIN_INTF_RESIZE_AND_MOVE = 2,
+};
+
 class QVLCApp;
 class QMenu;
 class MainInterface;
-- 
1.7.5.4




More information about the vlc-devel mailing list