interface_widgets.cpp 25.8 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
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 );
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
53 54
static int ItemChanged( vlc_object_t *, const char *,
                        vlc_value_t, vlc_value_t, void * );
55

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

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

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

105 106 107 108 109
void VideoWidget::SetMinSize()
{
    setMinimumSize( 16, 16 );
}

110
void VideoWidget::release( void *p_win )
111
{
112
    p_vout = NULL;
113
}
114 115


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

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

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

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

147
    QHBoxLayout *backgroundLayout = new QHBoxLayout( this );
148
    backgroundLayout->addWidget( label );
149 150

    resize( 300, 150 );
151
    updateGeometry();
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
152 153 154 155
    i_runs = 0;
    b_need_update = VLC_FALSE;
    var_AddCallback( THEPL, "item-change", ItemChanged, this );
    ON_TIMEOUT( update() );
156 157
}

Clément Stenac's avatar
Clément Stenac committed
158
BackgroundWidget::~BackgroundWidget()
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
159 160 161 162 163 164 165 166 167 168 169
{
    var_DelCallback( THEPL, "item-change", ItemChanged, this );
}

static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
        vlc_value_t oldval, vlc_value_t newval, void *param )
{
    BackgroundWidget *p_d = (BackgroundWidget*)param;
    p_d->b_need_update = VLC_TRUE;
    return VLC_SUCCESS;
}
170

Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
171
void BackgroundWidget::update()
172
{
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
173 174 175 176 177 178 179 180 181
    /* Timer runs at 150 ms, dont' update more than once every 750ms */
    i_runs++;
    if( i_runs % 6 != 0 ) return;

    /* Get Input and clear if non-existant */
    input_thread_t *p_input =
                     MainInputManager::getInstance( p_intf )->getInput();
    if( !p_input || p_input->b_dead )
    {
182
        label->setPixmap( QPixmap( ":/vlc128.png" ) );
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
        return;
    }


    if( b_need_update )
    {
        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
        {
            label->setPixmap( QPixmap( arturl ) );
            msg_Dbg( p_intf, "changing input b_need_update done %s", psz_arturl );
        }
        free( psz_arturl );
    }
    b_need_update = false;
204 205
}

206 207
QSize BackgroundWidget::sizeHint() const
{
208
    return label->size();
209 210
}

211 212
void BackgroundWidget::resizeEvent( QResizeEvent *e )
{
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
213 214 215 216 217 218
    if( e->size().height() < MAX_BG_SIZE -1 )
    {
        label->setMaximumWidth( e->size().height() );
        label->setMaximumHeight( e->size().width() );
    }
    else
219
    {
Ilkka Ollakka's avatar
 
Ilkka Ollakka committed
220 221
        label->setMaximumHeight( MAX_BG_SIZE );
        label->setMaximumWidth( MAX_BG_SIZE );
222
    }
223
}
224

225 226 227 228
void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
{
    QVLCMenu::PopupMenu( p_intf, true );
}
229

Clément Stenac's avatar
Clément Stenac committed
230 231 232 233
/**********************************************************************
 * Visualization selector panel
 **********************************************************************/
VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
234
                                QFrame( NULL ), p_intf( _p_i )
Clément Stenac's avatar
Clément Stenac committed
235 236
{
    QHBoxLayout *layout = new QHBoxLayout( this );
237
    layout->setMargin( 0 );
Clément Stenac's avatar
Clément Stenac committed
238
    QPushButton *prevButton = new QPushButton( "Prev" );
239
    QPushButton *nextButton = new QPushButton( "Next" );
Clément Stenac's avatar
Clément Stenac committed
240 241
    layout->addWidget( prevButton );
    layout->addWidget( nextButton );
Clément Stenac's avatar
Clément Stenac committed
242 243

    layout->addItem( new QSpacerItem( 40,20,
244 245
                              QSizePolicy::Expanding, QSizePolicy::Minimum ) );
    layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
Clément Stenac's avatar
Clément Stenac committed
246 247 248 249 250 251 252

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

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

Clément Stenac's avatar
Clément Stenac committed
253
    setLayout( layout );
254
    setMaximumHeight( 35 );
Clément Stenac's avatar
Clément Stenac committed
255 256 257 258 259 260
}

