1 /*****************************************************************************
2 * playlist.cpp : Custom widgets for the playlist
3 ****************************************************************************
4 * Copyright © 2007-2008 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * ( at your option ) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
29 #include "components/playlist/panels.hpp"
30 #include "components/playlist/selector.hpp"
31 #include "components/playlist/playlist.hpp"
32 #include "input_manager.hpp" /* art signal */
36 #include <QSpacerItem>
38 #include <QPushButton>
39 #include <QVBoxLayout>
41 /**********************************************************************
42 * Playlist Widget. The embedded playlist
43 **********************************************************************/
45 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i,
47 : p_intf ( _p_i ), parent( _parent )
49 setContentsMargins( 3, 3, 3, 3 );
51 /* Left Part and design */
52 QSplitter *leftW = new QSplitter( Qt::Vertical, this );
55 selector = new PLSelector( this, p_intf, THEPL );
56 leftW->addWidget( selector );
58 /* Create a Container for the Art Label
59 in order to have a beautiful resizing for the selector above it */
60 QWidget *artContainer = new QWidget;
61 QHBoxLayout *artContLay = new QHBoxLayout( artContainer );
62 artContLay->setMargin( 0 );
63 artContLay->setSpacing( 0 );
64 artContainer->setMaximumHeight( 128 );
68 art->setMinimumHeight( 128 );
69 art->setMinimumWidth( 128 );
70 art->setMaximumHeight( 128 );
71 art->setMaximumWidth( 128 );
72 art->setScaledContents( true );
73 art->setPixmap( QPixmap( ":/noart.png" ) );
74 art->setToolTip( qtr( "Double click to get media information" ) );
76 artContLay->addWidget( art, 1 );
78 leftW->addWidget( artContainer );
80 /* Initialisation of the playlist */
81 playlist_t * p_playlist = THEPL;
83 playlist_item_t *p_root =
84 playlist_GetPreferredNode( THEPL, THEPL->p_local_category );
87 rightPanel = new StandardPLPanel( this, p_intf, THEPL, p_root );
89 /* Connect the activation of the selector to a redefining of the PL */
90 CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
92 /* Connect the activated() to the rootChanged() signal
93 This will be used by StandardPLPanel to setCurrentRootId, that will
94 change the label of the addButton */
95 connect( selector, SIGNAL( activated( int ) ),
96 this, SIGNAL( rootChanged( int ) ) );
98 /* Forward removal requests from the selector to the main panel */
99 CONNECT( qobject_cast<PLSelector *>( selector )->model,
101 qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
103 emit rootChanged( p_root->i_id );
106 CONNECT( THEMIM->getIM(), artChanged( QString ) , this, setArt( QString ) );
108 /* Add the two sides of the QSplitter */
110 addWidget( rightPanel );
113 sizeList << 180 << 420 ;
114 setSizes( sizeList );
115 //setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
116 setStretchFactor( 0, 0 );
117 setStretchFactor( 1, 3 );
118 leftW->setMaximumWidth( 250 );
119 setCollapsible( 1, false );
121 /* In case we want to keep the splitter informations */
122 // components shall never write there setting to a fixed location, may infer
123 // with other uses of the same component...
124 // getSettings()->beginGroup( "playlist" );
125 restoreState( getSettings()->value("splitterSizes").toByteArray());
127 setAcceptDrops( true );
128 setWindowTitle( qtr( "Playlist" ) );
129 setWindowIcon( QApplication::windowIcon() );
132 void PlaylistWidget::setArt( QString url )
136 art->setPixmap( QPixmap( url.isEmpty() ? ":/noart.png" : url ) );
141 PlaylistWidget::~PlaylistWidget()
143 getSettings()->beginGroup("playlistdialog");
144 getSettings()->setValue( "splitterSizes", saveState() );
145 getSettings()->endGroup();
148 #include "main_interface.hpp"
149 void PlaylistWidget::dropEvent(QDropEvent *event)
151 if( p_intf->p_sys->p_mi )
152 p_intf->p_sys->p_mi->dropEvent( event );
154 void PlaylistWidget::dragEnterEvent(QDragEnterEvent *event)
156 event->acceptProposedAction();