interface_widgets.cpp 10.3 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
#include "qt4.hpp"
26
#include "components/interface_widgets.hpp"
27
#include "main_interface.hpp"
28
#include "input_manager.hpp"
29

Clément Stenac's avatar
Clément Stenac committed
30
#include <vlc_vout.h>
31

Clément Stenac's avatar
Clément Stenac committed
32 33
#include <QLabel>
#include <QSpacerItem>
Clément Stenac's avatar
Clément Stenac committed
34
#include <QCursor>
Clément Stenac's avatar
Clément Stenac committed
35
#include <QPushButton>
36
#include <QHBoxLayout>
Clément Stenac's avatar
Clément Stenac committed
37
#include <QMenu>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
38 39
#include <QPalette>
#include <QResizeEvent>
40

41
#define ICON_SIZE 300
42

43 44 45 46
/**********************************************************************
 * Video Widget. A simple frame on which video is drawn
 * This class handles resize issues
 **********************************************************************/
47 48 49 50 51
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 );

52
VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
{
    vlc_mutex_init( p_intf, &lock );
    p_vout = NULL;

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

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 );
        }
    }
    vlc_mutex_unlock( &lock );
    vlc_mutex_destroy( &lock );
}

QSize VideoWidget::sizeHint() const
{
82
    return widgetSize;
83 84
}

85
void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
86 87 88 89 90 91 92 93
                           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;
94
    setMinimumSize( 16, 16 );
95
    return (void*)winId();
96 97
}

98
void VideoWidget::release( void *p_win )
99
{
100
    p_vout = NULL;
101
}
102 103 104 105 106 107 108
/**********************************************************************
 * 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 )
{
109

Clément Stenac's avatar
Clément Stenac committed
110
    setAutoFillBackground( true );
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
    plt =  palette();
    plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
    plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
    setPalette( plt );

    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 );
}

Clément Stenac's avatar
Clément Stenac committed
126
BackgroundWidget::~BackgroundWidget()
127 128 129 130 131
{
    backgroundLayout->takeAt(0);
    delete backgroundLayout;
}

132 133 134 135 136 137 138 139
void BackgroundWidget::setArt( QString url )
{
    if( url.isNull() )
        label->setPixmap( QPixmap( ":/vlc128.png" ) );
    else
        label->setPixmap( QPixmap( url ) );
}

140 141 142 143 144
QSize BackgroundWidget::sizeHint() const
{
    return widgetSize;
}

145 146 147 148 149 150 151
void BackgroundWidget::resizeEvent( QResizeEvent *e )
{
    if( e->size().height() < ICON_SIZE -1 )
        label->setMaximumWidth( e->size().height() );
    else
        label->setMaximumWidth( ICON_SIZE );
}
152

Clément Stenac's avatar
Clément Stenac committed
153 154 155 156 157 158 159
/**********************************************************************
 * Visualization selector panel
 **********************************************************************/
VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
                                                QFrame( NULL ), p_intf( _p_i )
{
    QHBoxLayout *layout = new QHBoxLayout( this );
160
    layout->setMargin( 0 );
Clément Stenac's avatar
Clément Stenac committed
161 162 163 164
    QPushButton *prevButton = new QPushButton( "Prev" );
    QPushButton *nextButton = new QPushButton( "Next");
    layout->addWidget( prevButton );
    layout->addWidget( nextButton );
Clément Stenac's avatar
Clément Stenac committed
165 166 167 168 169 170 171 172 173 174 175

    layout->addItem( new QSpacerItem( 40,20,
                              QSizePolicy::Expanding, QSizePolicy::Minimum) );
    layout->addWidget( new QLabel( qtr("Current visualization:") ) );

    current = new QLabel( qtr( "None" ) );
    layout->addWidget( current );

    BUTTONACT( prevButton, prev() );
    BUTTONACT( nextButton, next() );

Clément Stenac's avatar
Clément Stenac committed
176
    setLayout( layout );
177
    setMaximumHeight( 35 );
Clément Stenac's avatar
Clément Stenac committed
178 179 180 181 182 183
}

VisualSelector::~VisualSelector()
{
}

Clément Stenac's avatar
Clément Stenac committed
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 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 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
void VisualSelector::prev()
{
    char *psz_new = aout_VisualPrev( p_intf );
    if( psz_new )
    {
        current->setText( qfu( psz_new ) );
        free( psz_new );
    }
}

void VisualSelector::next()
{
    char *psz_new = aout_VisualNext( p_intf );
    if( psz_new )
    {
        current->setText( qfu( psz_new ) );
        free( psz_new );
    }
}

/**********************************************************************
 * More controls
 **********************************************************************/
