1 /*****************************************************************************
2 * playlist.cpp : Custom widgets for the playlist
3 ****************************************************************************
4 * Copyright © 2007-2008 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
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.
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.
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 *****************************************************************************/
29 #include "components/playlist/panels.hpp"
30 #include "components/playlist/selector.hpp"
31 #include "components/playlist/playlist.hpp"
33 #include "input_manager.hpp" /* art signal */
34 #include "main_interface.hpp" /* DropEvent TODO remove this*/
36 /**********************************************************************
37 * Playlist Widget. The embedded playlist
38 **********************************************************************/
40 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) : p_intf ( _p_i )
42 setContentsMargins( 3, 3, 3, 3 );
44 /* Left Part and design */
45 QSplitter *leftW = new QSplitter( Qt::Vertical, this );
48 selector = new PLSelector( this, p_intf );
49 leftW->addWidget( selector );
51 /* Create a Container for the Art Label
52 in order to have a beautiful resizing for the selector above it */
53 QWidget *artContainer = new QWidget;
54 QHBoxLayout *artContLay = new QHBoxLayout( artContainer );
55 artContLay->setMargin( 0 );
56 artContLay->setSpacing( 0 );
57 artContainer->setMaximumHeight( 128 );
60 art = new ArtLabel( artContainer, p_intf );
61 art->setToolTip( qtr( "Double click to get media information" ) );
63 CONNECT( THEMIM->getIM(), artChanged( QString ),
64 art, showArtUpdate( const QString& ) );
66 artContLay->addWidget( art, 1 );
68 leftW->addWidget( artContainer );
70 /* Initialisation of the playlist */
71 playlist_t * p_playlist = THEPL;
73 playlist_item_t *p_root =
74 playlist_GetPreferredNode( THEPL, THEPL->p_local_category );
77 rightPanel = new StandardPLPanel( this, p_intf, THEPL, p_root );
79 /* Connect the activation of the selector to a redefining of the PL */
80 CONNECT( selector, activated( playlist_item_t * ),
81 rightPanel, setRoot( playlist_item_t * ) );
83 /* Connect the activated() to the rootChanged() signal
84 This will be used by StandardPLPanel to setCurrentRootId, that will
85 change the label of the addButton */
86 connect( selector, SIGNAL( activated( playlist_item_t * ) ),
87 this, SIGNAL( rootChanged( playlist_item_t * ) ) );
89 /* Forward removal requests from the selector to the main panel */
90 /* CONNECT( qobject_cast<PLSelector *>( selector )->model,
92 qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) ); */
94 emit rootChanged( p_root );
96 /* Add the two sides of the QSplitter */
98 addWidget( rightPanel );
101 sizeList << 180 << 420 ;
102 setSizes( sizeList );
103 //setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
104 setStretchFactor( 0, 0 );
105 setStretchFactor( 1, 3 );
106 leftW->setMaximumWidth( 250 );
107 setCollapsible( 1, false );
109 /* In case we want to keep the splitter informations */
110 // components shall never write there setting to a fixed location, may infer
111 // with other uses of the same component...
112 // getSettings()->beginGroup( "playlist" );
113 getSettings()->beginGroup("Playlist");
114 restoreState( getSettings()->value("splitterSizes").toByteArray());
115 getSettings()->endGroup();
117 setAcceptDrops( true );
118 setWindowTitle( qtr( "Playlist" ) );
119 setWindowRole( "vlc-playlist" );
120 setWindowIcon( QApplication::windowIcon() );
123 PlaylistWidget::~PlaylistWidget()
125 getSettings()->beginGroup("Playlist");
126 getSettings()->setValue( "splitterSizes", saveState() );
127 getSettings()->endGroup();
128 msg_Dbg( p_intf, "Playlist Destroyed" );
131 void PlaylistWidget::dropEvent( QDropEvent *event )
133 if( p_intf->p_sys->p_mi )
134 p_intf->p_sys->p_mi->dropEventPlay( event, false );
136 void PlaylistWidget::dragEnterEvent( QDragEnterEvent *event )
138 event->acceptProposedAction();
141 void PlaylistWidget::closeEvent( QCloseEvent *event )
143 if( THEDP->isDying() )
145 /* FIXME is it needed ? */
150 if( p_intf->p_sys->p_mi )
151 p_intf->p_sys->p_mi->togglePlaylist();