From ba42d61b37c0deeefb035599a2df69ff4ada4e09 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Stenac?= <zorglub@videolan.org>
Date: Sun, 27 Aug 2006 17:06:24 +0000
Subject: [PATCH] Add ability to put some background when there is no video

---
 modules/gui/qt4/components/video_widget.cpp | 56 +++++++++++++++------
 modules/gui/qt4/components/video_widget.hpp |  8 ++-
 modules/gui/qt4/main_interface.cpp          | 15 ++++--
 modules/gui/qt4/ui/main_interface.ui        |  2 +-
 4 files changed, 59 insertions(+), 22 deletions(-)

diff --git a/modules/gui/qt4/components/video_widget.cpp b/modules/gui/qt4/components/video_widget.cpp
index dfdf98e2cece..6fda625a343f 100644
--- a/modules/gui/qt4/components/video_widget.cpp
+++ b/modules/gui/qt4/components/video_widget.cpp
@@ -26,6 +26,7 @@
 #include "qt4.hpp"
 #include "components/video_widget.hpp"
 #include "main_interface.hpp"
+#include <QHBoxLayout>
 
 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
                         unsigned int *, unsigned int * );
@@ -33,11 +34,12 @@ static void DoRelease( intf_thread_t *, void * );
 static int DoControl( intf_thread_t *, void *, int, va_list );
 
 bool need_update;
-       
-VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ),
-                                                              p_intf( _p_i )
+
+VideoWidget::VideoWidget( intf_thread_t *_p_i, bool _always ) : QFrame( NULL ),
+                                                               p_intf( _p_i )
 {
     vlc_mutex_init( p_intf, &lock );
+    always = _always;
 
     p_intf->pf_request_window  = ::DoRequest;
     p_intf->pf_release_window  = ::DoRelease;
@@ -50,6 +52,9 @@ VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ),
     connect( DialogsProvider::getInstance(NULL)->fixed_timer,
              SIGNAL( timeout() ), this, SLOT( update() ) );
 
+    if( always )
+        DrawBackground();
+
     need_update = false;
 }
 
@@ -106,6 +111,9 @@ void *VideoWidget::Request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
     }
     p_vout = p_nvout;
 
+    if( always )
+        CleanBackground();
+
     setMinimumSize( 1,1 );
     p_intf->p_sys->p_mi->videoSize = QSize( *pi_width, *pi_height );
     updateGeometry();
@@ -120,23 +128,40 @@ static void DoRelease( intf_thread_t *p_intf, void *p_win )
 
 void VideoWidget::Release( void *p_win )
 {
-    if( !config_GetInt( p_intf, "qt-always-video" ) );
+    p_vout = NULL;
+    if( config_GetInt( p_intf, "qt-always-video" ) == 0 )
     {
         p_intf->p_sys->p_mi->videoSize = QSize ( 1,1 );
+        updateGeometry();
+        need_update = true;
+    }
+    else
+    {
+        DrawBackground();
     }
 
-    updateGeometry();
-
-    if( !config_GetInt( p_intf, "qt-always-video" ) )
-        need_update = true;
-    p_vout = NULL;
 }
 
-
 static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
 {
     return p_intf->p_sys->p_video->Control( p_win, i_q, a );
-} 
+}
+
+int VideoWidget::DrawBackground()
+{
+    QLabel *label = new QLabel( "VLC Rulez d4 Worldz" );
+    backgroundLayout = new QHBoxLayout;
+    backgroundLayout->addWidget( label );
+    setLayout( backgroundLayout );
+    return 0;
+}
+
+int VideoWidget::CleanBackground()
+{
+    backgroundLayout->takeAt(0);
+    delete backgroundLayout;
+    return 0;
+}
 
 int VideoWidget::Control( void *p_window, int i_query, va_list args )
 {
@@ -160,16 +185,17 @@ int VideoWidget::Control( void *p_window, int i_query, va_list args )
 
             if( !i_width && p_vout ) i_width = p_vout->i_window_width;
             if( !i_height && p_vout ) i_height = p_vout->i_window_height;
-           
-            frame->resize( i_width, i_height );
+            p_intf->p_sys->p_mi->videoSize = QSize( i_width, i_height );
+            updateGeometry();
+            need_update = true;
             i_ret = VLC_SUCCESS;
-            break; 
+            break;
         }
         case VOUT_SET_STAY_ON_TOP:
         {
             /// \todo
             break;
-        }   
+        }
         default:
             msg_Warn( p_intf, "unsupported control query" );
             break;
