interface_widgets.cpp 27.4 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.
 *****************************************************************************/

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"
32
#include "util/customwidgets.hpp"
Clément Stenac's avatar
Clément Stenac committed
33
#include <vlc_vout.h>
34

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

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

53
VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
54 55 56
{
    vlc_mutex_init( p_intf, &lock );
    p_vout = NULL;
57

58
    CONNECT( this, askResize(), this, SetMinSize() );
59
    CONNECT( this, askVideoToShow(), this, show() );
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
    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
{
85
    return widgetSize;
86 87
}

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

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

107
void VideoWidget::release( void *p_win )
108
{
109
    p_vout = NULL;
110
}
111 112


113 114 115 116
/**********************************************************************
 * Background Widget. Show a simple image background. Currently,
 * it's a static cone.
 **********************************************************************/
117 118 119 120
#define ICON_SIZE 128
#define MAX_BG_SIZE 400
#define MIN_BG_SIZE 64

121 122 123
BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
                                        QFrame( NULL ), p_intf( _p_i )
{
124 125
    /* We should use that one to take the more size it can */
    setSizePolicy( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding );
126

127
    /* A dark background */
Clément Stenac's avatar
Clément Stenac committed
128
    setAutoFillBackground( true );
129 130 131 132 133
    plt =  palette();
    plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
    plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
    setPalette( plt );

134
    /* A cone in the middle */
135
    label = new QLabel;
136 137
//    label->setScaledContents( true );
    label->setMargin( 5 );
138 139
    label->setMaximumHeight( MAX_BG_SIZE );
    label->setMaximumWidth( MAX_BG_SIZE );
140 141
    label->setMinimumHeight( MIN_BG_SIZE );
    label->setMinimumWidth( MIN_BG_SIZE );
142
    label->setPixmap( QPixmap( ":/vlc128.png" ) );
143

144
    QHBoxLayout *backgroundLayout = new QHBoxLayout( this );
145
    backgroundLayout->addWidget( label );
146 147

    resize( 300, 150 );
148
    updateGeometry();
149 150
}

Clément Stenac's avatar
Clément Stenac committed
151
BackgroundWidget::~BackgroundWidget()
152
{}
153

154 155 156 157 158 159
void BackgroundWidget::setArt( QString url )
{
    if( url.isNull() )
        label->setPixmap( QPixmap( ":/vlc128.png" ) );
    else
        label->setPixmap( QPixmap( url ) );
160
    updateGeometry();
161 162
}

163 164
QSize BackgroundWidget::sizeHint() const
{
165
    return label->size();
166 167
}

168 169
void BackgroundWidget::resizeEvent( QResizeEvent *e )
{
170 171
    msg_Dbg( p_intf, "BG size, %i, %i", e->size().width(), e->size().height() );
    if( e->size().height() < label->height() )
172
    {
173
        label->resize( e->size().height(), e->size().height() );
174
    }
175
}
176

177 178 179 180
void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
{
    QVLCMenu::PopupMenu( p_intf, true );
}
181

Clément Stenac's avatar
Clément Stenac committed
182 183 184 185
/**********************************************************************
 * Visualization selector panel
 **********************************************************************/
VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
186
                                QFrame( NULL ), p_intf( _p_i )
Clément Stenac's avatar
Clément Stenac committed
187 188
{
    QHBoxLayout *layout = new QHBoxLayout( this );
189
    layout->setMargin( 0 );
Clément Stenac's avatar
Clément Stenac committed
190
    QPushButton *prevButton = new QPushButton( "Prev" );
191
    QPushButton *nextButton = new QPushButton( "Next" );
Clément Stenac's avatar
Clément Stenac committed
192 193
    layout->addWidget( prevButton );
    layout->addWidget( nextButton );
Clément Stenac's avatar
Clément Stenac committed
194 195

    layout->addItem( new QSpacerItem( 40,20,
196 197
                              QSizePolicy::Expanding, QSizePolicy::Minimum ) );
    layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
Clément Stenac's avatar
Clément Stenac committed
198 199 200 201 202 203 204

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

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

Clément Stenac's avatar
Clément Stenac committed
205
    setLayout( layout );
206
    setMaximumHeight( 35 );
Clément Stenac's avatar
Clément Stenac committed
207 208 209 210 211 212
}

VisualSelector::~VisualSelector()
{
}

Clément Stenac's avatar
Clément Stenac committed
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
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 );
    }
}

