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