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->header()->setSortIndicatorShown( true );
50 view->header()->setClickable( true );
51 view->setSelectionMode( QAbstractItemView::ExtendedSelection );
53 // connect( view->header(), SIGNAL( sectionClicked( int)), view, SLOT( sortByColumn(int)));
55 connect( view, SIGNAL( activated( const QModelIndex& ) ), model,
56 SLOT( activateItem( const QModelIndex& ) ) );
58 connect( view, SIGNAL( rightClicked( QModelIndex , QPoint ) ),
59 this, SLOT( doPopup( QModelIndex, QPoint ) ) );
62 SIGNAL( dataChanged( const QModelIndex&, const QModelIndex& ) ),
63 this, SLOT( handleExpansion( const QModelIndex& ) ) );
65 QVBoxLayout *layout = new QVBoxLayout();
66 layout->setSpacing( 0 ); layout->setMargin( 0 );
68 QHBoxLayout *buttons = new QHBoxLayout();
69 repeatButton = new QPushButton( this );
70 buttons->addWidget( repeatButton );
71 randomButton = new QPushButton( this );
72 buttons->addWidget( randomButton );
74 if( model->hasRandom() ) randomButton->setText( qtr( "Random" ) );
75 else randomButton->setText( qtr( "No random" ) );
77 if( model->hasRepeat() ) repeatButton->setText( qtr( "Repeat One" ) );
78 else if( model->hasLoop() ) repeatButton->setText( qtr( "Repeat All" ) );
79 else repeatButton->setText( qtr( "No Repeat" ) );
81 connect( repeatButton, SIGNAL( clicked() ), this, SLOT( toggleRepeat() ));
82 connect( randomButton, SIGNAL( clicked() ), this, SLOT( toggleRandom() ));
84 layout->addWidget( view );
85 layout->addLayout( buttons );
89 void StandardPLPanel::toggleRepeat()
91 if( model->hasRepeat() )
93 model->setRepeat( false ); model->setLoop( true );
94 repeatButton->setText( qtr( "Repeat All" ) );
96 else if( model->hasLoop() )
98 model->setRepeat( false ) ; model->setLoop( false );
99 repeatButton->setText( qtr( "No Repeat" ) );
103 model->setRepeat( true );
104 repeatButton->setText( qtr( "Repeat One" ) );
108 void StandardPLPanel::toggleRandom()
110 bool prev = model->hasRandom();
111 model->setRandom( !prev );
112 randomButton->setText( prev ? qtr( "No Random" ) : qtr( "Random" ) );
115 void StandardPLPanel::handleExpansion( const QModelIndex &index )
118 if( model->isCurrent( index ) )
121 while( parent.isValid() )
123 view->setExpanded( parent, true );
124 parent = model->parent( parent );
129 void StandardPLPanel::doPopup( QModelIndex index, QPoint point )
131 assert( index.isValid() );
132 QItemSelectionModel *selection = view->selectionModel();
133 QModelIndexList list = selection->selectedIndexes();
134 model->popup( index, point, list );
137 void StandardPLPanel::setRoot( int i_root_id )
139 playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id );
141 p_item = playlist_GetPreferredNode( THEPL, p_item );
143 model->rebuild( p_item );
146 void StandardPLPanel::keyPressEvent( QKeyEvent *e )
157 void StandardPLPanel::deleteSelection()
159 QItemSelectionModel *selection = view->selectionModel();
160 QModelIndexList list = selection->selectedIndexes();
161 model->doDelete( list );
164 StandardPLPanel::~StandardPLPanel()