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 #include "util/views.hpp"
38 StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf,
39 playlist_t *p_playlist,
40 playlist_item_t *p_root ):
41 PLPanel( _parent, _p_intf )
43 model = new PLModel( p_playlist, p_root, -1, this );
44 view = new QVLCTreeView( 0 );
45 view->setModel(model);
46 view->header()->resizeSection( 0, 300 );
47 view->setSelectionMode( QAbstractItemView::ExtendedSelection );
49 connect( view, SIGNAL( activated( const QModelIndex& ) ), model,
50 SLOT( activateItem( const QModelIndex& ) ) );
52 connect( view, SIGNAL( rightClicked( QModelIndex , QPoint ) ),
53 this, SLOT( doPopup( QModelIndex, QPoint ) ) );
56 SIGNAL( dataChanged( const QModelIndex&, const QModelIndex& ) ),
57 this, SLOT( handleExpansion( const QModelIndex& ) ) );
59 QVBoxLayout *layout = new QVBoxLayout();
60 layout->setSpacing( 0 ); layout->setMargin( 0 );
62 QHBoxLayout *buttons = new QHBoxLayout();
63 repeatButton = new QPushButton( this );
64 buttons->addWidget( repeatButton );
65 randomButton = new QPushButton( this );
66 buttons->addWidget( randomButton );
68 if( model->hasRandom() ) randomButton->setText( qtr( "Random" ) );
69 else randomButton->setText( qtr( "No random" ) );
71 if( model->hasRepeat() ) repeatButton->setText( qtr( "Repeat One" ) );
72 else if( model->hasLoop() ) repeatButton->setText( qtr( "Repeat All" ) );
73 else repeatButton->setText( qtr( "No Repeat" ) );
75 connect( repeatButton, SIGNAL( clicked() ), this, SLOT( toggleRepeat() ));
76 connect( randomButton, SIGNAL( clicked() ), this, SLOT( toggleRandom() ));
78 layout->addWidget( view );
79 layout->addLayout( buttons );
83 void StandardPLPanel::toggleRepeat()
85 if( model->hasRepeat() )
87 model->setRepeat( false ); model->setLoop( true );
88 repeatButton->setText( qtr( "Repeat All" ) );
90 else if( model->hasLoop() )
92 model->setRepeat( false ) ; model->setLoop( false );
93 repeatButton->setText( qtr( "No Repeat" ) );
97 model->setRepeat( true );
98 repeatButton->setText( qtr( "Repeat One" ) );
102 void StandardPLPanel::toggleRandom()
104 bool prev = model->hasRandom();
105 model->setRandom( !prev );
106 randomButton->setText( prev ? qtr( "No Random" ) : qtr( "Random" ) );
109 void StandardPLPanel::handleExpansion( const QModelIndex &index )
112 if( model->isCurrent( index ) )
115 while( parent.isValid() )
117 view->setExpanded( parent, true );
118 parent = model->parent( parent );
123 void StandardPLPanel::doPopup( QModelIndex index, QPoint point )
125 assert( index.isValid() );
126 QItemSelectionModel *selection = view->selectionModel();
127 QModelIndexList list = selection->selectedIndexes();
128 model->popup( index, point, list );
131 void StandardPLPanel::setRoot( int i_root_id )
133 playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id );
135 model->rebuild( p_item );
138 void StandardPLPanel::keyPressEvent( QKeyEvent *e )
149 void StandardPLPanel::deleteSelection()
151 QItemSelectionModel *selection = view->selectionModel();
152 QModelIndexList list = selection->selectedIndexes();
153 model->doDelete( list );
156 StandardPLPanel::~StandardPLPanel()