interface_widgets.cpp 24.9 KB
Newer Older
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
 *          Jean-Baptiste Kempf <jb@videolan.org>
9
 *          Rafaël Carré <funman@videolanorg>
10 11 12 13
 *
 * 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
14
 * ( at your option ) any later version.
15 16 17 18 19 20 21 22 23 24 25
 *
 * 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.
 *****************************************************************************/

zorglub's avatar
zorglub committed
26
#include "dialogs_provider.hpp"
27
#include "components/interface_widgets.hpp"
28
#include "main_interface.hpp"
29
#include "input_manager.hpp"
30
#include "menus.hpp"
31
#include "util/input_slider.hpp"
zorglub's avatar
zorglub committed
32
#include <vlc_vout.h>
33

zorglub's avatar
zorglub committed
34 35
#include <QLabel>
#include <QSpacerItem>
zorglub's avatar
zorglub committed
36
#include <QCursor>
zorglub's avatar
zorglub committed
37
#include <QPushButton>
38
#include <QHBoxLayout>
zorglub's avatar
zorglub committed
39
#include <QMenu>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
40 41
#include <QPalette>
#include <QResizeEvent>
42

43 44
#define ICON_SIZE 128
#define MAX_BG_SIZE 300
zorglub's avatar
zorglub committed
45

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

55
VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
56 57 58
{
    vlc_mutex_init( p_intf, &lock );
    p_vout = NULL;
59
    CONNECT( this, askResize(), this, SetMinSize() );
60
    CONNECT( this, askVideoToShow(), this, show() );
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    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
{
86
    return widgetSize;
87 88
}

89
void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
90 91
                           unsigned int *pi_width, unsigned int *pi_height )
{
92
    emit askVideoToShow();
93 94 95 96 97 98
    if( p_vout )
    {
        msg_Dbg( p_intf, "embedded video already in use" );
        return NULL;
    }
    p_vout = p_nvout;
99
    emit askResize();
100
    return ( void* )winId();
101 102
}

103 104 105 106 107
void VideoWidget::SetMinSize()
{
    setMinimumSize( 16, 16 );
}

108
void VideoWidget::release( void *p_win )
109
{
110
    p_vout = NULL;
111
}
112 113 114 115 116 117 118
/**********************************************************************
 * 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 )
{
119

zorglub's avatar
zorglub committed
120
    setAutoFillBackground( true );
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 );

126
    label = new QLabel;
127 128 129 130 131 132 133 134 135
    label->setMaximumHeight( ICON_SIZE );
    label->setMaximumWidth( ICON_SIZE );
    label->setScaledContents( true );
    label->setPixmap( QPixmap( ":/vlc128.png" ) );
    backgroundLayout = new QHBoxLayout;
    backgroundLayout->addWidget( label );
    setLayout( backgroundLayout );
}

zorglub's avatar
zorglub committed
136
BackgroundWidget::~BackgroundWidget()
137
{
138
    backgroundLayout->takeAt( 0 );
139 140 141
    delete backgroundLayout;
}

142 143 144 145 146 147 148 149
void BackgroundWidget::setArt( QString url )
{
    if( url.isNull() )
        label->setPixmap( QPixmap( ":/vlc128.png" ) );
    else
        label->setPixmap( QPixmap( url ) );
}

150 151 152 153 154
QSize BackgroundWidget::sizeHint() const
{
    return widgetSize;
}

155 156 157 158 159 160 161
void BackgroundWidget::resizeEvent( QResizeEvent *e )
{
    if( e->size().height() < ICON_SIZE -1 )
        label->setMaximumWidth( e->size().height() );
    else
        label->setMaximumWidth( ICON_SIZE );
}
162

163 164 165 166
void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
{
    QVLCMenu::PopupMenu( p_intf, true );
}
zorglub's avatar
zorglub committed
167 168 169 170 171 172 173
/**********************************************************************
 * Visualization selector panel
 **********************************************************************/
VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
                                                QFrame( NULL ), p_intf( _p_i )
{
    QHBoxLayout *layout = new QHBoxLayout( this );
174
    layout->setMargin( 0 );
zorglub's avatar
zorglub committed
175
    QPushButton *prevButton = new QPushButton( "Prev" );
176
    QPushButton *nextButton = new QPushButton( "Next" );
zorglub's avatar
zorglub committed
177 178
    layout->addWidget( prevButton );
    layout->addWidget( nextButton );
zorglub's avatar
zorglub committed
179 180

    layout->addItem( new QSpacerItem( 40,20,
181 182
                              QSizePolicy::Expanding, QSizePolicy::Minimum ) );
    layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
zorglub's avatar
zorglub committed
183 184 185 186 187 188 189

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

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

zorglub's avatar
zorglub committed
190
    setLayout( layout );
191
    setMaximumHeight( 35 );
zorglub's avatar
zorglub committed
192 193 194 195 196 197
}

VisualSelector::~VisualSelector()
{
}

zorglub's avatar
zorglub committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
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 );
    }
}

/**********************************************************************
219
 * TEH controls
zorglub's avatar
zorglub committed
220
 **********************************************************************/
221 222 223 224 225 226

#define setupSmallButton( aButton ){  \
    aButton->setMaximumSize( QSize( 26, 26 ) ); \
    aButton->setMinimumSize( QSize( 26, 26 ) ); \
    aButton->setIconSize( QSize( 20, 20 ) ); }

227
AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
zorglub's avatar
zorglub committed
228 229
                                           QFrame( NULL ), p_intf( _p_i )
{
230 231 232
    QHBoxLayout *advLayout = new QHBoxLayout( this );
    advLayout->setMargin( 0 );
    advLayout->setSpacing( 0 );
zorglub's avatar
zorglub committed
233

234 235 236 237 238
/* FIXME A to B function */
    ABButton = new QPushButton( "AB" );
    ABButton->setMaximumSize( QSize( 26, 26 ) );
    ABButton->setIconSize( QSize( 20, 20 ) );
    advLayout->addWidget( ABButton );
239
    BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
zorglub's avatar
zorglub committed
240

241 242 243 244 245 246 247 248 249 250 251 252
//FIXME Frame by frame function
    frameButton = new QPushButton( "Fr" );
    frameButton->setMaximumSize( QSize( 26, 26 ) );
    frameButton->setIconSize( QSize( 20, 20 ) );
    advLayout->addWidget( frameButton );
    BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );

/* FIXME Record function */
    recordButton = new QPushButton( "R" );
    recordButton->setMaximumSize( QSize( 26, 26 ) );
    recordButton->setIconSize( QSize( 20, 20 ) );
    advLayout->addWidget( recordButton );
253
    BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
254
            qtr( "Record" ), record() );
255

256 257 258 259 260
    snapshotButton = new QPushButton( "S" );
    snapshotButton->setMaximumSize( QSize( 26, 26 ) );
    snapshotButton->setIconSize( QSize( 20, 20 ) );
    advLayout->addWidget( snapshotButton );
    BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
261

zorglub's avatar
zorglub committed
262 263
}

264
AdvControlsWidget::~AdvControlsWidget()
zorglub's avatar
zorglub committed
265 266 267
{
}

268
void AdvControlsWidget::enableInput( bool enable )
zorglub's avatar
zorglub committed
269
{
270 271
    ABButton->setEnabled( enable );
    recordButton->setEnabled( enable );
zorglub's avatar
zorglub committed
272
}
273
void AdvControlsWidget::enableVideo( bool enable )
zorglub's avatar
zorglub committed
274 275
{
    snapshotButton->setEnabled( enable );
276
    frameButton->setEnabled( enable );
zorglub's avatar
zorglub committed
277 278
}

279
void AdvControlsWidget::snapshot()
zorglub's avatar
zorglub committed
280
{
281 282
    vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
    if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
zorglub's avatar
zorglub committed
283 284
}

285
void AdvControlsWidget::frame(){}
286
void AdvControlsWidget::fromAtoB(){}
287 288 289 290 291 292
void AdvControlsWidget::record(){}

/*****************************
 * DA Control Widget !
 *****************************/
ControlsWidget::ControlsWidget( intf_thread_t *_p_i, bool b_advControls ) :
293 294 295
                             QFrame( NULL ), p_intf( _p_i )
{
    controlLayout = new QGridLayout( this );
296 297
    controlLayout->setSpacing( 0 );
    setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
298

299 300
    /** The main Slider **/
    slider = new InputSlider( Qt::Horizontal, NULL );
301
    controlLayout->addWidget( slider, 0, 1, 1, 16 );
302 303 304 305 306 307 308
    /* Update the position when the IM has changed */
    CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
             slider, setPosition( float,int, int ) );
    /* And update the IM, when the position has changed */
    CONNECT( slider, sliderDragged( float ),
             THEMIM->getIM(), sliderUpdate( float ) );

