]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/standardpanel.cpp
* Add random/loop buttons
[vlc] / modules / gui / qt4 / components / playlist / standardpanel.cpp
1 /*****************************************************************************
2  * standardpanel.cpp : The "standard" playlist panel : just a treeview
3  ****************************************************************************
4  * Copyright (C) 2000-2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #include "playlist_model.hpp"
25 #include "components/playlist/panels.hpp"
26 #include <QTreeView>
27 #include <QPushButton>
28 #include <QHBoxLayout>
29 #include <QVBoxLayout>
30 #include <QHeaderView>
31 #include "qt4.hpp"
32 #include <assert.h>
33
34 StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf,
35                                   playlist_t *p_playlist,
36                                   playlist_item_t *p_root ):
37                                   PLPanel( _parent, _p_intf )
38 {
39     model = new PLModel( p_playlist, p_root, -1, this );
40     view = new QTreeView( 0 );
41     view->setModel(model);
42     view->header()->resizeSection( 0, 300 );
43
44     connect( view, SIGNAL( activated( const QModelIndex& ) ), model,
45              SLOT( activateItem( const QModelIndex& ) ) );
46
47     connect( model,
48              SIGNAL( dataChanged( const QModelIndex&, const QModelIndex& ) ),
49              this, SLOT( handleExpansion( const QModelIndex& ) ) );
50
51     model->Rebuild();
52
53     QVBoxLayout *layout = new QVBoxLayout();
54     layout->setSpacing( 0 ); layout->setMargin( 0 );
55
56     QHBoxLayout *buttons = new QHBoxLayout();
57     repeatButton = new QPushButton( this );
58     buttons->addWidget( repeatButton );
59     randomButton = new QPushButton( this );
60     buttons->addWidget( randomButton );
61
62     if( model->hasRandom() ) randomButton->setText( qtr( "Random" ) );
63     else randomButton->setText( qtr( "No random" ) );
64
65     if( model->hasRepeat() ) repeatButton->setText( qtr( "Repeat One" ) );
66     else if( model->hasLoop() ) repeatButton->setText( qtr( "Repeat All" ) );
67     else repeatButton->setText( qtr( "No Repeat" ) );
68
69     connect( repeatButton, SIGNAL( clicked() ), this, SLOT( toggleRepeat() ));
70     connect( randomButton, SIGNAL( clicked() ), this, SLOT( toggleRandom() ));
71
72     layout->addWidget( view );
73     layout->addLayout( buttons );
74     setLayout( layout );
75 }
76
77 void StandardPLPanel::toggleRepeat()
78 {
79     if( model->hasRepeat() )
80     {
81         model->setRepeat( false ); model->setLoop( true );
82         repeatButton->setText( qtr( "Repeat All" ) );
83     }
84     else if( model->hasLoop() )
85     {
86         model->setRepeat( false ) ; model->setLoop( false );
87         repeatButton->setText( qtr( "No Repeat" ) );
88     }
89     else
90     {
91         model->setRepeat( true );
92         repeatButton->setText( qtr( "Repeat One" ) );
93     }
94 }
95
96 void StandardPLPanel::toggleRandom()
97 {
98     bool prev = model->hasRandom();
99     model->setRandom( !prev );
100     randomButton->setText( prev ? qtr( "No Random" ) : qtr( "Random" ) );
101 }
102
103 void StandardPLPanel::handleExpansion( const QModelIndex &index )
104 {
105     QModelIndex parent;
106     if( model->isCurrent( index ) )
107     {
108         parent = index;
109         while( parent.isValid() )
110         {
111             view->setExpanded( parent, true );
112             parent = model->parent( parent );
113         }
114     }
115 }
116
117 void StandardPLPanel::setRoot( int i_root_id )
118 {
119     playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id );
120     assert( p_item );
121     model->rebuildRoot( p_item );
122     model->Rebuild();
123 }
124
125 StandardPLPanel::~StandardPLPanel()
126 {}