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>
37 #include <QSpacerItem>
38 #include "util/views.hpp"
39 #include "util/customwidgets.hpp"
41 StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf,
42 playlist_t *p_playlist,
43 playlist_item_t *p_root ):
44 PLPanel( _parent, _p_intf )
46 model = new PLModel( p_playlist, p_root, -1, this );
47 view = new QVLCTreeView( 0 );
48 view->setModel(model);
49 view->setIconSize( QSize(20,20) );
50 view->setAlternatingRowColors( true );
51 view->header()->resizeSection( 0, 300 );
52 view->header()->setSortIndicatorShown( true );
53 view->header()->setClickable( true );
54 view->setSelectionMode( QAbstractItemView::ExtendedSelection );
56 connect( view, SIGNAL( activated( const QModelIndex& ) ), model,
57 SLOT( activateItem( const QModelIndex& ) ) );
59 connect( view, SIGNAL( rightClicked( QModelIndex , QPoint ) ),
60 this, SLOT( doPopup( QModelIndex, QPoint ) ) );
63 SIGNAL( dataChanged( const QModelIndex&, const QModelIndex& ) ),
64 this, SLOT( handleExpansion( const QModelIndex& ) ) );
66 QVBoxLayout *layout = new QVBoxLayout();
67 layout->setSpacing( 0 ); layout->setMargin( 0 );
69 QHBoxLayout *buttons = new QHBoxLayout();
71 repeatButton = new QPushButton( 0 ); buttons->addWidget( repeatButton );
72 if( model->hasRepeat() ) repeatButton->setText( qtr( "Repeat One" ) );
73 else if( model->hasLoop() ) repeatButton->setText( qtr( "Repeat All" ) );
74 else repeatButton->setText( qtr( "No Repeat" ) );
75 connect( repeatButton, SIGNAL( clicked() ), this, SLOT( toggleRepeat() ));
77 randomButton = new QPushButton( 0 ); buttons->addWidget( randomButton );
78 if( model->hasRandom() ) randomButton->setText( qtr( "Random" ) );
79 else randomButton->setText( qtr( "No random" ) );
80 connect( randomButton, SIGNAL( clicked() ), this, SLOT( toggleRandom() ));
82 QSpacerItem *spacer = new QSpacerItem( 10, 20 );buttons->addItem( spacer );
84 QLabel *filter = new QLabel( qfu( "&Search:" ) + " " );
85 buttons->addWidget( filter );
86 searchLine = new ClickLineEdit( qfu( "Playlist filter" ), 0 );
87 connect( searchLine, SIGNAL( textChanged(QString) ),
88 this, SLOT( search(QString)) );
89 buttons->addWidget( searchLine ); filter->setBuddy( searchLine );
91 QPushButton *clear = new QPushButton( qfu( "CL") );
92 buttons->addWidget( clear );
93 connect( clear, SIGNAL( clicked() ), this, SLOT( clearFilter() ) );
95 layout->addWidget( view );
96 layout->addLayout( buttons );
97 // layout->addWidget( bar );
101 void StandardPLPanel::toggleRepeat()
103 if( model->hasRepeat() )
105 model->setRepeat( false ); model->setLoop( true );
106 repeatButton->setText( qtr( "Repeat All" ) );
108 else if( model->hasLoop() )
110 model->setRepeat( false ) ; model->setLoop( false );
111 repeatButton->setText( qtr( "No Repeat" ) );
115 model->setRepeat( true );
116 repeatButton->setText( qtr( "Repeat One" ) );
120 void StandardPLPanel::toggleRandom()
122 bool prev = model->hasRandom();
123 model->setRandom( !prev );
124 randomButton->setText( prev ? qtr( "No Random" ) : qtr( "Random" ) );
127 void StandardPLPanel::handleExpansion( const QModelIndex &index )
130 if( model->isCurrent( index ) )
133 while( parent.isValid() )
135 view->setExpanded( parent, true );
136 parent = model->parent( parent );
141 void StandardPLPanel::clearFilter()
143 searchLine->setText( "" );
146 void StandardPLPanel::search( QString searchText )
148 model->search( searchText );
151 void StandardPLPanel::doPopup( QModelIndex index, QPoint point )
153 assert( index.isValid() );
154 QItemSelectionModel *selection = view->selectionModel();
155 QModelIndexList list = selection->selectedIndexes();
156 model->popup( index, point, list );
159 void StandardPLPanel::setRoot( int i_root_id )
161 playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id );
163 p_item = playlist_GetPreferredNode( THEPL, p_item );
165 model->rebuild( p_item );
168 void StandardPLPanel::keyPressEvent( QKeyEvent *e )
179 void StandardPLPanel::deleteSelection()
181 QItemSelectionModel *selection = view->selectionModel();
182 QModelIndexList list = selection->selectedIndexes();
183 model->doDelete( list );
186 StandardPLPanel::~StandardPLPanel()