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
 *          Ilkka Ollakka <ileoo@videolan.org>
11 12 13 14
 *
 * 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
15
 * ( at your option ) any later version.
16 17 18 19 20 21 22 23 24 25 26
 *
 * 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.
 *****************************************************************************/

27
#include "dialogs_provider.hpp"
28
#include "components/interface_widgets.hpp"
29
#include "main_interface.hpp"
30
#include "input_manager.hpp"
31
#include "menus.hpp"
32
#include "util/input_slider.hpp"
33
#include "util/customwidgets.hpp"
Clément Stenac's avatar
Clément Stenac committed
34
#include <vlc_vout.h>
35

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

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

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

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
/**********************************************************************
 * Background Widget. Show a simple image background. Currently,
 * it's a static cone.
 **********************************************************************/
118 119 120 121
#define ICON_SIZE 128
#define MAX_BG_SIZE 400
#define MIN_BG_SIZE 64

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

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

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

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

    resize( 300, 150 );
149
    updateGeometry();
150
    CONNECT( THEMIM, inputChanged( input_thread_t *), this, update( input_thread_t * ) );
151 152
}

Clément Stenac's avatar
Clément Stenac committed
153
BackgroundWidget::~BackgroundWidget()
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
154 155 156
{
}

157

158
void BackgroundWidget::update( input_thread_t *p_input )
159
{
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
160 161
    if( !p_input || p_input->b_dead )
    {
162
        label->setPixmap( QPixmap( ":/vlc128.png" ) );
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
163 164 165 166
        return;
    }


167 168 169 170 171 172 173 174
    vlc_object_yield( p_input );
    char *psz_arturl = input_item_GetArtURL( input_GetItem(p_input) );
    vlc_object_release( p_input );
    QString url = qfu( psz_arturl );
    QString arturl = url.replace( "file://",QString("" ) );
    if( arturl.isNull() )
        label->setPixmap( QPixmap( ":/vlc128.png" ) );
    else
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
175
    {
176 177
        label->setPixmap( QPixmap( arturl ) );
        msg_Dbg( p_intf, "changing input b_need_update done %s", psz_arturl );
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
178
    }
179
    free( psz_arturl );
180 181
}

182 183
QSize BackgroundWidget::sizeHint() const
{
184
    return label->size();
185 186
}

187 188
void BackgroundWidget::resizeEvent( QResizeEvent *e )
{
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
189 190 191 192 193 194
    if( e->size().height() < MAX_BG_SIZE -1 )
    {
        label->setMaximumWidth( e->size().height() );
        label->setMaximumHeight( e->size().width() );
    }
    else
195
    {
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
196 197
        label->setMaximumHeight( MAX_BG_SIZE );
        label->setMaximumWidth( MAX_BG_SIZE );
198
    }
199
}
200

201 202 203 204
void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
{
    QVLCMenu::PopupMenu( p_intf, true );
}
205

Clément Stenac's avatar
Clément Stenac committed
206 207 208 209
/**********************************************************************
 * Visualization selector panel
 **********************************************************************/
VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
210
                                QFrame( NULL ), p_intf( _p_i )
Clément Stenac's avatar
Clément Stenac committed
211 212
{
    QHBoxLayout *layout = new QHBoxLayout( this );
213
    layout->setMargin( 0 );
Clément Stenac's avatar
Clément Stenac committed
214
    QPushButton *prevButton = new QPushButton( "Prev" );
215
    QPushButton *nextButton = new QPushButton( "Next" );
Clément Stenac's avatar
Clément Stenac committed
216 217
    layout->addWidget( prevButton );
    layout->addWidget( nextButton );
Clément Stenac's avatar
Clément Stenac committed
218 219

    layout->addItem( new QSpacerItem( 40,20,
220 221
                              QSizePolicy::Expanding, QSizePolicy::Minimum ) );
    layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
Clément Stenac's avatar
Clément Stenac committed
222 223 224 225 226 227 228

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

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

Clément Stenac's avatar
Clément Stenac committed
229
    setLayout( layout );
230
    setMaximumHeight( 35 );
Clément Stenac's avatar
Clément Stenac committed
231 232 233 234 235 236
}

