]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/selector.cpp
Qt4: move the selector from View/Model to QTreeWidget
[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 <assert.h>
29
30 #include "components/playlist/selector.hpp"
31 #include "qt4.hpp"
32
33 #include <QVBoxLayout>
34 #include <QHeaderView>
35 #include <QTreeWidget>
36
37 #include <vlc_playlist.h>
38
39 PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf ) : QWidget( p ), p_intf(_p_intf)
40 {
41 //    model = new PLModel( THEPL, p_intf, THEPL->p_root_category, 1, this );
42     view = new QTreeWidget;
43     view->setIconSize( QSize( 24,24 ) );
44 //    view->setAlternatingRowColors( true );
45     view->setIndentation( 0 );
46     view->header()->hide();
47 //    view->setModel( model );
48
49     view->setAcceptDrops(true);
50     view->setDropIndicatorShown(true);
51
52
53     createItems();
54     CONNECT( view, itemActivated( QTreeWidgetItem *, int ),
55              this, setSource( QTreeWidgetItem *) );
56     CONNECT( view, itemClicked( QTreeWidgetItem *, int ),
57              this, setSource( QTreeWidgetItem *) );
58
59     QVBoxLayout *layout = new QVBoxLayout();
60     layout->setSpacing( 0 ); layout->setMargin( 0 );
61     layout->addWidget( view );
62     setLayout( layout );
63
64     /* select the first item */
65 //  view->setCurrentIndex( model->index( 0, 0, QModelIndex() ) );
66 }
67
68 void PLSelector::setSource( QTreeWidgetItem *item )
69 {
70     if( item )
71     {
72         playlist_item_t *pl_item =
73                 item->data( 0, Qt::UserRole ).value<playlist_item_t *>();
74         emit activated( pl_item );
75     }
76 }
77
78 void PLSelector::createItems()
79 {
80     assert( view );
81     QTreeWidgetItem *pl = new QTreeWidgetItem( view );
82     pl->setText( 0, qtr( "Playlist" ) );
83     pl->setData( 0, Qt::UserRole, QVariant::fromValue( THEPL->p_local_category ) );
84 /*    QTreeWidgetItem *empty = new QTreeWidgetItem( view );
85     empty->setFlags(Qt::NoItemFlags);
86 */
87     QTreeWidgetItem *lib = new QTreeWidgetItem( view );
88     lib->setText( 0, qtr( "Library" ) );
89     lib->setData( 0, Qt::UserRole, QVariant::fromValue( THEPL->p_ml_category ) );
90 /*
91     QTreeWidgetItem *empty2 = new QTreeWidgetItem( view );
92     empty2->setFlags(Qt::NoItemFlags);*/
93
94
95
96 }
97 PLSelector::~PLSelector()
98 {
99 }