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 );
45 view->setSelectionMode( QAbstractItemView::ExtendedSelection );
47 connect( view, SIGNAL( activated( const QModelIndex& ) ), model,
48 SLOT( activateItem( const QModelIndex& ) ) );
51 SIGNAL( dataChanged( const QModelIndex&, const QModelIndex& ) ),
52 this, SLOT( handleExpansion( const QModelIndex& ) ) );
56 QVBoxLayout *layout = new QVBoxLayout();
57 layout->setSpacing( 0 ); layout->setMargin( 0 );
59 QHBoxLayout *buttons = new QHBoxLayout();
60 repeatButton = new QPushButton( this );
61 buttons->addWidget( repeatButton );
62 randomButton = new QPushButton( this );
63 buttons->addWidget( randomButton );
65 if( model->hasRandom() ) randomButton->setText( qtr( "Random" ) );
66 else randomButton->setText( qtr( "No random" ) );
68 if( model->hasRepeat() ) repeatButton->setText( qtr( "Repeat One" ) );
69 else if( model->hasLoop() ) repeatButton->setText( qtr( "Repeat All" ) );
70 else repeatButton->setText( qtr( "No Repeat" ) );
72 connect( repeatButton, SIGNAL( clicked() ), this, SLOT( toggleRepeat() ));
73 connect( randomButton, SIGNAL( clicked() ), this, SLOT( toggleRandom() ));
75 layout->addWidget( view );
76 layout->addLayout( buttons );
80 void StandardPLPanel::toggleRepeat()
82 if( model->hasRepeat() )
84 model->setRepeat( false ); model->setLoop( true );
85 repeatButton->setText( qtr( "Repeat All" ) );
87 else if( model->hasLoop() )
89 model->setRepeat( false ) ; model->setLoop( false );
90 repeatButton->setText( qtr( "No Repeat" ) );
94 model->setRepeat( true );
95 repeatButton->setText( qtr( "Repeat One" ) );
99 void StandardPLPanel::toggleRandom()
101 bool prev = model->hasRandom();
102 model->setRandom( !prev );
103 randomButton->setText( prev ? qtr( "No Random" ) : qtr( "Random" ) );
106 void StandardPLPanel::handleExpansion( const QModelIndex &index )
109 if( model->isCurrent( index ) )
112 while( parent.isValid() )
114 view->setExpanded( parent, true );
115 parent = model->parent( parent );
120 void StandardPLPanel::setRoot( int i_root_id )
122 playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id );
124 model->rebuildRoot( p_item );
128 void StandardPLPanel::keyPressEvent( QKeyEvent *e )
139 void StandardPLPanel::deleteSelection()
141 QItemSelectionModel *selection = view->selectionModel();
142 QModelIndexList list = selection->selectedIndexes();
143 model->doDelete( list );
146 StandardPLPanel::~StandardPLPanel()