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