]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
qt4 : QT4 album art in allways-video.
[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 <vlc_vout.h>
31
32 #include <QLabel>
33 #include <QSpacerItem>
34 #include <QCursor>
35 #include <QPushButton>
36 #include <QHBoxLayout>
37 #include <QMenu>
38 #include <QPalette>
39 #include <QResizeEvent>
40
41 #define ICON_SIZE 300
42
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 );
51
52 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
53 {
54     vlc_mutex_init( p_intf, &lock );
55     p_vout = NULL;
56
57     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
58 }
59
60 VideoWidget::~VideoWidget()
61 {
62     vlc_mutex_lock( &lock );
63     if( p_vout )
64     {
65         if( !p_intf->psz_switch_intf )
66         {
67             if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
68                 vout_Control( p_vout, VOUT_REPARENT );
69         }
70         else
71         {
72             if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
73                 vout_Control( p_vout, VOUT_CLOSE );
74         }
75     }
76     vlc_mutex_unlock( &lock );
77     vlc_mutex_destroy( &lock );
78 }
79
80 QSize VideoWidget::sizeHint() const
81 {
82     return widgetSize;
83 }
84
85 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
86                            unsigned int *pi_width, unsigned int *pi_height )
87 {
88     if( p_vout )
89     {
90         msg_Dbg( p_intf, "embedded video already in use" );
91         return NULL;
92     }
93     p_vout = p_nvout;
94     setMinimumSize( 16, 16 );
95     return (void*)winId();
96 }
97
98 void VideoWidget::release( void *p_win )
99 {
100     p_vout = NULL;
101 }
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 )
108 {
109
110     setAutoFillBackground( true );
111     plt =  palette();
112     plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
113     plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
114     setPalette( plt );
115
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 void BackgroundWidget::setArt( QString url )
133 {
134     if( url.isNull() )
135         label->setPixmap( QPixmap( ":/vlc128.png" ) );
136     else
137         label->setPixmap( QPixmap( url ) );
138 }
139
140 QSize BackgroundWidget::sizeHint() const
141 {
142     return widgetSize;
143 }
144
145 void BackgroundWidget::resizeEvent( QResizeEvent *e )
146 {
147     if( e->size().height() < ICON_SIZE -1 )
148         label->setMaximumWidth( e->size().height() );
149     else
150         label->setMaximumWidth( ICON_SIZE );
151 }
152
153 /**********************************************************************
154  * Visualization selector panel
155  **********************************************************************/
156 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
157                                                 QFrame( NULL ), p_intf( _p_i )
158 {
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 );
165
166     layout->addItem( new QSpacerItem( 40,20,
167                               QSizePolicy::Expanding, QSizePolicy::Minimum) );
168     layout->addWidget( new QLabel( qtr("Current visualization:") ) );
169
170     current = new QLabel( qtr( "None" ) );
171     layout->addWidget( current );
172
173     BUTTONACT( prevButton, prev() );
174     BUTTONACT( nextButton, next() );
175
176     setLayout( layout );
177     setMaximumHeight( 35 );
178 }
179
180 VisualSelector::~VisualSelector()
181 {
182 }
183
184 void VisualSelector::prev()
185 {
186     char *psz_new = aout_VisualPrev( p_intf );
187     if( psz_new )
188     {
189         current->setText( qfu( psz_new ) );
190         free( psz_new );
191     }
192 }
193
194 void VisualSelector::next()
195 {
196     char *psz_new = aout_VisualNext( p_intf );
197     if( psz_new )
198     {
199         current->setText( qfu( psz_new ) );
200         free( psz_new );
201     }
202 }
203
204 /**********************************************************************
205  * More controls
206  **********************************************************************/
207 ControlsWidget::ControlsWidget( intf_thread_t *_p_i ) :
208                                            QFrame( NULL ), p_intf( _p_i )
209 {
210     QHBoxLayout *layout = new QHBoxLayout( this );
211     layout->setMargin( 0 );
212
213     slowerButton = new QPushButton( "S" );
214     BUTTON_SET_ACT( slowerButton, "S", qtr("Slower" ), slower() );
215     layout->addWidget( slowerButton );
216     slowerButton->setMaximumWidth( 35 );
217
218     normalButton = new QPushButton( "N" );
219     BUTTON_SET_ACT( normalButton, "N", qtr("Normal rate"), normal() );
220     layout->addWidget( normalButton );
221     normalButton->setMaximumWidth( 35 );
222
223     fasterButton = new QPushButton( "F" );
224     BUTTON_SET_ACT( fasterButton, "F", qtr("Faster" ), faster() );
225     layout->addWidget( fasterButton );
226     fasterButton->setMaximumWidth( 35 );
227
228     layout->addItem( new QSpacerItem( 100,20,
229                               QSizePolicy::Expanding, QSizePolicy::Minimum) );
230
231     snapshotButton = new QPushButton( "S" );
232     BUTTON_SET_ACT( snapshotButton, "S", qtr("Take a snapshot"), snapshot() );
233     layout->addWidget( snapshotButton );
234     snapshotButton->setMaximumWidth( 35 );
235
236     fullscreenButton = new QPushButton( "F" );
237     BUTTON_SET_ACT( fullscreenButton, "F", qtr("Fullscreen"), fullscreen() );
238     layout->addWidget( fullscreenButton );
239     fullscreenButton->setMaximumWidth( 35 );
240 }
241
242 ControlsWidget::~ControlsWidget()
243 {
244 }
245
246 void ControlsWidget::enableInput( bool enable )
247 {
248     slowerButton->setEnabled( enable );
249     normalButton->setEnabled( enable );
250     fasterButton->setEnabled( enable );
251 }
252 void ControlsWidget::enableVideo( bool enable )
253 {
254     snapshotButton->setEnabled( enable );
255     fullscreenButton->setEnabled( enable );
256 }
257
258 void ControlsWidget::slower()
259 {
260     THEMIM->getIM()->slower();
261 }
262
263 void ControlsWidget::faster()
264 {
265     THEMIM->getIM()->faster();
266 }
267
268 void ControlsWidget::normal()
269 {
270     THEMIM->getIM()->normalRate();
271 }
272
273 void ControlsWidget::snapshot()
274 {
275 }
276
277 void ControlsWidget::fullscreen()
278 {
279 }
280
281 /**********************************************************************
282  * Playlist Widget. The embedded playlist
283  **********************************************************************/
284 #include "components/playlist/panels.hpp"
285 #include "components/playlist/selector.hpp"
286
287 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) :
288                                 p_intf ( _p_intf)
289 {
290     /* Left Part and design */
291     QWidget *leftW = new QWidget( this );
292     QVBoxLayout *left = new QVBoxLayout( leftW );
293
294     /* Source Selector */
295     selector = new PLSelector( this, p_intf, THEPL );
296     left->addWidget( selector );
297
298     /* Art label */
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 );
307
308     /* Initialisation of the playlist */
309     playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
310                                                 THEPL->p_local_category );
311
312     rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( this,
313                               p_intf, THEPL, p_root ) );
314
315     /* Connects */
316     CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
317
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,
322              shouldRemove( int ),
323              qobject_cast<StandardPLPanel *>(rightPanel), removeItem(int) );
324
325     connect( selector, SIGNAL(activated( int )),
326              this, SIGNAL( rootChanged( int ) ) );
327     emit rootChanged( p_root->i_id );
328
329     /* Add the two sides of the QSplitter */
330     addWidget( leftW );
331     addWidget( rightPanel );
332
333     leftW->setMaximumWidth( 250 );
334     setCollapsible( 1, false );
335
336     QList<int> sizeList;
337     sizeList << 180 << 520 ;
338     setSizes( sizeList );
339 }
340
341 void PlaylistWidget::setArt( QString url )
342 {
343     if( url.isNull() )
344         art->setPixmap( QPixmap( ":/noart.png" ) );
345     else if( prevArt != url )
346         art->setPixmap( QPixmap( url ) );
347     prevArt = url;
348     emit artSet( url );
349 }
350
351 PlaylistWidget::~PlaylistWidget()
352 {
353 }
354
355 QSize PlaylistWidget::sizeHint() const
356 {
357     return widgetSize;
358 }
359