]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
Some size fixes
[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
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     setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
152     QHBoxLayout *layout = new QHBoxLayout( this );
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( 30 );
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     setFrameStyle(QFrame::StyledPanel | QFrame::Sunken );
178     selector = new PLSelector( this, p_intf, THEPL );
179     selector->setMaximumWidth( 130 );
180     left->addWidget( selector );
181
182     QPushButton *undockButton = new QPushButton( "UN", this );
183     undockButton->setMaximumWidth( 25 );
184     undockButton->setToolTip( qtr( "Undock playlist for main interface" ) );
185     QPushButton *sourcesButton = new QPushButton( "Sources", this );
186     sourcesButton->setToolTip( qtr( "Select additional stream sources" ) );
187     middle->addWidget( undockButton );
188     middle->addWidget( sourcesButton );
189     left->addLayout( middle );
190
191     QLabel *art = new QLabel( "" );
192     art->setMaximumHeight( 128 );
193     art->setMaximumWidth( 128 );
194     art->setScaledContents( true );
195     art->setPixmap( QPixmap( art_xpm ) ); //":/vlc128.png" ) );
196     left->addWidget( art );
197
198     playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
199                                                 THEPL->p_local_category );
200
201     rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( this,
202                               p_intf, THEPL, p_root ) );
203
204     CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
205
206     QHBoxLayout *layout = new QHBoxLayout(this);
207     layout->addLayout( left, 0 );
208     layout->addWidget( rightPanel, 10 );
209     setLayout( layout );
210 }
211
212 PlaylistWidget::~PlaylistWidget()
213 {
214 }
215
216 QSize PlaylistWidget::sizeHint() const
217 {
218     fprintf( stderr, "PL Size %ix%i\n", widgetSize.width(), widgetSize.height() );
219     return widgetSize;
220 }
221