]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
Qt4 - Fullscreen button should work now. hasVideo() does not work, so force the activ...
[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  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * ( at your option ) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #include "dialogs_provider.hpp"
26 #include "qt4.hpp"
27 #include "components/interface_widgets.hpp"
28 #include "main_interface.hpp"
29 #include "input_manager.hpp"
30
31 #include "util/input_slider.hpp"
32 #include <vlc_vout.h>
33
34 #include <QLabel>
35 #include <QSpacerItem>
36 #include <QCursor>
37 #include <QPushButton>
38 #include <QHBoxLayout>
39 #include <QMenu>
40 #include <QPalette>
41 #include <QResizeEvent>
42
43 #define ICON_SIZE 300
44
45 /**********************************************************************
46  * Video Widget. A simple frame on which video is drawn
47  * This class handles resize issues
48  **********************************************************************/
49 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
50                         unsigned int *, unsigned int * );
51 static void DoRelease( intf_thread_t *, void * );
52 static int DoControl( intf_thread_t *, void *, int, va_list );
53
54 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
55 {
56     vlc_mutex_init( p_intf, &lock );
57     p_vout = NULL;
58     CONNECT( this, askResize(), this, SetMinSize() );
59     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
60 }
61
62 VideoWidget::~VideoWidget()
63 {
64     vlc_mutex_lock( &lock );
65     if( p_vout )
66     {
67         if( !p_intf->psz_switch_intf )
68         {
69             if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
70                 vout_Control( p_vout, VOUT_REPARENT );
71         }
72         else
73         {
74             if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
75                 vout_Control( p_vout, VOUT_CLOSE );
76         }
77     }
78     vlc_mutex_unlock( &lock );
79     vlc_mutex_destroy( &lock );
80 }
81
82 QSize VideoWidget::sizeHint() const
83 {
84     return widgetSize;
85 }
86
87 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
88                            unsigned int *pi_width, unsigned int *pi_height )
89 {
90     if( p_vout )
91     {
92         msg_Dbg( p_intf, "embedded video already in use" );
93         return NULL;
94     }
95     p_vout = p_nvout;
96     emit askResize();
97     return ( void* )winId();
98 }
99
100 void VideoWidget::SetMinSize()
101 {
102     setMinimumSize( 16, 16 );
103 }
104
105 void VideoWidget::release( void *p_win )
106 {
107     p_vout = NULL;
108 }
109 /**********************************************************************
110  * Background Widget. Show a simple image background. Currently,
111  * it's a static cone.
112  **********************************************************************/
113 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
114                                         QFrame( NULL ), p_intf( _p_i )
115 {
116
117     setAutoFillBackground( true );
118     plt =  palette();
119     plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
120     plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
121     setPalette( plt );
122
123     label = new QLabel( "" );
124     label->setMaximumHeight( ICON_SIZE );
125     label->setMaximumWidth( ICON_SIZE );
126     label->setScaledContents( true );
127     label->setPixmap( QPixmap( ":/vlc128.png" ) );
128     backgroundLayout = new QHBoxLayout;
129     backgroundLayout->addWidget( label );
130     setLayout( backgroundLayout );
131 }
132
133 BackgroundWidget::~BackgroundWidget()
134 {
135     backgroundLayout->takeAt( 0 );
136     delete backgroundLayout;
137 }
138
139 void BackgroundWidget::setArt( QString url )
140 {
141     if( url.isNull() )
142         label->setPixmap( QPixmap( ":/vlc128.png" ) );
143     else
144         label->setPixmap( QPixmap( url ) );
145 }
146
147 QSize BackgroundWidget::sizeHint() const
148 {
149     return widgetSize;
150 }
151
152 void BackgroundWidget::resizeEvent( QResizeEvent *e )
153 {
154     if( e->size().height() < ICON_SIZE -1 )
155         label->setMaximumWidth( e->size().height() );
156     else
157         label->setMaximumWidth( ICON_SIZE );
158 }
159
160 /**********************************************************************
161  * Visualization selector panel
162  **********************************************************************/
163 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
164                                                 QFrame( NULL ), p_intf( _p_i )
165 {
166     QHBoxLayout *layout = new QHBoxLayout( this );
167     layout->setMargin( 0 );
168     QPushButton *prevButton = new QPushButton( "Prev" );
169     QPushButton *nextButton = new QPushButton( "Next" );
170     layout->addWidget( prevButton );
171     layout->addWidget( nextButton );
172
173     layout->addItem( new QSpacerItem( 40,20,
174                               QSizePolicy::Expanding, QSizePolicy::Minimum ) );
175     layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
176
177     current = new QLabel( qtr( "None" ) );
178     layout->addWidget( current );
179
180     BUTTONACT( prevButton, prev() );
181     BUTTONACT( nextButton, next() );
182
183     setLayout( layout );
184     setMaximumHeight( 35 );
185 }
186
187 VisualSelector::~VisualSelector()
188 {
189 }
190
191 void VisualSelector::prev()
192 {
193     char *psz_new = aout_VisualPrev( p_intf );
194     if( psz_new )
195     {
196         current->setText( qfu( psz_new ) );
197         free( psz_new );
198     }
199 }
200
201 void VisualSelector::next()
202 {
203     char *psz_new = aout_VisualNext( p_intf );
204     if( psz_new )
205     {
206         current->setText( qfu( psz_new ) );
207         free( psz_new );
208     }
209 }
210
211 /**********************************************************************
212  * TEH controls
213  **********************************************************************/
214
215 #define setupSmallButton( aButton ){  \
216     aButton->setMaximumSize( QSize( 26, 26 ) ); \
217     aButton->setMinimumSize( QSize( 26, 26 ) ); \
218     aButton->setIconSize( QSize( 20, 20 ) ); }
219
220 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
221                                            QFrame( NULL ), p_intf( _p_i )
222 {
223     QHBoxLayout *advLayout = new QHBoxLayout( this );
224     advLayout->setMargin( 0 );
225     advLayout->setSpacing( 0 );
226
227 /* FIXME A to B function */
228     ABButton = new QPushButton( "AB" );
229     ABButton->setMaximumSize( QSize( 26, 26 ) );
230     ABButton->setIconSize( QSize( 20, 20 ) );
231     advLayout->addWidget( ABButton );
232     BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
233
234     snapshotButton = new QPushButton( "S" );
235     snapshotButton->setMaximumSize( QSize( 26, 26 ) );
236     snapshotButton->setIconSize( QSize( 20, 20 ) );
237     advLayout->addWidget( snapshotButton );
238     BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
239
240 //FIXME Frame by frame function
241     frameButton = new QPushButton( "Fr" );
242     frameButton->setMaximumSize( QSize( 26, 26 ) );
243     frameButton->setIconSize( QSize( 20, 20 ) );
244     advLayout->addWidget( frameButton );
245     BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
246
247 /* FIXME Record function */
248     recordButton = new QPushButton( "R" );
249     recordButton->setMaximumSize( QSize( 26, 26 ) );
250     recordButton->setIconSize( QSize( 20, 20 ) );
251     advLayout->addWidget( recordButton );
252     BUTTON_SET_ACT( recordButton, "R", qtr( "Record" ), record() );
253
254     normalButton = new QPushButton( "N" );
255     normalButton->setMaximumSize( QSize( 26, 26 ) );
256     normalButton->setIconSize( QSize( 20, 20 ) );
257     advLayout->addWidget( normalButton );
258     BUTTON_SET_ACT( normalButton, "N", qtr( "Normal rate" ), normal() );
259
260 }
261
262 AdvControlsWidget::~AdvControlsWidget()
263 {
264 }
265
266 void AdvControlsWidget::enableInput( bool enable )
267 {
268 //    slowerButton->setEnabled( enable );
269     ABButton->setEnabled( enable );
270     recordButton->setEnabled( enable );
271     normalButton->setEnabled( enable );
272 //    fasterButton->setEnabled( enable );
273 }
274 void AdvControlsWidget::enableVideo( bool enable )
275 {
276     snapshotButton->setEnabled( enable );
277     frameButton->setEnabled( enable );
278     //fullscreenButton->setEnabled( enable );
279 }
280
281 void AdvControlsWidget::normal()
282 {
283     THEMIM->getIM()->normalRate();
284 }
285
286 void AdvControlsWidget::snapshot()
287 {
288 }
289
290 void AdvControlsWidget::frame(){}
291 void AdvControlsWidget::fromAtoB(){}
292 void AdvControlsWidget::record(){}
293
294 /*****************************
295  * DA Control Widget !
296  *****************************/
297 ControlsWidget::ControlsWidget( intf_thread_t *_p_i, bool b_advControls ) :
298                              QFrame( NULL ), p_intf( _p_i )
299 {
300     //QSize size( 500, 200 );
301     //resize( size );
302     controlLayout = new QGridLayout( this );
303
304 #if DEBUG_COLOR
305     QPalette palette2;
306     palette2.setColor(this->backgroundRole(), Qt::magenta);
307     setPalette(palette2);
308 #endif
309
310     /** The main Slider **/
311     slider = new InputSlider( Qt::Horizontal, NULL );
312     controlLayout->addWidget( slider, 0, 1, 1, 16 );
313     /* Update the position when the IM has changed */
314     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
315              slider, setPosition( float,int, int ) );
316     /* And update the IM, when the position has changed */
317     CONNECT( slider, sliderDragged( float ),
318              THEMIM->getIM(), sliderUpdate( float ) );
319
320     /** Slower and faster Buttons **/
321     slowerButton = new QPushButton( "S" );
322     BUTTON_SET_ACT( slowerButton, "S", qtr( "Slower" ), slower() );
323     controlLayout->addWidget( slowerButton, 0, 0 );
324     slowerButton->setMaximumSize( QSize( 26, 20 ) );
325
326     fasterButton = new QPushButton( "F" );
327     BUTTON_SET_ACT( fasterButton, "F", qtr( "Faster" ), faster() );
328     controlLayout->addWidget( fasterButton, 0, 17 );
329     fasterButton->setMaximumSize( QSize( 26, 20 ) );
330
331     /** TODO: Insert here the AdvControls Widget 
332      * Then fix all the size issues in main_interface.cpp
333      **/
334     /* advanced Controls handling */
335     b_advancedVisible = b_advControls;
336
337     advControls = new AdvControlsWidget( p_intf );
338     controlLayout->addWidget( advControls, 1, 3, 2, 5, Qt::AlignBottom );
339     if( !b_advancedVisible ) advControls->hide();
340 //THIS should be removed.    need_components_update = true;
341
342     /** Disc and Menus handling */
343     discFrame = new QFrame( this );
344
345     QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
346     discLayout->setSpacing( 0 );
347     discLayout->setMargin( 0 );
348
349     prevSectionButton = new QPushButton( discFrame );
350     setupSmallButton( prevSectionButton );
351     discLayout->addWidget( prevSectionButton );
352
353     menuButton = new QPushButton( discFrame );
354     setupSmallButton( menuButton );
355     discLayout->addWidget( menuButton );
356
357     nextSectionButton = new QPushButton( discFrame );
358     setupSmallButton( nextSectionButton );
359     discLayout->addWidget( nextSectionButton );
360
361     controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
362
363     BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
364     BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
365     BUTTON_SET_IMG( menuButton, "", previous.png, "" );
366
367     discFrame->hide();
368
369     /* Change the navigation button display when the IM navigation changes */
370     CONNECT( THEMIM->getIM(), navigationChanged( int ),
371              this, setNavigation( int ) );
372     /* Changes the IM navigation when triggered on the nav buttons */
373     CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
374              sectionPrev() );
375     CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
376              sectionNext() );
377     CONNECT( menuButton, clicked(), THEMIM->getIM(),
378              sectionMenu() );
379
380     /** TODO
381      * Telextext QFrame
382      **/
383
384     /** Play Buttons **/
385     QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
386     sizePolicy.setHorizontalStretch( 0 );
387     sizePolicy.setVerticalStretch( 0 );
388 //  sizePolicy.setHeightForWidth( playButton->sizePolicy().hasHeightForWidth() );
389
390     /* Play */
391     playButton = new QPushButton;
392     playButton->setSizePolicy( sizePolicy );
393     playButton->setMaximumSize( QSize( 45, 45 ) );
394     playButton->setIconSize( QSize( 30, 30 ) );
395
396     controlLayout->addWidget( playButton, 2, 0, 2, 2, Qt::AlignBottom );
397     
398     controlLayout->setColumnMinimumWidth( 2, 20 );
399     controlLayout->setColumnStretch( 2, 0 );
400
401     /** Prev + Stop + Next Block **/
402     QHBoxLayout *controlButLayout = new QHBoxLayout;
403     controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
404
405     /* Prev */
406     QPushButton *prevButton = new QPushButton;
407     prevButton->setSizePolicy( sizePolicy );
408     setupSmallButton( prevButton );
409
410     controlButLayout->addWidget( prevButton );
411
412     /* Stop */
413     QPushButton *stopButton = new QPushButton;
414     stopButton->setSizePolicy( sizePolicy );
415     setupSmallButton( stopButton );
416
417     controlButLayout->addWidget( stopButton );
418
419     /* next */
420     QPushButton *nextButton = new QPushButton;
421     nextButton->setSizePolicy( sizePolicy );
422     setupSmallButton( nextButton );
423
424     controlButLayout->addWidget( nextButton );
425
426     /* Add this block to the main layout */
427     controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
428
429     BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
430     BUTTON_SET_ACT_I( prevButton, "" , previous.png,
431                       qtr( "Previous" ), prev() );
432     BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
433     BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
434
435     controlLayout->setColumnStretch( 8 , 10 );
436     controlLayout->setColumnStretch( 9, 0 );
437     
438     /*
439      * Other first Line buttons
440      * Might need to be inside a frame to avoid a few resizing pb
441      * FIXME
442      */
443     /** Fullscreen/Visualisation **/
444     fullscreenButton = new QPushButton( "F" );
445     BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
446     setupSmallButton( fullscreenButton );
447     controlLayout->addWidget( fullscreenButton, 3, 10 );
448
449     /** Playlist Button **/
450     playlistButton = new QPushButton;
451     setupSmallButton( playlistButton );
452
453     controlLayout->addWidget( playlistButton, 3, 11 );
454
455     /** extended Settings **/
456     QPushButton *extSettingsButton = new QPushButton( "F" );
457     BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
458             extSettings() );
459     setupSmallButton( extSettingsButton );
460     controlLayout->addWidget( extSettingsButton, 3, 12 );
461
462     /** Preferences **/
463     QPushButton *prefsButton = new QPushButton( "P" );
464     BUTTON_SET_ACT( prefsButton, "P", qtr( "Preferences / Settings" ),
465             prefs() );
466     setupSmallButton( prefsButton );
467     controlLayout->addWidget( prefsButton, 3, 13 );
468     
469     controlLayout->setColumnStretch( 14, 5 );
470
471     /* Volume */
472     VolumeClickHandler *h = new VolumeClickHandler( p_intf, this );
473
474     QLabel *volMuteLabel = new QLabel;
475     volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
476     volMuteLabel->setToolTip( qtr( "Mute" ) );
477     volMuteLabel->installEventFilter( h );
478
479     /** TODO: 
480      * Change this slider to use a nice Amarok-like one 
481      * Add a Context menu to change to the most useful %
482      * **/
483     /** FIXME
484      *  THis percerntage thing has to be handled correctly
485      *  This has to match to the OSD
486      **/
487     volumeSlider = new QSlider;
488     volumeSlider->setSizePolicy( sizePolicy );
489     volumeSlider->setMaximumSize( QSize( 80, 200 ) );
490     volumeSlider->setOrientation( Qt::Horizontal );
491
492     volumeSlider->setMaximum( 100 );
493     volumeSlider->setFocusPolicy( Qt::NoFocus );
494     controlLayout->addWidget( volMuteLabel, 3, 15 );
495     controlLayout->addWidget( volumeSlider, 3, 16, 1, 2 );
496
497     /* Volume control connection */
498     CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
499
500 }
501 ControlsWidget::~ControlsWidget()
502 {
503 }
504 void ControlsWidget::stop()
505 {
506     THEMIM->stop();
507 }
508
509 void ControlsWidget::play()
510 {
511     if( THEPL )
512         msg_Dbg( p_intf, "There is %i playlist items", THEPL->items.i_size ); /* FIXME: remove me */
513     if( playlist_IsEmpty( THEPL ) )
514     {
515         /* The playlist is empty, open a file requester */
516         THEDP->openFileDialog();
517         setStatus( 0 );
518         return;
519     }
520     THEMIM->togglePlayPause();
521 }
522
523 void ControlsWidget::prev()
524 {
525     THEMIM->prev();
526 }
527
528 void ControlsWidget::next()
529 {
530     THEMIM->next();
531 }
532
533 void ControlsWidget::setNavigation( int navigation )
534 {
535 #define HELP_MENU N_( "Menu" )
536 #define HELP_PCH N_( "Previous chapter" )
537 #define HELP_NCH N_( "Next chapter" )
538 #define HELP_PTR N_( "Previous track" )
539 #define HELP_NTR N_( "Next track" )
540
541     // 1 = chapter, 2 = title, 0 = no
542     if( navigation == 0 )
543     {
544         discFrame->hide();
545     } else if( navigation == 1 ) {
546         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
547         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
548         menuButton->show();
549         discFrame->show();
550     } else {
551         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
552         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
553         menuButton->hide();
554         discFrame->show();
555     }
556 }
557
558 static bool b_my_volume;
559 void ControlsWidget::updateVolume( int sliderVolume )
560 {
561     if( !b_my_volume )
562     {
563         int i_res = sliderVolume * AOUT_VOLUME_MAX /
564                             ( 2*volumeSlider->maximum() );
565         aout_VolumeSet( p_intf, i_res );
566     }
567 }
568
569 void ControlsWidget::updateOnTimer()
570 {
571     /* Audio part */
572     audio_volume_t i_volume;
573     aout_VolumeGet( p_intf, &i_volume );
574     i_volume = ( i_volume *  200 )/ AOUT_VOLUME_MAX ;
575     int i_gauge = volumeSlider->value();
576     b_my_volume = false;
577     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
578     {
579         b_my_volume = true;
580         volumeSlider->setValue( i_volume );
581         b_my_volume = false;
582     }
583
584     /* Activate the interface buttons according to the presence of the input */
585     enableInput( THEMIM->getIM()->hasInput() );
586     enableVideo( true );
587     //enableVideo( THEMIM->getIM()->hasVideo() );
588 }
589
590 void ControlsWidget::setStatus( int status )
591 {
592     if( status == PLAYING_S ) // Playing
593         playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
594     else
595         playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
596 }
597
598 /**
599  * TODO
600  * This functions toggle the fullscreen mode
601  * If there is no video, it should first activate Visualisations... 
602  *  This has also to be fixed in enableVideo()
603  */
604 void ControlsWidget::fullscreen()
605 {
606     vlc_object_t *p_vout = (vlc_object_t *)vlc_object_find( p_intf,
607                 VLC_OBJECT_VOUT, FIND_CHILD );
608     if( p_vout)
609     {
610         var_Get( p_vout, "fullscreen", &val );
611         val.b_bool = !val.b_bool;
612         var_Set( p_vout, "fullscreen", val );
613     }
614 }
615
616 void ControlsWidget::extSettings()
617 {
618     THEDP->extendedDialog();
619 }
620 void ControlsWidget::prefs()
621 {
622     THEDP->prefsDialog();
623 }
624
625 void ControlsWidget::slower()
626 {
627     THEMIM->getIM()->slower();
628 }
629
630 void ControlsWidget::faster()
631 {
632     THEMIM->getIM()->faster();
633 }
634
635 void ControlsWidget::enableInput( bool enable )
636 {
637     slowerButton->setEnabled( enable );
638     slider->setEnabled( enable );
639     fasterButton->setEnabled( enable );
640
641     /* Advanced Buttons too */
642     advControls->enableInput( enable );
643 }
644
645 void ControlsWidget::enableVideo( bool enable )
646 {
647     // TODO Later make the fullscreenButton toggle Visualisation and so on.
648     fullscreenButton->setEnabled( enable );
649
650     /* Advanced Buttons too */
651     advControls->enableVideo( enable );
652 }
653
654 void ControlsWidget::toggleAdvanced()
655 {
656     if( !VISIBLE( advControls ) )
657     {
658         advControls->show();
659         b_advancedVisible = true;
660     }
661     else
662     {
663         advControls->hide();
664         b_advancedVisible = false;
665     }
666     //FIXME connect this one :D
667     emit advancedControlsToggled( b_advancedVisible );  //  doComponentsUpdate();
668 }
669
670 /**********************************************************************
671  * Playlist Widget. The embedded playlist
672  **********************************************************************/
673 #include "components/playlist/panels.hpp"
674 #include "components/playlist/selector.hpp"
675
676 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) :
677                                 p_intf ( _p_intf )
678 {
679     /* Left Part and design */
680     QWidget *leftW = new QWidget( this );
681     QVBoxLayout *left = new QVBoxLayout( leftW );
682
683     /* Source Selector */
684     selector = new PLSelector( this, p_intf, THEPL );
685     left->addWidget( selector );
686
687     /* Art label */
688     art = new QLabel( "" );
689     art->setMinimumHeight( 128 );
690     art->setMinimumWidth( 128 );
691     art->setMaximumHeight( 128 );
692     art->setMaximumWidth( 128 );
693     art->setScaledContents( true );
694     art->setPixmap( QPixmap( ":/noart.png" ) );
695     left->addWidget( art );
696
697     /* Initialisation of the playlist */
698     playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
699                                                 THEPL->p_local_category );
700
701     rightPanel = qobject_cast<PLPanel *>( new StandardPLPanel( this,
702                               p_intf, THEPL, p_root ) );
703
704     /* Connects */
705     CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
706
707     CONNECT( qobject_cast<StandardPLPanel *>( rightPanel )->model,
708              artSet( QString ) , this, setArt( QString ) );
709     /* Forward removal requests from the selector to the main panel */
710     CONNECT( qobject_cast<PLSelector *>( selector )->model,
711              shouldRemove( int ),
712              qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
713
714     connect( selector, SIGNAL( activated( int ) ),
715              this, SIGNAL( rootChanged( int ) ) );
716     emit rootChanged( p_root->i_id );
717
718     /* Add the two sides of the QSplitter */
719     addWidget( leftW );
720     addWidget( rightPanel );
721
722     leftW->setMaximumWidth( 250 );
723     setCollapsible( 1, false );
724
725     QList<int> sizeList;
726     sizeList << 180 << 520 ;
727     setSizes( sizeList );
728 }
729
730 void PlaylistWidget::setArt( QString url )
731 {
732     if( url.isNull() )
733         art->setPixmap( QPixmap( ":/noart.png" ) );
734     else if( prevArt != url )
735         art->setPixmap( QPixmap( url ) );
736     prevArt = url;
737     emit artSet( url );
738 }
739
740 PlaylistWidget::~PlaylistWidget()
741 {
742 }
743
744 QSize PlaylistWidget::sizeHint() const
745 {
746     return widgetSize;
747 }
748