interface_widgets.cpp 8.22 KB
Newer Older
1
/*****************************************************************************
2
 * interface_widgets.cpp : Custom widgets for the main interface
3
 ****************************************************************************
4 5
 * Copyright (C) 2006 the VideoLAN team
 * $Id$
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

24
#include "dialogs_provider.hpp"
25 26
#include <vlc/vout.h>
#include "qt4.hpp"
27
#include "components/interface_widgets.hpp"
28
#include "main_interface.hpp"
29
#include "input_manager.hpp"
30
#include <QHBoxLayout>
31

32 33
#define ICON_SIZE 128

34 35 36 37
/**********************************************************************
 * Video Widget. A simple frame on which video is drawn
 * This class handles resize issues
 **********************************************************************/
38 39 40 41 42
static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
                        unsigned int *, unsigned int * );
static void DoRelease( intf_thread_t *, void * );
static int DoControl( intf_thread_t *, void *, int, va_list );

43
bool need_update;
44

45
VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
46 47 48 49 50 51 52 53 54 55
{
    vlc_mutex_init( p_intf, &lock );

    p_intf->pf_request_window  = ::DoRequest;
    p_intf->pf_release_window  = ::DoRelease;
    p_intf->pf_control_window  = ::DoControl;
    p_intf->p_sys->p_video = this;
    p_vout = NULL;

    setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
56

Clément Stenac's avatar
Clément Stenac committed
57
    ON_TIMEOUT( update() );
58 59 60 61 62 63 64 65 66 67
    need_update = false;
}

void VideoWidget::update()
{
    if( need_update )
    {
        p_intf->p_sys->p_mi->resize( p_intf->p_sys->p_mi->sizeHint() );
        need_update = false;
    }
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
}

VideoWidget::~VideoWidget()
{
    vlc_mutex_lock( &lock );
    if( p_vout )
    {
        if( !p_intf->psz_switch_intf )
        {
            if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
                vout_Control( p_vout, VOUT_REPARENT );
        }
        else
        {
            if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
                vout_Control( p_vout, VOUT_CLOSE );
        }
    }
    p_intf->pf_request_window = NULL;
    p_intf->pf_release_window = NULL;
    p_intf->pf_control_window = NULL;
    vlc_mutex_unlock( &lock );
    vlc_mutex_destroy( &lock );
}

QSize VideoWidget::sizeHint() const
{
95
    return widgetSize;
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
}

static void *DoRequest( intf_thread_t *p_intf, vout_thread_t *p_vout,
                        int *pi1, int *pi2, unsigned int*pi3,unsigned int*pi4)
{
    return p_intf->p_sys->p_video->Request( p_vout, pi1, pi2, pi3, pi4 );
}

void *VideoWidget::Request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
                           unsigned int *pi_width, unsigned int *pi_height )
{
    if( p_vout )
    {
        msg_Dbg( p_intf, "embedded video already in use" );
        return NULL;
    }
    p_vout = p_nvout;

114
    setMinimumSize( 1,1 );
115
    widgetSize = QSize( *pi_width, *pi_height );
116
    updateGeometry();
117
    need_update = true;
118 119 120 121 122 123 124 125 126 127
    return  (void*)winId();
}

static void DoRelease( intf_thread_t *p_intf, void *p_win )
{
    return p_intf->p_sys->p_video->Release( p_win );
}

void VideoWidget::Release( void *p_win )
{
128 129
    p_vout = NULL;
    if( config_GetInt( p_intf, "qt-always-video" ) == 0 )
130
    {
131
        widgetSize = QSize ( 1,1 );
132 133 134
        updateGeometry();
        need_update = true;
    }
135 136 137 138 139
}

