standardpanel.cpp 7.92 KB
Newer Older
zorglub's avatar
zorglub committed
1
2
3
4
/*****************************************************************************
 * standardpanel.cpp : The "standard" playlist panel : just a treeview
 ****************************************************************************
 * Copyright (C) 2000-2005 the VideoLAN team
5
 * $Id$
zorglub's avatar
zorglub committed
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.
 *****************************************************************************/

zorglub's avatar
zorglub committed
24
#include "qt4.hpp"
zorglub's avatar
zorglub committed
25
#include "dialogs_provider.hpp"
zorglub's avatar
zorglub committed
26
#include "playlist_model.hpp"
zorglub's avatar
zorglub committed
27
#include "components/playlist/panels.hpp"
zorglub's avatar
zorglub committed
28
29
#include "util/customwidgets.hpp"

zorglub's avatar
zorglub committed
30
31
#include <vlc_intf_strings.h>

zorglub's avatar
zorglub committed
32
#include <QTreeView>
zorglub's avatar
zorglub committed
33
34
#include <QPushButton>
#include <QHBoxLayout>
zorglub's avatar
zorglub committed
35
36
#include <QVBoxLayout>
#include <QHeaderView>
zorglub's avatar
zorglub committed
37
38
#include <QKeyEvent>
#include <QModelIndexList>
zorglub's avatar
zorglub committed
39
40
41
#include <QToolBar>
#include <QLabel>
#include <QSpacerItem>
zorglub's avatar
zorglub committed
42
#include <QMenu>
zorglub's avatar
zorglub committed
43
44

#include <assert.h>
zorglub's avatar
zorglub committed
45

46
StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
zorglub's avatar
zorglub committed
47
                                  intf_thread_t *_p_intf,
zorglub's avatar
zorglub committed
48
                                  playlist_t *p_playlist,
zorglub's avatar
zorglub committed
49
                                  playlist_item_t *p_root ):
zorglub's avatar
zorglub committed
50
51
                                  PLPanel( _parent, _p_intf )
{
zorglub's avatar
zorglub committed
52
    model = new PLModel( p_playlist, p_intf, p_root, -1, this );
zorglub's avatar
zorglub committed
53
    view = new QVLCTreeView( 0 );
zorglub's avatar
zorglub committed
54
    view->setModel(model);
zorglub's avatar
zorglub committed
55
56
    view->setIconSize( QSize(20,20) );
    view->setAlternatingRowColors( true );
zorglub's avatar
zorglub committed
57
    view->header()->resizeSection( 0, 230 );
zorglub's avatar
zorglub committed
58
    view->header()->resizeSection( 1, 170 );
zorglub's avatar
zorglub committed
59
60
    view->header()->setSortIndicatorShown( true );
    view->header()->setClickable( true );
zorglub's avatar
zorglub committed
61

zorglub's avatar
zorglub committed
62
    view->setSelectionMode( QAbstractItemView::ExtendedSelection );
63
64
65
66
    view->setDragEnabled( true );
    view->setAcceptDrops( true );
    view->setDropIndicatorShown( true );
    view->setAutoScroll( true );
zorglub's avatar
zorglub committed
67

zorglub's avatar
zorglub committed
68
69
70
71
72
73
    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& ) );
zorglub's avatar
Qt4:    
zorglub committed
74

zorglub's avatar
zorglub committed
75
76
77
    currentRootId = -1;
    CONNECT( parent, rootChanged(int), this, setCurrentRootId( int ) );

zorglub's avatar
zorglub committed
78
79
    QVBoxLayout *layout = new QVBoxLayout();
    layout->setSpacing( 0 ); layout->setMargin( 0 );
zorglub's avatar
zorglub committed
80
81
82

    QHBoxLayout *buttons = new QHBoxLayout();

zorglub's avatar
zorglub committed
83
84
85
86
87
    addButton = new QPushButton( "+", this );
    addButton->setMaximumWidth( 25 );
    BUTTONACT( addButton, add() );
    buttons->addWidget( addButton );

