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 label = new QLabel( "" );
117 label->setMaximumHeight( ICON_SIZE );
118 label->setMaximumWidth( ICON_SIZE );
119 label->setScaledContents( true );
120 label->setPixmap( QPixmap( ":/vlc128.png" ) );
121 backgroundLayout = new QHBoxLayout;
122 backgroundLayout->addWidget( label );
123 setLayout( backgroundLayout );
126 BackgroundWidget::~BackgroundWidget()
128 backgroundLayout->takeAt(0);
129 delete backgroundLayout;
132 void BackgroundWidget::setArt( QString url )
135 label->setPixmap( QPixmap( ":/vlc128.png" ) );
137 label->setPixmap( QPixmap( url ) );
140 QSize BackgroundWidget::sizeHint() const
145 void BackgroundWidget::resizeEvent( QResizeEvent *e )
147 if( e->size().height() < ICON_SIZE -1 )
148 label->setMaximumWidth( e->size().height() );
150 label->setMaximumWidth( ICON_SIZE );
153 /**********************************************************************
154 * Visualization selector panel
155 **********************************************************************/
156 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
157 QFrame( NULL ), p_intf( _p_i )
159 QHBoxLayout *layout = new QHBoxLayout( this );
160 layout->setMargin( 0 );
161 QPushButton *prevButton = new QPushButton( "Prev" );
162 QPushButton *nextButton = new QPushButton( "Next");
163 layout->addWidget( prevButton );
164 layout->addWidget( nextButton );
166 layout->addItem( new QSpacerItem( 40,20,
167 QSizePolicy::Expanding, QSizePolicy::Minimum) );
168 layout->addWidget( new QLabel( qtr("Current visualization:") ) );
170 current = new QLabel( qtr( "None" ) );
171 layout->addWidget( current );
173 BUTTONACT( prevButton, prev() );
174 BUTTONACT( nextButton, next() );
177 setMaximumHeight( 35 );
180 VisualSelector::~VisualSelector()
184 void VisualSelector::prev()
186 char *psz_new = aout_VisualPrev( p_intf );
189 current->setText( qfu( psz_new ) );
194 void VisualSelector::next()
196 char *psz_new = aout_VisualNext( p_intf );
199 current->setText( qfu( psz_new ) );
204 /**********************************************************************
206 **********************************************************************/
207 ControlsWidget::ControlsWidget( intf_thread_t *_p_i ) :
208 QFrame( NULL ), p_intf( _p_i )
210 QHBoxLayout *layout = new QHBoxLayout( this );
211 layout->setMargin( 0 );
213 slowerButton = new QPushButton( "S" );
214 BUTTON_SET_ACT( slowerButton, "S", qtr("Slower" ), slower() );
215 layout->addWidget( slowerButton );
216 slowerButton->setMaximumWidth( 35 );
218 normalButton = new QPushButton( "N" );
219 BUTTON_SET_ACT( normalButton, "N", qtr("Normal rate"), normal() );
220 layout->addWidget( normalButton );
221 normalButton->setMaximumWidth( 35 );
223 fasterButton = new QPushButton( "F" );
224 BUTTON_SET_ACT( fasterButton, "F", qtr("Faster" ), faster() );
225 layout->addWidget( fasterButton );
226 fasterButton->setMaximumWidth( 35 );
228 layout->addItem( new QSpacerItem( 100,20,
229 QSizePolicy::Expanding, QSizePolicy::Minimum) );
231 snapshotButton = new QPushButton( "S" );
232 BUTTON_SET_ACT( snapshotButton, "S", qtr("Take a snapshot"), snapshot() );
233 layout->addWidget( snapshotButton );
234 snapshotButton->setMaximumWidth( 35 );
236 fullscreenButton = new QPushButton( "F" );
237 BUTTON_SET_ACT( fullscreenButton, "F", qtr("Fullscreen"), fullscreen() );
238 layout->addWidget( fullscreenButton );
239 fullscreenButton->setMaximumWidth( 35 );
242 ControlsWidget::~ControlsWidget()
246 void ControlsWidget::enableInput( bool enable )
248 slowerButton->setEnabled( enable );
249 normalButton->setEnabled( enable );
250 fasterButton->setEnabled( enable );
252 void ControlsWidget::enableVideo( bool enable )
254 snapshotButton->setEnabled( enable );
255 fullscreenButton->setEnabled( enable );
258 void ControlsWidget::slower()
260 THEMIM->getIM()->slower();
263 void ControlsWidget::faster()
265 THEMIM->getIM()->faster();
268 void ControlsWidget::normal()
270 THEMIM->getIM()->normalRate();
273 void ControlsWidget::snapshot()
277 void ControlsWidget::fullscreen()
281 /**********************************************************************
282 * Playlist Widget. The embedded playlist
283 **********************************************************************/
284 #include "components/playlist/panels.hpp"
285 #include "components/playlist/selector.hpp"
287 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) :
290 /* Left Part and design */
291 QWidget *leftW = new QWidget( this );
292 QVBoxLayout *left = new QVBoxLayout( leftW );
294 /* Source Selector */
295 selector = new PLSelector( this, p_intf, THEPL );
296 left->addWidget( selector );
299 art = new QLabel( "" );
300 art->setMinimumHeight( 128 );
301 art->setMinimumWidth( 128 );
302 art->setMaximumHeight( 128 );
303 art->setMaximumWidth( 128 );
304 art->setScaledContents( true );
305 art->setPixmap( QPixmap( ":/noart.png" ) );
306 left->addWidget( art );
308 /* Initialisation of the playlist */
309 playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
310 THEPL->p_local_category );
312 rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( this,
313 p_intf, THEPL, p_root ) );
316 CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
318 CONNECT( qobject_cast<StandardPLPanel *>(rightPanel)->model,
319 artSet( QString ) , this, setArt( QString ) );
320 /* Forward removal requests from the selector to the main panel */
321 CONNECT( qobject_cast<PLSelector *>(selector)->model,
323 qobject_cast<StandardPLPanel *>(rightPanel), removeItem(int) );
325 connect( selector, SIGNAL(activated( int )),
326 this, SIGNAL( rootChanged( int ) ) );
327 emit rootChanged( p_root->i_id );
329 /* Add the two sides of the QSplitter */
331 addWidget( rightPanel );
333 leftW->setMaximumWidth( 250 );
334 setCollapsible( 1, false );
337 sizeList << 180 << 520 ;
338 setSizes( sizeList );
341 void PlaylistWidget::setArt( QString url )
344 art->setPixmap( QPixmap( ":/noart.png" ) );
345 else if( prevArt != url )
346 art->setPixmap( QPixmap( url ) );
351 PlaylistWidget::~PlaylistWidget()
355 QSize PlaylistWidget::sizeHint() const