]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/playlist.cpp
various modules: adjust to new playlist design
[vlc] / modules / gui / qt4 / components / playlist / playlist.cpp
1 /*****************************************************************************
2  * playlist.cpp : Custom widgets for the playlist
3  ****************************************************************************
4  * Copyright © 2007-2008 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 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include "components/playlist/standardpanel.hpp"
30 #include "components/playlist/selector.hpp"
31 #include "components/playlist/playlist.hpp"
32
33 #include "input_manager.hpp" /* art signal */
34 #include "main_interface.hpp" /* DropEvent TODO remove this*/
35
36 #include <QGroupBox>
37
38 #include <iostream>
39 /**********************************************************************
40  * Playlist Widget. The embedded playlist
41  **********************************************************************/
42
43 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QWidget *_par )
44                : QSplitter( _par ), p_intf ( _p_i )
45 {
46     setContentsMargins( 3, 3, 3, 3 );
47
48     /* Left Part and design */
49     leftSplitter = new QSplitter( Qt::Vertical, this );
50
51     /* Source Selector */
52     selector = new PLSelector( this, p_intf );
53     QVBoxLayout *selBox = new QVBoxLayout();
54     selBox->setContentsMargins(5,5,5,0);
55     selBox->addWidget( selector );
56     QGroupBox *selGroup = new QGroupBox( qtr( "Media Browser") );
57     selGroup->setLayout( selBox );
58     leftSplitter->addWidget( selGroup );
59
60     /* Create a Container for the Art Label
61        in order to have a beautiful resizing for the selector above it */
62     QWidget *artContainer = new QWidget;
63     QHBoxLayout *artContLay = new QHBoxLayout( artContainer );
64     artContLay->setMargin( 0 );
65     artContLay->setSpacing( 0 );
66     artContainer->setMaximumHeight( 128 );
67
68     /* Art label */
69     art = new ArtLabel( artContainer, p_intf );
70     art->setToolTip( qtr( "Double click to get media information" ) );
71
72     CONNECT( THEMIM->getIM(), artChanged( QString ),
73              art, showArtUpdate( const QString& ) );
74
75     artContLay->addWidget( art, 1 );
76
77     leftSplitter->addWidget( artContainer );
78
79     /* Initialisation of the playlist */
80     playlist_t * p_playlist = THEPL;
81     PL_LOCK;
82     playlist_item_t *p_root = THEPL->p_playing;
83
84     PL_UNLOCK;
85
86     rightPanel = new StandardPLPanel( this, p_intf, THEPL, p_root );
87
88     /* Connect the activation of the selector to a redefining of the PL */
89     CONNECT( selector, activated( playlist_item_t * ),
90              rightPanel, setRoot( playlist_item_t * ) );
91
92     rightPanel->setRoot( p_root );
93
94     /* Add the two sides of the QSplitter */
95     addWidget( leftSplitter );
96     addWidget( rightPanel );
97
98     QList<int> sizeList;
99     sizeList << 180 << 420 ;
100     setSizes( sizeList );
101     //setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
102     setStretchFactor( 0, 0 );
103     setStretchFactor( 1, 3 );
104     leftSplitter->setMaximumWidth( 250 );
105     setCollapsible( 1, false );
106
107     /* In case we want to keep the splitter informations */
108     // components shall never write there setting to a fixed location, may infer
109     // with other uses of the same component...
110     // getSettings()->beginGroup( "playlist" );
111     getSettings()->beginGroup("Playlist");
112     restoreState( getSettings()->value("splitterSizes").toByteArray());
113     leftSplitter->restoreState( getSettings()->value("leftSplitterGeometry").toByteArray() );
114     getSettings()->endGroup();
115
116     setAcceptDrops( true );
117     setWindowTitle( qtr( "Playlist" ) );
118     setWindowRole( "vlc-playlist" );
119     setWindowIcon( QApplication::windowIcon() );
120 }
121
122 PlaylistWidget::~PlaylistWidget()
123 {
124     getSettings()->beginGroup("Playlist");
125     getSettings()->setValue( "splitterSizes", saveState() );
126     getSettings()->setValue( "leftSplitterGeometry", leftSplitter->saveState() );
127     getSettings()->endGroup();
128     msg_Dbg( p_intf, "Playlist Destroyed" );
129 }
130
131 void PlaylistWidget::dropEvent( QDropEvent *event )
132 {
133     if( p_intf->p_sys->p_mi )
134         p_intf->p_sys->p_mi->dropEventPlay( event, false );
135 }
136 void PlaylistWidget::dragEnterEvent( QDragEnterEvent *event )
137 {
138     event->acceptProposedAction();
139 }
140
141 void PlaylistWidget::closeEvent( QCloseEvent *event )
142 {
143     if( THEDP->isDying() )
144     {
145         /* FIXME is it needed ? */
146         event->accept();
147     }
148     else
149     {
150         hide();
151         event->ignore();
152     }
153 }