standardpanel.cpp 5.85 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 "qt4.hpp"
Clément Stenac's avatar
Clément Stenac committed
25
#include "playlist_model.hpp"
26
#include "components/playlist/panels.hpp"
Clément Stenac's avatar
Clément Stenac committed
27 28
#include "util/customwidgets.hpp"

Clément Stenac's avatar
Clément Stenac committed
29
#include <QTreeView>
Clément Stenac's avatar
Clément Stenac committed
30 31
#include <QPushButton>
#include <QHBoxLayout>
32 33
#include <QVBoxLayout>
#include <QHeaderView>
Clément Stenac's avatar
Clément Stenac committed
34 35
#include <QKeyEvent>
#include <QModelIndexList>
Clément Stenac's avatar
Clément Stenac committed
36 37 38
#include <QToolBar>
#include <QLabel>
#include <QSpacerItem>
Clément Stenac's avatar
Clément Stenac committed
39 40

#include <assert.h>
Clément Stenac's avatar
Clément Stenac committed
41

Clément Stenac's avatar
Clément Stenac committed
42
StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf,
Clément Stenac's avatar
Clément Stenac committed
43
                                  playlist_t *p_playlist,
Clément Stenac's avatar
Clément Stenac committed
44
                                  playlist_item_t *p_root ):
45 46
                                  PLPanel( _parent, _p_intf )
{
47
    model = new PLModel( p_playlist, p_root, -1, this );
Clément Stenac's avatar
Clément Stenac committed
48
    view = new QVLCTreeView( 0 );
Clément Stenac's avatar
Clément Stenac committed
49
    view->setModel(model);
50 51
    view->setIconSize( QSize(20,20) );
    view->setAlternatingRowColors( true );
Clément Stenac's avatar
Clément Stenac committed
52
    view->header()->resizeSection( 0, 230 );
Clément Stenac's avatar
Clément Stenac committed
53
    view->header()->resizeSection( 2, 60 );
Clément Stenac's avatar
Clément Stenac committed
54 55
    view->header()->setSortIndicatorShown( true );
    view->header()->setClickable( true );
Clément Stenac's avatar
Clément Stenac committed
56
    view->setSelectionMode( QAbstractItemView::ExtendedSelection );
57

Clément Stenac's avatar
Clément Stenac committed
58 59 60 61 62 63
    CONNECT( view, activated( const QModelIndex& ) ,
             model,activateItem( const QModelIndex& ) );
    CONNECT( view, rightClicked( QModelIndex , QPoint ),
             this, doPopup( QModelIndex, QPoint ) );
    CONNECT( model, dataChanged( const QModelIndex&, const QModelIndex& ),
             this, handleExpansion( const QModelIndex& ) );
Clément Stenac's avatar
Qt4:  
Clément Stenac committed
64

65 66
    QVBoxLayout *layout = new QVBoxLayout();
    layout->setSpacing( 0 ); layout->setMargin( 0 );
Clément Stenac's avatar
Clément Stenac committed
67 68 69

    QHBoxLayout *buttons = new QHBoxLayout();

Clément Stenac's avatar
Clément Stenac committed
70
    repeatButton = new QPushButton( 0 ); buttons->addWidget( repeatButton );
Clément Stenac's avatar
Clément Stenac committed
71 72 73
    if( model->hasRepeat() ) repeatButton->setText( qtr( "Repeat One" ) );
    else if( model->hasLoop() ) repeatButton->setText( qtr( "Repeat All" ) );
    else repeatButton->setText( qtr( "No Repeat" ) );
Clément Stenac's avatar
Clément Stenac committed
74
    BUTTONACT( repeatButton, toggleRepeat() );
Clément Stenac's avatar
Clément Stenac committed
75 76 77 78

    randomButton = new QPushButton( 0 ); buttons->addWidget( randomButton );
    if( model->hasRandom() ) randomButton->setText( qtr( "Random" ) );
    else randomButton->setText( qtr( "No random" ) );
Clément Stenac's avatar
Clément Stenac committed
79
    BUTTONACT( randomButton, toggleRandom() );
Clément Stenac's avatar
Clément Stenac committed
80

Clément Stenac's avatar
Clément Stenac committed
81 82 83 84 85
    QSpacerItem *spacer = new QSpacerItem( 10, 20 );buttons->addItem( spacer );

    QLabel *filter = new QLabel( qfu( "&Search:" ) + " " );
    buttons->addWidget( filter );
    searchLine = new  ClickLineEdit( qfu( "Playlist filter" ), 0 );
Clément Stenac's avatar
Clément Stenac committed
86
    CONNECT( searchLine, textChanged(QString), this, search(QString));
Clément Stenac's avatar
Clément Stenac committed
87 88 89 90
    buttons->addWidget( searchLine ); filter->setBuddy( searchLine );

    QPushButton *clear = new QPushButton( qfu( "CL") );
    buttons->addWidget( clear );
Clément Stenac's avatar
Clément Stenac committed
91
    BUTTONACT( clear, clearFilter() );
Clément Stenac's avatar
Clément Stenac committed
92

93
    layout->addWidget( view );
Clément Stenac's avatar
Clément Stenac committed
94
    layout->addLayout( buttons );
Clément Stenac's avatar
Clément Stenac committed
95
//    layout->addWidget( bar );
96 97 98
    setLayout( layout );
}

