]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/playlist.cpp
Don't include config.h from the headers - refs #297.
[vlc] / modules / gui / qt4 / components / playlist / playlist.cpp
1 /*****************************************************************************
2  * playlist.cpp : Custom widgets for the playlist
3  ****************************************************************************
4  * Copyright © 2006 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 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include "components/playlist/panels.hpp"
29 #include "components/playlist/selector.hpp"
30 #include "components/playlist/playlist.hpp"
31 #include "input_manager.hpp" /* art */
32
33 #include <QSettings>
34 #include <QLabel>
35 #include <QSpacerItem>
36 #include <QCursor>
37 #include <QPushButton>
38 #include <QVBoxLayout>
39
40 /**********************************************************************
41  * Playlist Widget. The embedded playlist
42  **********************************************************************/
43
44 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QSettings *settings, QWidget *_parent ) :
45                                 p_intf ( _p_i ), parent( _parent )
46 {
47     /* Left Part and design */
48     QSplitter *leftW = new QSplitter( Qt::Vertical, this );
49
50     /* Source Selector */
51     selector = new PLSelector( this, p_intf, THEPL );
52     leftW->addWidget( selector );
53
54     /* Art label */
55     art = new ArtLabel;
56     art->setMinimumHeight( 128 );
57     art->setMinimumWidth( 128 );
58     art->setMaximumHeight( 128 );
59     art->setMaximumWidth( 128 );
60     art->setScaledContents( true );
61     art->setPixmap( QPixmap( ":/noart.png" ) );
62     art->setToolTip( qtr( "Double click to get the media informations" ) );
63     leftW->addWidget( art );
64
65     /* Initialisation of the playlist */
66     playlist_item_t *p_root =
67                   playlist_GetPreferredNode( THEPL, THEPL->p_local_category );
68
69     rightPanel = new StandardPLPanel( this, p_intf, THEPL, p_root );
70
71     /* Connect the activation of the selector to a redefining of the PL */
72     CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
73
74     /* Connect the activated() to the rootChanged() signal
75        This will be used by StandardPLPanel to setCurrentRootId, that will 
76        change the label of the addButton  */
77     connect( selector, SIGNAL( activated( int ) ),
78              this, SIGNAL( rootChanged( int ) ) );
79
80     CONNECT( THEMIM->getIM(), artChanged( QString ) , this, setArt( QString ) );
81     /* Forward removal requests from the selector to the main panel */
82     CONNECT( qobject_cast<PLSelector *>( selector )->model,
83              shouldRemove( int ),
84              qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
85
86     emit rootChanged( p_root->i_id );
87
88     /* Add the two sides of the QSplitter */
89     addWidget( leftW );
90     addWidget( rightPanel );
91
92     QList<int> sizeList;
93     sizeList << 180 << 420 ;
94     setSizes( sizeList );
95     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
96     setStretchFactor( 0, 0 );
97     setStretchFactor( 1, 3 );
98     leftW->setMaximumWidth( 250 );
99     setCollapsible( 1, false );
100
101     /* In case we want to keep the splitter informations */
102     settings->beginGroup( "playlist" );
103     restoreState( settings->value("splitterSizes").toByteArray());
104     resize( settings->value("size", QSize(600, 300)).toSize());
105     move( settings->value("pos", QPoint( 0, 400)).toPoint());
106     settings->endGroup();
107 }
108
109 void PlaylistWidget::setArt( QString url )
110 {
111     if( url.isNull() )
112     {
113         art->setPixmap( QPixmap( ":/noart.png" ) );
114     }
115     else if( prevArt != url )
116     {
117         art->setPixmap( QPixmap( url ) );
118         prevArt = url;
119     }
120 }
121
122 QSize PlaylistWidget::sizeHint() const
123 {
124    return QSize( 600 , 300 );
125 }
126
127 PlaylistWidget::~PlaylistWidget()
128 {}
129
130 void PlaylistWidget::savingSettings( QSettings *settings )
131 {
132     settings->beginGroup( "playlist" );
133     settings->setValue( "pos", parent->pos() );
134     settings->setValue( "size", parent->size() );
135     settings->setValue( "splitterSizes", saveState() );
136     settings->endGroup();
137 }
138