]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
Qt4 - PlaylistWidget use a much nicer QSplitter. Removes also too much class inherita...
[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 #include <QPalette>
39 #include <QResizeEvent>
40
41 #define ICON_SIZE 128
42
43 /**********************************************************************
44  * Video Widget. A simple frame on which video is drawn
45  * This class handles resize issues
46  **********************************************************************/
47 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
48                         unsigned int *, unsigned int * );
49 static void DoRelease( intf_thread_t *, void * );
50 static int DoControl( intf_thread_t *, void *, int, va_list );
51
52 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
53 {
54     vlc_mutex_init( p_intf, &lock );
55     p_vout = NULL;
56
57     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
58 }
59
60 VideoWidget::~VideoWidget()
61 {
62     vlc_mutex_lock( &lock );
63     if( p_vout )
64     {
65         if( !p_intf->psz_switch_intf )
66         {
67             if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
68                 vout_Control( p_vout, VOUT_REPARENT );
69         }
70         else
71         {
72             if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
73                 vout_Control( p_vout, VOUT_CLOSE );
74         }
75     }
76     vlc_mutex_unlock( &lock );
77     vlc_mutex_destroy( &lock );
78 }
79
80 QSize VideoWidget::sizeHint() const
81 {
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( 16, 16 );
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     return widgetSize;
136 }
137
138 void BackgroundWidget::resizeEvent( QResizeEvent *e )
139 {
140     if( e->size().height() < ICON_SIZE -1 )
141         label->setMaximumWidth( e->size().height() );
142     else
143         label->setMaximumWidth( ICON_SIZE );
144 }
145
146 /**********************************************************************
147  * Visualization selector panel
148  **********************************************************************/
149 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
150                                                 QFrame( NULL ), p_intf( _p_i )
151 {
152     QHBoxLayout *layout = new QHBoxLayout( this );
153     layout->setMargin( 0 );
154     QPushButton *prevButton = new QPushButton( "Prev" );
155     QPushButton *nextButton = new QPushButton( "Next");
156     layout->addWidget( prevButton );
157     layout->addWidget( nextButton );
158
159     layout->addItem( new QSpacerItem( 40,20,
160                               QSizePolicy::Expanding, QSizePolicy::Minimum) );
161     layout->addWidget( new QLabel( qtr("Current visualization:") ) );
162
163     current = new QLabel( qtr( "None" ) );
164     layout->addWidget( current );
165
166     BUTTONACT( prevButton, prev() );
167     BUTTONACT( nextButton, next() );
168
169     setLayout( layout );
170     setMaximumHeight( 35 );
171 }
172
173 VisualSelector::~VisualSelector()
174 {
175 }
176
177 void VisualSelector::prev()
178 {
179     char *psz_new = aout_VisualPrev( p_intf );
180     if( psz_new )
181     {
182         current->setText( qfu( psz_new ) );
183         free( psz_new );
184     }
185 }
186
187 void VisualSelector::next()
188 {
189     char *psz_new = aout_VisualNext( p_intf );
190     if( psz_new )
191     {
192         current->setText( qfu( psz_new ) );
193         free( psz_new );
194     }
195 }
196
197 /**********************************************************************
198  * More controls
199  **********************************************************************/
200 ControlsWidget::ControlsWidget( intf_thread_t *_p_i ) :
201                                            QFrame( NULL ), p_intf( _p_i )
202 {
203     QHBoxLayout *layout = new QHBoxLayout( this );
204     layout->setMargin( 0 );
205
206     slowerButton = new QPushButton( "S" );
207     BUTTON_SET_ACT( slowerButton, "S", qtr("Slower" ), slower() );
208     layout->addWidget( slowerButton );
209     slowerButton->setMaximumWidth( 35 );
210
211     normalButton = new QPushButton( "N" );
212     BUTTON_SET_ACT( normalButton, "N", qtr("Normal rate"), normal() );
213     layout->addWidget( normalButton );
214     normalButton->setMaximumWidth( 35 );
215
216     fasterButton = new QPushButton( "F" );
217     BUTTON_SET_ACT( fasterButton, "F", qtr("Faster" ), faster() );
218     layout->addWidget( fasterButton );
219     fasterButton->setMaximumWidth( 35 );
220
221     layout->addItem( new QSpacerItem( 100,20,
222                               QSizePolicy::Expanding, QSizePolicy::Minimum) );
223
224     snapshotButton = new QPushButton( "S" );
225     BUTTON_SET_ACT( snapshotButton, "S", qtr("Take a snapshot"), snapshot() );
226     layout->addWidget( snapshotButton );
227     snapshotButton->setMaximumWidth( 35 );
228
229     fullscreenButton = new QPushButton( "F" );
230     BUTTON_SET_ACT( fullscreenButton, "F", qtr("Fullscreen"), fullscreen() );
231     layout->addWidget( fullscreenButton );
232     fullscreenButton->setMaximumWidth( 35 );
233 }
234
235 ControlsWidget::~ControlsWidget()
236 {
237 }
238
239 void ControlsWidget::enableInput( bool enable )
240 {
241     slowerButton->setEnabled( enable );
242     normalButton->setEnabled( enable );
243     fasterButton->setEnabled( enable );
244 }
245 void ControlsWidget::enableVideo( bool enable )
246 {
247     snapshotButton->setEnabled( enable );
248     fullscreenButton->setEnabled( enable );
249 }
250
251 void ControlsWidget::slower()
252 {
253     THEMIM->getIM()->slower();
254 }
255
256 void ControlsWidget::faster()
257 {
258     THEMIM->getIM()->faster();
259 }
260
261 void ControlsWidget::normal()
262 {
263     THEMIM->getIM()->normalRate();
264 }
265
266 void ControlsWidget::snapshot()
267 {
268 }
269
270 void ControlsWidget::fullscreen()
271 {
272 }
273
274 /**********************************************************************
275  * Playlist Widget. The embedded playlist
276  **********************************************************************/
277 #include "components/playlist/panels.hpp"
278 #include "components/playlist/selector.hpp"
279
280 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) :
281                                 p_intf ( _p_intf)
282 {
283     /* Left Part and design */
284     QWidget *leftW = new QWidget( this );
285     QVBoxLayout *left = new QVBoxLayout( leftW );
286
287     /* Source Selector */
288     selector = new PLSelector( this, p_intf, THEPL );
289     selector->setMaximumWidth( 130 );
290     left->addWidget( selector );
291
292     /* Art label */
293     art = new QLabel( "" );
294     art->setMinimumHeight( 128 );
295     art->setMinimumWidth( 128 );
296     art->setMaximumHeight( 128 );
297     art->setMaximumWidth( 128 );
298     art->setScaledContents( true );
299     art->setPixmap( QPixmap( ":/noart.png" ) );
300     left->addWidget( art );
301
302     /* Initialisation of the playlist */
303     playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
304                                                 THEPL->p_local_category );
305
306     rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( this,
307                               p_intf, THEPL, p_root ) );
308
309     /* Connects */
310     CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
311
312     CONNECT( qobject_cast<StandardPLPanel *>(rightPanel)->model,
313              artSet( QString ) , this, setArt( QString ) );
314     /* Forward removal requests from the selector to the main panel */
315     CONNECT( qobject_cast<PLSelector *>(selector)->model,
316              shouldRemove( int ),
317              qobject_cast<StandardPLPanel *>(rightPanel), removeItem(int) );
318
319     connect( selector, SIGNAL(activated( int )),
320              this, SIGNAL( rootChanged( int ) ) );
321     emit rootChanged( p_root->i_id );
322
323     /* Add the two sides of the QSplitter */
324     addWidget( leftW );
325     addWidget( rightPanel );
326
327     /* FIXME Sizing to do */
328 }
329
330 void PlaylistWidget::setArt( QString url )
331 {
332     if( url.isNull() )
333         art->setPixmap( QPixmap( ":/noart.png" ) );
334     else if( prevArt != url )
335         art->setPixmap( QPixmap( url ) );
336     prevArt = url;
337 }
338
339 PlaylistWidget::~PlaylistWidget()
340 {
341 }
342
343 QSize PlaylistWidget::sizeHint() const
344 {
345     return widgetSize;
346 }
347