]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/selector.cpp
Qt4 - Better behaviour for the left panel of the playlist.
[vlc] / modules / gui / qt4 / components / playlist / selector.cpp
1 /*****************************************************************************
2  * selector.cpp : Playlist source selector
3  ****************************************************************************
4  * Copyright (C) 2000-2005 the VideoLAN team
5  * $Id: standardpanel.cpp 16024 2006-07-13 13:51:05Z xtophe $
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include "components/playlist/selector.hpp"
29 #include "qt4.hpp"
30
31 #include <QVBoxLayout>
32 #include <QHeaderView>
33 #include <QTreeView>
34
35 PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf,
36                         playlist_t *p_playlist ) : QWidget( p ), p_intf(_p_intf)
37 {
38     model = new PLModel( THEPL, p_intf, THEPL->p_root_category, 1, this );
39     view = new QTreeView( 0 );
40     view->setIconSize( QSize( 24,24 ) );
41     view->setAlternatingRowColors( true );
42     view->setIndentation( 0 );
43     view->header()->hide();
44     view->setModel( model );
45
46     view->setAcceptDrops(true);
47     view->setDropIndicatorShown(true);
48
49     CONNECT( view, activated( const QModelIndex& ),
50              this, setSource( const QModelIndex& ) );
51     CONNECT( view, clicked( const QModelIndex& ),
52              this, setSource( const QModelIndex& ) );
53
54     QVBoxLayout *layout = new QVBoxLayout();
55     layout->setSpacing( 0 ); layout->setMargin( 0 );
56     layout->addWidget( view );
57     setLayout( layout );
58
59     /* select the first item */
60     view->setCurrentIndex( model->index( 0, 0, QModelIndex() ) );
61 }
62
63 void PLSelector::setSource( const QModelIndex &index )
64 {
65     if( model )
66         emit activated( model->itemId( index ) );
67 }
68
69 PLSelector::~PLSelector()
70 {
71 }