playlist.cpp 4.7 KB
Newer Older
1
/*****************************************************************************
2
 * playlist.cpp : Custom widgets for the playlist
3
 ****************************************************************************
4
 * Copyright © 2006 the VideoLAN team
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * $Id$
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
 *          Jean-Baptiste Kempf <jb@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.
 *****************************************************************************/

#include "components/playlist/panels.hpp"
#include "components/playlist/selector.hpp"
#include "components/playlist/playlist.hpp"
28
#include "input_manager.hpp" /* art */
29
30
31
32
33
34
35
36
37
38
39
40

#include <QSettings>
#include <QLabel>
#include <QSpacerItem>
#include <QCursor>
#include <QPushButton>
#include <QVBoxLayout>

/**********************************************************************
 * Playlist Widget. The embedded playlist
 **********************************************************************/

41
42
PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QSettings *settings, QWidget *_parent ) :
                                p_intf ( _p_i ), parent( _parent )
43
44
{
    /* Left Part and design */
45
    QSplitter *leftW = new QSplitter( Qt::Vertical, this );
46
47
48

    /* Source Selector */
    selector = new PLSelector( this, p_intf, THEPL );
49
    leftW->addWidget( selector );
50
51
52
53
54
55
56
57
58

    /* Art label */
    art = new QLabel( "" );
    art->setMinimumHeight( 128 );
    art->setMinimumWidth( 128 );
    art->setMaximumHeight( 128 );
    art->setMaximumWidth( 128 );
    art->setScaledContents( true );
    art->setPixmap( QPixmap( ":/noart.png" ) );
59
    leftW->addWidget( art );
60
61
62
63
64
65
66
67

    /* Initialisation of the playlist */
    playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
                                                THEPL->p_local_category );

    rightPanel = qobject_cast<PLPanel *>( new StandardPLPanel( this,
                              p_intf, THEPL, p_root ) );

68
    /* Connect the activation of the selector to a redefining of the PL */
69
70
    CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );

71
72
73
74
75
76
    /* Connect the activated() to the rootChanged() signal
       This will be used by StandardPLPanel to setCurrentRootId, that will 
       change the label of the addButton  */
    connect( selector, SIGNAL( activated( int ) ),
             this, SIGNAL( rootChanged( int ) ) );

77
    CONNECT( THEMIM->getIM(), artChanged( QString ) , this, setArt( QString ) );
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
    /* Forward removal requests from the selector to the main panel */
    CONNECT( qobject_cast<PLSelector *>( selector )->model,
             shouldRemove( int ),
             qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );

    emit rootChanged( p_root->i_id );

    /* Add the two sides of the QSplitter */
    addWidget( leftW );
    addWidget( rightPanel );

    QList<int> sizeList;
    sizeList << 180 << 420 ;
    setSizes( sizeList );
    setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
93
94
    setStretchFactor( 0, 0 );
    setStretchFactor( 1, 3 );
95
96
    leftW->setMaximumWidth( 250 );
    setCollapsible( 1, false );
97
98
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
125
126
127
128
129
130
131

    /* In case we want to keep the splitter informations */
    settings->beginGroup( "playlist" );
    restoreState( settings->value("splitterSizes").toByteArray());
    resize( settings->value("size", QSize(600, 300)).toSize());
    move( settings->value("pos", QPoint( 0, 400)).toPoint());
    settings->endGroup();
}

void PlaylistWidget::setArt( QString url )
{
    if( url.isNull() )
    {
        art->setPixmap( QPixmap( ":/noart.png" ) );
        emit artSet( url );
    }
    else if( prevArt != url )
    {
        art->setPixmap( QPixmap( url ) );
        prevArt = url;
        emit artSet( url );
    }
}

QSize PlaylistWidget::sizeHint() const
{
   return QSize( 600 , 300 );
}

PlaylistWidget::~PlaylistWidget()
{}

void PlaylistWidget::savingSettings( QSettings *settings )
{
    settings->beginGroup( "playlist" );
132
133
134
    settings->setValue( "pos", parent->pos() );
    settings->setValue( "size", parent->size() );
    settings->setValue( "splitterSizes", saveState() );
135
136
137
    settings->endGroup();
}