static int DoControl( intf_thread_t *p_intf, void *p_win, int i_q, va_list a )
{
    return p_intf->p_sys->p_video->Control( p_win, i_q, a );
140 141
}

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
int VideoWidget::Control( void *p_window, int i_query, va_list args )
{
    int i_ret = VLC_EGENERIC;
    vlc_mutex_lock( &lock );
    switch( i_query )
    {
        case VOUT_GET_SIZE:
        {
            unsigned int *pi_width  = va_arg( args, unsigned int * );
            unsigned int *pi_height = va_arg( args, unsigned int * );
            *pi_width = frame->width();
            *pi_height = frame->height();
            i_ret = VLC_SUCCESS;
            break;
        }
        case VOUT_SET_SIZE:
        {
            unsigned int i_width  = va_arg( args, unsigned int );
            unsigned int i_height = va_arg( args, unsigned int );

            if( !i_width && p_vout ) i_width = p_vout->i_window_width;
            if( !i_height && p_vout ) i_height = p_vout->i_window_height;
164
            widgetSize = QSize( i_width, i_height );
165 166
            updateGeometry();
            need_update = true;
167
            i_ret = VLC_SUCCESS;
168
            break;
169 170 171 172 173
        }
        case VOUT_SET_STAY_ON_TOP:
        {
            /// \todo
            break;
174
        }
175 176 177 178 179 180 181
        default:
            msg_Warn( p_intf, "unsupported control query" );
            break;
    }
    vlc_mutex_unlock( &lock );
    return i_ret;
}
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221

/**********************************************************************
 * Background Widget. Show a simple image background. Currently,
 * it's a static cone.
 **********************************************************************/
BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
                                        QFrame( NULL ), p_intf( _p_i )
{
    DrawBackground();
    CONNECT( THEMIM->getIM(), audioStarted(), this, hasAudio() );
    CONNECT( THEMIM->getIM(), audioStarted(), this, hasVideo() );
}

int BackgroundWidget::DrawBackground()
{
   setAutoFillBackground( true );
    plt =  palette();
    plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
    plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
    setPalette( plt );

    backgroundLayout = new QHBoxLayout;
    label = new QLabel( "" );
    label->setMaximumHeight( ICON_SIZE );
    label->setMaximumWidth( ICON_SIZE );
    label->setScaledContents( true );
    label->setPixmap( QPixmap( ":/vlc128.png" ) );
    backgroundLayout = new QHBoxLayout;
    backgroundLayout->addWidget( label );
    setLayout( backgroundLayout );
    return 0;
}

int BackgroundWidget::CleanBackground()
{
    backgroundLayout->takeAt(0);
    delete backgroundLayout;
    return 0;
}

222 223 224 225 226
QSize BackgroundWidget::sizeHint() const
{
    return widgetSize;
}

227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
void BackgroundWidget::hasAudio()
{
    /* We have video already, do nothing */
    if( THEMIM->getIM()->b_has_video )
    {

    }
    else
    {
        /* Show the panel to the user */
        fprintf( stderr, "Showing panel\n" );
    }
}

void BackgroundWidget::resizeEvent( QResizeEvent *e )
{
    if( e->size().height() < ICON_SIZE -1 )
        label->setMaximumWidth( e->size().height() );
    else
        label->setMaximumWidth( ICON_SIZE );
}
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283

/**********************************************************************
 * Playlist Widget. The embedded playlist
 **********************************************************************/
#include "components/playlist/panels.hpp"
#include "components/playlist/selector.hpp"

PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) : QFrame(NULL),
                                                            p_intf( _p_intf )
{
    selector = new PLSelector( this, p_intf, THEPL );
    selector->setMaximumWidth( 130 );

    playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
                                                THEPL->p_local_category );

    rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( this,
                              p_intf, THEPL, p_root ) );

    CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );

    QHBoxLayout *layout = new QHBoxLayout();
    layout->addWidget( selector, 0 );
    layout->addWidget( rightPanel, 10 );
    setLayout( layout );
}

PlaylistWidget::~PlaylistWidget()
{
}

QSize PlaylistWidget::sizeHint() const
{
    return widgetSize;
}