s/informations/information/
[vlc/asuraparaju-public.git] / modules / gui / qt4 / components / playlist / playlist.cpp
blobbc2c6435464f112b6c19468b269e5a6aac9a4362
1 /*****************************************************************************
2 * playlist.cpp : Custom widgets for the playlist
3 ****************************************************************************
4 * Copyright © 2007-2010 the VideoLAN team
5 * $Id$
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 *****************************************************************************/
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
29 #include "components/playlist/standardpanel.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 #include <QGroupBox>
38 #include <iostream>
39 /**********************************************************************
40 * Playlist Widget. The embedded playlist
41 **********************************************************************/
43 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par )
44 : QSplitter( _par ), p_intf ( _p_i )
46 setContentsMargins( 3, 3, 3, 3 );
48 /* Left Part and design */
49 leftSplitter = new QSplitter( Qt::Vertical, this );
51 /* Source Selector */
52 selector = new PLSelector( this, p_intf );
54 QLabel *selLabel = new QLabel( qtr( "Media Browser" ) );
55 QFont font;
56 font.setBold( true );
57 selLabel->setFont( font );
58 selLabel->setMargin( 5 );
60 QVBoxLayout *selBox = new QVBoxLayout();
61 selBox->setContentsMargins(0,0,0,0);
62 selBox->setSpacing( 0 );
63 selBox->addWidget( selLabel );
64 selBox->addWidget( selector );
66 QWidget *mediaBrowser = new QWidget();
67 mediaBrowser->setLayout( selBox );
68 leftSplitter->addWidget( mediaBrowser );
70 /* Create a Container for the Art Label
71 in order to have a beautiful resizing for the selector above it */
72 QWidget *artContainer = new QWidget;
73 QHBoxLayout *artContLay = new QHBoxLayout( artContainer );
74 artContLay->setMargin( 0 );
75 artContLay->setSpacing( 0 );
76 artContainer->setMaximumHeight( 128 );
78 /* Art label */
79 art = new ArtLabel( artContainer, p_intf );
80 art->setToolTip( qtr( "Double click to get media information" ) );
82 CONNECT( THEMIM->getIM(), artChanged( QString ),
83 art, showArtUpdate( const QString& ) );
85 artContLay->addWidget( art, 1 );
87 leftSplitter->addWidget( artContainer );
89 /* Initialisation of the playlist */
90 playlist_t * p_playlist = THEPL;
91 PL_LOCK;
92 playlist_item_t *p_root = THEPL->p_playing;
94 PL_UNLOCK;
96 rightPanel = new StandardPLPanel( this, p_intf, THEPL, p_root );
98 /* Connect the activation of the selector to a redefining of the PL */
99 DCONNECT( selector, activated( playlist_item_t * ),
100 rightPanel, setRoot( playlist_item_t * ) );
102 rightPanel->setRoot( p_root );
104 /* Add the two sides of the QSplitter */
105 addWidget( leftSplitter );
106 addWidget( rightPanel );
108 QList<int> sizeList;
109 sizeList << 180 << 420 ;
110 setSizes( sizeList );
111 //setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
112 setStretchFactor( 0, 0 );
113 setStretchFactor( 1, 3 );
114 leftSplitter->setMaximumWidth( 250 );
115 setCollapsible( 1, false );
117 /* In case we want to keep the splitter information */
118 // components shall never write there setting to a fixed location, may infer
119 // with other uses of the same component...
120 getSettings()->beginGroup("Playlist");
121 restoreState( getSettings()->value("splitterSizes").toByteArray());
122 leftSplitter->restoreState( getSettings()->value("leftSplitterGeometry").toByteArray() );
123 getSettings()->endGroup();
125 setAcceptDrops( true );
126 setWindowTitle( qtr( "Playlist" ) );
127 setWindowRole( "vlc-playlist" );
128 setWindowIcon( QApplication::windowIcon() );
131 PlaylistWidget::~PlaylistWidget()
133 getSettings()->beginGroup("Playlist");
134 getSettings()->setValue( "splitterSizes", saveState() );
135 getSettings()->setValue( "leftSplitterGeometry", leftSplitter->saveState() );
136 getSettings()->endGroup();
137 msg_Dbg( p_intf, "Playlist Destroyed" );
140 void PlaylistWidget::dropEvent( QDropEvent *event )
142 if( p_intf->p_sys->p_mi )
143 p_intf->p_sys->p_mi->dropEventPlay( event, false );
145 void PlaylistWidget::dragEnterEvent( QDragEnterEvent *event )
147 event->acceptProposedAction();
150 void PlaylistWidget::closeEvent( QCloseEvent *event )
152 if( THEDP->isDying() )
154 p_intf->p_sys->p_mi->playlistVisible = true;
155 event->accept();
157 else
159 p_intf->p_sys->p_mi->playlistVisible = false;
160 hide();
161 event->ignore();
165 void PlaylistWidget::forceHide()
167 leftSplitter->hide();
168 rightPanel->hide();
169 updateGeometry();
172 void PlaylistWidget::forceShow()
174 leftSplitter->show();
175 rightPanel->show();
176 updateGeometry();