VisualSelector::~VisualSelector()
{
}

Clément Stenac's avatar
Clément Stenac committed
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
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 );
    }
}

/**********************************************************************
258
 * TEH controls
Clément Stenac's avatar
Clément Stenac committed
259
 **********************************************************************/
260 261 262 263 264 265

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

266
AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
Clément Stenac's avatar
Clément Stenac committed
267 268
                                           QFrame( NULL ), p_intf( _p_i )
{
269 270 271
    QHBoxLayout *advLayout = new QHBoxLayout( this );
    advLayout->setMargin( 0 );
    advLayout->setSpacing( 0 );
Clément Stenac's avatar
Clément Stenac committed
272

273
    /* A to B Button */
274 275 276 277
    ABButton = new QPushButton( "AB" );
    ABButton->setMaximumSize( QSize( 26, 26 ) );
    ABButton->setIconSize( QSize( 20, 20 ) );
    advLayout->addWidget( ABButton );
278
    BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
279
    timeA = timeB = 0;
280 281
    CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
             this, AtoBLoop( float, int, int ) );
Clément Stenac's avatar
Clément Stenac committed
282

283 284 285 286 287 288 289 290 291 292
    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() );

    recordButton = new QPushButton( "R" );
    recordButton->setMaximumSize( QSize( 26, 26 ) );
    recordButton->setIconSize( QSize( 20, 20 ) );
    advLayout->addWidget( recordButton );
293
    BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
294
            qtr( "Record" ), record() );
295

296
    /* Snapshot Button */
297 298 299 300 301
    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
302 303
}

304
AdvControlsWidget::~AdvControlsWidget()
305
{}
Clément Stenac's avatar
Clément Stenac committed
306

307
void AdvControlsWidget::enableInput( bool enable )
Clément Stenac's avatar
Clément Stenac committed
308
{
309 310
    ABButton->setEnabled( enable );
    recordButton->setEnabled( enable );
Clément Stenac's avatar
Clément Stenac committed
311
}
312

313
void AdvControlsWidget::enableVideo( bool enable )
Clément Stenac's avatar
Clément Stenac committed
314 315
{
    snapshotButton->setEnabled( enable );
316
    frameButton->setEnabled( enable );
Clément Stenac's avatar
Clément Stenac committed
317 318
}

319
void AdvControlsWidget::snapshot()
Clément Stenac's avatar
Clément Stenac committed
320
{
321 322
    vout_thread_t *p_vout =
        (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
323
    if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
Clément Stenac's avatar
Clément Stenac committed
324 325
}

326
/* Function called when the button is clicked() */
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
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" );
}
346

347
/* Function called regularly when in an AtoB loop */
348 349 350 351
void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
{
    if( timeB )
    {
352
        if( i_time >= (int)(timeB/1000000) )
353 354 355
            var_SetTime( THEMIM->getInput(), "time" , timeA );
    }
}
356

357
/* FIXME Record function */
358
void AdvControlsWidget::record(){}
359 360

//FIXME Frame by frame function
361 362
void AdvControlsWidget::frame(){}

363 364 365
/*****************************
 * DA Control Widget !
 *****************************/
366
ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
367
                                MainInterface *_p_mi,
368 369
                                bool b_advControls,
                                bool b_shiny ) :
370
                                QFrame( NULL ), p_intf( _p_i )
371 372
{
    controlLayout = new QGridLayout( this );
373
    controlLayout->setSpacing( 0 );
374
    setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Minimum );
375

376 377
    /** The main Slider **/
    slider = new InputSlider( Qt::Horizontal, NULL );
378
    controlLayout->addWidget( slider, 0, 1, 1, 16 );
379 380
    /* Update the position when the IM has changed */
    CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
381
             slider, setPosition( float, int, int ) );
382 383 384 385
    /* And update the IM, when the position has changed */
    CONNECT( slider, sliderDragged( float ),
             THEMIM->getIM(), sliderUpdate( float ) );