309
    /** Slower and faster Buttons **/
310
    slowerButton = new QPushButton;
311
    slowerButton->setFlat( true );
312
    slowerButton->setMaximumSize( QSize( 26, 20 ) );
313

314
    BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
315 316
    controlLayout->addWidget( slowerButton, 0, 0 );

317
    fasterButton = new QPushButton;
318
    fasterButton->setFlat( true );
319
    fasterButton->setMaximumSize( QSize( 26, 20 ) );
320

321
    BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
322
    controlLayout->addWidget( fasterButton, 0, 17 );
323

324 325 326 327
    /* advanced Controls handling */
    b_advancedVisible = b_advControls;

    advControls = new AdvControlsWidget( p_intf );
328
    controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
329 330
    if( !b_advancedVisible ) advControls->hide();

331 332 333
    /** Disc and Menus handling */
    discFrame = new QFrame( this );

334 335 336
    QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
    discLayout->setSpacing( 0 );
    discLayout->setMargin( 0 );
337

338
    prevSectionButton = new QPushButton( discFrame );
339
    setupSmallButton( prevSectionButton );
340 341
    discLayout->addWidget( prevSectionButton );

342
    menuButton = new QPushButton( discFrame );
343 344 345
    setupSmallButton( menuButton );
    discLayout->addWidget( menuButton );

346
    nextSectionButton = new QPushButton( discFrame );
347
    setupSmallButton( nextSectionButton );
348 349
    discLayout->addWidget( nextSectionButton );

350
    controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
351 352 353 354 355

    BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
    BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
    BUTTON_SET_IMG( menuButton, "", previous.png, "" );

356
    discFrame->hide();
357 358 359

    /* Change the navigation button display when the IM navigation changes */
    CONNECT( THEMIM->getIM(), navigationChanged( int ),
360
             this, setNavigation( int ) );
361 362 363 364 365 366 367 368
    /* Changes the IM navigation when triggered on the nav buttons */
    CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
             sectionPrev() );
    CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
             sectionNext() );
    CONNECT( menuButton, clicked(), THEMIM->getIM(),
             sectionMenu() );

369 370
    /** TODO
     * Telextext QFrame
371
     * Merge with upper menu in a StackLayout
372 373
     **/

374
    /** Play Buttons **/
375
    QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
376 377 378 379
    sizePolicy.setHorizontalStretch( 0 );
    sizePolicy.setVerticalStretch( 0 );

    /* Play */
380
    playButton = new QPushButton;
381
    playButton->setSizePolicy( sizePolicy );
382 383
    playButton->setMaximumSize( QSize( 38, 38 ) );
    playButton->setMinimumSize( QSize( 45, 45 ) );
384
    playButton->setIconSize( QSize( 30, 30 ) );
385

386
    controlLayout->addWidget( playButton, 2, 0, 2, 2 );
387

388 389
    controlLayout->setColumnMinimumWidth( 2, 20 );
    controlLayout->setColumnStretch( 2, 0 );
390 391 392 393 394 395 396 397

    /** Prev + Stop + Next Block **/
    QHBoxLayout *controlButLayout = new QHBoxLayout;
    controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */

    /* Prev */
    QPushButton *prevButton = new QPushButton;
    prevButton->setSizePolicy( sizePolicy );
398
    setupSmallButton( prevButton );
399 400 401 402 403 404

    controlButLayout->addWidget( prevButton );

    /* Stop */
    QPushButton *stopButton = new QPushButton;
    stopButton->setSizePolicy( sizePolicy );
405
    setupSmallButton( stopButton );
406 407 408 409 410 411

    controlButLayout->addWidget( stopButton );

    /* next */
    QPushButton *nextButton = new QPushButton;
    nextButton->setSizePolicy( sizePolicy );
412
    setupSmallButton( nextButton );
413 414 415 416 417 418

    controlButLayout->addWidget( nextButton );

    /* Add this block to the main layout */
    controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );

419
    BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
420
    BUTTON_SET_ACT_I( prevButton, "" , previous.png,
421 422 423
                      qtr( "Previous" ), prev() );
    BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
    BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
