]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
Don't spit too much debug
[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 "qt4.hpp"
26 #include "components/interface_widgets.hpp"
27 #include "main_interface.hpp"
28 #include "input_manager.hpp"
29
30 #include "pixmaps/art.xpm"
31 #include <vlc/vout.h>
32
33 #include <QLabel>
34 #include <QSpacerItem>
35 #include <QCursor>
36 #include <QPushButton>
37 #include <QHBoxLayout>
38 #include <QMenu>
39
40 #define ICON_SIZE 128
41
42 /**********************************************************************
43  * Video Widget. A simple frame on which video is drawn
44  * This class handles resize issues
45  **********************************************************************/
46 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
47                         unsigned int *, unsigned int * );
48 static void DoRelease( intf_thread_t *, void * );
49 static int DoControl( intf_thread_t *, void *, int, va_list );
50
51 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
52 {
53     vlc_mutex_init( p_intf, &lock );
54     p_vout = NULL;
55
56     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
57 }
58
59 VideoWidget::~VideoWidget()
60 {
61     vlc_mutex_lock( &lock );
62     if( p_vout )
63     {
64         if( !p_intf->psz_switch_intf )
65         {
66             if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
67                 vout_Control( p_vout, VOUT_REPARENT );
68         }
69         else
70         {
71             if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
72                 vout_Control( p_vout, VOUT_CLOSE );
73         }
74     }
75     vlc_mutex_unlock( &lock );
76     vlc_mutex_destroy( &lock );
77 }
78
79 QSize VideoWidget::sizeHint() const
80 {
81     fprintf( stderr, "Video Size %ix%i\n", widgetSize.width(), widgetSize.height() );
82     return widgetSize;
83 }
84
85 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
86                            unsigned int *pi_width, unsigned int *pi_height )
87 {
88     if( p_vout )
89     {
90         msg_Dbg( p_intf, "embedded video already in use" );
91         return NULL;
92     }
93     p_vout = p_nvout;
94     setMinimumSize( 1,1 );
95     return (void*)winId();
96 }
97
98 void VideoWidget::release( void *p_win )
99 {
100     p_vout = NULL;
101 }
102 /**********************************************************************
103  * Background Widget. Show a simple image background. Currently,
104  * it's a static cone.
105  **********************************************************************/
106 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
107                                         QFrame( NULL ), p_intf( _p_i )
108 {
109
110     setAutoFillBackground( true );
111     plt =  palette();
112     plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
113     plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
114     setPalette( plt );
115
116     backgroundLayout = new QHBoxLayout;
117     label = new QLabel( "" );
118     label->setMaximumHeight( ICON_SIZE );
119     label->setMaximumWidth( ICON_SIZE );
120     label->setScaledContents( true );
121     label->setPixmap( QPixmap( ":/vlc128.png" ) );
122     backgroundLayout = new QHBoxLayout;
123     backgroundLayout->addWidget( label );
124     setLayout( backgroundLayout );
125 }
126
127 BackgroundWidget::~BackgroundWidget()
128 {
129     backgroundLayout->takeAt(0);
130     delete backgroundLayout;
131 }
132
133 QSize BackgroundWidget::sizeHint() const
134 {
135     fprintf( stderr, "BG %ix%i\n", widgetSize.width(), widgetSize.height() );
136     return widgetSize;
137 }
138
139 void BackgroundWidget::resizeEvent( QResizeEvent *e )
140 {
141     if( e->size().height() < ICON_SIZE -1 )
142         label->setMaximumWidth( e->size().height() );
143     else
144         label->setMaximumWidth( ICON_SIZE );
145 }
146
147 /**********************************************************************
148  * Visualization selector panel
149  **********************************************************************/
150 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
151                                                 QFrame( NULL ), p_intf( _p_i )
152 {
153     QHBoxLayout *layout = new QHBoxLayout( this );
154     layout->setMargin( 0 );
155     QPushButton *prevButton = new QPushButton( "Prev" );
156     QPushButton *nextButton = new QPushButton( "Next");
157     layout->addWidget( prevButton );
158     layout->addWidget( nextButton );
159
160     layout->addItem( new QSpacerItem( 40,20,
161                               QSizePolicy::Expanding, QSizePolicy::Minimum) );
162     layout->addWidget( new QLabel( qtr("Current visualization:") ) );
163
164     current = new QLabel( qtr( "None" ) );
165     layout->addWidget( current );
166
167     BUTTONACT( prevButton, prev() );
168     BUTTONACT( nextButton, next() );
169
170     setLayout( layout );
171     setMaximumHeight( 35 );
172 }
173
174 VisualSelector::~VisualSelector()
175 {
176 }
177
178 void VisualSelector::prev()
179 {
180     char *psz_new = aout_VisualPrev( p_intf );
181     if( psz_new )
182     {
183         current->setText( qfu( psz_new ) );
184         free( psz_new );
185     }
186 }
187
188 void VisualSelector::next()
189 {
190     char *psz_new = aout_VisualNext( p_intf );
191     if( psz_new )
192     {
193         current->setText( qfu( psz_new ) );
194         free( psz_new );
195     }
196 }
197
198 /**********************************************************************
199  * More controls
200  **********************************************************************/
201 ControlsWidget::ControlsWidget( intf_thread_t *_p_i ) :
202                                            QFrame( NULL ), p_intf( _p_i )
203 {
204     QHBoxLayout *layout = new QHBoxLayout( this );
205     layout->setMargin( 0 );
206
207     slowerButton = new QPushButton( "S" );
208     BUTTON_SET_ACT( slowerButton, "S", qtr("Slower" ), slower() );
209     layout->addWidget( slowerButton );
210     slowerButton->setMaximumWidth( 35 );
211
212     normalButton = new QPushButton( "N" );
213     BUTTON_SET_ACT( normalButton, "N", qtr("Normal rate"), normal() );
214     layout->addWidget( normalButton );
215     normalButton->setMaximumWidth( 35 );
216
217     fasterButton = new QPushButton( "F" );
218     BUTTON_SET_ACT( fasterButton, "F", qtr("Faster" ), faster() );
219     layout->addWidget( fasterButton );
220     fasterButton->setMaximumWidth( 35 );
221
222     layout->addItem( new QSpacerItem( 100,20,
223                               QSizePolicy::Expanding, QSizePolicy::Minimum) );
224
225     snapshotButton = new QPushButton( "S" );
226     BUTTON_SET_ACT( snapshotButton, "S", qtr("Take a snapshot"), snapshot() );
227     layout->addWidget( snapshotButton );
228     snapshotButton->setMaximumWidth( 35 );
229
230     fullscreenButton = new QPushButton( "F" );
231     BUTTON_SET_ACT( fullscreenButton, "F", qtr("Fullscreen"), fullscreen() );
232     layout->addWidget( fullscreenButton );
233     fullscreenButton->setMaximumWidth( 35 );
234 }
235
236 ControlsWidget::~ControlsWidget()
237 {
238 }
239
240 void ControlsWidget::enableInput( bool enable )
241 {
242     slowerButton->setEnabled( enable );
243     normalButton->setEnabled( enable );
244     fasterButton->setEnabled( enable );
245 }
246 void ControlsWidget::enableVideo( bool enable )
247 {
248     snapshotButton->setEnabled( enable );
249     fullscreenButton->setEnabled( enable );
250 }
251
252 void ControlsWidget::slower()
253 {
254     THEMIM->getIM()->slower();
255 }
256
257 void ControlsWidget::faster()
258 {
259     THEMIM->getIM()->faster();
260 }
261
262 void ControlsWidget::normal()
263 {
264     THEMIM->getIM()->normalRate();
265 }
266
267 void ControlsWidget::snapshot()
268 {
269 }
270
271 void ControlsWidget::fullscreen()
272 {
273 }
274
275 /**********************************************************************
276  * Playlist Widget. The embedded playlist
277  **********************************************************************/
278 #include "components/playlist/panels.hpp"
279 #include "components/playlist/selector.hpp"
280
281 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) :
282                                 BasePlaylistWidget ( _p_intf)
283 {
284     QVBoxLayout *left = new QVBoxLayout( );
285
286     selector = new PLSelector( this, p_intf, THEPL );
287     selector->setMaximumWidth( 130 );
288     left->addWidget( selector );
289
290     art = new QLabel( "" );
291     art->setMaximumHeight( 128 );
292     art->setMaximumWidth( 128 );
293     art->setScaledContents( true );
294     art->setPixmap( QPixmap( art_xpm ) ); //":/vlc128.png" ) );
295     left->addWidget( art );
296
297     playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
298                                                 THEPL->p_local_category );
299
300     rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( this,
301                               p_intf, THEPL, p_root ) );
302
303     CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
304
305     CONNECT( qobject_cast<StandardPLPanel *>(rightPanel)->model, artSet( QString ) , this, setArt( QString ) );
306
307     connect( selector, SIGNAL(activated( int )),
308              this, SIGNAL( rootChanged( int ) ) );
309     emit rootChanged( p_root->i_id );
310
311     QHBoxLayout *layout = new QHBoxLayout(this);
312     layout->addLayout( left, 0 );
313     layout->addWidget( rightPanel, 10 );
314     setLayout( layout );
315 }
316
317 void PlaylistWidget::setArt( QString url )
318 {
319     if( prevArt != url )
320     {
321         fprintf( stderr, "Display %s\n", qta( url ) );
322         art->setPixmap( QPixmap( url ) );
323         prevArt = url;
324     }
325 }
326
327 PlaylistWidget::~PlaylistWidget()
328 {
329 }
330
331 QSize PlaylistWidget::sizeHint() const
332 {
333     return widgetSize;
334 }
335