]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/playlist.cpp
Qt4 - Remember playlist's size.
[vlc] / modules / gui / qt4 / components / playlist / playlist.cpp
1 /*****************************************************************************
2  * interface_widgets.cpp : Custom widgets for the main interface
3  ****************************************************************************
4  * Copyright ( C ) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Clément Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *          Rafaël Carré <funman@videolanorg>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * ( at your option ) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #include "components/playlist/panels.hpp"
27 #include "components/playlist/selector.hpp"
28 #include "components/playlist/playlist.hpp"
29
30 #include <QSettings>
31 #include <QLabel>
32 #include <QSpacerItem>
33 #include <QCursor>
34 #include <QPushButton>
35 #include <QVBoxLayout>
36
37 /**********************************************************************
38  * Playlist Widget. The embedded playlist
39  **********************************************************************/
40
41 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QSettings *settings, QWidget *_parent ) :
42                                 p_intf ( _p_i ), parent( _parent )
43 {
44     /* Left Part and design */
45     QSplitter *leftW = new QSplitter( Qt::Vertical, this );
46
47     /* Source Selector */
48     selector = new PLSelector( this, p_intf, THEPL );
49     leftW->addWidget( selector );
50
51     /* Art label */
52     art = new QLabel( "" );
53     art->setMinimumHeight( 128 );
54     art->setMinimumWidth( 128 );
55     art->setMaximumHeight( 128 );
56     art->setMaximumWidth( 128 );
57     art->setScaledContents( true );
58     art->setPixmap( QPixmap( ":/noart.png" ) );
59     leftW->addWidget( art );
60
61     /* Initialisation of the playlist */
62     playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
63                                                 THEPL->p_local_category );
64
65     rightPanel = qobject_cast<PLPanel *>( new StandardPLPanel( this,
66                               p_intf, THEPL, p_root ) );
67
68     /* Connects */
69     CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
70
71     CONNECT( qobject_cast<StandardPLPanel *>( rightPanel )->model,
72              artSet( QString ) , this, setArt( QString ) );
73     /* Forward removal requests from the selector to the main panel */
74     CONNECT( qobject_cast<PLSelector *>( selector )->model,
75              shouldRemove( int ),
76              qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
77
78     connect( selector, SIGNAL( activated( int ) ),
79              this, SIGNAL( rootChanged( int ) ) );
80     emit rootChanged( p_root->i_id );
81
82     /* Add the two sides of the QSplitter */
83     addWidget( leftW );
84     addWidget( rightPanel );
85
86     QList<int> sizeList;
87     sizeList << 180 << 420 ;
88     setSizes( sizeList );
89     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
90     setStretchFactor( 0, 0 );
91     setStretchFactor( 1, 3 );
92     leftW->setMaximumWidth( 250 );
93     setCollapsible( 1, false );
94
95     /* In case we want to keep the splitter informations */
96     settings->beginGroup( "playlist" );
97     restoreState( settings->value("splitterSizes").toByteArray());
98     resize( settings->value("size", QSize(600, 300)).toSize());
99     move( settings->value("pos", QPoint( 0, 400)).toPoint());
100     settings->endGroup();
101 }
102
103 void PlaylistWidget::setArt( QString url )
104 {
105     if( url.isNull() )
106     {
107         art->setPixmap( QPixmap( ":/noart.png" ) );
108         emit artSet( url );
109     }
110     else if( prevArt != url )
111     {
112         art->setPixmap( QPixmap( url ) );
113         prevArt = url;
114         emit artSet( url );
115     }
116 }
117
118 QSize PlaylistWidget::sizeHint() const
119 {
120    return QSize( 600 , 300 );
121 }
122
123 PlaylistWidget::~PlaylistWidget()
124 {}
125
126 void PlaylistWidget::savingSettings( QSettings *settings )
127 {
128     settings->beginGroup( "playlist" );
129     settings->setValue( "pos", parent->pos() );
130     settings->setValue( "size", parent->size() );
131     settings->setValue( "splitterSizes", saveState() );
132     settings->endGroup();
133 }
134