/**********************************************************************
234
 * TEH controls
Clément Stenac's avatar
Clément Stenac committed
235
 **********************************************************************/
236 237 238 239 240 241

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

242
AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
Clément Stenac's avatar
Clément Stenac committed
243 244
                                           QFrame( NULL ), p_intf( _p_i )
{
245 246 247
    QHBoxLayout *advLayout = new QHBoxLayout( this );
    advLayout->setMargin( 0 );
    advLayout->setSpacing( 0 );
Clément Stenac's avatar
Clément Stenac committed
248

249
    /* A to B Button */
250 251 252 253
    ABButton = new QPushButton( "AB" );
    ABButton->setMaximumSize( QSize( 26, 26 ) );
    ABButton->setIconSize( QSize( 20, 20 ) );
    advLayout->addWidget( ABButton );
254
    BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
255
    timeA = timeB = 0;
256 257
    CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
             this, AtoBLoop( float, int, int ) );
Clément Stenac's avatar
Clément Stenac committed
258

259
    //FIXME Frame by frame function
260 261 262 263 264 265
    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() );

266
    /* FIXME Record function */
267 268 269 270
    recordButton = new QPushButton( "R" );
    recordButton->setMaximumSize( QSize( 26, 26 ) );
    recordButton->setIconSize( QSize( 20, 20 ) );
    advLayout->addWidget( recordButton );
271
    BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
272
            qtr( "Record" ), record() );
273

274
    /* Snapshot Button */
275 276 277 278 279
    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() );
Clément Stenac's avatar
Clément Stenac committed
280 281
}

282
AdvControlsWidget::~AdvControlsWidget()
283
{}
Clément Stenac's avatar
Clément Stenac committed
284

285
void AdvControlsWidget::enableInput( bool enable )
Clément Stenac's avatar
Clément Stenac committed
286
{
287 288
    ABButton->setEnabled( enable );
    recordButton->setEnabled( enable );
Clément Stenac's avatar
Clément Stenac committed
289
}
290

291
void AdvControlsWidget::enableVideo( bool enable )
Clément Stenac's avatar
Clément Stenac committed
292 293
{
    snapshotButton->setEnabled( enable );
294
    frameButton->setEnabled( enable );
Clément Stenac's avatar
Clément Stenac committed
295 296
}

297
void AdvControlsWidget::snapshot()
Clément Stenac's avatar
Clément Stenac committed
298
{
299 300
    vout_thread_t *p_vout =
        (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
301
    if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
Clément Stenac's avatar
Clément Stenac committed
302 303
}

304
/* Function called when the button is clicked() */
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
void AdvControlsWidget::fromAtoB()
{
    if( !timeA )
    {
        timeA = var_GetTime( THEMIM->getInput(), "time"  );
        ABButton->setText( "A->..." );
        return;
    }
    if( !timeB )
    {
        timeB = var_GetTime( THEMIM->getInput(), "time"  );
        var_SetTime( THEMIM->getInput(), "time" , timeA );
        ABButton->setText( "A<=>B" );
        return;
    }
    timeA = 0;
    timeB = 0;
    ABButton->setText( "AB" );
}
324

325
/* Function called regularly when in an AtoB loop */
326 327 328 329
void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
{
    if( timeB )
    {
330
        if( i_time >= (int)(timeB/1000000) )
331 332 333
            var_SetTime( THEMIM->getInput(), "time" , timeA );
    }
}
334

335 336 337
void AdvControlsWidget::record(){}
void AdvControlsWidget::frame(){}

338 339 340
/*****************************
 * DA Control Widget !
 *****************************/
341 342 343
ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
                                bool b_advControls,
                                bool b_shiny ) :
