]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/playlist.cpp
Merge branch 'master' of git@git.videolan.org:vlc
[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/panels.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 <QSettings>
37 #include <QLabel>
38 #include <QSpacerItem>
39 #include <QCursor>
40 #include <QPushButton>
41 #include <QVBoxLayout>
42
43 /**********************************************************************
44  * Playlist Widget. The embedded playlist
45  **********************************************************************/
46
47 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) : p_intf ( _p_i )
48 {
49     setContentsMargins( 3, 3, 3, 3 );
50
51     /* Left Part and design */
52     QSplitter *leftW = new QSplitter( Qt::Vertical, this );
53
54     /* Source Selector */
55     selector = new PLSelector( this, p_intf );
56     leftW->addWidget( selector );
57
58     /* Create a Container for the Art Label
59        in order to have a beautiful resizing for the selector above it */
60     QWidget *artContainer = new QWidget;
61     QHBoxLayout *artContLay = new QHBoxLayout( artContainer );
62     artContLay->setMargin( 0 );
63     artContLay->setSpacing( 0 );
64     artContainer->setMaximumHeight( 128 );
65
66     /* Art label */
67     art = new ArtLabel( artContainer, p_intf );
68     art->setToolTip( qtr( "Double click to get media information" ) );
69
70     artContLay->addWidget( art, 1 );
71
72     leftW->addWidget( artContainer );
73
74     /* Initialisation of the playlist */
75     playlist_t * p_playlist = THEPL;
76     PL_LOCK;
77     playlist_item_t *p_root =
78                   playlist_GetPreferredNode( THEPL, THEPL->p_local_category );
79     PL_UNLOCK;
80
81     rightPanel = new StandardPLPanel( this, p_intf, THEPL, p_root );
82
83     /* Connect the activation of the selector to a redefining of the PL */
84     CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
85
86     /* Connect the activated() to the rootChanged() signal
87        This will be used by StandardPLPanel to setCurrentRootId, that will
88        change the label of the addButton  */
89     connect( selector, SIGNAL( activated( int ) ),
90              this, SIGNAL( rootChanged( int ) ) );
91
92     /* Forward removal requests from the selector to the main panel */
93     CONNECT( qobject_cast<PLSelector *>( selector )->model,
94              shouldRemove( int ),
95              qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
96
97     emit rootChanged( p_root->i_id );
98
99     /* Add the two sides of the QSplitter */
100     addWidget( leftW );
101     addWidget( rightPanel );
102
103     QList<int> sizeList;
104     sizeList << 180 << 420 ;
105     setSizes( sizeList );
106     //setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
107     setStretchFactor( 0, 0 );
108     setStretchFactor( 1, 3 );
109     leftW->setMaximumWidth( 250 );
110     setCollapsible( 1, false );
111
112     /* In case we want to keep the splitter informations */
113     // components shall never write there setting to a fixed location, may infer
114     // with other uses of the same component...
115     // getSettings()->beginGroup( "playlist" );
116     getSettings()->beginGroup("Playlist");
117     restoreState( getSettings()->value("splitterSizes").toByteArray());
118     getSettings()->endGroup();
119
120     setAcceptDrops( true );
121     setWindowTitle( qtr( "Playlist" ) );
122     setWindowIcon( QApplication::windowIcon() );
123 }
124
125 PlaylistWidget::~PlaylistWidget()
126 {
127     getSettings()->beginGroup("Playlist");
128     getSettings()->setValue( "splitterSizes", saveState() );
129     getSettings()->endGroup();
130     msg_Dbg( p_intf, "Playlist Destroyed" );
131 }
132
133 void PlaylistWidget::dropEvent( QDropEvent *event )
134 {
135     if( p_intf->p_sys->p_mi )
136         p_intf->p_sys->p_mi->dropEventPlay( event, false );
137 }
138 void PlaylistWidget::dragEnterEvent( QDragEnterEvent *event )
139 {
140     event->acceptProposedAction();
141 }
142
143 void PlaylistWidget::closeEvent( QCloseEvent *event )
144 {
145     if( THEDP->isDying() )
146     {
147         /* FIXME is it needed ? */
148         close();
149     }
150     else
151     {
152         if( p_intf->p_sys->p_mi )
153             p_intf->p_sys->p_mi->togglePlaylist();
154     }
155     event->accept();
156 }