]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
Rework of the embedded stuff. This breaks everything :)
[vlc] / modules / gui / qt4 / components / interface_widgets.cpp
1 /*****************************************************************************
2  * interface_widgets.cpp : Custom widgets for the main interface
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #include "dialogs_provider.hpp"
25 #include <vlc/vout.h>
26 #include "qt4.hpp"
27 #include "components/interface_widgets.hpp"
28 #include "main_interface.hpp"
29 #include "input_manager.hpp"
30 #include <QHBoxLayout>
31
32 #define ICON_SIZE 128
33
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 );
42
43 bool need_update;
44
45 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
46 {
47     vlc_mutex_init( p_intf, &lock );
48
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;
53     p_vout = NULL;
54
55     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
56
57     ON_TIMEOUT( update() );
58     need_update = false;
59 }
60
61 void VideoWidget::update()
62 {
63     if( need_update )
64     {
65         p_intf->p_sys->p_mi->resize( p_intf->p_sys->p_mi->sizeHint() );
66         need_update = false;
67     }
68 }
69
70 VideoWidget::~VideoWidget()
71 {
72     vlc_mutex_lock( &lock );
73     if( p_vout )
74     {
75         if( !p_intf->psz_switch_intf )
76         {
77             if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
78                 vout_Control( p_vout, VOUT_REPARENT );
79         }
80         else
81         {
82             if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
83                 vout_Control( p_vout, VOUT_CLOSE );
84         }
85     }
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 );
91 }
92
93 QSize VideoWidget::sizeHint() const
94 {
95     return widgetSize;
96 }
97
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)
100 {
101     return p_intf->p_sys->p_video->Request( p_vout, pi1, pi2, pi3, pi4 );
102 }
103
104 void *VideoWidget::Request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
105                            unsigned int *pi_width, unsigned int *pi_height )
106 {
107     if( p_vout )
108     {
109         msg_Dbg( p_intf, "embedded video already in use" );
110         return NULL;
111     }
112     p_vout = p_nvout;
113
114     setMinimumSize( 1,1 );
115     widgetSize = QSize( *pi_width, *pi_height );
116     updateGeometry();
117     need_update = true;
118     return  (void*)winId();
119 }
120
121 static void DoRelease( intf_thread_t *p_intf, void *p_win )
122 {
123     return p_intf->p_sys->p_video->Release( p_win );
124 }
125
126 void VideoWidget::Release( void *p_win )
127 {
128     p_vout = NULL;
129     if( config_GetInt( p_intf, "qt-always-video" ) == 0 )
130     {
131         widgetSize = QSize ( 1,1 );
132         updateGeometry();
133         need_update = true;
134     }
135 }
136
137 static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
138 {
139     return p_intf->p_sys->p_video->Control( p_win, i_q, a );
140 }
141
142 int VideoWidget::Control( void *p_window, int i_query, va_list args )
143 {
144     int i_ret = VLC_EGENERIC;
145     vlc_mutex_lock( &lock );
146     switch( i_query )
147     {
148         case VOUT_GET_SIZE:
149         {
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();
154             i_ret = VLC_SUCCESS;
155             break;
156         }
157         case VOUT_SET_SIZE:
158         {
159             unsigned int i_width  = va_arg( args, unsigned int );
160             unsigned int i_height = va_arg( args, unsigned int );
161
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             widgetSize = QSize( i_width, i_height );
165             updateGeometry();
166             need_update = true;
167             i_ret = VLC_SUCCESS;
168             break;
169         }
170         case VOUT_SET_STAY_ON_TOP:
171         {
172             /// \todo
173             break;
174         }
175         default:
176             msg_Warn( p_intf, "unsupported control query" );
177             break;
178     }
179     vlc_mutex_unlock( &lock );
180     return i_ret;
181 }
182
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 )
189 {
190     DrawBackground();
191     CONNECT( THEMIM->getIM(), audioStarted(), this, hasAudio() );
192     CONNECT( THEMIM->getIM(), audioStarted(), this, hasVideo() );
193 }
194
195 int BackgroundWidget::DrawBackground()
196 {
197    setAutoFillBackground( true );
198     plt =  palette();
199     plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
200     plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
201     setPalette( plt );
202
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 );
212     return 0;
213 }
214
215 int BackgroundWidget::CleanBackground()
216 {
217     backgroundLayout->takeAt(0);
218     delete backgroundLayout;
219     return 0;
220 }
221
222 QSize BackgroundWidget::sizeHint() const
223 {
224     return widgetSize;
225 }
226
227 void BackgroundWidget::hasAudio()
228 {
229     /* We have video already, do nothing */
230     if( THEMIM->getIM()->b_has_video )
231     {
232
233     }
234     else
235     {
236         /* Show the panel to the user */
237         fprintf( stderr, "Showing panel\n" );
238     }
239 }
240
241 void BackgroundWidget::resizeEvent( QResizeEvent *e )
242 {
243     if( e->size().height() < ICON_SIZE -1 )
244         label->setMaximumWidth( e->size().height() );
245     else
246         label->setMaximumWidth( ICON_SIZE );
247 }
248
249 /**********************************************************************
250  * Playlist Widget. The embedded playlist
251  **********************************************************************/
252 #include "components/playlist/panels.hpp"
253 #include "components/playlist/selector.hpp"
254
255 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) : QFrame(NULL),
256                                                             p_intf( _p_intf )
257 {
258     selector = new PLSelector( this, p_intf, THEPL );
259     selector->setMaximumWidth( 130 );
260
261     playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
262                                                 THEPL->p_local_category );
263
264     rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( this,
265                               p_intf, THEPL, p_root ) );
266
267     CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
268
269     QHBoxLayout *layout = new QHBoxLayout();
270     layout->addWidget( selector, 0 );
271     layout->addWidget( rightPanel, 10 );
272     setLayout( layout );
273 }
274
275 PlaylistWidget::~PlaylistWidget()
276 {
277 }
278
279 QSize PlaylistWidget::sizeHint() const
280 {
281     return widgetSize;
282 }
283