]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/playlist.cpp
Qt4 - Playlist: fix the resizing of the QSPlitter containing the art.
[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, QSettings *settings, QWidget *_parent ) :
46                                 p_intf ( _p_i ), parent( _parent )
47 {
48     /* Left Part and design */
49     QSplitter *leftW = new QSplitter( Qt::Vertical, this );
50
51     /* Source Selector */
52     selector = new PLSelector( this, p_intf, THEPL );
53     leftW->addWidget( selector );
54
55     QWidget *artContainer = new QWidget;
56     QHBoxLayout *artContLay = new QHBoxLayout( artContainer );
57
58     /* Art label */
59     art = new ArtLabel;
60     art->setMinimumHeight( 128 );
61     art->setMinimumWidth( 128 );
62     art->setMaximumHeight( 128 );
63     art->setMaximumWidth( 128 );
64     art->setScaledContents( true );
65     art->setPixmap( QPixmap( ":/noart.png" ) );
66     art->setToolTip( qtr( "Double click to get the media informations" ) );
67     artContLay->addWidget( art, 1 );
68
69     leftW->addWidget( artContainer );
70
71     /* Initialisation of the playlist */
72     playlist_item_t *p_root =
73                   playlist_GetPreferredNode( THEPL, THEPL->p_local_category );
74
75     rightPanel = new StandardPLPanel( this, p_intf, THEPL, p_root );
76
77     /* Connect the activation of the selector to a redefining of the PL */
78     CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
79
80     /* Connect the activated() to the rootChanged() signal
81        This will be used by StandardPLPanel to setCurrentRootId, that will
82        change the label of the addButton  */
83     connect( selector, SIGNAL( activated( int ) ),
84              this, SIGNAL( rootChanged( int ) ) );
85
86     CONNECT( THEMIM->getIM(), artChanged( QString ) , this, setArt( QString ) );
87     /* Forward removal requests from the selector to the main panel */
88     CONNECT( qobject_cast<PLSelector *>( selector )->model,
89              shouldRemove( int ),
90              qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
91
92     emit rootChanged( p_root->i_id );
93
94     /* Add the two sides of the QSplitter */
95     addWidget( leftW );
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     leftW->setMaximumWidth( 250 );
105     setCollapsible( 1, false );
106
107     /* In case we want to keep the splitter informations */
108     settings->beginGroup( "playlist" );
109     restoreState( settings->value("splitterSizes").toByteArray());
110     resize( settings->value("size", QSize(600, 300)).toSize());
111     move( settings->value("pos", QPoint( 0, 400)).toPoint());
112     settings->endGroup();
113 }
114
115 void PlaylistWidget::setArt( QString url )
116 {
117     if( url.isNull() )
118     {
119         art->setPixmap( QPixmap( ":/noart.png" ) );
120     }
121     else if( prevArt != url )
122     {
123         art->setPixmap( QPixmap( url ) );
124         prevArt = url;
125     }
126 }
127
128 QSize PlaylistWidget::sizeHint() const
129 {
130    return QSize( 600 , 300 );
131 }
132
133 PlaylistWidget::~PlaylistWidget()
134 {}
135
136 void PlaylistWidget::savingSettings( QSettings *settings )
137 {
138     settings->beginGroup( "playlist" );
139     settings->setValue( "pos", parent->pos() );
140     settings->setValue( "size", parent->size() );
141     settings->setValue( "splitterSizes", saveState() );
142     settings->endGroup();
143 }
144