VisualSelector::~VisualSelector()
{
}

Clément Stenac's avatar
Clément Stenac committed
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
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 );
    }
}

/**********************************************************************
282
 * TEH controls
Clément Stenac's avatar
Clément Stenac committed
283
 **********************************************************************/
284 285 286 287 288 289

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

290
AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
Clément Stenac's avatar
Clément Stenac committed
291 292
                                           QFrame( NULL ), p_intf( _p_i )
{
293 294 295
    QHBoxLayout *advLayout = new QHBoxLayout( this );
    advLayout->setMargin( 0 );
    advLayout->setSpacing( 0 );
Clément Stenac's avatar
Clément Stenac committed
296

297
    /* A to B Button */
298 299 300 301
    ABButton = new QPushButton( "AB" );
    ABButton->setMaximumSize( QSize( 26, 26 ) );
    ABButton->setIconSize( QSize( 20, 20 ) );
    advLayout->addWidget( ABButton );
302
    BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
303
    timeA = timeB = 0;
304 305
    CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
             this, AtoBLoop( float, int, int ) );
Clément Stenac's avatar
Clément Stenac committed
306

307 308 309 310 311 312 313 314 315 316
    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 );
317
    BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
318
            qtr( "Record" ), record() );
319

320
    /* Snapshot Button */
321 322 323 324 325
    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
326 327
}

328
AdvControlsWidget::~AdvControlsWidget()
329
{}
Clément Stenac's avatar
Clément Stenac committed
330

331
void AdvControlsWidget::enableInput( bool enable )
Clément Stenac's avatar
Clément Stenac committed
332
{
333 334
    ABButton->setEnabled( enable );
    recordButton->setEnabled( enable );
Clément Stenac's avatar
Clément Stenac committed
335
}
336

337
void AdvControlsWidget::enableVideo( bool enable )
Clément Stenac's avatar
Clément Stenac committed
338 339
{
    snapshotButton->setEnabled( enable );
340
    frameButton->setEnabled( enable );
Clément Stenac's avatar
Clément Stenac committed
341 342
}

343
void AdvControlsWidget::snapshot()
Clément Stenac's avatar
Clément Stenac committed
344
{
345 346
    vout_thread_t *p_vout =
        (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
347
    if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
Clément Stenac's avatar
Clément Stenac committed
348 349
}

350
/* Function called when the button is clicked() */
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
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" );
}
370

371
/* Function called regularly when in an AtoB loop */
372 373 374 375
void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
{
    if( timeB )
    {
376
        if( i_time >= (int)(timeB/1000000) )
377 378 379
            var_SetTime( THEMIM->getInput(), "time" , timeA );
    }
}
380

381
/* FIXME Record function */
382
void AdvControlsWidget::record(){}
383 384

//FIXME Frame by frame function
385 386
void AdvControlsWidget::frame(){}

387 388 389
/*****************************
 * DA Control Widget !
 *****************************/
390
ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
391
                                MainInterface *_p_mi,
392 393
                                bool b_advControls,
                                bool b_shiny ) :
394
                                QFrame( NULL ), p_intf( _p_i )
395 396
{
    controlLayout = new QGridLayout( this );
397
    controlLayout->setSpacing( 0 );
398
    setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Minimum );
399

400 401
    /** The main Slider **/
    slider = new InputSlider( Qt::Horizontal, NULL );
402
    controlLayout->addWidget( slider, 0, 1, 1, 16 );
403 404
    /* Update the position when the IM has changed */
    CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
405
             slider, setPosition( float, int, int ) );
406 407 408 409
    /* And update the IM, when the position has changed */
    CONNECT( slider, sliderDragged( float ),
             THEMIM->getIM(), sliderUpdate( float ) );

410
    /** Slower and faster Buttons **/
411
    slowerButton = new QPushButton;
412
    slowerButton->setFlat( true );