344
                                QFrame( NULL ), p_intf( _p_i )
345 346
{
    controlLayout = new QGridLayout( this );
347
    controlLayout->setSpacing( 0 );
348
    setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Minimum );
349

350 351
    /** The main Slider **/
    slider = new InputSlider( Qt::Horizontal, NULL );
352
    controlLayout->addWidget( slider, 0, 1, 1, 16 );
353 354
    /* Update the position when the IM has changed */
    CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
355
             slider, setPosition( float, int, int ) );
356 357 358 359
    /* And update the IM, when the position has changed */
    CONNECT( slider, sliderDragged( float ),
             THEMIM->getIM(), sliderUpdate( float ) );

360
    /** Slower and faster Buttons **/
361
    slowerButton = new QPushButton;
362
    slowerButton->setFlat( true );
363
    slowerButton->setMaximumSize( QSize( 26, 20 ) );
364

365
    BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
366 367
    controlLayout->addWidget( slowerButton, 0, 0 );

368
    fasterButton = new QPushButton;
369
    fasterButton->setFlat( true );
370
    fasterButton->setMaximumSize( QSize( 26, 20 ) );
371

372
    BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
373
    controlLayout->addWidget( fasterButton, 0, 17 );
374

375 376 377 378
    /* advanced Controls handling */
    b_advancedVisible = b_advControls;

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

382 383 384
    /** Disc and Menus handling */
    discFrame = new QFrame( this );

385 386 387
    QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
    discLayout->setSpacing( 0 );
    discLayout->setMargin( 0 );
388

389
    prevSectionButton = new QPushButton( discFrame );
390
    setupSmallButton( prevSectionButton );
391 392
    discLayout->addWidget( prevSectionButton );

393
    menuButton = new QPushButton( discFrame );
394 395 396
    setupSmallButton( menuButton );
    discLayout->addWidget( menuButton );

397
    nextSectionButton = new QPushButton( discFrame );
398
    setupSmallButton( nextSectionButton );
399 400
    discLayout->addWidget( nextSectionButton );

401
    controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
402 403 404 405 406

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

407
    discFrame->hide();
408 409 410

    /* Change the navigation button display when the IM navigation changes */
    CONNECT( THEMIM->getIM(), navigationChanged( int ),
411
             this, setNavigation( int ) );
412 413 414 415 416 417 418 419
    /* 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() );

420 421
    /** TODO
     * Telextext QFrame
422
     * Merge with upper menu in a StackLayout
423 424
     **/

425
    /** Play Buttons **/
426
    QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
427 428 429 430
    sizePolicy.setHorizontalStretch( 0 );
    sizePolicy.setVerticalStretch( 0 );

    /* Play */
431
    playButton = new QPushButton;
432
    playButton->setSizePolicy( sizePolicy );
433 434
    playButton->setMaximumSize( QSize( 38, 38 ) );
    playButton->setMinimumSize( QSize( 45, 45 ) );
435
    playButton->setIconSize( QSize( 30, 30 ) );
436

437
    controlLayout->addWidget( playButton, 2, 0, 2, 2 );
438

439 440
    controlLayout->setColumnMinimumWidth( 2, 20 );
    controlLayout->setColumnStretch( 2, 0 );
441 442 443 444 445 446 447 448

    /** 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 );
449
    setupSmallButton( prevButton );
450 451 452 453 454 455

    controlButLayout->addWidget( prevButton );

    /* Stop */
    QPushButton *stopButton = new QPushButton;
    stopButton->setSizePolicy( sizePolicy );
456
    setupSmallButton( stopButton );
457 458 459 460 461 462

    controlButLayout->addWidget( stopButton );

    /* next */
    QPushButton *nextButton = new QPushButton;
    nextButton->setSizePolicy( sizePolicy );
463
    setupSmallButton( nextButton );
464 465 466 467

    controlButLayout->addWidget( nextButton );

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

470
    BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
