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 StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf,
35 playlist_t *p_playlist,
36 playlist_item_t *p_root ):
37 PLPanel( _parent, _p_intf )
39 model = new PLModel( p_playlist, p_root, -1, this );
40 view = new QTreeView( 0 );
41 view->setModel(model);
42 view->header()->resizeSection( 0, 300 );
44 connect( view, SIGNAL( activated( const QModelIndex& ) ), model,
45 SLOT( activateItem( const QModelIndex& ) ) );
48 SIGNAL( dataChanged( const QModelIndex&, const QModelIndex& ) ),
49 this, SLOT( handleExpansion( const QModelIndex& ) ) );
53 QVBoxLayout *layout = new QVBoxLayout();
54 layout->setSpacing( 0 ); layout->setMargin( 0 );
56 QHBoxLayout *buttons = new QHBoxLayout();
57 repeatButton = new QPushButton( this );
58 buttons->addWidget( repeatButton );
59 randomButton = new QPushButton( this );
60 buttons->addWidget( randomButton );
62 if( model->hasRandom() ) randomButton->setText( qtr( "Random" ) );
63 else randomButton->setText( qtr( "No random" ) );
65 if( model->hasRepeat() ) repeatButton->setText( qtr( "Repeat One" ) );
66 else if( model->hasLoop() ) repeatButton->setText( qtr( "Repeat All" ) );
67 else repeatButton->setText( qtr( "No Repeat" ) );
69 connect( repeatButton, SIGNAL( clicked() ), this, SLOT( toggleRepeat() ));
70 connect( randomButton, SIGNAL( clicked() ), this, SLOT( toggleRandom() ));
72 layout->addWidget( view );
73 layout->addLayout( buttons );
77 void StandardPLPanel::toggleRepeat()
79 if( model->hasRepeat() )
81 model->setRepeat( false ); model->setLoop( true );
82 repeatButton->setText( qtr( "Repeat All" ) );
84 else if( model->hasLoop() )
86 model->setRepeat( false ) ; model->setLoop( false );
87 repeatButton->setText( qtr( "No Repeat" ) );
91 model->setRepeat( true );
92 repeatButton->setText( qtr( "Repeat One" ) );
96 void StandardPLPanel::toggleRandom()
98 bool prev = model->hasRandom();
99 model->setRandom( !prev );
100 randomButton->setText( prev ? qtr( "No Random" ) : qtr( "Random" ) );
103 void StandardPLPanel::handleExpansion( const QModelIndex &index )
106 if( model->isCurrent( index ) )
109 while( parent.isValid() )
111 view->setExpanded( parent, true );
112 parent = model->parent( parent );
117 void StandardPLPanel::setRoot( int i_root_id )
119 playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id );
121 model->rebuildRoot( p_item );
125 StandardPLPanel::~StandardPLPanel()