[vlc-devel] commit: implements --qt-keep-size (persistent main windows for qt4) ( Joseph Tulou )

git version control git at videolan.org
Sat Jan 24 15:03:36 CET 2009


vlc | branch: master | Joseph Tulou <brezhoneg1 at yahoo.fr> | Sat Jan 24 12:05:25 2009 +0100| [32b29b9e09887f54ed205ccd22764f3e72d416a1] | committer: Jean-Baptiste Kempf 

implements --qt-keep-size (persistent main windows for qt4)

this patch features :
- persistent resizable main windows
- video confined to preexisting window size

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=32b29b9e09887f54ed205ccd22764f3e72d416a1
---

 modules/gui/qt4/components/interface_widgets.cpp |   10 +++-
 modules/gui/qt4/components/interface_widgets.hpp |    2 +-
 modules/gui/qt4/main_interface.cpp               |   72 +++++++++++++++++++++-
 modules/gui/qt4/main_interface.hpp               |    4 +
 modules/gui/qt4/qt4.cpp                          |    8 +++
 5 files changed, 92 insertions(+), 4 deletions(-)

diff --git a/modules/gui/qt4/components/interface_widgets.cpp b/modules/gui/qt4/components/interface_widgets.cpp
index 8f49308..3c07475 100644
--- a/modules/gui/qt4/components/interface_widgets.cpp
+++ b/modules/gui/qt4/components/interface_widgets.cpp
@@ -101,9 +101,17 @@ VideoWidget::~VideoWidget()
  * Request the video to avoid the conflicts
  **/
 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
-                            unsigned int *pi_width, unsigned int *pi_height )
+                            unsigned int *pi_width, unsigned int *pi_height,
+                            bool b_keep_size )
 {
     msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
+
+    if( b_keep_size )
+    {
+        *pi_width  = size().width();
+        *pi_height = size().height();
+    }
+
     emit askVideoWidgetToShow( *pi_width, *pi_height );
     if( p_vout )
     {
diff --git a/modules/gui/qt4/components/interface_widgets.hpp b/modules/gui/qt4/components/interface_widgets.hpp
index a429410..71c3bf3 100644
--- a/modules/gui/qt4/components/interface_widgets.hpp
+++ b/modules/gui/qt4/components/interface_widgets.hpp
@@ -60,7 +60,7 @@ public:
     virtual ~VideoWidget();
 
     void *request( vout_thread_t *, int *, int *,
-                   unsigned int *, unsigned int * );
+                   unsigned int *, unsigned int *, bool );
     void  release( void );
     int   control( void *, int, va_list );
 
diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index e58b443..5946080 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -99,6 +99,9 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /* Set The Video In emebedded Mode or not */
     videoEmbeddedFlag = config_GetInt( p_intf, "embedded-video" );
 
+    /* Do we confine videos within a persistent resizeable window */
+    b_keep_size = config_GetInt( p_intf, "qt-keep-size" );
+
     /* Are we in the enhanced always-video mode or not ? */
     i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
 
@@ -106,6 +109,15 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     settings = getSettings();
     settings->beginGroup( "MainWindow" );
 
+    /**
+     * Retrieve saved sizes for main window
+     *   mainBasedSize = based window size for normal mode
+     *                  (no video, no background)
+     *   mainVideoSize = window size with video (all modes)
+     **/
+    mainBasedSize = settings->value( "mainBasedSize", QSize( 350, 120 ) ).toSize();
+    mainVideoSize = settings->value( "mainVideoSize", QSize( 400, 300 ) ).toSize();
+
     /* Visualisation, not really used yet */
     visualSelectorEnabled = settings->value( "visual-selector", false).toBool();
 
@@ -209,6 +221,20 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     settings->beginGroup( "MainWindow" );
     QVLCTools::restoreWidgetPosition( settings, this, QSize(380, 60) );
 
+    /* resize to previously saved main window size if appicable */ 
+    if( b_keep_size )
+    {
+       if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
+           i_visualmode == QT_MINIMAL_MODE )
+       {
+           resize( mainVideoSize );
+       }
+       else
+       {
+           resize( mainBasedSize );
+       }
+    }
+
     bool b_visible = settings->value( "playlist-visible", 0 ).toInt();
     settings->endGroup();
 
@@ -259,6 +285,9 @@ MainInterface::~MainInterface()
     settings->setValue( "adv-controls",
                         getControlsVisibilityStatus() & CONTROLS_ADVANCED );
 
+    settings->setValue( "mainBasedSize", mainBasedSize );
+    settings->setValue( "mainVideoSize", mainVideoSize );
+
     if( bgWidget )
         settings->setValue( "backgroundSize", bgWidget->size() );
 