424

425 426
    controlLayout->setColumnStretch( 8 , 10 );
    controlLayout->setColumnStretch( 9, 0 );
427

428 429 430 431 432
    /*
     * Other first Line buttons
     * Might need to be inside a frame to avoid a few resizing pb
     * FIXME
     */
433 434 435
    /** Fullscreen/Visualisation **/
    fullscreenButton = new QPushButton( "F" );
    BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
436
    setupSmallButton( fullscreenButton );
437
    controlLayout->addWidget( fullscreenButton, 3, 10 );
438

439 440
    /** Playlist Button **/
    playlistButton = new QPushButton;
441
    setupSmallButton( playlistButton );
442
    controlLayout->addWidget( playlistButton, 3, 11 );
443
    BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
444 445 446

    /** extended Settings **/
    QPushButton *extSettingsButton = new QPushButton( "F" );
447
    BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
448
            extSettings() );
449
    setupSmallButton( extSettingsButton );
450 451
    controlLayout->addWidget( extSettingsButton, 3, 12 );

452
    controlLayout->setColumnStretch( 14, 5 );
453 454 455 456

    /* Volume */
    VolumeClickHandler *h = new VolumeClickHandler( p_intf, this );

457
    volMuteLabel = new QLabel;
458
    volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
459
    volMuteLabel->setToolTip( qtr( "Mute" ) );
460
    volMuteLabel->installEventFilter( h );
461

462
    /** TODO:
463
     * Change this slider to use a nice Amarok-like one
464 465 466 467 468
     * **/
    /** FIXME
     *  THis percerntage thing has to be handled correctly
     *  This has to match to the OSD
     **/
469 470
    volumeSlider = new QSlider;
    volumeSlider->setSizePolicy( sizePolicy );
471
    volumeSlider->setMaximumSize( QSize( 80, 200 ) );
472 473
    volumeSlider->setOrientation( Qt::Horizontal );

474
    volumeSlider->setMaximum( VOLUME_MAX );
475
    volumeSlider->setFocusPolicy( Qt::NoFocus );
476 477
    controlLayout->addWidget( volMuteLabel, 3, 15 );
    controlLayout->addWidget( volumeSlider, 3, 16, 1, 2 );
478 479 480

    /* Volume control connection */
    CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
481
    msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
482 483 484 485 486 487 488 489 490 491 492
}
ControlsWidget::~ControlsWidget()
{
}
void ControlsWidget::stop()
{
    THEMIM->stop();
}

void ControlsWidget::play()
{
493
    if( THEPL->current.i_size == 0 )
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
    {
        /* The playlist is empty, open a file requester */
        THEDP->openFileDialog();
        setStatus( 0 );
        return;
    }
    THEMIM->togglePlayPause();
}

void ControlsWidget::prev()
{
    THEMIM->prev();
}

void ControlsWidget::next()
{
    THEMIM->next();
}

void ControlsWidget::setNavigation( int navigation )
{
515 516 517 518 519
#define HELP_MENU N_( "Menu" )
#define HELP_PCH N_( "Previous chapter" )
#define HELP_NCH N_( "Next chapter" )
#define HELP_PTR N_( "Previous track" )
#define HELP_NTR N_( "Next track" )
520 521 522 523 524 525

    // 1 = chapter, 2 = title, 0 = no
    if( navigation == 0 )
    {
        discFrame->hide();
    } else if( navigation == 1 ) {
526 527
        prevSectionButton->setToolTip( qfu( HELP_PCH ) );
        nextSectionButton->setToolTip( qfu( HELP_NCH ) );
528 529 530
        menuButton->show();
        discFrame->show();
    } else {
531 532
        prevSectionButton->setToolTip( qfu( HELP_PCH ) );
        nextSectionButton->setToolTip( qfu( HELP_NCH ) );
533 534 535 536 537 538
        menuButton->hide();
        discFrame->show();
    }
}

static bool b_my_volume;
539
void ControlsWidget::updateVolume( int i_sliderVolume )
540 541 542
{
    if( !b_my_volume )
    {
543
        int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
544 545
        aout_VolumeSet( p_intf, i_res );
    }
546 547
    if( i_sliderVolume == 0 )
        volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
548
    else if( i_sliderVolume < VOLUME_MAX / 2 )
549 550
        volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
    else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
551 552 553 554
}

