]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
Layout for album art
[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 <QPushButton>
34 #include <QHBoxLayout>
35
36 #define ICON_SIZE 128
37
38 /**********************************************************************
39  * Video Widget. A simple frame on which video is drawn
40  * This class handles resize issues
41  **********************************************************************/
42 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
43                         unsigned int *, unsigned int * );
44 static void DoRelease( intf_thread_t *, void * );
45 static int DoControl( intf_thread_t *, void *, int, va_list );
46
47 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
48 {
49     vlc_mutex_init( p_intf, &lock );
50     p_vout = NULL;
51     setFrameStyle(QFrame::Panel | QFrame::Raised);
52
53     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
54 }
55
56 VideoWidget::~VideoWidget()
57 {
58     vlc_mutex_lock( &lock );
59     if( p_vout )
60     {
61         if( !p_intf->psz_switch_intf )
62         {
63             if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
64                 vout_Control( p_vout, VOUT_REPARENT );
65         }
66         else
67         {
68             if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
69                 vout_Control( p_vout, VOUT_CLOSE );
70         }
71     }
72     vlc_mutex_unlock( &lock );
73     vlc_mutex_destroy( &lock );
74 }
75
76 QSize VideoWidget::sizeHint() const
77 {
78     fprintf( stderr, "Video Size %ix%i\n", widgetSize.width(), widgetSize.height() );
79     return widgetSize;
80 }
81
82 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
83                            unsigned int *pi_width, unsigned int *pi_height )
84 {
85     if( p_vout )
86     {
87         msg_Dbg( p_intf, "embedded video already in use" );
88         return NULL;
89     }
90     p_vout = p_nvout;
91     setMinimumSize( 1,1 );
92     return (void*)winId();
93 }
94
95 void VideoWidget::release( void *p_win )
96 {
97     p_vout = NULL;
98 }
99 /**********************************************************************
100  * Background Widget. Show a simple image background. Currently,
101  * it's a static cone.
102  **********************************************************************/
103 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
104                                         QFrame( NULL ), p_intf( _p_i )
105 {
106     setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
107     DrawBackground();
108 }
109
110 BackgroundWidget::~BackgroundWidget()
111 {
112     CleanBackground();
113 }
114
115 int BackgroundWidget::DrawBackground()
116 {
117    setAutoFillBackground( true );
118     plt =  palette();
119     plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
120     plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
121     setPalette( plt );
122
123     backgroundLayout = new QHBoxLayout;
124     label = new QLabel( "" );
125     label->setMaximumHeight( ICON_SIZE );
126     label->setMaximumWidth( ICON_SIZE );
127     label->setScaledContents( true );
128     label->setPixmap( QPixmap( ":/vlc128.png" ) );
129     backgroundLayout = new QHBoxLayout;
130     backgroundLayout->addWidget( label );
131     setLayout( backgroundLayout );
132     return 0;
133 }
134
135 int BackgroundWidget::CleanBackground()
136 {
137     backgroundLayout->takeAt(0);
138     delete backgroundLayout;
139     return 0;
140 }
141
142 QSize BackgroundWidget::sizeHint() const
143 {
144     fprintf( stderr, "BG %ix%i\n", widgetSize.width(), widgetSize.height() );
145     return widgetSize;
146 }
147
148 void BackgroundWidget::resizeEvent( QResizeEvent *e )
149 {
150     if( e->size().height() < ICON_SIZE -1 )
151         label->setMaximumWidth( e->size().height() );
152     else
153         label->setMaximumWidth( ICON_SIZE );
154 }
155
156 /**********************************************************************
157  * Playlist Widget. The embedded playlist
158  **********************************************************************/
159 #include "components/playlist/panels.hpp"
160 #include "components/playlist/selector.hpp"
161
162 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) : QFrame(NULL),
163                                                             p_intf( _p_intf )
164 {
165     QVBoxLayout *left = new QVBoxLayout( );
166     QHBoxLayout *middle = new QHBoxLayout;
167
168     setFrameStyle(QFrame::StyledPanel | QFrame::Sunken );
169     selector = new PLSelector( this, p_intf, THEPL );
170     selector->setMaximumWidth( 130 );
171     left->addWidget( selector );
172
173     QPushButton *undockButton = new QPushButton( "UN", this );
174     undockButton->setMaximumWidth( 25 );
175     undockButton->setToolTip( qtr( "Undock playlist for main interface" ) );
176     QPushButton *sourcesButton = new QPushButton( "Sources", this );
177     sourcesButton->setToolTip( qtr( "Select additional stream sources" ) );
178     middle->addWidget( undockButton );
179     middle->addWidget( sourcesButton );
180     left->addLayout( middle );
181
182     QLabel *art = new QLabel( "" );
183     art->setMaximumHeight( 128 );
184     art->setMaximumWidth( 128 );
185     art->setScaledContents( true );
186     art->setPixmap( QPixmap( art_xpm ) ); //":/vlc128.png" ) );
187     left->addWidget( art );
188
189     playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
190                                                 THEPL->p_local_category );
191
192     rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( this,
193                               p_intf, THEPL, p_root ) );
194
195     CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
196
197     QHBoxLayout *layout = new QHBoxLayout(this);
198     layout->addLayout( left, 0 );
199     layout->addWidget( rightPanel, 10 );
200     setLayout( layout );
201 }
202
203 PlaylistWidget::~PlaylistWidget()
204 {
205 }
206
207 QSize PlaylistWidget::sizeHint() const
208 {
209     fprintf( stderr, "PL Size %ix%i\n", widgetSize.width(), widgetSize.height() );
210     return widgetSize;
211 }
212