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>
41 /**********************************************************************
42 * Video Widget. A simple frame on which video is drawn
43 * This class handles resize issues
44 **********************************************************************/
45 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
46 unsigned int *, unsigned int * );
47 static void DoRelease( intf_thread_t *, void * );
48 static int DoControl( intf_thread_t *, void *, int, va_list );
50 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
52 vlc_mutex_init( p_intf, &lock );
55 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
58 VideoWidget::~VideoWidget()
60 vlc_mutex_lock( &lock );
63 if( !p_intf->psz_switch_intf )
65 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
66 vout_Control( p_vout, VOUT_REPARENT );
70 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
71 vout_Control( p_vout, VOUT_CLOSE );
74 vlc_mutex_unlock( &lock );
75 vlc_mutex_destroy( &lock );
78 QSize VideoWidget::sizeHint() const
83 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
84 unsigned int *pi_width, unsigned int *pi_height )
88 msg_Dbg( p_intf, "embedded video already in use" );
92 setMinimumSize( 0, 0 );
93 return (void*)winId();
96 void VideoWidget::release( void *p_win )
100 /**********************************************************************
101 * Background Widget. Show a simple image background. Currently,
102 * it's a static cone.
103 **********************************************************************/
104 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
105 QFrame( NULL ), p_intf( _p_i )
108 setAutoFillBackground( true );
110 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
111 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
114 backgroundLayout = new QHBoxLayout;
115 label = new QLabel( "" );
116 label->setMaximumHeight( ICON_SIZE );
117 label->setMaximumWidth( ICON_SIZE );
118 label->setScaledContents( true );
119 label->setPixmap( QPixmap( ":/vlc128.png" ) );
120 backgroundLayout = new QHBoxLayout;
121 backgroundLayout->addWidget( label );
122 setLayout( backgroundLayout );
125 BackgroundWidget::~BackgroundWidget()
127 backgroundLayout->takeAt(0);
128 delete backgroundLayout;
131 QSize BackgroundWidget::sizeHint() const
136 void BackgroundWidget::resizeEvent( QResizeEvent *e )
138 if( e->size().height() < ICON_SIZE -1 )
139 label->setMaximumWidth( e->size().height() );
141 label->setMaximumWidth( ICON_SIZE );
144 /**********************************************************************
145 * Visualization selector panel
146 **********************************************************************/
147 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
148 QFrame( NULL ), p_intf( _p_i )
150 QHBoxLayout *layout = new QHBoxLayout( this );
151 layout->setMargin( 0 );
152 QPushButton *prevButton = new QPushButton( "Prev" );
153 QPushButton *nextButton = new QPushButton( "Next");
154 layout->addWidget( prevButton );
155 layout->addWidget( nextButton );
157 layout->addItem( new QSpacerItem( 40,20,
158 QSizePolicy::Expanding, QSizePolicy::Minimum) );
159 layout->addWidget( new QLabel( qtr("Current visualization:") ) );
161 current = new QLabel( qtr( "None" ) );
162 layout->addWidget( current );
164 BUTTONACT( prevButton, prev() );
165 BUTTONACT( nextButton, next() );
168 setMaximumHeight( 35 );
171 VisualSelector::~VisualSelector()
175 void VisualSelector::prev()
177 char *psz_new = aout_VisualPrev( p_intf );
180 current->setText( qfu( psz_new ) );
185 void VisualSelector::next()
187 char *psz_new = aout_VisualNext( p_intf );
190 current->setText( qfu( psz_new ) );
195 /**********************************************************************
197 **********************************************************************/
198 ControlsWidget::ControlsWidget( intf_thread_t *_p_i ) :
199 QFrame( NULL ), p_intf( _p_i )
201 QHBoxLayout *layout = new QHBoxLayout( this );
202 layout->setMargin( 0 );
204 slowerButton = new QPushButton( "S" );
205 BUTTON_SET_ACT( slowerButton, "S", qtr("Slower" ), slower() );
206 layout->addWidget( slowerButton );
207 slowerButton->setMaximumWidth( 35 );
209 normalButton = new QPushButton( "N" );
210 BUTTON_SET_ACT( normalButton, "N", qtr("Normal rate"), normal() );
211 layout->addWidget( normalButton );
212 normalButton->setMaximumWidth( 35 );
214 fasterButton = new QPushButton( "F" );
215 BUTTON_SET_ACT( fasterButton, "F", qtr("Faster" ), faster() );
216 layout->addWidget( fasterButton );
217 fasterButton->setMaximumWidth( 35 );
219 layout->addItem( new QSpacerItem( 100,20,
220 QSizePolicy::Expanding, QSizePolicy::Minimum) );
222 snapshotButton = new QPushButton( "S" );
223 BUTTON_SET_ACT( snapshotButton, "S", qtr("Take a snapshot"), snapshot() );
224 layout->addWidget( snapshotButton );
225 snapshotButton->setMaximumWidth( 35 );
227 fullscreenButton = new QPushButton( "F" );
228 BUTTON_SET_ACT( fullscreenButton, "F", qtr("Fullscreen"), fullscreen() );
229 layout->addWidget( fullscreenButton );
230 fullscreenButton->setMaximumWidth( 35 );
233 ControlsWidget::~ControlsWidget()
237 void ControlsWidget::enableInput( bool enable )
239 slowerButton->setEnabled( enable );
240 normalButton->setEnabled( enable );
241 fasterButton->setEnabled( enable );
243 void ControlsWidget::enableVideo( bool enable )
245 snapshotButton->setEnabled( enable );
246 fullscreenButton->setEnabled( enable );
249 void ControlsWidget::slower()
251 THEMIM->getIM()->slower();
254 void ControlsWidget::faster()
256 THEMIM->getIM()->faster();
259 void ControlsWidget::normal()
261 THEMIM->getIM()->normalRate();
264 void ControlsWidget::snapshot()
268 void ControlsWidget::fullscreen()
272 /**********************************************************************
273 * Playlist Widget. The embedded playlist
274 **********************************************************************/
275 #include "components/playlist/panels.hpp"
276 #include "components/playlist/selector.hpp"
278 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) :
279 BasePlaylistWidget ( _p_intf)
281 QVBoxLayout *left = new QVBoxLayout( );
283 selector = new PLSelector( this, p_intf, THEPL );
284 selector->setMaximumWidth( 130 );
285 left->addWidget( selector );
287 art = new QLabel( "" );
288 art->setMinimumHeight( 128 );
289 art->setMinimumWidth( 128 );
290 art->setMaximumHeight( 128 );
291 art->setMaximumWidth( 128 );
292 art->setScaledContents( true );
294 art->setPixmap( QPixmap( ":/noart.png" ) );
295 left->addWidget( art );
297 playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
298 THEPL->p_local_category );
300 rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( this,
301 p_intf, THEPL, p_root ) );
303 CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
305 CONNECT( qobject_cast<StandardPLPanel *>(rightPanel)->model,
306 artSet( QString ) , this, setArt( QString ) );
307 /* Forward removal requests from the selector to the main panel */
308 CONNECT( qobject_cast<PLSelector *>(selector)->model,
310 qobject_cast<StandardPLPanel *>(rightPanel), removeItem(int) );
312 connect( selector, SIGNAL(activated( int )),
313 this, SIGNAL( rootChanged( int ) ) );
314 emit rootChanged( p_root->i_id );
316 QHBoxLayout *layout = new QHBoxLayout(this);
317 layout->addLayout( left, 0 );
318 layout->addWidget( rightPanel, 10 );
322 void PlaylistWidget::setArt( QString url )
325 art->setPixmap( QPixmap( ":/noart.png" ) );
326 else if( prevArt != url )
327 art->setPixmap( QPixmap( url ) );
331 PlaylistWidget::~PlaylistWidget()
335 QSize PlaylistWidget::sizeHint() const