zorglub's avatar
zorglub committed
88
    repeatButton = new QPushButton( 0 ); buttons->addWidget( repeatButton );
zorglub's avatar
zorglub committed
89
90
91
    if( model->hasRepeat() ) repeatButton->setText( qtr( "R1" ) );
    else if( model->hasLoop() ) repeatButton->setText( qtr( "RA" ) );
    else repeatButton->setText( qtr( "NR" ) );
zorglub's avatar
zorglub committed
92
    BUTTONACT( repeatButton, toggleRepeat() );
zorglub's avatar
zorglub committed
93
94

    randomButton = new QPushButton( 0 ); buttons->addWidget( randomButton );
zorglub's avatar
zorglub committed
95
96
    if( model->hasRandom() ) randomButton->setText( qtr( " RND" ) );
    else randomButton->setText( qtr( "NRND" ) );
zorglub's avatar
zorglub committed
97
    BUTTONACT( randomButton, toggleRandom() );
zorglub's avatar
zorglub committed
98

zorglub's avatar
zorglub committed
99
100
    QSpacerItem *spacer = new QSpacerItem( 10, 20 );buttons->addItem( spacer );

zorglub's avatar
zorglub committed
101
    QLabel *filter = new QLabel( qtr(I_PL_SEARCH) + " " );
zorglub's avatar
zorglub committed
102
    buttons->addWidget( filter );
zorglub's avatar
zorglub committed
103
    searchLine = new  ClickLineEdit( qtr(I_PL_FILTER), 0 );
zorglub's avatar
zorglub committed
104
    CONNECT( searchLine, textChanged(QString), this, search(QString));
zorglub's avatar
zorglub committed
105
106
107
    buttons->addWidget( searchLine ); filter->setBuddy( searchLine );

    QPushButton *clear = new QPushButton( qfu( "CL") );
zorglub's avatar
zorglub committed
108
    clear->setMaximumWidth( 30 );
zorglub's avatar
zorglub committed
109
    buttons->addWidget( clear );
zorglub's avatar
zorglub committed
110
    BUTTONACT( clear, clearFilter() );
zorglub's avatar
zorglub committed
111

zorglub's avatar
zorglub committed
112
    layout->addWidget( view );
zorglub's avatar
zorglub committed
113
    layout->addLayout( buttons );
zorglub's avatar
zorglub committed
114
//    layout->addWidget( bar );
zorglub's avatar
zorglub committed
115
116
117
    setLayout( layout );
}

zorglub's avatar
zorglub committed
118
119
120
121
122
void StandardPLPanel::toggleRepeat()
{
    if( model->hasRepeat() )
    {
        model->setRepeat( false ); model->setLoop( true );
zorglub's avatar
zorglub committed
123
        repeatButton->setText( qtr(I_PL_LOOP) );
zorglub's avatar
zorglub committed
124
125
126
127
    }
    else if( model->hasLoop() )
    {
        model->setRepeat( false ) ; model->setLoop( false );
zorglub's avatar
zorglub committed
128
        repeatButton->setText( qtr(I_PL_NOREPEAT) );
zorglub's avatar
zorglub committed
129
130
131
132
    }
    else
    {
        model->setRepeat( true );
zorglub's avatar
zorglub committed
133
        repeatButton->setText( qtr(I_PL_REPEAT) );
zorglub's avatar
zorglub committed
134
135
136
137
138
139
140
    }
}

void StandardPLPanel::toggleRandom()
{
    bool prev = model->hasRandom();
    model->setRandom( !prev );
zorglub's avatar
zorglub committed
141
    randomButton->setText( prev ? qtr(I_PL_NORANDOM) : qtr(I_PL_RANDOM) );
zorglub's avatar
zorglub committed
142
143
}

