playlist.cpp 5.12 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
PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i,
                                QWidget *_parent )
               : p_intf ( _p_i ), parent( _parent )
48
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
49 50
    setContentsMargins( 3, 3, 3, 3 );

51
    /* Left Part and design */
52
    QSplitter *leftW = new QSplitter( Qt::Vertical, this );
53 54 55

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

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

66
    /* Art label */
67
    art = new ArtLabel( p_intf );
68
    art->setToolTip( qtr( "Double click to get media information" ) );
69

70 71 72
    artContLay->addWidget( art, 1 );

    leftW->addWidget( artContainer );
73 74

    /* Initialisation of the playlist */
75
    playlist_t * p_playlist = THEPL;
76
    PL_LOCK;
77 78
    playlist_item_t *p_root =
                  playlist_GetPreferredNode( THEPL, THEPL->p_local_category );
79
    PL_UNLOCK;
80

81
    rightPanel = new StandardPLPanel( this, p_intf, THEPL, p_root );
82

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

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

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

99
    /* art */
100 101
    CONNECT( THEMIM->getIM(), artChanged( input_item_t* ) ,
             art, update( input_item_t* ) );
102

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

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

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

    setAcceptDrops( true );
    setWindowTitle( qtr( "Playlist" ) );
    setWindowIcon( QApplication::windowIcon() );
125 126 127 128
}

PlaylistWidget::~PlaylistWidget()
{
129
    getSettings()->beginGroup("playlistdialog");
130
    getSettings()->setValue( "splitterSizes", saveState() );
131
    getSettings()->endGroup();
132 133
}

134 135 136 137 138 139 140 141 142 143 144
#include "main_interface.hpp"
void PlaylistWidget::dropEvent(QDropEvent *event)
{
    if( p_intf->p_sys->p_mi )
        p_intf->p_sys->p_mi->dropEvent( event );
}
void PlaylistWidget::dragEnterEvent(QDragEnterEvent *event)
{
    event->acceptProposedAction();
}

145 146 147 148 149 150 151 152 153 154 155 156
void PlaylistWidget::closeEvent( QCloseEvent *event )
{
    if( THEDP->isDying() )
    {
        close();
    }
    else
    {
        if( p_intf->p_sys->p_mi )
            p_intf->p_sys->p_mi->togglePlaylist();
    }
}