diff --git a/modules/gui/qt4/components/video_widget.hpp b/modules/gui/qt4/components/video_widget.hpp
index 068629e5a366..0f1ef7002284 100644
--- a/modules/gui/qt4/components/video_widget.hpp
+++ b/modules/gui/qt4/components/video_widget.hpp
@@ -29,11 +29,13 @@
 #include <QWidget>
 #include <QFrame>
 
+class QHBoxLayout;
+
 class VideoWidget : public QFrame
 {
     Q_OBJECT
 public:
-    VideoWidget( intf_thread_t *);
+    VideoWidget( intf_thread_t *, bool );
     virtual ~VideoWidget();
 
     virtual QSize sizeHint() const;
@@ -45,7 +47,11 @@ public:
     int i_video_height, i_video_width;
     vout_thread_t *p_vout;
 private:
+    int DrawBackground();
+    int CleanBackground();
+    bool always;
     QWidget *frame;
+    QHBoxLayout *backgroundLayout;
     intf_thread_t *p_intf;
     vlc_mutex_t lock;
 private slots:
diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index 711037cd265a..bbe5c487898f 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -60,6 +60,8 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     ui.volLowLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
     ui.volHighLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
     ui.volumeSlider->setMaximum( 100 );
+    ui.playlistButton->setIcon( QIcon( ":/pixmaps/volume-low.png" ) );
+
 
     VolumeClickHandler *h = new VolumeClickHandler( this );
     ui.volLowLabel->installEventFilter(h);
@@ -76,7 +78,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 //    if( config_GetInt( p_intf, "embedded" ) )
 
     {
-        videoWidget = new VideoWidget( p_intf );
+        videoWidget = new VideoWidget( p_intf, config_GetInt( p_intf, "qt-always-video" ) ? true:false );
         if( config_GetInt( p_intf, "qt-always-video" ) )
         {
             QSettings settings( "VideoLAN", "VLC" );
@@ -92,12 +94,15 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     readSettings( "MainWindow" );
 
     addSize = QSize( ui.vboxLayout->margin() * 2, PREF_H );
-    if( config_GetInt( p_intf, "qt-always-video" ) )
-        mainSize = videoSize + addSize;
-    else
-        mainSize = QSize( PREF_W, PREF_H );
+//    if( config_GetInt( p_intf, "qt-always-video" ) )
+        mainSize.setWidth( videoSize.width() + addSize.width() );
+        mainSize.setHeight( videoSize.height() + addSize.height() );
+//    else
+//        mainSize = QSize( PREF_W, PREF_H );
+    fprintf( stderr, "Resulting size %ix%i", mainSize.width(), mainSize.height() );
     resize( mainSize );
     mainSize = size();
+    fprintf( stderr, "After size %ix%i", mainSize.width(), mainSize.height() );
 
     setMinimumSize( PREF_W, addSize.height() );
 
diff --git a/modules/gui/qt4/ui/main_interface.ui b/modules/gui/qt4/ui/main_interface.ui
index fd4273efebca..15b4e60ee429 100644
--- a/modules/gui/qt4/ui/main_interface.ui
+++ b/modules/gui/qt4/ui/main_interface.ui
@@ -219,7 +219,7 @@
      <item>
       <widget class="QPushButton" name="playlistButton" >
        <property name="text" >
-        <string>_("Playlist")</string>
+        <string> </string>
        </property>
       </widget>
      </item>
-- 
GitLab