standardpanel.cpp 2.92 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * standardpanel.cpp : The "standard" playlist panel : just a treeview
 ****************************************************************************
 * Copyright (C) 2000-2005 the VideoLAN team
5
 * $Id$
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

Clément Stenac's avatar
Clément Stenac committed
24
#include "playlist_model.hpp"
25
#include "components/playlist/panels.hpp"
Clément Stenac's avatar
Clément Stenac committed
26
#include <QTreeView>
27 28 29 30
#include <QVBoxLayout>
#include <QHeaderView>
#include "qt4.hpp"
#include <assert.h>
31

Clément Stenac's avatar
Clément Stenac committed
32
StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf,
Clément Stenac's avatar
Clément Stenac committed
33
                                  playlist_t *p_playlist,
Clément Stenac's avatar
Clément Stenac committed
34
                                  playlist_item_t *p_root ):
35 36
                                  PLPanel( _parent, _p_intf )
{
37 38 39
    model = new PLModel( p_playlist, p_root, -1, this );
    model->Rebuild();
    view = new QTreeView( 0 );
Clément Stenac's avatar
Clément Stenac committed
40
    view->setModel(model);
41 42 43 44 45
    view->header()->resizeSection( 0, 300 );

    connect( view, SIGNAL( activated( const QModelIndex& ) ), model,
             SLOT( activateItem( const QModelIndex& ) ) );

Clément Stenac's avatar
Qt4:  
Clément Stenac committed
46 47 48 49
    connect( model,
             SIGNAL( dataChanged( const QModelIndex&, const QModelIndex& ) ),
             this, SLOT( handleExpansion( const QModelIndex& ) ) );

50 51 52 53 54 55
    QVBoxLayout *layout = new QVBoxLayout();
    layout->setSpacing( 0 ); layout->setMargin( 0 );
    layout->addWidget( view );
    setLayout( layout );
}

Clément Stenac's avatar
Qt4:  
Clément Stenac committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
void StandardPLPanel::handleExpansion( const QModelIndex &index )
{
    fprintf( stderr, "Checking expansion\n" );
    QModelIndex parent;
    if( model->isCurrent( index ) )
    {
        fprintf( stderr, "It is the current one\n" ) ;
        parent = index;
        while( parent.isValid() )
        {
            fprintf( stderr, "Expanding %s\n",
         (model->data( parent, Qt::DisplayRole )).toString().toUtf8().data() );
            view->setExpanded( parent, true );
            parent = model->parent( parent );
        }
    }
}

74 75 76 77 78
void StandardPLPanel::setRoot( int i_root_id )
{
    playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id );
    assert( p_item );
    model->rebuildRoot( p_item );
Clément Stenac's avatar
Clément Stenac committed
79
    model->Rebuild();
80 81 82 83
}

StandardPLPanel::~StandardPLPanel()
{}