playlist.cpp 4.88 KB
Newer Older
1
/*****************************************************************************
2
 * playlist.cpp : Custom widgets for the playlist
3
 ****************************************************************************
4
 * Copyright © 2007-2008 the VideoLAN team
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 * $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.
 *****************************************************************************/
24

25
26
27
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
28
29
30
31

#include "components/playlist/panels.hpp"
#include "components/playlist/selector.hpp"
#include "components/playlist/playlist.hpp"
32
#include "input_manager.hpp" /* art signal */
33
34
35
36
37
38
39
40
41
42
43
44

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

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

45
46
47
48
PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i,
                                QSettings *settings,
                                QWidget *_parent )
               : p_intf ( _p_i ), parent( _parent )
49
50
{
    /* Left Part and design */
51
    QSplitter *leftW = new QSplitter( Qt::Vertical, this );
52
53
54

    /* Source Selector */
    selector = new PLSelector( this, p_intf, THEPL );
55
    leftW->addWidget( selector );
56

57
58
    /* Create a Container for the Art Label
       in order to have a beautiful resizing for the selector above it */
59
60
    QWidget *artContainer = new QWidget;
    QHBoxLayout *artContLay = new QHBoxLayout( artContainer );
61
62
63
    artContLay->setMargin( 0 );
    artContLay->setSpacing( 0 );
    artContainer->setMaximumHeight( 128 );
64

65
    /* Art label */
66
    art = new ArtLabel;
67
68
69
70
71
72
    art->setMinimumHeight( 128 );
    art->setMinimumWidth( 128 );
    art->setMaximumHeight( 128 );
    art->setMaximumWidth( 128 );
    art->setScaledContents( true );
    art->setPixmap( QPixmap( ":/noart.png" ) );
73
    art->setToolTip( qtr( "Double click to get the media informations" ) );
74

75
76
77
    artContLay->addWidget( art, 1 );

    leftW->addWidget( artContainer );
78
79

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

83
    rightPanel = new StandardPLPanel( this, p_intf, THEPL, p_root );
84

85
    /* Connect the activation of the selector to a redefining of the PL */
86
87
    CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );

88
    /* Connect the activated() to the rootChanged() signal
89
       This will be used by StandardPLPanel to setCurrentRootId, that will
90
91
92
93
       change the label of the addButton  */
    connect( selector, SIGNAL( activated( int ) ),
             this, SIGNAL( rootChanged( int ) ) );

94
95
96
97
98
99
100
    /* 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 );

101
102
103
    /* art */
    CONNECT( THEMIM->getIM(), artChanged( QString ) , this, setArt( QString ) );

104
105
106
107
108
109
110
    /* Add the two sides of the QSplitter */
    addWidget( leftW );
    addWidget( rightPanel );

    QList<int> sizeList;
    sizeList << 180 << 420 ;
    setSizes( sizeList );
111
    //setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
112
113
    setStretchFactor( 0, 0 );
    setStretchFactor( 1, 3 );
114
115
    leftW->setMaximumWidth( 250 );
    setCollapsible( 1, false );
116
117

    /* In case we want to keep the splitter informations */
118
119
120
    // components shall never write there setting to a fixed location, may infer
    // with other uses of the same component...
    // settings->beginGroup( "playlist" );
121
122
123
124
125
    restoreState( settings->value("splitterSizes").toByteArray());
}

void PlaylistWidget::setArt( QString url )
{
Rafaël Carré's avatar
Rafaël Carré committed
126
    if( prevArt != url )
127
    {
Rafaël Carré's avatar
Rafaël Carré committed
128
        art->setPixmap( QPixmap( url.isEmpty() ? ":/noart.png" : url ) );
129
130
131
132
133
134
135
136
137
138
139
140
141
142
        prevArt = url;
    }
}

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

PlaylistWidget::~PlaylistWidget()
{}

void PlaylistWidget::savingSettings( QSettings *settings )
{
143
    settings->setValue( "splitterSizes", saveState() );
144
145
}