386
    /** Slower and faster Buttons **/
387
    slowerButton = new QPushButton;
388
    slowerButton->setFlat( true );
389
    slowerButton->setMaximumSize( QSize( 26, 20 ) );
390

391
    BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
392 393
    controlLayout->addWidget( slowerButton, 0, 0 );

394
    fasterButton = new QPushButton;
395
    fasterButton->setFlat( true );
396
    fasterButton->setMaximumSize( QSize( 26, 20 ) );
397

398
    BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
399
    controlLayout->addWidget( fasterButton, 0, 17 );
400

401 402 403 404
    /* advanced Controls handling */
    b_advancedVisible = b_advControls;

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

408 409 410
    /** Disc and Menus handling */
    discFrame = new QFrame( this );

411 412 413
    QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
    discLayout->setSpacing( 0 );
    discLayout->setMargin( 0 );
414

415
    prevSectionButton = new QPushButton( discFrame );
416
    setupSmallButton( prevSectionButton );
417 418
    discLayout->addWidget( prevSectionButton );

419
    menuButton = new QPushButton( discFrame );
420 421 422
    setupSmallButton( menuButton );
    discLayout->addWidget( menuButton );

423
    nextSectionButton = new QPushButton( discFrame );
424
    setupSmallButton( nextSectionButton );
425 426
    discLayout->addWidget( nextSectionButton );

427
    controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
428 429 430 431 432

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

433
    discFrame->hide();
434 435 436

    /* Change the navigation button display when the IM navigation changes */
    CONNECT( THEMIM->getIM(), navigationChanged( int ),
437
             this, setNavigation( int ) );
438 439 440 441 442 443 444 445
    /* 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() );

446 447
    /** TODO
     * Telextext QFrame
448
     * Merge with upper menu in a StackLayout
449 450
     **/

451
    /** Play Buttons **/
452
    QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
453 454 455 456
    sizePolicy.setHorizontalStretch( 0 );
    sizePolicy.setVerticalStretch( 0 );

    /* Play */
457
    playButton = new QPushButton;
458
    playButton->setSizePolicy( sizePolicy );
459 460
    playButton->setMaximumSize( QSize( 38, 38 ) );
    playButton->setMinimumSize( QSize( 45, 45 ) );
461
    playButton->setIconSize( QSize( 30, 30 ) );
462

463
    controlLayout->addWidget( playButton, 2, 0, 2, 2 );
464

465 466
    controlLayout->setColumnMinimumWidth( 2, 20 );
    controlLayout->setColumnStretch( 2, 0 );
467 468 469 470 471 472 473 474

    /** 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 );
475
    setupSmallButton( prevButton );
476 477 478 479 480 481

    controlButLayout->addWidget( prevButton );

    /* Stop */
    QPushButton *stopButton = new QPushButton;
    stopButton->setSizePolicy( sizePolicy );
482
    setupSmallButton( stopButton );
483 484 485 486 487 488

    controlButLayout->addWidget( stopButton );

    /* next */
    QPushButton *nextButton = new QPushButton;
    nextButton->setSizePolicy( sizePolicy );
489
    setupSmallButton( nextButton );
490 491 492 493

    controlButLayout->addWidget( nextButton );

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

496
    BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
497
    BUTTON_SET_ACT_I( prevButton, "" , previous.png,
498 499 500
                      qtr( "Previous" ), prev() );
    BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
    BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
501

502
    controlLayout->setColumnStretch( 7 , 2 );
503

504 505 506
    /*
     * Other first Line buttons
     */
507 508 509
    /** Fullscreen/Visualisation **/
    fullscreenButton = new QPushButton( "F" );
    BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
510
    setupSmallButton( fullscreenButton );
511
    controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
512

513 514
    /** Playlist Button **/
    playlistButton = new QPushButton;
515
    setupSmallButton( playlistButton );
516
    controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
517
    BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
518
    CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
519 520 521

    /** extended Settings **/
    QPushButton *extSettingsButton = new QPushButton( "F" );
522
    BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
523
            extSettings() );