zorglub's avatar
Qt4:    
zorglub committed
144
145
146
147
148
void StandardPLPanel::handleExpansion( const QModelIndex &index )
{
    QModelIndex parent;
    if( model->isCurrent( index ) )
    {
149
        view->scrollTo( index, QAbstractItemView::EnsureVisible );
zorglub's avatar
Qt4:    
zorglub committed
150
151
152
153
154
155
156
157
158
        parent = index;
        while( parent.isValid() )
        {
            view->setExpanded( parent, true );
            parent = model->parent( parent );
        }
    }
}

zorglub's avatar
zorglub committed
159
160
161
162
163
164
165
void StandardPLPanel::setCurrentRootId( int _new )
{
    currentRootId = _new;
    if( currentRootId == THEPL->p_local_category->i_id ||
        currentRootId == THEPL->p_local_onelevel->i_id  )
    {
        addButton->setEnabled( true );
zorglub's avatar
zorglub committed
166
        addButton->setToolTip( qtr(I_PL_ADDPL) );
zorglub's avatar
zorglub committed
167
168
169
170
171
    }
    else if( currentRootId == THEPL->p_ml_category->i_id ||
             currentRootId == THEPL->p_ml_onelevel->i_id )
    {
        addButton->setEnabled( true );
zorglub's avatar
zorglub committed
172
        addButton->setToolTip( qtr(I_PL_ADDML) );
zorglub's avatar
zorglub committed
173
174
175
176
177
178
179
180
181
182
183
    }
    else
        addButton->setEnabled( false );
}

void StandardPLPanel::add()
{
    QMenu *popup = new QMenu();
    if( currentRootId == THEPL->p_local_category->i_id ||
        currentRootId == THEPL->p_local_onelevel->i_id )
    {
zorglub's avatar
zorglub committed
184
185
186
        popup->addAction( qtr(I_PL_ADDF), THEDP, SLOT(simplePLAppendDialog()));
        popup->addAction( qtr(I_PL_ADVADD), THEDP, SLOT(PLAppendDialog()) );
        popup->addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) );
zorglub's avatar
zorglub committed
187
188
189
190
    }
    else if( currentRootId == THEPL->p_ml_category->i_id ||
             currentRootId == THEPL->p_ml_onelevel->i_id )
    {
zorglub's avatar
zorglub committed
191
192
193
        popup->addAction( qtr(I_PL_ADDF), THEDP, SLOT(simpleMLAppendDialog()));
        popup->addAction( qtr(I_PL_ADVADD), THEDP, SLOT( MLAppendDialog() ) );
        popup->addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
zorglub's avatar
zorglub committed
194
195
196
197
    }
    popup->popup( QCursor::pos() );
}

zorglub's avatar
zorglub committed
198
199
200
201
202
203
204
205
206
207
void StandardPLPanel::clearFilter()
{
    searchLine->setText( "" );
}

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

zorglub's avatar
zorglub committed
208
209
void StandardPLPanel::doPopup( QModelIndex index, QPoint point )
{
210
    if( !index.isValid() ) return;
zorglub's avatar
zorglub committed
211
212
213
214
215
    QItemSelectionModel *selection = view->selectionModel();
    QModelIndexList list = selection->selectedIndexes();
    model->popup( index, point, list );
}

zorglub's avatar
zorglub committed
216
217
void StandardPLPanel::setRoot( int i_root_id )
{
218
219
    playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id,
                                                    VLC_TRUE );
zorglub's avatar
zorglub committed
220
    assert( p_item );
221
222
    p_item = playlist_GetPreferredNode( THEPL, p_item );
    assert( p_item );
zorglub's avatar
zorglub committed
223
    model->rebuild( p_item );
zorglub's avatar
zorglub committed
224
225
}

zorglub's avatar
zorglub committed
226
227
228
229
230
void StandardPLPanel::removeItem( int i_id )
{
    model->removeItem( i_id );
}

zorglub's avatar
zorglub committed
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
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 );
}

zorglub's avatar
zorglub committed
249
250
StandardPLPanel::~StandardPLPanel()
{}