1 /*****************************************************************************
2 * interface_widgets.cpp : Custom widgets for the main interface
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include "dialogs_provider.hpp"
27 #include "components/interface_widgets.hpp"
28 #include "main_interface.hpp"
29 #include "input_manager.hpp"
30 #include <QHBoxLayout>
34 /**********************************************************************
35 * Video Widget. A simple frame on which video is drawn
36 * This class handles resize issues
37 **********************************************************************/
38 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
39 unsigned int *, unsigned int * );
40 static void DoRelease( intf_thread_t *, void * );
41 static int DoControl( intf_thread_t *, void *, int, va_list );
45 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
47 vlc_mutex_init( p_intf, &lock );
49 p_intf->pf_request_window = ::DoRequest;
50 p_intf->pf_release_window = ::DoRelease;
51 p_intf->pf_control_window = ::DoControl;
52 p_intf->p_sys->p_video = this;
55 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
57 ON_TIMEOUT( update() );
61 void VideoWidget::update()
65 p_intf->p_sys->p_mi->resize( p_intf->p_sys->p_mi->sizeHint() );
70 VideoWidget::~VideoWidget()
72 vlc_mutex_lock( &lock );
75 if( !p_intf->psz_switch_intf )
77 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
78 vout_Control( p_vout, VOUT_REPARENT );
82 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
83 vout_Control( p_vout, VOUT_CLOSE );
86 p_intf->pf_request_window = NULL;
87 p_intf->pf_release_window = NULL;
88 p_intf->pf_control_window = NULL;
89 vlc_mutex_unlock( &lock );
90 vlc_mutex_destroy( &lock );
93 QSize VideoWidget::sizeHint() const
95 return p_intf->p_sys->p_mi->videoSize;
98 static void *DoRequest( intf_thread_t *p_intf, vout_thread_t *p_vout,
99 int *pi1, int *pi2, unsigned int*pi3,unsigned int*pi4)
101 return p_intf->p_sys->p_video->Request( p_vout, pi1, pi2, pi3, pi4 );
104 void *VideoWidget::Request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
105 unsigned int *pi_width, unsigned int *pi_height )
109 msg_Dbg( p_intf, "embedded video already in use" );
114 setMinimumSize( 1,1 );
115 p_intf->p_sys->p_mi->videoSize = QSize( *pi_width, *pi_height );
118 return (void*)winId();
121 static void DoRelease( intf_thread_t *p_intf, void *p_win )
123 return p_intf->p_sys->p_video->Release( p_win );
126 void VideoWidget::Release( void *p_win )
129 if( config_GetInt( p_intf, "qt-always-video" ) == 0 )
131 p_intf->p_sys->p_mi->videoSize = QSize ( 1,1 );
137 static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
139 return p_intf->p_sys->p_video->Control( p_win, i_q, a );
142 int VideoWidget::Control( void *p_window, int i_query, va_list args )
144 int i_ret = VLC_EGENERIC;
145 vlc_mutex_lock( &lock );
150 unsigned int *pi_width = va_arg( args, unsigned int * );
151 unsigned int *pi_height = va_arg( args, unsigned int * );
152 *pi_width = frame->width();
153 *pi_height = frame->height();
159 unsigned int i_width = va_arg( args, unsigned int );
160 unsigned int i_height = va_arg( args, unsigned int );
162 if( !i_width && p_vout ) i_width = p_vout->i_window_width;
163 if( !i_height && p_vout ) i_height = p_vout->i_window_height;
164 p_intf->p_sys->p_mi->videoSize = QSize( i_width, i_height );
170 case VOUT_SET_STAY_ON_TOP:
176 msg_Warn( p_intf, "unsupported control query" );
179 vlc_mutex_unlock( &lock );
183 /**********************************************************************
184 * Background Widget. Show a simple image background. Currently,
185 * it's a static cone.
186 **********************************************************************/
187 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
188 QFrame( NULL ), p_intf( _p_i )
191 CONNECT( THEMIM->getIM(), audioStarted(), this, hasAudio() );
192 CONNECT( THEMIM->getIM(), audioStarted(), this, hasVideo() );
195 int BackgroundWidget::DrawBackground()
197 setAutoFillBackground( true );
199 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
200 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
203 backgroundLayout = new QHBoxLayout;
204 label = new QLabel( "" );
205 label->setMaximumHeight( ICON_SIZE );
206 label->setMaximumWidth( ICON_SIZE );
207 label->setScaledContents( true );
208 label->setPixmap( QPixmap( ":/vlc128.png" ) );
209 backgroundLayout = new QHBoxLayout;
210 backgroundLayout->addWidget( label );
211 setLayout( backgroundLayout );
215 int BackgroundWidget::CleanBackground()
217 backgroundLayout->takeAt(0);
218 delete backgroundLayout;
222 void BackgroundWidget::hasAudio()
224 /* We have video already, do nothing */
225 if( THEMIM->getIM()->b_has_video )
231 /* Show the panel to the user */
232 fprintf( stderr, "Showing panel\n" );
236 void BackgroundWidget::resizeEvent( QResizeEvent *e )
238 if( e->size().height() < ICON_SIZE -1 )
239 label->setMaximumWidth( e->size().height() );
241 label->setMaximumWidth( ICON_SIZE );