524
    setupSmallButton( extSettingsButton );
525
    controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
526

527
    controlLayout->setColumnStretch( 14, 5 );
528

529
    /* Volume */
530
    VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
531

532
    volMuteLabel = new QLabel;
533
    volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
534
    volMuteLabel->setToolTip( qtr( "Mute" ) );
535
    volMuteLabel->installEventFilter( hVolLabel );
536
    controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
537

538 539 540
    if( b_shiny )
    {
        volumeSlider = new SoundSlider( this,
541 542
            config_GetInt( p_intf, "volume-step" ),
            config_GetInt( p_intf, "qt-volume-complete" ) );
543 544 545 546 547 548
    }
    else
    {
        volumeSlider = new QSlider( this );
        volumeSlider->setOrientation( Qt::Horizontal );
    }
549
    volumeSlider->setMaximumSize( QSize( 200, 40 ) );
550
    volumeSlider->setMinimumSize( QSize( 106, 30 ) );
551
    volumeSlider->setFocusPolicy( Qt::NoFocus );
552
    controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
553

554
    /* Set the volume from the config */
555 556
    volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
                              VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
557 558

    /* Volume control connection */
559
    resize( QSize( 400, 60 ) );
560
    CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
561
    msg_Dbg( p_intf, "controls size: %i - %i", size().width(), size().height() );
562
}
563

564 565 566
ControlsWidget::~ControlsWidget()
{
}
567

568
/*
569 570 571 572
QSize ControlsWidget::sizeHint() const
{
    return QSize( 300, 50 );
}
573
*/
574

575 576 577 578 579 580 581
void ControlsWidget::stop()
{
    THEMIM->stop();
}

void ControlsWidget::play()
{
582
    if( THEPL->current.i_size == 0 )
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
    {
        /* 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 )
{
604 605 606 607 608
#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" )
609 610 611 612 613 614

    // 1 = chapter, 2 = title, 0 = no
    if( navigation == 0 )
    {
        discFrame->hide();
    } else if( navigation == 1 ) {
615 616
        prevSectionButton->setToolTip( qfu( HELP_PCH ) );
        nextSectionButton->setToolTip( qfu( HELP_NCH ) );
617 618 619
        menuButton->show();
        discFrame->show();
    } else {
620 621
        prevSectionButton->setToolTip( qfu( HELP_PCH ) );
        nextSectionButton->setToolTip( qfu( HELP_NCH ) );
622 623 624 625 626 627
        menuButton->hide();
        discFrame->show();
    }
}

static bool b_my_volume;
628
void ControlsWidget::updateVolume( int i_sliderVolume )
629 630 631
{
    if( !b_my_volume )
    {
632
        int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
633 634
        aout_VolumeSet( p_intf, i_res );
    }
635 636
    if( i_sliderVolume == 0 )
        volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
637
    else if( i_sliderVolume < VOLUME_MAX / 2 )
638 639
        volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
    else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
640 641 642 643
}

void ControlsWidget::updateOnTimer()
{
644
    /* Audio part */
645 646
    audio_volume_t i_volume;
    aout_VolumeGet( p_intf, &i_volume );
647
    i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
648 649 650 651 652 653 654 655
    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;
    }
656

657
    /* Activate the interface buttons according to the presence of the input */
658
    enableInput( THEMIM->getIM()->hasInput() );
659
    //enableVideo( THEMIM->getIM()->hasVideo() );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
660
    enableVideo( true );
661
}
662

663 664
void ControlsWidget::setStatus( int status )
{
665 666
    if( status == PLAYING_S ) // Playing
        playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
667
    else
668
        playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
669
}
670

671 672
/**
 * TODO
673
 * This functions toggle the fullscreen mode
674
 * If there is no video, it should first activate Visualisations...
675
 *  This has also to be fixed in enableVideo()
676
 */
Clément Stenac's avatar
Clément Stenac committed
677 678
void ControlsWidget::fullscreen()
{
679 680
    vout_thread_t *p_vout =
        (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
681
    if( p_vout)
682
    {
683
        var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
684
        vlc_object_release( p_vout );
685
    }
686 687 688 689 690 691
}

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

693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
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 );
708 709 710

    /* Advanced Buttons too */
    advControls->enableInput( enable );
