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 *****************************************************************************/
25 #include "playlist_model.hpp"
26 #include "components/playlist/panels.hpp"
27 #include "util/customwidgets.hpp"
30 #include <QPushButton>
31 #include <QHBoxLayout>
32 #include <QVBoxLayout>
33 #include <QHeaderView>
35 #include <QModelIndexList>
38 #include <QSpacerItem>
42 StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf,
43 playlist_t *p_playlist,
44 playlist_item_t *p_root ):
45 PLPanel( _parent, _p_intf )
47 model = new PLModel( p_playlist, p_root, -1, this );
48 view = new QVLCTreeView( 0 );
49 view->setModel(model);
50 view->setIconSize( QSize(20,20) );
51 view->setAlternatingRowColors( true );
52 view->header()->resizeSection( 0, 230 );
53 view->header()->resizeSection( 2, 60 );
54 view->header()->setSortIndicatorShown( true );
55 view->header()->setClickable( true );
56 view->setSelectionMode( QAbstractItemView::ExtendedSelection );
58 CONNECT( view, activated( const QModelIndex& ) ,
59 model,activateItem( const QModelIndex& ) );
60 CONNECT( view, rightClicked( QModelIndex , QPoint ),
61 this, doPopup( QModelIndex, QPoint ) );
62 CONNECT( model, dataChanged( const QModelIndex&, const QModelIndex& ),
63 this, handleExpansion( const QModelIndex& ) );
65 QVBoxLayout *layout = new QVBoxLayout();
66 layout->setSpacing( 0 ); layout->setMargin( 0 );
68 QHBoxLayout *buttons = new QHBoxLayout();
70 repeatButton = new QPushButton( 0 ); buttons->addWidget( repeatButton );
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" ) );
74 BUTTONACT( repeatButton, toggleRepeat() );
76 randomButton = new QPushButton( 0 ); buttons->addWidget( randomButton );
77 if( model->hasRandom() ) randomButton->setText( qtr( "Random" ) );
78 else randomButton->setText( qtr( "No random" ) );
79 BUTTONACT( randomButton, toggleRandom() );
81 QSpacerItem *spacer = new QSpacerItem( 10, 20 );buttons->addItem( spacer );
83 QLabel *filter = new QLabel( qfu( "&Search:" ) + " " );
84 buttons->addWidget( filter );
85 searchLine = new ClickLineEdit( qfu( "Playlist filter" ), 0 );
86 CONNECT( searchLine, textChanged(QString), this, search(QString));
87 buttons->addWidget( searchLine ); filter->setBuddy( searchLine );
89 QPushButton *clear = new QPushButton( qfu( "CL") );
90 buttons->addWidget( clear );
91 BUTTONACT( clear, clearFilter() );
93 layout->addWidget( view );
94 layout->addLayout( buttons );
95 // layout->addWidget( bar );
99 void StandardPLPanel::toggleRepeat()
101 if( model->hasRepeat() )
103 model->setRepeat( false ); model->setLoop( true );
104 repeatButton->setText( qtr( "Repeat All" ) );
106 else if( model->hasLoop() )
108 model->setRepeat( false ) ; model->setLoop( false );
109 repeatButton->setText( qtr( "No Repeat" ) );
113 model->setRepeat( true );
114 repeatButton->setText( qtr( "Repeat One" ) );
118 void StandardPLPanel::toggleRandom()
120 bool prev = model->hasRandom();
121 model->setRandom( !prev );
122 randomButton->setText( prev ? qtr( "No Random" ) : qtr( "Random" ) );
125 void StandardPLPanel::handleExpansion( const QModelIndex &index )
128 if( model->isCurrent( index ) )
131 while( parent.isValid() )
133 view->setExpanded( parent, true );
134 parent = model->parent( parent );
139 void StandardPLPanel::clearFilter()
141 searchLine->setText( "" );
144 void StandardPLPanel::search( QString searchText )
146 model->search( searchText );
149 void StandardPLPanel::doPopup( QModelIndex index, QPoint point )
151 if( !index.isValid() ) return;
152 QItemSelectionModel *selection = view->selectionModel();
153 QModelIndexList list = selection->selectedIndexes();
154 model->popup( index, point, list );
157 void StandardPLPanel::setRoot( int i_root_id )
159 playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id );
161 p_item = playlist_GetPreferredNode( THEPL, p_item );
163 model->rebuild( p_item );
166 void StandardPLPanel::keyPressEvent( QKeyEvent *e )
177 void StandardPLPanel::deleteSelection()
179 QItemSelectionModel *selection = view->selectionModel();
180 QModelIndexList list = selection->selectedIndexes();
181 model->doDelete( list );
184 StandardPLPanel::~StandardPLPanel()