471
    BUTTON_SET_ACT_I( prevButton, "" , previous.png,
472 473 474
                      qtr( "Previous" ), prev() );
    BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
    BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
475

476
    controlLayout->setColumnStretch( 7 , 2 );
477

478 479 480 481 482
    /*
     * Other first Line buttons
     * Might need to be inside a frame to avoid a few resizing pb
     * FIXME
     */
483 484 485
    /** Fullscreen/Visualisation **/
    fullscreenButton = new QPushButton( "F" );
    BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
486
    setupSmallButton( fullscreenButton );
487
    controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
488

489 490
    /** Playlist Button **/
    playlistButton = new QPushButton;
491
    setupSmallButton( playlistButton );
492
    controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
493
    BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
494 495 496

    /** extended Settings **/
    QPushButton *extSettingsButton = new QPushButton( "F" );
497
    BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
498
            extSettings() );
499
    setupSmallButton( extSettingsButton );
500
    controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
501

502
    controlLayout->setColumnStretch( 14, 5 );
503

504
    /* Volume */
505
    VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
506

507
    volMuteLabel = new QLabel;
508
    volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
509
    volMuteLabel->setToolTip( qtr( "Mute" ) );
510
    volMuteLabel->installEventFilter( hVolLabel );
511
    controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
512

513 514 515
    if( b_shiny )
    {
        volumeSlider = new SoundSlider( this,
516 517
            config_GetInt( p_intf, "volume-step" ),
            config_GetInt( p_intf, "qt-volume-complete" ) );
518 519 520 521 522 523
    }
    else
    {
        volumeSlider = new QSlider( this );
        volumeSlider->setOrientation( Qt::Horizontal );
    }
524
    volumeSlider->setMaximumSize( QSize( 200, 40 ) );
525
    volumeSlider->setMinimumSize( QSize( 106, 30 ) );
526
    volumeSlider->setFocusPolicy( Qt::NoFocus );
527
    controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
528

529
    /* Set the volume from the config */
530 531
    volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
                              VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
532 533

    /* Volume control connection */
534
    resize( QSize( 400, 60 ) );
535
    CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
536
    msg_Dbg( p_intf, "controls size: %i - %i", size().width(), size().height() );
537
}
538

539 540 541
ControlsWidget::~ControlsWidget()
{
}
542

543
/*
544 545 546 547
QSize ControlsWidget::sizeHint() const
{
    return QSize( 300, 50 );
}
548
*/
549

550 551 552 553 554 555 556
void ControlsWidget::stop()
{
    THEMIM->stop();
}

void ControlsWidget::play()
{
557
    if( THEPL->current.i_size == 0 )
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
    {
        /* 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 )
{
579 580 581 582 583
#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" )
584 585 586 587 588 589

    // 1 = chapter, 2 = title, 0 = no
    if( navigation == 0 )
    {
        discFrame->hide();
    } else if( navigation == 1 ) {
590 591
        prevSectionButton->setToolTip( qfu( HELP_PCH ) );
        nextSectionButton->setToolTip( qfu( HELP_NCH ) );
592 593 594
        menuButton->show();
        discFrame->show();
    } else {
595 596
        prevSectionButton->setToolTip( qfu( HELP_PCH ) );
        nextSectionButton->setToolTip( qfu( HELP_NCH ) );
597 598 599 600 601 602
        menuButton->hide();
        discFrame->show();
    }
}

static bool b_my_volume;
603
void ControlsWidget::updateVolume( int i_sliderVolume )
604 605 606
{
    if( !b_my_volume )
    {
607
        int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
608 609
        aout_VolumeSet( p_intf, i_res );
    }
610 611
    if( i_sliderVolume == 0 )
        volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
612
    else if( i_sliderVolume < VOLUME_MAX / 2 )
613 614
        volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
    else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
615 616 617 618
}

void ControlsWidget::updateOnTimer()
{
619
    /* Audio part */
620 621
    audio_volume_t i_volume;
    aout_VolumeGet( p_intf, &i_volume );
622
    i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
623 624 625 626 627 628 629 630
    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;
    }
631

632
    /* Activate the interface buttons according to the presence of the input */
633
    enableInput( THEMIM->getIM()->hasInput() );
634
    //enableVideo( THEMIM->getIM()->hasVideo() );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
635
    enableVideo( true );
636
}
637