413
    slowerButton->setMaximumSize( QSize( 26, 20 ) );
414

415
    BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
416 417
    controlLayout->addWidget( slowerButton, 0, 0 );

418
    fasterButton = new QPushButton;
419
    fasterButton->setFlat( true );
420
    fasterButton->setMaximumSize( QSize( 26, 20 ) );
421

422
    BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
423
    controlLayout->addWidget( fasterButton, 0, 17 );
424

425 426 427 428
    /* advanced Controls handling */
    b_advancedVisible = b_advControls;

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

432 433 434
    /** Disc and Menus handling */
    discFrame = new QFrame( this );

435 436 437
    QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
    discLayout->setSpacing( 0 );
    discLayout->setMargin( 0 );
438

439
    prevSectionButton = new QPushButton( discFrame );
440
    setupSmallButton( prevSectionButton );
441 442
    discLayout->addWidget( prevSectionButton );

443
    menuButton = new QPushButton( discFrame );
444 445 446
    setupSmallButton( menuButton );
    discLayout->addWidget( menuButton );

447
    nextSectionButton = new QPushButton( discFrame );
448
    setupSmallButton( nextSectionButton );
449 450
    discLayout->addWidget( nextSectionButton );

451
    controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
452 453 454 455 456

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

457
    discFrame->hide();
458 459 460

    /* Change the navigation button display when the IM navigation changes */
    CONNECT( THEMIM->getIM(), navigationChanged( int ),
461
             this, setNavigation( int ) );
462 463 464 465 466 467 468 469
    /* 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() );

470 471
    /** TODO
     * Telextext QFrame
472
     * Merge with upper menu in a StackLayout
473 474
     **/

475
    /** Play Buttons **/
476
    QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
477 478 479 480
    sizePolicy.setHorizontalStretch( 0 );
    sizePolicy.setVerticalStretch( 0 );

    /* Play */
481
    playButton = new QPushButton;
482
    playButton->setSizePolicy( sizePolicy );
483 484
    playButton->setMaximumSize( QSize( 38, 38 ) );
    playButton->setMinimumSize( QSize( 45, 45 ) );
485
    playButton->setIconSize( QSize( 30, 30 ) );
486

487
    controlLayout->addWidget( playButton, 2, 0, 2, 2 );
488

489 490
    controlLayout->setColumnMinimumWidth( 2, 20 );
    controlLayout->setColumnStretch( 2, 0 );
491 492 493 494 495 496 497 498

    /** 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 );
499
    setupSmallButton( prevButton );
500 501 502 503 504 505

    controlButLayout->addWidget( prevButton );

    /* Stop */
    QPushButton *stopButton = new QPushButton;
    stopButton->setSizePolicy( sizePolicy );
506
    setupSmallButton( stopButton );
507 508 509 510 511 512

    controlButLayout->addWidget( stopButton );

    /* next */
    QPushButton *nextButton = new QPushButton;
    nextButton->setSizePolicy( sizePolicy );
513
    setupSmallButton( nextButton );
514 515 516 517

    controlButLayout->addWidget( nextButton );

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

520
    BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
521
    BUTTON_SET_ACT_I( prevButton, "" , previous.png,
522 523 524
                      qtr( "Previous" ), prev() );
    BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
    BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
525

526
    controlLayout->setColumnStretch( 7 , 2 );
527

528 529 530
    /*
     * Other first Line buttons
     */
531 532 533
    /** Fullscreen/Visualisation **/
    fullscreenButton = new QPushButton( "F" );
    BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
534
    setupSmallButton( fullscreenButton );
535
    controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
536

537 538
    /** Playlist Button **/
    playlistButton = new QPushButton;
539
    setupSmallButton( playlistButton );
540
    controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
541
    BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
542
    CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
543 544 545

    /** extended Settings **/
    QPushButton *extSettingsButton = new QPushButton( "F" );
546
    BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
547
            extSettings() );
548
    setupSmallButton( extSettingsButton );
549
    controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
550

551
    controlLayout->setColumnStretch( 14, 5 );
