1 /*****************************************************************************
2 * standardpanel.cpp : The "standard" playlist panel : just a treeview
3 ****************************************************************************
4 * Copyright (C) 2000-2005 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
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.
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.
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 *****************************************************************************/
24 #include "playlist_model.hpp"
25 #include "components/playlist/panels.hpp"
27 #include <QPushButton>
28 #include <QHBoxLayout>
29 #include <QVBoxLayout>
30 #include <QHeaderView>
34 #include <QModelIndexList>
36 StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf,
37 playlist_t *p_playlist,
38 playlist_item_t *p_root ):
39 PLPanel( _parent, _p_intf )
41 model = new PLModel( p_playlist, p_root, -1, this );
42 view = new QTreeView( 0 );
43 view->setModel(model);
44 view->header()->resizeSection( 0, 300 );
46 connect( view, SIGNAL( activated( const QModelIndex& ) ), model,
47 SLOT( activateItem( const QModelIndex& ) ) );
50 SIGNAL( dataChanged( const QModelIndex&, const QModelIndex& ) ),
51 this, SLOT( handleExpansion( const QModelIndex& ) ) );
55 QVBoxLayout *layout = new QVBoxLayout();
56 layout->setSpacing( 0 ); layout->setMargin( 0 );
58 QHBoxLayout *buttons = new QHBoxLayout();
59 repeatButton = new QPushButton( this );
60 buttons->addWidget( repeatButton );
61 randomButton = new QPushButton( this );
62 buttons->addWidget( randomButton );
64 if( model->hasRandom() ) randomButton->setText( qtr( "Random" ) );
65 else randomButton->setText( qtr( "No random" ) );
67 if( model->hasRepeat() ) repeatButton->setText( qtr( "Repeat One" ) );
68 else if( model->hasLoop() ) repeatButton->setText( qtr( "Repeat All" ) );
69 else repeatButton->setText( qtr( "No Repeat" ) );
71 connect( repeatButton, SIGNAL( clicked() ), this, SLOT( toggleRepeat() ));
72 connect( randomButton, SIGNAL( clicked() ), this, SLOT( toggleRandom() ));
74 layout->addWidget( view );
75 layout->addLayout( buttons );
79 void StandardPLPanel::toggleRepeat()
81 if( model->hasRepeat() )
83 model->setRepeat( false ); model->setLoop( true );
84 repeatButton->setText( qtr( "Repeat All" ) );
86 else if( model->hasLoop() )
88 model->setRepeat( false ) ; model->setLoop( false );
89 repeatButton->setText( qtr( "No Repeat" ) );
93 model->setRepeat( true );
94 repeatButton->setText( qtr( "Repeat One" ) );
98 void StandardPLPanel::toggleRandom()
100 bool prev = model->hasRandom();
101 model->setRandom( !prev );
102 randomButton->setText( prev ? qtr( "No Random" ) : qtr( "Random" ) );
105 void StandardPLPanel::handleExpansion( const QModelIndex &index )
108 if( model->isCurrent( index ) )
111 while( parent.isValid() )
113 view->setExpanded( parent, true );
114 parent = model->parent( parent );
119 void StandardPLPanel::setRoot( int i_root_id )
121 playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id );
123 model->rebuildRoot( p_item );
127 void StandardPLPanel::keyPressEvent( QKeyEvent *e )
138 void StandardPLPanel::deleteSelection()
140 QItemSelectionModel *selection = view->selectionModel();
141 QModelIndexList list = selection->selectedIndexes();
142 model->doDelete( list );
145 StandardPLPanel::~StandardPLPanel()