638 639
void ControlsWidget::setStatus( int status )
{
640 641
    if( status == PLAYING_S ) // Playing
        playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
642
    else
643
        playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
644
}
645

646 647
/**
 * TODO
648
 * This functions toggle the fullscreen mode
649
 * If there is no video, it should first activate Visualisations...
650
 *  This has also to be fixed in enableVideo()
651
 */
Clément Stenac's avatar
Clément Stenac committed
652 653
void ControlsWidget::fullscreen()
{
654 655
    vout_thread_t *p_vout =
        (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
656
    if( p_vout)
657
    {
658
        var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
659
        vlc_object_release( p_vout );
660
    }
661 662 663 664 665 666
}

void ControlsWidget::extSettings()
{
    THEDP->extendedDialog();
}
Clément Stenac's avatar
Clément Stenac committed
667

668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
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 );
683 684 685

    /* Advanced Buttons too */
    advControls->enableInput( enable );
686 687
}

688
void ControlsWidget::enableVideo( bool enable )
689
{
690 691
    // TODO Later make the fullscreenButton toggle Visualisation and so on.
    fullscreenButton->setEnabled( enable );
692 693 694

    /* Advanced Buttons too */
    advControls->enableVideo( enable );
695 696
}

697 698 699 700 701 702 703 704 705 706 707 708 709
void ControlsWidget::toggleAdvanced()
{
    if( !VISIBLE( advControls ) )
    {
        advControls->show();
        b_advancedVisible = true;
    }
    else
    {
        advControls->hide();
        b_advancedVisible = false;
    }
    //FIXME connect this one :D
710
    emit advancedControlsToggled( b_advancedVisible );  //  doComponentsUpdate();
711
}
712

713 714 715 716 717 718
/**********************************************************************
 * Playlist Widget. The embedded playlist
 **********************************************************************/
#include "components/playlist/panels.hpp"
#include "components/playlist/selector.hpp"

719 720 721
#include <QSplitter>

PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QSettings *settings ) :
722
                                p_intf ( _p_i )
723
{
724 725 726
    /* Left Part and design */
    QWidget *leftW = new QWidget( this );
    QVBoxLayout *left = new QVBoxLayout( leftW );
Clément Stenac's avatar
Clément Stenac committed
727

728
    /* Source Selector */
729
    selector = new PLSelector( this, p_intf, THEPL );
Clément Stenac's avatar
Clément Stenac committed
730 731
    left->addWidget( selector );

732
    /* Art label */
733
    art = new QLabel( "" );
734 735
    art->setMinimumHeight( 128 );
    art->setMinimumWidth( 128 );
Clément Stenac's avatar
Clément Stenac committed
736 737 738
    art->setMaximumHeight( 128 );
    art->setMaximumWidth( 128 );
    art->setScaledContents( true );
739
    art->setPixmap( QPixmap( ":/noart.png" ) );
Clément Stenac's avatar
Clément Stenac committed
740
    left->addWidget( art );
741

742
    /* Initialisation of the playlist */
743 744 745
    playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
                                                THEPL->p_local_category );

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

749
    /* Connects */
750
    CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
751

752
    CONNECT( qobject_cast<StandardPLPanel *>( rightPanel )->model,
Clément Stenac's avatar
Clément Stenac committed
753 754
             artSet( QString ) , this, setArt( QString ) );
    /* Forward removal requests from the selector to the main panel */