Clément Stenac's avatar
Clément Stenac committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
void StandardPLPanel::toggleRepeat()
{
    if( model->hasRepeat() )
    {
        model->setRepeat( false ); model->setLoop( true );
        repeatButton->setText( qtr( "Repeat All" ) );
    }
    else if( model->hasLoop() )
    {
        model->setRepeat( false ) ; model->setLoop( false );
        repeatButton->setText( qtr( "No Repeat" ) );
    }
    else
    {
        model->setRepeat( true );
        repeatButton->setText( qtr( "Repeat One" ) );
    }
}

void StandardPLPanel::toggleRandom()
{
    bool prev = model->hasRandom();
    model->setRandom( !prev );
    randomButton->setText( prev ? qtr( "No Random" ) : qtr( "Random" ) );
}

Clément Stenac's avatar
Qt4:  
Clément Stenac committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138
void StandardPLPanel::handleExpansion( const QModelIndex &index )
{
    QModelIndex parent;
    if( model->isCurrent( index ) )
    {
        parent = index;
        while( parent.isValid() )
        {
            view->setExpanded( parent, true );
            parent = model->parent( parent );
        }
    }
}

Clément Stenac's avatar
Clément Stenac committed
139 140 141 142 143 144 145 146 147 148
void StandardPLPanel::clearFilter()
{
    searchLine->setText( "" );
}

void StandardPLPanel::search( QString searchText )
{
    model->search( searchText );
}

Clément Stenac's avatar
Clément Stenac committed
149 150
void StandardPLPanel::doPopup( QModelIndex index, QPoint point )
{
151
    if( !index.isValid() ) return;
Clément Stenac's avatar
Clément Stenac committed
152 153 154 155 156
    QItemSelectionModel *selection = view->selectionModel();
    QModelIndexList list = selection->selectedIndexes();
    model->popup( index, point, list );
}

157 158 159 160
void StandardPLPanel::setRoot( int i_root_id )
{
    playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id );
    assert( p_item );
161 162
    p_item = playlist_GetPreferredNode( THEPL, p_item );
    assert( p_item );
Clément Stenac's avatar
Clément Stenac committed
163
    model->rebuild( p_item );
164 165
}

Clément Stenac's avatar
Clément Stenac committed
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
void StandardPLPanel::keyPressEvent( QKeyEvent *e )
{
    switch( e->key() )
    {
    case Qt::Key_Back:
    case Qt::Key_Delete:
        deleteSelection();
        break;
    }
}

void StandardPLPanel::deleteSelection()
{
    QItemSelectionModel *selection = view->selectionModel();
    QModelIndexList list = selection->selectedIndexes();
    model->doDelete( list );
}

184 185
StandardPLPanel::~StandardPLPanel()
{}