711 712
}

713
void ControlsWidget::enableVideo( bool enable )
714
{
715 716
    // TODO Later make the fullscreenButton toggle Visualisation and so on.
    fullscreenButton->setEnabled( enable );
717 718 719

    /* Advanced Buttons too */
    advControls->enableVideo( enable );
720 721
}

722 723 724 725 726 727 728 729 730 731 732 733
void ControlsWidget::toggleAdvanced()
{
    if( !VISIBLE( advControls ) )
    {
        advControls->show();
        b_advancedVisible = true;
    }
    else
    {
        advControls->hide();
        b_advancedVisible = false;
    }
734
    emit advancedControlsToggled( b_advancedVisible );
735
}
736

737

738 739 740 741 742
/**********************************************************************
 * Speed control widget
 **********************************************************************/
SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
                             QFrame( NULL ), p_intf( _p_i )
743
{
744
    QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
745 746
    sizePolicy.setHorizontalStretch( 0 );
    sizePolicy.setVerticalStretch( 0 );
747

748 749 750 751 752 753
    speedSlider = new QSlider;
    speedSlider->setSizePolicy( sizePolicy );
    speedSlider->setMaximumSize( QSize( 80, 200 ) );
    speedSlider->setOrientation( Qt::Vertical );
    speedSlider->setTickPosition( QSlider::TicksRight );

754
    speedSlider->setRange( -100, 100 );
755 756 757
    speedSlider->setSingleStep( 10 );
    speedSlider->setPageStep( 20 );
    speedSlider->setTickInterval( 20 );
758

759
    CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
760

761 762
    normalSpeedButton = new QPushButton( "N" );
    normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
763 764
    normalSpeedButton->setFlat( true );
    normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
765

766
    CONNECT( normalSpeedButton, clicked(), this, resetRate() );
767

768
    QVBoxLayout *speedControlLayout = new QVBoxLayout;
769 770 771
    speedControlLayout->addWidget(speedSlider);
    speedControlLayout->addWidget(normalSpeedButton);
    setLayout(speedControlLayout);
772 773 774
}

SpeedControlWidget::~SpeedControlWidget()
775
{}
776

777 778 779
#define RATE_SLIDER_MAXIMUM 3.0
#define RATE_SLIDER_MINIMUM 0.3
#define RATE_SLIDER_LENGTH 100.0
780 781 782

void SpeedControlWidget::updateControls( int rate )
{
783 784 785 786 787
    if( speedSlider->isSliderDown() )
    {
        //We don't want to change anything if the user is using the slider
        return;
    }
788

789 790
    int sliderValue;
    double speed = INPUT_RATE_DEFAULT / (double)rate;
791

792
    if( rate >= INPUT_RATE_DEFAULT )
793
    {
794 795 796 797 798 799 800
        if( speed < RATE_SLIDER_MINIMUM )
        {
            sliderValue = speedSlider->minimum();
        }
        else
        {
            sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
801
                                        / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
802 803 804 805 806 807 808 809 810 811 812
        }
    }
    else
    {
        if( speed > RATE_SLIDER_MAXIMUM )
        {
            sliderValue = speedSlider->maximum();
        }
        else
        {
            sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
813
                                        / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
814 815
        }
    }
816

817 818 819 820
    //Block signals to avoid feedback loop
    speedSlider->blockSignals( true );
    speedSlider->setValue( sliderValue );
    speedSlider->blockSignals( false );
821 822 823 824
}

void SpeedControlWidget::updateRate( int sliderValue )
{
825
    int rate;
826

827 828 829
    if( sliderValue < 0.0 )
    {
        rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
830
            ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
831 832 833
    }
    else
    {
834
        rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
835
            ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
836
    }
837

838
    THEMIM->getIM()->setRate(rate);
839 840 841 842
}

void SpeedControlWidget::resetRate()
{
843
    THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
844
}