void ControlsWidget::updateOnTimer()
{
555
    /* Audio part */
556 557
    audio_volume_t i_volume;
    aout_VolumeGet( p_intf, &i_volume );
558
    i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2) ;
559 560 561 562 563 564 565 566
    int i_gauge = volumeSlider->value();
    b_my_volume = false;
    if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
    {
        b_my_volume = true;
        volumeSlider->setValue( i_volume );
        b_my_volume = false;
    }
567

568
    /* Activate the interface buttons according to the presence of the input */
569
    enableInput( THEMIM->getIM()->hasInput() );
570
    //enableVideo( THEMIM->getIM()->hasVideo() );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
571
    enableVideo( true );
572
}
573

574 575
void ControlsWidget::setStatus( int status )
{
576 577
    if( status == PLAYING_S ) // Playing
        playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
578
    else
579
        playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
580
}
581

582 583
/**
 * TODO
584
 * This functions toggle the fullscreen mode
585
 * If there is no video, it should first activate Visualisations...
586
 *  This has also to be fixed in enableVideo()
587
 */
zorglub's avatar
zorglub committed
588 589
void ControlsWidget::fullscreen()
{
590
    vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
591
    if( p_vout)
592
    {
593
        var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
594
        vlc_object_release( p_vout );
595
    }
596 597 598 599 600 601
}

void ControlsWidget::extSettings()
{
    THEDP->extendedDialog();
}
zorglub's avatar
zorglub committed
602

603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
void ControlsWidget::slower()
{
    THEMIM->getIM()->slower();
}

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

void ControlsWidget::enableInput( bool enable )
{
    slowerButton->setEnabled( enable );
    slider->setEnabled( enable );
    fasterButton->setEnabled( enable );
618 619 620

    /* Advanced Buttons too */
    advControls->enableInput( enable );
621 622
}

623
void ControlsWidget::enableVideo( bool enable )
624
{
625 626
    // TODO Later make the fullscreenButton toggle Visualisation and so on.
    fullscreenButton->setEnabled( enable );
627 628 629

    /* Advanced Buttons too */
    advControls->enableVideo( enable );
630 631
}

632 633 634 635 636 637 638 639 640 641 642 643 644
void ControlsWidget::toggleAdvanced()
{
    if( !VISIBLE( advControls ) )
    {
        advControls->show();
        b_advancedVisible = true;
    }
    else
    {
        advControls->hide();
        b_advancedVisible = false;
    }
    //FIXME connect this one :D
645
    emit advancedControlsToggled( b_advancedVisible );  //  doComponentsUpdate();
646
}
647

648 649 650 651 652 653
/**********************************************************************
 * Playlist Widget. The embedded playlist
 **********************************************************************/
#include "components/playlist/panels.hpp"
#include "components/playlist/selector.hpp"

654 655
PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) :
                                p_intf ( _p_i )
656
{
657 658 659
    /* Left Part and design */
    QWidget *leftW = new QWidget( this );
    QVBoxLayout *left = new QVBoxLayout( leftW );
zorglub's avatar
zorglub committed
660

661
    /* Source Selector */
662
    selector = new PLSelector( this, p_intf, THEPL );
zorglub's avatar
zorglub committed
663 664
    left->addWidget( selector );

665
    /* Art label */
666
    art = new QLabel( "" );
667 668
    art->setMinimumHeight( 128 );
    art->setMinimumWidth( 128 );
zorglub's avatar
zorglub committed
669 670 671
    art->setMaximumHeight( 128 );
    art->setMaximumWidth( 128 );
    art->setScaledContents( true );
672
    art->setPixmap( QPixmap( ":/noart.png" ) );
zorglub's avatar
zorglub committed
673
    left->addWidget( art );
674

675
    /* Initialisation of the playlist */
676 677 678
    playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
                                                THEPL->p_local_category );

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

682
    /* Connects */
683
    CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
zorglub's avatar
zorglub committed
684

685
    CONNECT( qobject_cast<StandardPLPanel *>( rightPanel )->model,
zorglub's avatar
zorglub committed
686 687
             artSet( QString ) , this, setArt( QString ) );
    /* Forward removal requests from the selector to the main panel */
