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
84 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
85 unsigned int *pi_width, unsigned int *pi_height )
89 msg_Dbg( p_intf, "embedded video already in use" );
93 setMinimumSize( 1,1 );
94 return (void*)winId();
97 void VideoWidget::release( void *p_win )
101 /**********************************************************************
102 * Background Widget. Show a simple image background. Currently,
103 * it's a static cone.
104 **********************************************************************/
105 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
106 QFrame( NULL ), p_intf( _p_i )
109 setAutoFillBackground( true );
111 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
112 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
115 backgroundLayout = new QHBoxLayout;
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 QSize BackgroundWidget::sizeHint() const
137 void BackgroundWidget::resizeEvent( QResizeEvent *e )
139 if( e->size().height() < ICON_SIZE -1 )
140 label->setMaximumWidth( e->size().height() );
142 label->setMaximumWidth( ICON_SIZE );
145 /**********************************************************************
146 * Visualization selector panel
147 **********************************************************************/
148 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
149 QFrame( NULL ), p_intf( _p_i )
151 QHBoxLayout *layout = new QHBoxLayout( this );
152 layout->setMargin( 0 );
153 QPushButton *prevButton = new QPushButton( "Prev" );
154 QPushButton *nextButton = new QPushButton( "Next");
155 layout->addWidget( prevButton );
156 layout->addWidget( nextButton );
158 layout->addItem( new QSpacerItem( 40,20,
159 QSizePolicy::Expanding, QSizePolicy::Minimum) );
160 layout->addWidget( new QLabel( qtr("Current visualization:") ) );
162 current = new QLabel( qtr( "None" ) );
163 layout->addWidget( current );
165 BUTTONACT( prevButton, prev() );
166 BUTTONACT( nextButton, next() );
169 setMaximumHeight( 35 );
172 VisualSelector::~VisualSelector()
176 void VisualSelector::prev()
178 char *psz_new = aout_VisualPrev( p_intf );
181 current->setText( qfu( psz_new ) );
186 void VisualSelector::next()
188 char *psz_new = aout_VisualNext( p_intf );
191 current->setText( qfu( psz_new ) );
196 /**********************************************************************
198 **********************************************************************/
199 ControlsWidget::ControlsWidget( intf_thread_t *_p_i ) :
200 QFrame( NULL ), p_intf( _p_i )
202 QHBoxLayout *layout = new QHBoxLayout( this );
203 layout->setMargin( 0 );
205 slowerButton = new QPushButton( "S" );
206 BUTTON_SET_ACT( slowerButton, "S", qtr("Slower" ), slower() );
207 layout->addWidget( slowerButton );
208 slowerButton->setMaximumWidth( 35 );
210 normalButton = new QPushButton( "N" );
211 BUTTON_SET_ACT( normalButton, "N", qtr("Normal rate"), normal() );
212 layout->addWidget( normalButton );
213 normalButton->setMaximumWidth( 35 );
215 fasterButton = new QPushButton( "F" );
216 BUTTON_SET_ACT( fasterButton, "F", qtr("Faster" ), faster() );
217 layout->addWidget( fasterButton );
218 fasterButton->setMaximumWidth( 35 );
220 layout->addItem( new QSpacerItem( 100,20,
221 QSizePolicy::Expanding, QSizePolicy::Minimum) );
223 snapshotButton = new QPushButton( "S" );
224 BUTTON_SET_ACT( snapshotButton, "S", qtr("Take a snapshot"), snapshot() );
225 layout->addWidget( snapshotButton );
226 snapshotButton->setMaximumWidth( 35 );
228 fullscreenButton = new QPushButton( "F" );
229 BUTTON_SET_ACT( fullscreenButton, "F", qtr("Fullscreen"), fullscreen() );
230 layout->addWidget( fullscreenButton );
231 fullscreenButton->setMaximumWidth( 35 );
234 ControlsWidget::~ControlsWidget()
238 void ControlsWidget::enableInput( bool enable )
240 slowerButton->setEnabled( enable );
241 normalButton->setEnabled( enable );
242 fasterButton->setEnabled( enable );
244 void ControlsWidget::enableVideo( bool enable )
246 snapshotButton->setEnabled( enable );
247 fullscreenButton->setEnabled( enable );
250 void ControlsWidget::slower()
252 THEMIM->getIM()->slower();
255 void ControlsWidget::faster()
257 THEMIM->getIM()->faster();
260 void ControlsWidget::normal()
262 THEMIM->getIM()->normalRate();
265 void ControlsWidget::snapshot()
269 void ControlsWidget::fullscreen()
273 /**********************************************************************
274 * Playlist Widget. The embedded playlist
275 **********************************************************************/
276 #include "components/playlist/panels.hpp"
277 #include "components/playlist/selector.hpp"
279 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) :
280 BasePlaylistWidget ( _p_intf)
282 QVBoxLayout *left = new QVBoxLayout( );
284 selector = new PLSelector( this, p_intf, THEPL );
285 selector->setMaximumWidth( 130 );
286 left->addWidget( selector );
288 art = new QLabel( "" );
289 art->setMaximumHeight( 128 );
290 art->setMaximumWidth( 128 );
291 art->setScaledContents( true );
292 art->setPixmap( QPixmap( art_xpm ) ); //":/vlc128.png" ) );
293 left->addWidget( art );
295 playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
296 THEPL->p_local_category );
298 rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( this,
299 p_intf, THEPL, p_root ) );
301 CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
303 CONNECT( qobject_cast<StandardPLPanel *>(rightPanel)->model, artSet( QString ) , this, setArt( QString ) );
305 connect( selector, SIGNAL(activated( int )),
306 this, SIGNAL( rootChanged( int ) ) );
307 emit rootChanged( p_root->i_id );
309 QHBoxLayout *layout = new QHBoxLayout(this);
310 layout->addLayout( left, 0 );
311 layout->addWidget( rightPanel, 10 );
315 void PlaylistWidget::setArt( QString url )
319 art->setPixmap( QPixmap( url ) );
324 PlaylistWidget::~PlaylistWidget()
328 QSize PlaylistWidget::sizeHint() const