552

553
    /* Volume */
554
    VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
555

556
    volMuteLabel = new QLabel;
557
    volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
558
    volMuteLabel->setToolTip( qtr( "Mute" ) );
559
    volMuteLabel->installEventFilter( hVolLabel );
560
    controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
561

562 563 564
    if( b_shiny )
    {
        volumeSlider = new SoundSlider( this,
565 566
            config_GetInt( p_intf, "volume-step" ),
            config_GetInt( p_intf, "qt-volume-complete" ) );
567 568 569 570 571 572
    }
    else
    {
        volumeSlider = new QSlider( this );
        volumeSlider->setOrientation( Qt::Horizontal );
    }
573
    volumeSlider->setMaximumSize( QSize( 200, 40 ) );
574
    volumeSlider->setMinimumSize( QSize( 106, 30 ) );
575
    volumeSlider->setFocusPolicy( Qt::NoFocus );
576
    controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
577

578
    /* Set the volume from the config */
579 580
    volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
                              VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
581 582

    /* Volume control connection */
583
    resize( QSize( 400, 60 ) );
584
    CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
585
    msg_Dbg( p_intf, "controls size: %i - %i", size().width(), size().height() );
586
}
587

588 589 590
ControlsWidget::~ControlsWidget()
{
}
591

592
/*
593 594 595 596
QSize ControlsWidget::sizeHint() const
{
    return QSize( 300, 50 );
}
597
*/
598

599 600 601 602 603 604 605
void ControlsWidget::stop()
{
    THEMIM->stop();
}

void ControlsWidget::play()
{
606
    if( THEPL->current.i_size == 0 )
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
    {
        /* 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 )
{
628 629 630 631 632
#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" )
633 634 635 636 637 638

    // 1 = chapter, 2 = title, 0 = no
    if( navigation == 0 )
    {
        discFrame->hide();
    } else if( navigation == 1 ) {
639 640
        prevSectionButton->setToolTip( qfu( HELP_PCH ) );
        nextSectionButton->setToolTip( qfu( HELP_NCH ) );
641 642 643
        menuButton->show();
        discFrame->show();
    } else {
644 645
        prevSectionButton->setToolTip( qfu( HELP_PCH ) );
        nextSectionButton->setToolTip( qfu( HELP_NCH ) );
646 647 648 649 650 651
        menuButton->hide();
        discFrame->show();
    }
}

static bool b_my_volume;
652
void ControlsWidget::updateVolume( int i_sliderVolume )
653 654 655
{
    if( !b_my_volume )
    {
656
        int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
657 658
        aout_VolumeSet( p_intf, i_res );
    }
659 660
    if( i_sliderVolume == 0 )
        volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
661
    else if( i_sliderVolume < VOLUME_MAX / 2 )
662 663
        volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
    else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
664 665 666 667
}

void ControlsWidget::updateOnTimer()
{
668
    /* Audio part */
669 670
    audio_volume_t i_volume;
    aout_VolumeGet( p_intf, &i_volume );
671
    i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
672 673 674 675 676 677 678 679
    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;
    }
680

681
    /* Activate the interface buttons according to the presence of the input */
682
    enableInput( THEMIM->getIM()->hasInput() );
683
    //enableVideo( THEMIM->getIM()->hasVideo() );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
684
    enableVideo( true );
685
}
686

687 688
void ControlsWidget::setStatus( int status )
{
689 690
    if( status == PLAYING_S ) // Playing
        playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
691
    else
692
        playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
693
}
694

695 696
/**
 * TODO
697
 * This functions toggle the fullscreen mode
698
 * If there is no video, it should first activate Visualisations...
699
 *  This has also to be fixed in enableVideo()
700
 */
Clément Stenac's avatar
Clément Stenac committed
701 702
void ControlsWidget::fullscreen()
{
703 704
    vout_thread_t *p_vout =
        (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
705
    if( p_vout)
706
    {
707
        var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
708
        vlc_object_release( p_vout );
709
    }
710 711 712 713 714 715
}

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

717 718 719 720 721 722 723 724 725 726 727 728 729 730 731
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 );
732 733 734

    /* Advanced Buttons too */
    advControls->enableInput( enable );
