]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/video_widget.cpp
Icons support
[vlc] / modules / gui / qt4 / components / video_widget.cpp
1 /*****************************************************************************
2  * video_widget.cpp : Embedded video output
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 <vlc/vout.h>
26 #include "qt4.hpp"
27 #include "components/video_widget.hpp"
28 #include "main_interface.hpp"
29
30 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
31                         unsigned int *, unsigned int * );
32 static void DoRelease( intf_thread_t *, void * );
33 static int DoControl( intf_thread_t *, void *, int, va_list );
34
35 bool need_update;
36        
37 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ),
38                                                               p_intf( _p_i )
39 {
40     vlc_mutex_init( p_intf, &lock );
41
42     p_intf->pf_request_window  = ::DoRequest;
43     p_intf->pf_release_window  = ::DoRelease;
44     p_intf->pf_control_window  = ::DoControl;
45     p_intf->p_sys->p_video = this;
46     p_vout = NULL;
47
48     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
49
50     connect( DialogsProvider::getInstance(NULL)->fixed_timer,
51              SIGNAL( timeout() ), this, SLOT( update() ) );
52
53     need_update = false;
54 }
55
56 void VideoWidget::update()
57 {
58     if( need_update )
59     {
60         p_intf->p_sys->p_mi->resize( p_intf->p_sys->p_mi->sizeHint() );
61         need_update = false;
62     }
63 }
64
65 VideoWidget::~VideoWidget()
66 {
67     vlc_mutex_lock( &lock );
68     if( p_vout )
69     {
70         if( !p_intf->psz_switch_intf )
71         {
72             if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
73                 vout_Control( p_vout, VOUT_REPARENT );
74         }
75         else
76         {
77             if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
78                 vout_Control( p_vout, VOUT_CLOSE );
79         }
80     }
81     p_intf->pf_request_window = NULL;
82     p_intf->pf_release_window = NULL;
83     p_intf->pf_control_window = NULL;
84     vlc_mutex_unlock( &lock );
85     vlc_mutex_destroy( &lock );
86 }
87
88 QSize VideoWidget::sizeHint() const
89 {
90     return p_intf->p_sys->p_mi->videoSize;
91 }
92
93 static void *DoRequest( intf_thread_t *p_intf, vout_thread_t *p_vout,
94                         int *pi1, int *pi2, unsigned int*pi3,unsigned int*pi4)
95 {
96     return p_intf->p_sys->p_video->Request( p_vout, pi1, pi2, pi3, pi4 );
97 }
98
99 void *VideoWidget::Request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
100                            unsigned int *pi_width, unsigned int *pi_height )
101 {
102     if( p_vout )
103     {
104         msg_Dbg( p_intf, "embedded video already in use" );
105         return NULL;
106     }
107     p_vout = p_nvout;
108
109     setMinimumSize( 1,1 );
110     p_intf->p_sys->p_mi->videoSize = QSize( *pi_width, *pi_height );
111     updateGeometry();
112     need_update = true;
113     return  (void*)winId();
114 }
115
116 static void DoRelease( intf_thread_t *p_intf, void *p_win )
117 {
118     return p_intf->p_sys->p_video->Release( p_win );
119 }
120
121 void VideoWidget::Release( void *p_win )
122 {
123     if( !config_GetInt( p_intf, "qt-always-video" ) );
124     {
125         p_intf->p_sys->p_mi->videoSize = QSize ( 1,1 );
126     }
127
128     updateGeometry();
129
130     if( !config_GetInt( p_intf, "qt-always-video" ) )
131         need_update = true;
132     p_vout = NULL;
133 }
134
135
136 static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
137 {
138     return p_intf->p_sys->p_video->Control( p_win, i_q, a );
139
140
141 int VideoWidget::Control( void *p_window, int i_query, va_list args )
142 {
143     int i_ret = VLC_EGENERIC;
144     vlc_mutex_lock( &lock );
145     switch( i_query )
146     {
147         case VOUT_GET_SIZE:
148         {
149             unsigned int *pi_width  = va_arg( args, unsigned int * );
150             unsigned int *pi_height = va_arg( args, unsigned int * );
151             *pi_width = frame->width();
152             *pi_height = frame->height();
153             i_ret = VLC_SUCCESS;
154             break;
155         }
156         case VOUT_SET_SIZE:
157         {
158             unsigned int i_width  = va_arg( args, unsigned int );
159             unsigned int i_height = va_arg( args, unsigned int );
160
161             if( !i_width && p_vout ) i_width = p_vout->i_window_width;
162             if( !i_height && p_vout ) i_height = p_vout->i_window_height;
163            
164             frame->resize( i_width, i_height );
165             i_ret = VLC_SUCCESS;
166             break; 
167         }
168         case VOUT_SET_STAY_ON_TOP:
169         {
170             /// \todo
171             break;
172         }   
173         default:
174             msg_Warn( p_intf, "unsupported control query" );
175             break;
176     }
177     vlc_mutex_unlock( &lock );
178     return i_ret;
179 }