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"
30 #include "pixmaps/art.xpm"
34 #include <QSpacerItem>
36 #include <QPushButton>
37 #include <QHBoxLayout>
42 /**********************************************************************
43 * Video Widget. A simple frame on which video is drawn
44 * This class handles resize issues
45 **********************************************************************/
46 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
47 unsigned int *, unsigned int * );
48 static void DoRelease( intf_thread_t *, void * );
49 static int DoControl( intf_thread_t *, void *, int, va_list );
51 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
53 vlc_mutex_init( p_intf, &lock );
56 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
59 VideoWidget::~VideoWidget()
61 vlc_mutex_lock( &lock );
64 if( !p_intf->psz_switch_intf )
66 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
67 vout_Control( p_vout, VOUT_REPARENT );
71 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
72 vout_Control( p_vout, VOUT_CLOSE );
75 vlc_mutex_unlock( &lock );
76 vlc_mutex_destroy( &lock );
79 QSize VideoWidget::sizeHint() const
81 fprintf( stderr, "Video Size %ix%i\n", widgetSize.width(), widgetSize.height() );
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( 1,1 );
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
135 fprintf( stderr, "BG %ix%i\n", widgetSize.width(), widgetSize.height() );
139 void BackgroundWidget::resizeEvent( QResizeEvent *e )
141 if( e->size().height() < ICON_SIZE -1 )
142 label->setMaximumWidth( e->size().height() );
144 label->setMaximumWidth( ICON_SIZE );
147 /**********************************************************************
148 * Visualization selector panel
149 **********************************************************************/
150 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
151 QFrame( NULL ), p_intf( _p_i )
153 QHBoxLayout *layout = new QHBoxLayout( this );
154 layout->setMargin( 0 );
155 QPushButton *prevButton = new QPushButton( "Prev" );
156 QPushButton *nextButton = new QPushButton( "Next");
157 layout->addWidget( prevButton );
158 layout->addWidget( nextButton );
160 layout->addItem( new QSpacerItem( 40,20,
161 QSizePolicy::Expanding, QSizePolicy::Minimum) );
162 layout->addWidget( new QLabel( qtr("Current visualization:") ) );
164 current = new QLabel( qtr( "None" ) );
165 layout->addWidget( current );
167 BUTTONACT( prevButton, prev() );
168 BUTTONACT( nextButton, next() );
171 setMaximumHeight( 35 );
174 VisualSelector::~VisualSelector()
178 void VisualSelector::prev()
180 char *psz_new = aout_VisualPrev( p_intf );
183 current->setText( qfu( psz_new ) );
188 void VisualSelector::next()
190 char *psz_new = aout_VisualNext( p_intf );
193 current->setText( qfu( psz_new ) );
198 /**********************************************************************
200 **********************************************************************/
201 ControlsWidget::ControlsWidget( intf_thread_t *_p_i ) :
202 QFrame( NULL ), p_intf( _p_i )
204 QHBoxLayout *layout = new QHBoxLayout( this );
205 layout->setMargin( 0 );
207 slowerButton = new QPushButton( "S" );
208 BUTTON_SET_ACT( slowerButton, "S", qtr("Slower" ), slower() );
209 layout->addWidget( slowerButton );
210 slowerButton->setMaximumWidth( 35 );
212 normalButton = new QPushButton( "N" );
213 BUTTON_SET_ACT( normalButton, "N", qtr("Normal rate"), normal() );
214 layout->addWidget( normalButton );
215 normalButton->setMaximumWidth( 35 );
217 fasterButton = new QPushButton( "F" );
218 BUTTON_SET_ACT( fasterButton, "F", qtr("Faster" ), faster() );
219 layout->addWidget( fasterButton );
220 fasterButton->setMaximumWidth( 35 );
222 layout->addItem( new QSpacerItem( 100,20,
223 QSizePolicy::Expanding, QSizePolicy::Minimum) );
225 snapshotButton = new QPushButton( "S" );
226 BUTTON_SET_ACT( snapshotButton, "S", qtr("Take a snapshot"), snapshot() );
227 layout->addWidget( snapshotButton );
228 snapshotButton->setMaximumWidth( 35 );
230 fullscreenButton = new QPushButton( "F" );
231 BUTTON_SET_ACT( fullscreenButton, "F", qtr("Fullscreen"), fullscreen() );
232 layout->addWidget( fullscreenButton );
233 fullscreenButton->setMaximumWidth( 35 );
236 ControlsWidget::~ControlsWidget()
240 void ControlsWidget::enableInput( bool enable )
242 slowerButton->setEnabled( enable );
243 normalButton->setEnabled( enable );
244 fasterButton->setEnabled( enable );
246 void ControlsWidget::enableVideo( bool enable )
248 snapshotButton->setEnabled( enable );
249 fullscreenButton->setEnabled( enable );
252 void ControlsWidget::slower()
254 THEMIM->getIM()->slower();
257 void ControlsWidget::faster()
259 THEMIM->getIM()->faster();
262 void ControlsWidget::normal()
264 THEMIM->getIM()->normalRate();
267 void ControlsWidget::snapshot()
271 void ControlsWidget::fullscreen()
275 /**********************************************************************
276 * Playlist Widget. The embedded playlist
277 **********************************************************************/
278 #include "components/playlist/panels.hpp"
279 #include "components/playlist/selector.hpp"
281 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) :
282 BasePlaylistWidget ( _p_intf)
284 QVBoxLayout *left = new QVBoxLayout( );
286 selector = new PLSelector( this, p_intf, THEPL );
287 selector->setMaximumWidth( 130 );
288 left->addWidget( selector );
290 art = new QLabel( "" );
291 art->setMaximumHeight( 128 );
292 art->setMaximumWidth( 128 );
293 art->setScaledContents( true );
294 art->setPixmap( QPixmap( art_xpm ) ); //":/vlc128.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, artSet( QString ) , this, setArt( QString ) );
307 connect( selector, SIGNAL(activated( int )),
308 this, SIGNAL( rootChanged( int ) ) );
309 emit rootChanged( p_root->i_id );
311 QHBoxLayout *layout = new QHBoxLayout(this);
312 layout->addLayout( left, 0 );
313 layout->addWidget( rightPanel, 10 );
317 void PlaylistWidget::setArt( QString url )
321 fprintf( stderr, "Display %s\n", qta( url ) );
322 art->setPixmap( QPixmap( url ) );
327 PlaylistWidget::~PlaylistWidget()
331 QSize PlaylistWidget::sizeHint() const