@@ -397,7 +426,6 @@ void MainInterface::handleMainUi( QSettings *settings )
     mainLayout->insertWidget( settings->value( "ToolbarPos", 0 ).toInt() ? 0: 3,
                               controls, 0, Qt::AlignBottom );
 
-
     /* Finish the sizing */
     main->updateGeometry();
 
@@ -518,6 +546,24 @@ int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
 
 QSize MainInterface::sizeHint() const
 {
+    if( b_keep_size )
+    {
+        if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
+            i_visualmode == QT_MINIMAL_MODE )
+        {
+                return mainVideoSize;
+        }
+        else
+        {
+            if( VISIBLE( bgWidget) ||
+                ( videoIsActive && videoWidget->isVisible() )
+              )
+                return mainVideoSize;
+            else
+                return mainBasedSize;
+        }
+    }
+
     int nwidth  = controls->sizeHint().width();
     int nheight = controls->isVisible() ?
                   controls->size().height()
@@ -596,7 +642,8 @@ void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
                                    unsigned int *pi_height )
 {
     /* Request the videoWidget */
-    void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
+    void *ret = videoWidget->request( p_nvout,pi_x, pi_y, 
+                                      pi_width, pi_height, b_keep_size );
     if( ret ) /* The videoWidget is available */
     {
         /* Did we have a bg ? Hide it! */
@@ -1071,6 +1118,27 @@ void MainInterface::keyPressEvent( QKeyEvent *e )
         e->ignore();
 }
 
+void MainInterface::resizeEvent( QResizeEvent * event )
+{
+    if( b_keep_size )
+    {
+        if( i_visualmode == QT_ALWAYS_VIDEO_MODE ||
+            i_visualmode == QT_MINIMAL_MODE )
+        {
+                mainVideoSize = size();
+        }
+        else
+        {
+            if( VISIBLE( bgWidget) ||
+                ( videoIsActive && videoWidget->isVisible() )
+              )
+                mainVideoSize = size();
+            else
+                mainBasedSize = size();
+        }
+    }
+}
+
 void MainInterface::wheelEvent( QWheelEvent *e )
 {
     int i_vlckey = qtWheelEventToVLCKey( e );
diff --git a/modules/gui/qt4/main_interface.hpp b/modules/gui/qt4/main_interface.hpp
index 2bb2d51..6355f85 100644
--- a/modules/gui/qt4/main_interface.hpp
+++ b/modules/gui/qt4/main_interface.hpp
@@ -132,6 +132,9 @@ private:
     bool                 visualSelectorEnabled;
     bool                 notificationEnabled; /// Systray Notifications
     bool                 bgWasVisible;
+    bool                 b_keep_size;         ///< persistent resizeable window 
+    QSize                mainBasedSize;       ///< based Wnd (normal mode only)
+    QSize                mainVideoSize;       ///< Wnd with video (all modes)
     int                  i_visualmode;        ///< Visual Mode
     pl_dock_e            i_pl_dock;
     bool                 isDocked() { return ( i_pl_dock != PL_UNDOCKED ); }
@@ -142,6 +145,7 @@ private:
     virtual void customEvent( QEvent *);
     virtual void keyPressEvent( QKeyEvent *);
     virtual void wheelEvent( QWheelEvent * );
+    virtual void resizeEvent( QResizeEvent * event );
 
 public slots:
     void undockPlaylist();
diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp
index f390bef..03e8d6a 100644
--- a/modules/gui/qt4/qt4.cpp
+++ b/modules/gui/qt4/qt4.cpp
@@ -84,6 +84,12 @@ static void ShowDialog   ( intf_thread_t *, int, int, intf_dialog_args_t * );
 #define MINIMIZED_LONGTEXT N_( "VLC will start with just an icon in " \
                                "your taskbar" )
 
+#define KEEPSIZE_TEXT N_( "Confine video to a persistent resizable window" )
+#define KEEPSIZE_LONGTEXT N_( "You can choose to confine a video to a " \
+                              "persistent resizeable window or let it freely " \
+                              "expand to match the original size. " \
+                              "By default, videos are expanded to original size." )
+
 #define TITLE_TEXT N_( "Show playing item name in window title" )
 #define TITLE_LONGTEXT N_( "Show the name of the song or video in the " \
                            "controler window title." )
@@ -176,6 +182,8 @@ vlc_module_begin ()
               SYSTRAY_LONGTEXT, false);
     add_bool( "qt-start-minimized", false, NULL, MINIMIZED_TEXT,
               MINIMIZED_LONGTEXT, true);
+    add_bool( "qt-keep-size", false, NULL, KEEPSIZE_TEXT,
+              KEEPSIZE_LONGTEXT, false )
     add_bool( "qt-name-in-title", true, NULL, TITLE_TEXT,
               TITLE_LONGTEXT, false );
     add_bool( "qt-fs-controller", true, NULL, QT_FULLSCREEN_TEXT,




More information about the vlc-devel mailing list