755
    CONNECT( qobject_cast<PLSelector *>( selector )->model,
Clément Stenac's avatar
Clément Stenac committed
756
             shouldRemove( int ),
757
             qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
758

759
    connect( selector, SIGNAL( activated( int ) ),
760 761
             this, SIGNAL( rootChanged( int ) ) );
    emit rootChanged( p_root->i_id );
762

763 764 765 766
    /* Add the two sides of the QSplitter */
    addWidget( leftW );
    addWidget( rightPanel );

767 768 769 770
    leftW->setMaximumWidth( 250 );
    setCollapsible( 1, false );

    QList<int> sizeList;
771
    sizeList << 180 << 420 ;
772
    setSizes( sizeList );
773
    setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
774

775 776 777 778 779 780
    /* In case we want to keep the splitter informations */
    settings->beginGroup( "playlist" );
    restoreState( settings->value("splitterSizes").toByteArray());
    resize( settings->value("size", QSize(600, 300)).toSize());
    move( settings->value("pos", QPoint( 0, 400)).toPoint());
    settings->endGroup();
781 782
}

783 784
void PlaylistWidget::setArt( QString url )
{
785
    if( url.isNull() )
786
    {
787
        art->setPixmap( QPixmap( ":/noart.png" ) );
788 789
        emit artSet( url );
    }
790
    else if( prevArt != url )
791
    {
Clément Stenac's avatar
Clément Stenac committed
792
        art->setPixmap( QPixmap( url ) );
793 794 795
        prevArt = url;
        emit artSet( url );
    }
796 797
}

798 799
QSize PlaylistWidget::sizeHint() const
{
800
   return QSize( 600 , 300 );
801 802
}

803
PlaylistWidget::~PlaylistWidget()
804
{}
805

806
void PlaylistWidget::savingSettings( QSettings *settings )
807
{
808 809 810
    settings->beginGroup( "playlist" );
    settings->setValue( "pos", pos() );
    settings->setValue( "size", size() );
811 812 813 814
    settings->setValue("splitterSizes", saveState() );
    settings->endGroup();
}

815 816 817 818 819
/**********************************************************************
 * Speed control widget
 **********************************************************************/
SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
                             QFrame( NULL ), p_intf( _p_i )
820
{
821
    QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
822 823
    sizePolicy.setHorizontalStretch( 0 );
    sizePolicy.setVerticalStretch( 0 );
824

825 826 827 828 829 830
    speedSlider = new QSlider;
    speedSlider->setSizePolicy( sizePolicy );
    speedSlider->setMaximumSize( QSize( 80, 200 ) );
    speedSlider->setOrientation( Qt::Vertical );
    speedSlider->setTickPosition( QSlider::TicksRight );

831
    speedSlider->setRange( -100, 100 );
832 833 834
    speedSlider->setSingleStep( 10 );
    speedSlider->setPageStep( 20 );
    speedSlider->setTickInterval( 20 );
835

836
    CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
837

838 839
    normalSpeedButton = new QPushButton( "N" );
    normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
840 841
    normalSpeedButton->setFlat( true );
    normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
842

843
    CONNECT( normalSpeedButton, clicked(), this, resetRate() );
844

845
    QVBoxLayout *speedControlLayout = new QVBoxLayout;
846 847 848
    speedControlLayout->addWidget(speedSlider);
    speedControlLayout->addWidget(normalSpeedButton);
    setLayout(speedControlLayout);
849 850 851
}

SpeedControlWidget::~SpeedControlWidget()
852
{}
853

854 855 856
#define RATE_SLIDER_MAXIMUM 3.0
#define RATE_SLIDER_MINIMUM 0.3
#define RATE_SLIDER_LENGTH 100.0
857 858 859

void SpeedControlWidget::updateControls( int rate )
{
860 861 862 863 864
    if( speedSlider->isSliderDown() )
    {
        //We don't want to change anything if the user is using the slider
        return;
    }
865

866 867
    int sliderValue;
    double speed = INPUT_RATE_DEFAULT / (double)rate;
868

869
    if( rate >= INPUT_RATE_DEFAULT )
870
    {
871 872 873 874 875 876 877
        if( speed < RATE_SLIDER_MINIMUM )
        {
            sliderValue = speedSlider->minimum();
        }
        else
        {
            sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
878
                                        / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
Rafaël Carré's avatar