]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/selector.cpp
22cad94f6be000d629566cb1e2c59c47c34246f9
[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$
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 ) : QWidget( p ), p_intf(_p_intf)
36 {
37     model = new PLModel( THEPL, p_intf, THEPL->p_root_category, 1, this );
38     view = new QTreeView( 0 );
39     view->setIconSize( QSize( 24,24 ) );
40     view->setAlternatingRowColors( true );
41     view->setIndentation( 0 );
42     view->header()->hide();
43     view->setModel( model );
44
45     view->setAcceptDrops(true);
46     view->setDropIndicatorShown(true);
47
48     CONNECT( view, activated( const QModelIndex& ),
49              this, setSource( const QModelIndex& ) );
50     CONNECT( view, clicked( const QModelIndex& ),
51              this, setSource( const QModelIndex& ) );
52
53     QVBoxLayout *layout = new QVBoxLayout();
54     layout->setSpacing( 0 ); layout->setMargin( 0 );
55     layout->addWidget( view );
56     setLayout( layout );
57
58     /* select the first item */
59     view->setCurrentIndex( model->index( 0, 0, QModelIndex() ) );
60 }
61
62 void PLSelector::setSource( const QModelIndex &index )
63 {
64     if( model )
65         emit activated( model->itemId( index ) );
66 }
67
68 PLSelector::~PLSelector()
69 {
70 }