1 /*****************************************************************************
2 * interface_widgets.cpp : Custom widgets for the main interface
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include "dialogs_provider.hpp"
26 #include "components/interface_widgets.hpp"
27 #include "main_interface.hpp"
28 #include "input_manager.hpp"
33 #include <QSpacerItem>
35 #include <QPushButton>
36 #include <QHBoxLayout>
39 #include <QResizeEvent>
43 /**********************************************************************
44 * Video Widget. A simple frame on which video is drawn
45 * This class handles resize issues
46 **********************************************************************/
47 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
48 unsigned int *, unsigned int * );
49 static void DoRelease( intf_thread_t *, void * );
50 static int DoControl( intf_thread_t *, void *, int, va_list );
52 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
54 vlc_mutex_init( p_intf, &lock );
57 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
60 VideoWidget::~VideoWidget()
62 vlc_mutex_lock( &lock );
65 if( !p_intf->psz_switch_intf )
67 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
68 vout_Control( p_vout, VOUT_REPARENT );
72 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
73 vout_Control( p_vout, VOUT_CLOSE );
76 vlc_mutex_unlock( &lock );
77 vlc_mutex_destroy( &lock );
80 QSize VideoWidget::sizeHint() const
85 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
86 unsigned int *pi_width, unsigned int *pi_height )
90 msg_Dbg( p_intf, "embedded video already in use" );
94 setMinimumSize( 16, 16 );
95 return (void*)winId();
98 void VideoWidget::release( void *p_win )
102 /**********************************************************************
103 * Background Widget. Show a simple image background. Currently,
104 * it's a static cone.
105 **********************************************************************/
106 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
107 QFrame( NULL ), p_intf( _p_i )
110 setAutoFillBackground( true );
112 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
113 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
116 backgroundLayout = new QHBoxLayout;
117 label = new QLabel( "" );
118 label->setMaximumHeight( ICON_SIZE );
119 label->setMaximumWidth( ICON_SIZE );
120 label->setScaledContents( true );
121 label->setPixmap( QPixmap( ":/vlc128.png" ) );
122 backgroundLayout = new QHBoxLayout;
123 backgroundLayout->addWidget( label );
124 setLayout( backgroundLayout );
127 BackgroundWidget::~BackgroundWidget()
129 backgroundLayout->takeAt(0);
130 delete backgroundLayout;
133 QSize BackgroundWidget::sizeHint() const
138 void BackgroundWidget::resizeEvent( QResizeEvent *e )
140 if( e->size().height() < ICON_SIZE -1 )
141 label->setMaximumWidth( e->size().height() );
143 label->setMaximumWidth( ICON_SIZE );
146 /**********************************************************************
147 * Visualization selector panel
148 **********************************************************************/
149 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
150 QFrame( NULL ), p_intf( _p_i )
152 QHBoxLayout *layout = new QHBoxLayout( this );
153 layout->setMargin( 0 );
154 QPushButton *prevButton = new QPushButton( "Prev" );
155 QPushButton *nextButton = new QPushButton( "Next");
156 layout->addWidget( prevButton );
157 layout->addWidget( nextButton );
159 layout->addItem( new QSpacerItem( 40,20,
160 QSizePolicy::Expanding, QSizePolicy::Minimum) );
161 layout->addWidget( new QLabel( qtr("Current visualization:") ) );
163 current = new QLabel( qtr( "None" ) );
164 layout->addWidget( current );
166 BUTTONACT( prevButton, prev() );
167 BUTTONACT( nextButton, next() );
170 setMaximumHeight( 35 );
173 VisualSelector::~VisualSelector()
177 void VisualSelector::prev()
179 char *psz_new = aout_VisualPrev( p_intf );
182 current->setText( qfu( psz_new ) );
187 void VisualSelector::next()
189 char *psz_new = aout_VisualNext( p_intf );
192 current->setText( qfu( psz_new ) );
197 /**********************************************************************
199 **********************************************************************/
200 ControlsWidget::ControlsWidget( intf_thread_t *_p_i ) :
201 QFrame( NULL ), p_intf( _p_i )
203 QHBoxLayout *layout = new QHBoxLayout( this );
204 layout->setMargin( 0 );
206 slowerButton = new QPushButton( "S" );
207 BUTTON_SET_ACT( slowerButton, "S", qtr("Slower" ), slower() );
208 layout->addWidget( slowerButton );
209 slowerButton->setMaximumWidth( 35 );
211 normalButton = new QPushButton( "N" );
212 BUTTON_SET_ACT( normalButton, "N", qtr("Normal rate"), normal() );
213 layout->addWidget( normalButton );
214 normalButton->setMaximumWidth( 35 );
216 fasterButton = new QPushButton( "F" );
217 BUTTON_SET_ACT( fasterButton, "F", qtr("Faster" ), faster() );
218 layout->addWidget( fasterButton );
219 fasterButton->setMaximumWidth( 35 );
221 layout->addItem( new QSpacerItem( 100,20,
222 QSizePolicy::Expanding, QSizePolicy::Minimum) );
224 snapshotButton = new QPushButton( "S" );
225 BUTTON_SET_ACT( snapshotButton, "S", qtr("Take a snapshot"), snapshot() );
226 layout->addWidget( snapshotButton );
227 snapshotButton->setMaximumWidth( 35 );
229 fullscreenButton = new QPushButton( "F" );
230 BUTTON_SET_ACT( fullscreenButton, "F", qtr("Fullscreen"), fullscreen() );
231 layout->addWidget( fullscreenButton );
232 fullscreenButton->setMaximumWidth( 35 );
235 ControlsWidget::~ControlsWidget()
239 void ControlsWidget::enableInput( bool enable )
241 slowerButton->setEnabled( enable );
242 normalButton->setEnabled( enable );
243 fasterButton->setEnabled( enable );
245 void ControlsWidget::enableVideo( bool enable )
247 snapshotButton->setEnabled( enable );
248 fullscreenButton->setEnabled( enable );
251 void ControlsWidget::slower()
253 THEMIM->getIM()->slower();
256 void ControlsWidget::faster()
258 THEMIM->getIM()->faster();
261 void ControlsWidget::normal()
263 THEMIM->getIM()->normalRate();
266 void ControlsWidget::snapshot()
270 void ControlsWidget::fullscreen()
274 /**********************************************************************
275 * Playlist Widget. The embedded playlist
276 **********************************************************************/
277 #include "components/playlist/panels.hpp"
278 #include "components/playlist/selector.hpp"
280 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) :
283 /* Left Part and design */
284 QWidget *leftW = new QWidget( this );
285 QVBoxLayout *left = new QVBoxLayout( leftW );
287 /* Source Selector */
288 selector = new PLSelector( this, p_intf, THEPL );
289 left->addWidget( selector );
292 art = new QLabel( "" );
293 art->setMinimumHeight( 128 );
294 art->setMinimumWidth( 128 );
295 art->setMaximumHeight( 128 );
296 art->setMaximumWidth( 128 );
297 art->setScaledContents( true );
298 art->setPixmap( QPixmap( ":/noart.png" ) );
299 left->addWidget( art );
301 /* Initialisation of the playlist */
302 playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
303 THEPL->p_local_category );
305 rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( this,
306 p_intf, THEPL, p_root ) );
309 CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
311 CONNECT( qobject_cast<StandardPLPanel *>(rightPanel)->model,
312 artSet( QString ) , this, setArt( QString ) );
313 /* Forward removal requests from the selector to the main panel */
314 CONNECT( qobject_cast<PLSelector *>(selector)->model,
316 qobject_cast<StandardPLPanel *>(rightPanel), removeItem(int) );
318 connect( selector, SIGNAL(activated( int )),
319 this, SIGNAL( rootChanged( int ) ) );
320 emit rootChanged( p_root->i_id );
322 /* Add the two sides of the QSplitter */
324 addWidget( rightPanel );
326 leftW->setMaximumWidth( 250 );
327 setCollapsible( 1, false );
330 sizeList << 180 << 520 ;
331 setSizes( sizeList );
334 void PlaylistWidget::setArt( QString url )
337 art->setPixmap( QPixmap( ":/noart.png" ) );
338 else if( prevArt != url )
339 art->setPixmap( QPixmap( url ) );
343 PlaylistWidget::~PlaylistWidget()
347 QSize PlaylistWidget::sizeHint() const