ControlsWidget::ControlsWidget( intf_thread_t *_p_i ) :
                                           QFrame( NULL ), p_intf( _p_i )
{
    QHBoxLayout *layout = new QHBoxLayout( this );
    layout->setMargin( 0 );

    slowerButton = new QPushButton( "S" );
    BUTTON_SET_ACT( slowerButton, "S", qtr("Slower" ), slower() );
    layout->addWidget( slowerButton );
    slowerButton->setMaximumWidth( 35 );

    normalButton = new QPushButton( "N" );
    BUTTON_SET_ACT( normalButton, "N", qtr("Normal rate"), normal() );
    layout->addWidget( normalButton );
    normalButton->setMaximumWidth( 35 );

    fasterButton = new QPushButton( "F" );
    BUTTON_SET_ACT( fasterButton, "F", qtr("Faster" ), faster() );
    layout->addWidget( fasterButton );
    fasterButton->setMaximumWidth( 35 );

    layout->addItem( new QSpacerItem( 100,20,
                              QSizePolicy::Expanding, QSizePolicy::Minimum) );

    snapshotButton = new QPushButton( "S" );
    BUTTON_SET_ACT( snapshotButton, "S", qtr("Take a snapshot"), snapshot() );
    layout->addWidget( snapshotButton );
    snapshotButton->setMaximumWidth( 35 );

    fullscreenButton = new QPushButton( "F" );
    BUTTON_SET_ACT( fullscreenButton, "F", qtr("Fullscreen"), fullscreen() );
    layout->addWidget( fullscreenButton );
    fullscreenButton->setMaximumWidth( 35 );
}

ControlsWidget::~ControlsWidget()
{
}

void ControlsWidget::enableInput( bool enable )
{
    slowerButton->setEnabled( enable );
    normalButton->setEnabled( enable );
    fasterButton->setEnabled( enable );
}
void ControlsWidget::enableVideo( bool enable )
{
    snapshotButton->setEnabled( enable );
    fullscreenButton->setEnabled( enable );
}

void ControlsWidget::slower()
{
    THEMIM->getIM()->slower();
}

void ControlsWidget::faster()
{
    THEMIM->getIM()->faster();
}

void ControlsWidget::normal()
{
    THEMIM->getIM()->normalRate();
}

void ControlsWidget::snapshot()
{
}

void ControlsWidget::fullscreen()
{
}

281 282 283 284 285 286
/**********************************************************************
 * Playlist Widget. The embedded playlist
 **********************************************************************/
#include "components/playlist/panels.hpp"
#include "components/playlist/selector.hpp"

287
PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) :
288
                                p_intf ( _p_intf)
289
{
290 291 292
    /* Left Part and design */
    QWidget *leftW = new QWidget( this );
    QVBoxLayout *left = new QVBoxLayout( leftW );
Clément Stenac's avatar
Clément Stenac committed
293

294
    /* Source Selector */
295
    selector = new PLSelector( this, p_intf, THEPL );
Clément Stenac's avatar
Clément Stenac committed
296 297
    left->addWidget( selector );

298
    /* Art label */
299
    art = new QLabel( "" );
300 301
    art->setMinimumHeight( 128 );
    art->setMinimumWidth( 128 );
Clément Stenac's avatar
Clément Stenac committed
302 303 304
    art->setMaximumHeight( 128 );
    art->setMaximumWidth( 128 );
    art->setScaledContents( true );
305
    art->setPixmap( QPixmap( ":/noart.png" ) );
Clément Stenac's avatar
Clément Stenac committed
306
    left->addWidget( art );
307

308
    /* Initialisation of the playlist */
309 310 311 312 313 314
    playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
                                                THEPL->p_local_category );

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

315
    /* Connects */
316
    CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
317

Clément Stenac's avatar
Clément Stenac committed
318 319 320 321 322 323
    CONNECT( qobject_cast<StandardPLPanel *>(rightPanel)->model,
             artSet( QString ) , this, setArt( QString ) );
    /* Forward removal requests from the selector to the main panel */
    CONNECT( qobject_cast<PLSelector *>(selector)->model,
             shouldRemove( int ),
             qobject_cast<StandardPLPanel *>(rightPanel), removeItem(int) );
324

325 326 327
    connect( selector, SIGNAL(activated( int )),
             this, SIGNAL( rootChanged( int ) ) );
    emit rootChanged( p_root->i_id );
328

329 330 331 332
    /* Add the two sides of the QSplitter */
    addWidget( leftW );
    addWidget( rightPanel );

333 334 335 336 337 338
    leftW->setMaximumWidth( 250 );
    setCollapsible( 1, false );

    QList<int> sizeList;
    sizeList << 180 << 520 ;
    setSizes( sizeList );
339 340
}

341 342
void PlaylistWidget::setArt( QString url )
{
343 344 345
    if( url.isNull() )
        art->setPixmap( QPixmap( ":/noart.png" ) );
    else if( prevArt != url )
Clément Stenac's avatar
Clément Stenac committed
346
        art->setPixmap( QPixmap( url ) );
347
    prevArt = url;
348
    emit artSet( url );
349 350
}

351 352 353 354 355 356 357 358 359
PlaylistWidget::~PlaylistWidget()
{
}

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