688
    CONNECT( qobject_cast<PLSelector *>( selector )->model,
zorglub's avatar
zorglub committed
689
             shouldRemove( int ),
690
             qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
691

692
    connect( selector, SIGNAL( activated( int ) ),
zorglub's avatar
zorglub committed
693 694
             this, SIGNAL( rootChanged( int ) ) );
    emit rootChanged( p_root->i_id );
695

696 697 698 699
    /* Add the two sides of the QSplitter */
    addWidget( leftW );
    addWidget( rightPanel );

700 701 702 703 704 705
    leftW->setMaximumWidth( 250 );
    setCollapsible( 1, false );

    QList<int> sizeList;
    sizeList << 180 << 520 ;
    setSizes( sizeList );
706 707
}

708 709
void PlaylistWidget::setArt( QString url )
{
710 711 712
    if( url.isNull() )
        art->setPixmap( QPixmap( ":/noart.png" ) );
    else if( prevArt != url )
713
    {
zorglub's avatar
zorglub committed
714
        art->setPixmap( QPixmap( url ) );
715 716 717
        prevArt = url;
        emit artSet( url );
    }
718 719
}

720 721 722 723
PlaylistWidget::~PlaylistWidget()
{
}

724 725 726 727 728
/**********************************************************************
 * Speed control widget
 **********************************************************************/
SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
                             QFrame( NULL ), p_intf( _p_i )
729
{
730
    QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
731 732
    sizePolicy.setHorizontalStretch( 0 );
    sizePolicy.setVerticalStretch( 0 );
733

734 735 736 737 738 739
    speedSlider = new QSlider;
    speedSlider->setSizePolicy( sizePolicy );
    speedSlider->setMaximumSize( QSize( 80, 200 ) );
    speedSlider->setOrientation( Qt::Vertical );
    speedSlider->setTickPosition( QSlider::TicksRight );

740
    speedSlider->setRange( -100, 100 );
741 742 743
    speedSlider->setSingleStep( 10 );
    speedSlider->setPageStep( 20 );
    speedSlider->setTickInterval( 20 );
744

745
    CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
746

747 748
    normalSpeedButton = new QPushButton( "N" );
    normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
749 750
    normalSpeedButton->setFlat( true );
    normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
751

752
    CONNECT( normalSpeedButton, clicked(), this, resetRate() );
753

754
    QVBoxLayout *speedControlLayout = new QVBoxLayout;
755 756 757
    speedControlLayout->addWidget(speedSlider);
    speedControlLayout->addWidget(normalSpeedButton);
    setLayout(speedControlLayout);
758 759 760 761 762 763
}

SpeedControlWidget::~SpeedControlWidget()
{
}

764 765 766
#define RATE_SLIDER_MAXIMUM 3.0
#define RATE_SLIDER_MINIMUM 0.3
#define RATE_SLIDER_LENGTH 100.0
767 768 769

void SpeedControlWidget::updateControls( int rate )
{
770 771 772 773 774
    if( speedSlider->isSliderDown() )
    {
        //We don't want to change anything if the user is using the slider
        return;
    }
775

776 777
    int sliderValue;
    double speed = INPUT_RATE_DEFAULT / (double)rate;
778

779
    if( rate >= INPUT_RATE_DEFAULT )
780
    {
781 782 783 784 785 786 787
        if( speed < RATE_SLIDER_MINIMUM )
        {
            sliderValue = speedSlider->minimum();
        }
        else
        {
            sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
788
                                        / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
789 790 791 792 793 794 795 796 797 798 799
        }
    }
    else
    {
        if( speed > RATE_SLIDER_MAXIMUM )
        {
            sliderValue = speedSlider->maximum();
        }
        else
        {
            sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
800
                                        / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
801 802
        }
    }
803

804 805 806 807
    //Block signals to avoid feedback loop
    speedSlider->blockSignals( true );
    speedSlider->setValue( sliderValue );
    speedSlider->blockSignals( false );
808 809 810 811
}

void SpeedControlWidget::updateRate( int sliderValue )
{
812
    int rate;
813

814 815 816
    if( sliderValue < 0.0 )
    {
        rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
817
                ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ) ;
818 819 820
    }
    else
    {
821 822
        rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
                ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
823
    }
824

825
    THEMIM->getIM()->setRate(rate);
826 827 828 829
}

void SpeedControlWidget::resetRate()
{
830
    THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
831
}