]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/selector.cpp
Initial drag and drop support for Qt
[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 #include "components/playlist/selector.hpp"
25 #include "qt4.hpp"
26 #include <QVBoxLayout>
27 #include <QHeaderView>
28 #include <QTreeView>
29
30 PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf,
31                         playlist_t *p_playlist ) : QWidget( p ), p_intf(_p_intf)
32 {
33     model = new PLModel( THEPL, THEPL->p_root_category, 1, this );
34     view = new QTreeView( 0 );
35     view->setIconSize( QSize( 24,24 ) );
36     view->setAlternatingRowColors( true );
37     view->setIndentation( 0 );
38     view->header()->hide();
39     view->setModel( model );
40
41     view->setDragEnabled(true);
42     view->setAcceptDrops(true);
43     view->setDropIndicatorShown(true);
44
45     CONNECT( view, activated( const QModelIndex& ),
46              this, setSource( const QModelIndex& ) );
47     CONNECT( view, clicked( const QModelIndex& ),
48              this, setSource( const QModelIndex& ) );
49
50     QVBoxLayout *layout = new QVBoxLayout();
51     layout->setSpacing( 0 ); layout->setMargin( 0 );
52     layout->addWidget( view );
53     setLayout( layout );
54 }
55
56 void PLSelector::setSource( const QModelIndex &index )
57 {
58     if( model )
59         emit activated( model->itemId( index ) );
60 }
61
62 PLSelector::~PLSelector()
63 {
64 }