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->setIconSize( QSize(20,20) );
47 view->setAlternatingRowColors( true );
48 view->header()->resizeSection( 0, 300 );
49 view->setSelectionMode( QAbstractItemView::ExtendedSelection );
51 connect( view, SIGNAL( activated( const QModelIndex& ) ), model,
52 SLOT( activateItem( const QModelIndex& ) ) );
54 connect( view, SIGNAL( rightClicked( QModelIndex , QPoint ) ),
55 this, SLOT( doPopup( QModelIndex, QPoint ) ) );
58 SIGNAL( dataChanged( const QModelIndex&, const QModelIndex& ) ),
59 this, SLOT( handleExpansion( const QModelIndex& ) ) );
61 QVBoxLayout *layout = new QVBoxLayout();
62 layout->setSpacing( 0 ); layout->setMargin( 0 );
64 QHBoxLayout *buttons = new QHBoxLayout();
65 repeatButton = new QPushButton( this );
66 buttons->addWidget( repeatButton );
67 randomButton = new QPushButton( this );
68 buttons->addWidget( randomButton );
70 if( model->hasRandom() ) randomButton->setText( qtr( "Random" ) );
71 else randomButton->setText( qtr( "No random" ) );
73 if( model->hasRepeat() ) repeatButton->setText( qtr( "Repeat One" ) );
74 else if( model->hasLoop() ) repeatButton->setText( qtr( "Repeat All" ) );
75 else repeatButton->setText( qtr( "No Repeat" ) );
77 connect( repeatButton, SIGNAL( clicked() ), this, SLOT( toggleRepeat() ));
78 connect( randomButton, SIGNAL( clicked() ), this, SLOT( toggleRandom() ));
80 layout->addWidget( view );
81 layout->addLayout( buttons );
85 void StandardPLPanel::toggleRepeat()
87 if( model->hasRepeat() )
89 model->setRepeat( false ); model->setLoop( true );
90 repeatButton->setText( qtr( "Repeat All" ) );
92 else if( model->hasLoop() )
94 model->setRepeat( false ) ; model->setLoop( false );
95 repeatButton->setText( qtr( "No Repeat" ) );
99 model->setRepeat( true );
100 repeatButton->setText( qtr( "Repeat One" ) );
104 void StandardPLPanel::toggleRandom()
106 bool prev = model->hasRandom();
107 model->setRandom( !prev );
108 randomButton->setText( prev ? qtr( "No Random" ) : qtr( "Random" ) );
111 void StandardPLPanel::handleExpansion( const QModelIndex &index )
114 if( model->isCurrent( index ) )
117 while( parent.isValid() )
119 view->setExpanded( parent, true );
120 parent = model->parent( parent );
125 void StandardPLPanel::doPopup( QModelIndex index, QPoint point )
127 assert( index.isValid() );
128 QItemSelectionModel *selection = view->selectionModel();
129 QModelIndexList list = selection->selectedIndexes();
130 model->popup( index, point, list );
133 void StandardPLPanel::setRoot( int i_root_id )
135 playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id );
137 p_item = playlist_GetPreferredNode( THEPL, p_item );
139 model->rebuild( p_item );
142 void StandardPLPanel::keyPressEvent( QKeyEvent *e )
153 void StandardPLPanel::deleteSelection()
155 QItemSelectionModel *selection = view->selectionModel();
156 QModelIndexList list = selection->selectedIndexes();
157 model->doDelete( list );
160 StandardPLPanel::~StandardPLPanel()