735 736
}

737
void ControlsWidget::enableVideo( bool enable )
738
{
739 740
    // TODO Later make the fullscreenButton toggle Visualisation and so on.
    fullscreenButton->setEnabled( enable );
741 742 743

    /* Advanced Buttons too */
    advControls->enableVideo( enable );
744 745
}

746 747 748 749 750 751 752 753 754 755 756 757
void ControlsWidget::toggleAdvanced()
{
    if( !VISIBLE( advControls ) )
    {
        advControls->show();
        b_advancedVisible = true;
    }
    else
    {
        advControls->hide();
        b_advancedVisible = false;
    }
758
    emit advancedControlsToggled( b_advancedVisible );
759
}
760

761

762 763 764 765 766
/**********************************************************************
 * Speed control widget
 **********************************************************************/
SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
                             QFrame( NULL ), p_intf( _p_i )
767
{
768
    QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
769 770
    sizePolicy.setHorizontalStretch( 0 );
    sizePolicy.setVerticalStretch( 0 );
771

772 773 774 775 776 777
    speedSlider = new QSlider;
    speedSlider->setSizePolicy( sizePolicy );
    speedSlider->setMaximumSize( QSize( 80, 200 ) );
    speedSlider->setOrientation( Qt::Vertical );
    speedSlider->setTickPosition( QSlider::TicksRight );

778
    speedSlider->setRange( -100, 100 );
779 780 781
    speedSlider->setSingleStep( 10 );
    speedSlider->setPageStep( 20 );
    speedSlider->setTickInterval( 20 );
782

783
    CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
784

785 786
    normalSpeedButton = new QPushButton( "N" );
    normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
787 788
    normalSpeedButton->setFlat( true );
    normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
789

790
    CONNECT( normalSpeedButton, clicked(), this, resetRate() );
791

792
    QVBoxLayout *speedControlLayout = new QVBoxLayout;
793 794 795
    speedControlLayout->addWidget(speedSlider);
    speedControlLayout->addWidget(normalSpeedButton);
    setLayout(speedControlLayout);
796 797 798
}

SpeedControlWidget::~SpeedControlWidget()
799
{}
800

801 802 803
#define RATE_SLIDER_MAXIMUM 3.0
#define RATE_SLIDER_MINIMUM 0.3
#define RATE_SLIDER_LENGTH 100.0
804 805 806

void SpeedControlWidget::updateControls( int rate )
{
807 808 809 810 811
    if( speedSlider->isSliderDown() )
    {
        //We don't want to change anything if the user is using the slider
        return;
    }
812

813 814
    int sliderValue;
    double speed = INPUT_RATE_DEFAULT / (double)rate;
815

816
    if( rate >= INPUT_RATE_DEFAULT )
817
    {
818 819 820 821 822 823 824
        if( speed < RATE_SLIDER_MINIMUM )
        {
            sliderValue = speedSlider->minimum();
        }
        else
        {
            sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
825
                                        / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
826 827 828 829 830 831 832 833 834 835 836
        }
    }
    else
    {
        if( speed > RATE_SLIDER_MAXIMUM )
        {
            sliderValue = speedSlider->maximum();
        }
        else
        {
            sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
837
                                        / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
838 839
        }
    }
840

841 842 843 844
    //Block signals to avoid feedback loop
    speedSlider->blockSignals( true );
    speedSlider->setValue( sliderValue );
    speedSlider->blockSignals( false );
845 846 847 848
}

void SpeedControlWidget::updateRate( int sliderValue )
{
849
    int rate;
850

851 852 853
    if( sliderValue < 0.0 )
    {
        rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
854
            ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
855 856 857
    }
    else
    {
858
        rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
859
            ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
860
    }
861

862
    THEMIM->getIM()->setRate(rate);
863 864 865 866
}

void SpeedControlWidget::resetRate()
{
867
    THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
868
}