]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
Playlist menu
[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 <QCursor>
34 #include <QPushButton>
35 #include <QHBoxLayout>
36 #include <QMenu>
37
38 #define ICON_SIZE 128
39
40 /**********************************************************************
41  * Video Widget. A simple frame on which video is drawn
42  * This class handles resize issues
43  **********************************************************************/
44 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
45                         unsigned int *, unsigned int * );
46 static void DoRelease( intf_thread_t *, void * );
47 static int DoControl( intf_thread_t *, void *, int, va_list );
48
49 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
50 {
51     vlc_mutex_init( p_intf, &lock );
52     p_vout = NULL;
53
54     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
55 }
56
57 VideoWidget::~VideoWidget()
58 {
59     vlc_mutex_lock( &lock );
60     if( p_vout )
61     {
62         if( !p_intf->psz_switch_intf )
63         {
64             if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
65                 vout_Control( p_vout, VOUT_REPARENT );
66         }
67         else
68         {
69             if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
70                 vout_Control( p_vout, VOUT_CLOSE );
71         }
72     }
73     vlc_mutex_unlock( &lock );
74     vlc_mutex_destroy( &lock );
75 }
76
77 QSize VideoWidget::sizeHint() const
78 {
79     fprintf( stderr, "Video Size %ix%i\n", widgetSize.width(), widgetSize.height() );
80     return widgetSize;
81 }
82
83 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
84                            unsigned int *pi_width, unsigned int *pi_height )
85 {
86     if( p_vout )
87     {
88         msg_Dbg( p_intf, "embedded video already in use" );
89         return NULL;
90     }
91     p_vout = p_nvout;
92     setMinimumSize( 1,1 );
93     return (void*)winId();
94 }
95
96 void VideoWidget::release( void *p_win )
97 {
98     p_vout = NULL;
99 }
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 )
106 {
107
108     setAutoFillBackground( true );
109     plt =  palette();
110     plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
111     plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
112     setPalette( plt );
113
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 );
123 }
124
125 BackgroundWidget::~BackgroundWidget()
126 {
127     backgroundLayout->takeAt(0);
128     delete backgroundLayout;
129 }
130
131 QSize BackgroundWidget::sizeHint() const
132 {
133     fprintf( stderr, "BG %ix%i\n", widgetSize.width(), widgetSize.height() );
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     setLayout( layout );
158     setMaximumHeight( 35 );
159 }
160
161 VisualSelector::~VisualSelector()
162 {
163 }
164
165 /**********************************************************************
166  * Playlist Widget. The embedded playlist
167  **********************************************************************/
168 #include "components/playlist/panels.hpp"
169 #include "components/playlist/selector.hpp"
170
171 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) : QFrame(NULL),
172                                                             p_intf( _p_intf )
173 {
174     QVBoxLayout *left = new QVBoxLayout( );
175     QHBoxLayout *middle = new QHBoxLayout;
176
177     selector = new PLSelector( this, p_intf, THEPL );
178     selector->setMaximumWidth( 130 );
179     left->addWidget( selector );
180
181     QPushButton *undockButton = new QPushButton( "UN", this );
182     undockButton->setMaximumWidth( 25 );
183     undockButton->setToolTip( qtr( "Undock playlist for main interface" ) );
184     BUTTONACT( undockButton, undock() );
185     middle->addWidget( undockButton );
186
187     addButton = new QPushButton( "+", this );
188     addButton->setMaximumWidth( 25 );
189     BUTTONACT( addButton, add() );
190     middle->addWidget( addButton );
191
192     left->addLayout( middle );
193
194     QLabel *art = new QLabel( "" );
195     art->setMaximumHeight( 128 );
196     art->setMaximumWidth( 128 );
197     art->setScaledContents( true );
198     art->setPixmap( QPixmap( art_xpm ) ); //":/vlc128.png" ) );
199     left->addWidget( art );
200
201     playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
202                                                 THEPL->p_local_category );
203     currentRootId = p_root->i_id;
204
205     rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( this,
206                               p_intf, THEPL, p_root ) );
207
208     CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
209     CONNECT( selector, activated( int ), this, setCurrentRootId( int ) );
210
211     QHBoxLayout *layout = new QHBoxLayout(this);
212     layout->addLayout( left, 0 );
213     layout->addWidget( rightPanel, 10 );
214     setLayout( layout );
215 }
216
217 PlaylistWidget::~PlaylistWidget()
218 {
219 }
220
221 void PlaylistWidget::setCurrentRootId( int _new )
222 {
223     currentRootId = _new;
224     if( currentRootId == THEPL->p_local_category->i_id ||
225         currentRootId == THEPL->p_local_onelevel->i_id  )
226     {
227         addButton->setEnabled( true );
228         addButton->setToolTip( qtr("Add to playlist" ) );
229     }
230     else if( currentRootId == THEPL->p_ml_category->i_id ||
231              currentRootId == THEPL->p_ml_onelevel->i_id )
232     {
233         addButton->setEnabled( true );
234         addButton->setToolTip( qtr("Add to media library" ) );
235     }
236     else
237         addButton->setEnabled( false );
238 }
239
240 void PlaylistWidget::undock()
241 {
242     hide();
243     THEDP->playlistDialog();
244     deleteLater();
245
246     QEvent *event = new QEvent( (QEvent::Type)(PLUndockEvent_Type) );
247     QApplication::postEvent( p_intf->p_sys->p_mi, event );
248 }
249
250 void PlaylistWidget::add()
251 {
252     QMenu *popup = new QMenu();
253     if( currentRootId == THEPL->p_local_category->i_id ||
254         currentRootId == THEPL->p_local_onelevel->i_id )
255     {
256         popup->addAction( "Add file", THEDP, SLOT( simplePLAppendDialog() ) );
257         popup->addAction( "Advanced add", THEDP, SLOT( PLAppendDialog() ) );
258     }
259     else if( currentRootId == THEPL->p_ml_category->i_id ||
260              currentRootId == THEPL->p_ml_onelevel->i_id )
261     {
262         popup->addAction( "Add file", THEDP, SLOT( simpleMLAppendDialog() ) );
263         popup->addAction( "Advanced add", THEDP, SLOT( MLAppendDialog() ) );
264         popup->addAction( "Directory", THEDP, SLOT( openMLDirectory() ) );
265     }
266     popup->popup( QCursor::pos() );
267 }
268
269 QSize PlaylistWidget::sizeHint() const
270 {
271     return widgetSize;
272 }
273