[vlc-devel] [PATCH 2/2] Resize qt interface while keeping the aspect ratio (on windows)

Mario Speiß 1034-135 at online.de
Sun Jul 15 17:16:23 CEST 2012


Handling the WM_SIZING-message for windows along with the current video size
supports to resize the interface and keeping the aspect ratio (ticket #6208).
Works only for windows machines, though...
The code could be extended to support the other window corners, too. Now only
the lower right corner provides this functionality while a video is playing.

Regards,

Mario
---
 modules/gui/qt4/main_interface.cpp       |    9 +++++++++
 modules/gui/qt4/main_interface.hpp       |    2 ++
 modules/gui/qt4/main_interface_win32.cpp |   23 +++++++++++++++++++++++
 3 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index 7e599ce..b2773c7 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -98,6 +98,8 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     b_interfaceFullScreen= false;
     b_hasPausedWhenMinimized = false;
 
+    i_video_cx = i_video_cy = 0;
+
 
     /* Ask for Privacy */
     FirstRun::CheckAndRun( this, p_intf );
@@ -652,6 +654,9 @@ void MainInterface::getVideoSlot( WId *p_id, int *pi_x, int *pi_y,
     /* Request the videoWidget */
     WId ret = videoWidget->request( pi_x, pi_y,
                                     pi_width, pi_height, !b_autoresize );
+    i_video_cx = *pi_width;
+    i_video_cy = *pi_height;
+
     *p_id = ret;
     if( ret ) /* The videoWidget is available */
     {
@@ -692,6 +697,8 @@ void MainInterface::releaseVideoSlot( void )
 
     /* We don't want to have a blank video to popup */
     stackCentralOldWidget = bgWidget;
+
+    i_video_cx = i_video_cy = 0;
 }
 
 void MainInterface::setVideoSize( unsigned int w, unsigned int h )
@@ -702,6 +709,8 @@ void MainInterface::setVideoSize( unsigned int w, unsigned int h )
 
 void MainInterface::videoSizeChanged( int w, int h )
 {
+    i_video_cx = w;
+    i_video_cy = h;
     if( b_autoresize && ( !playlistWidget || playlistWidget->artContainer->currentWidget() != videoWidget ) )
     {
         /* Calculate the future video widget position-
diff --git a/modules/gui/qt4/main_interface.hpp b/modules/gui/qt4/main_interface.hpp
index 78745ce..d092490 100644
--- a/modules/gui/qt4/main_interface.hpp
+++ b/modules/gui/qt4/main_interface.hpp
@@ -162,6 +162,8 @@ private:
     bool                 b_minimalView;         ///< Minimal video
     bool                 b_interfaceFullScreen;
     bool                 b_pauseOnMinimize;
+    int                  i_video_cx,
+                         i_video_cy;            /// current video output size
 
     /* States */
     bool                 playlistVisible;       ///< Is the playlist visible ?
diff --git a/modules/gui/qt4/main_interface_win32.cpp b/modules/gui/qt4/main_interface_win32.cpp
index e9f9752..5a640aa 100644
--- a/modules/gui/qt4/main_interface_win32.cpp
+++ b/modules/gui/qt4/main_interface_win32.cpp
@@ -181,6 +181,29 @@ bool MainInterface::winEvent ( MSG * msg, long * result )
                 }
             }
             break;
+        case WM_SIZING:
+            /* provide resizing while keeping aspect ratio of the video widget
+               if the interface is resized with the lower-right corner */
+            if( msg->wParam == WMSZ_BOTTOMRIGHT )
+            {
+                RECT* r = (RECT*)msg->lParam;
+                float ar = 0;
+                if( i_video_cx > 0 && i_video_cy > 0 )
+                {
+                    ar = (float)w / (float)h;
+                    QPoint pt( 0, 0 );
+                    pt = stackCentralW->mapToGlobal( pt );
+                    QRect rc_video = stackCentralW->rect().translated( pt );
+                    QRect rc_frame = frameGeometry();
+                    int topmargin = rc_video.top() - rc_frame.top();
+                    int bottommargin = rc_frame.bottom() - rc_video.bottom();
+                    int newheight = ((float)(rc_video.width() + (r->right - rc_frame.right())) / ar + 0.5 );
+                    //update the new height
+                    r->bottom = r->top + newheight + topmargin + bottommargin;
+                    return true;
+                }
+            }
+        }
         case WM_APPCOMMAND:
             cmd = GET_APPCOMMAND_LPARAM(msg->lParam);
 
-- 
1.7.5.4




More information about the vlc-devel mailing list