]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
3607bcf0d1a6d95c827f5c399e5e8be3212618ed
[vlc] / modules / gui / qt4 / components / interface_widgets.cpp
1 /*****************************************************************************
2  * interface_widgets.cpp : Custom widgets for the main interface
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #include "dialogs_provider.hpp"
25 #include "qt4.hpp"
26 #include "components/interface_widgets.hpp"
27 #include "main_interface.hpp"
28 #include "input_manager.hpp"
29
30 #include "pixmaps/art.xpm"
31 #include <vlc/vout.h>
32
33 #include <QLabel>
34 #include <QSpacerItem>
35 #include <QCursor>
36 #include <QPushButton>
37 #include <QHBoxLayout>
38 #include <QMenu>
39
40 #define ICON_SIZE 128
41
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 );
50
51 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
52 {
53     vlc_mutex_init( p_intf, &lock );
54     p_vout = NULL;
55
56     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
57 }
58
59 VideoWidget::~VideoWidget()
60 {
61     vlc_mutex_lock( &lock );
62     if( p_vout )
63     {
64         if( !p_intf->psz_switch_intf )
65         {
66             if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
67                 vout_Control( p_vout, VOUT_REPARENT );
68         }
69         else
70         {
71             if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
72                 vout_Control( p_vout, VOUT_CLOSE );
73         }
74     }
75     vlc_mutex_unlock( &lock );
76     vlc_mutex_destroy( &lock );
77 }
78
79 QSize VideoWidget::sizeHint() const
80 {
81     return widgetSize;
82 }
83
84 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
85                            unsigned int *pi_width, unsigned int *pi_height )
86 {
87     if( p_vout )
88     {
89         msg_Dbg( p_intf, "embedded video already in use" );
90         return NULL;
91     }
92     p_vout = p_nvout;
93     setMinimumSize( 1,1 );
94     return (void*)winId();
95 }
96
97 void VideoWidget::release( void *p_win )
98 {
99     p_vout = NULL;
100 }
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 )
107 {
108
109     setAutoFillBackground( true );
110     plt =  palette();
111     plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
112     plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
113     setPalette( plt );
114
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 );
124 }
125
126 BackgroundWidget::~BackgroundWidget()
127 {
128     backgroundLayout->takeAt(0);
129     delete backgroundLayout;
130 }
131
132 QSize BackgroundWidget::sizeHint() const
133 {
134     return widgetSize;
135 }
136
137 void BackgroundWidget::resizeEvent( QResizeEvent *e )
138 {
139     if( e->size().height() < ICON_SIZE -1 )
140         label->setMaximumWidth( e->size().height() );
141     else
142         label->setMaximumWidth( ICON_SIZE );
143 }
144
145 /**********************************************************************
146  * Visualization selector panel
147  **********************************************************************/
148 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
149                                                 QFrame( NULL ), p_intf( _p_i )
150 {
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 );
157
158     layout->addItem( new QSpacerItem( 40,20,
159                               QSizePolicy::Expanding, QSizePolicy::Minimum) );
160     layout->addWidget( new QLabel( qtr("Current visualization:") ) );
161
162     current = new QLabel( qtr( "None" ) );
163     layout->addWidget( current );
164
165     BUTTONACT( prevButton, prev() );
166     BUTTONACT( nextButton, next() );
167
168     setLayout( layout );
169     setMaximumHeight( 35 );
170 }
171
172 VisualSelector::~VisualSelector()
173 {
174 }
175
176 void VisualSelector::prev()
177 {
178     char *psz_new = aout_VisualPrev( p_intf );
179     if( psz_new )
180     {
181         current->setText( qfu( psz_new ) );
182         free( psz_new );
183     }
184 }
185
186 void VisualSelector::next()
187 {
188     char *psz_new = aout_VisualNext( p_intf );
189     if( psz_new )
190     {
191         current->setText( qfu( psz_new ) );
192         free( psz_new );
193     }
194 }
195
196 /**********************************************************************
197  * More controls
198  **********************************************************************/
199 ControlsWidget::ControlsWidget( intf_thread_t *_p_i ) :
200                                            QFrame( NULL ), p_intf( _p_i )
201 {
202     QHBoxLayout *layout = new QHBoxLayout( this );
203     layout->setMargin( 0 );
204
205     slowerButton = new QPushButton( "S" );
206     BUTTON_SET_ACT( slowerButton, "S", qtr("Slower" ), slower() );
207     layout->addWidget( slowerButton );
208     slowerButton->setMaximumWidth( 35 );
209
210     normalButton = new QPushButton( "N" );
211     BUTTON_SET_ACT( normalButton, "N", qtr("Normal rate"), normal() );
212     layout->addWidget( normalButton );
213     normalButton->setMaximumWidth( 35 );
214
215     fasterButton = new QPushButton( "F" );
216     BUTTON_SET_ACT( fasterButton, "F", qtr("Faster" ), faster() );
217     layout->addWidget( fasterButton );
218     fasterButton->setMaximumWidth( 35 );
219
220     layout->addItem( new QSpacerItem( 100,20,
221                               QSizePolicy::Expanding, QSizePolicy::Minimum) );
222
223     snapshotButton = new QPushButton( "S" );
224     BUTTON_SET_ACT( snapshotButton, "S", qtr("Take a snapshot"), snapshot() );
225     layout->addWidget( snapshotButton );
226     snapshotButton->setMaximumWidth( 35 );
227
228     fullscreenButton = new QPushButton( "F" );
229     BUTTON_SET_ACT( fullscreenButton, "F", qtr("Fullscreen"), fullscreen() );
230     layout->addWidget( fullscreenButton );
231     fullscreenButton->setMaximumWidth( 35 );
232 }
233
234 ControlsWidget::~ControlsWidget()
235 {
236 }
237
238 void ControlsWidget::enableInput( bool enable )
239 {
240     slowerButton->setEnabled( enable );
241     normalButton->setEnabled( enable );
242     fasterButton->setEnabled( enable );
243 }
244 void ControlsWidget::enableVideo( bool enable )
245 {
246     snapshotButton->setEnabled( enable );
247     fullscreenButton->setEnabled( enable );
248 }
249
250 void ControlsWidget::slower()
251 {
252     THEMIM->getIM()->slower();
253 }
254
255 void ControlsWidget::faster()
256 {
257     THEMIM->getIM()->faster();
258 }
259
260 void ControlsWidget::normal()
261 {
262     THEMIM->getIM()->normalRate();
263 }
264
265 void ControlsWidget::snapshot()
266 {
267 }
268
269 void ControlsWidget::fullscreen()
270 {
271 }
272
273 /**********************************************************************
274  * Playlist Widget. The embedded playlist
275  **********************************************************************/
276 #include "components/playlist/panels.hpp"
277 #include "components/playlist/selector.hpp"
278
279 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) :
280                                 BasePlaylistWidget ( _p_intf)
281 {
282     QVBoxLayout *left = new QVBoxLayout( );
283
284     selector = new PLSelector( this, p_intf, THEPL );
285     selector->setMaximumWidth( 130 );
286     left->addWidget( selector );
287
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 );
294
295     playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
296                                                 THEPL->p_local_category );
297
298     rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( this,
299                               p_intf, THEPL, p_root ) );
300
301     CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
302
303     CONNECT( qobject_cast<StandardPLPanel *>(rightPanel)->model, artSet( QString ) , this, setArt( QString ) );
304
305     connect( selector, SIGNAL(activated( int )),
306              this, SIGNAL( rootChanged( int ) ) );
307     emit rootChanged( p_root->i_id );
308
309     QHBoxLayout *layout = new QHBoxLayout(this);
310     layout->addLayout( left, 0 );
311     layout->addWidget( rightPanel, 10 );
312     setLayout( layout );
313 }
314
315 void PlaylistWidget::setArt( QString url )
316 {
317     if( prevArt != url )
318     {
319         art->setPixmap( QPixmap( url ) );
320         prevArt = url;
321     }
322 }
323
324 PlaylistWidget::~PlaylistWidget()
325 {
326 }
327
328 QSize PlaylistWidget::sizeHint() const
329 {
330     return widgetSize;
331 }
332