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